git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] Have a filter_start/filter_end API.

From
Alex Riesen <raa.lkml@gmail.com>
Date
Oct 7, 2007, 16:07 UTC
Message-ID
<20071007160707.GA3270@steel.home>
In-Reply-To
<20071007145355.GC10024@artemis.corp>
Pierre Habouzit, Sun, Oct 07, 2007 16:53:55 +0200:
Show 12 quoted lines
> On Sat, Oct 06, 2007 at 09:06:21AM +0000, Alex Riesen wrote:
> > If you continue to insist the code is generic enough to justify its
> > residence in strbuf.c, continue reading.
> >
> > First off, what was wrong with dumb
> >
> >     void strbuf_make_room(struct strbuf *, size_t newsize);
> >
> > again?
> 
>   If newsize is >= sb->alloc then the area is reallocated, the pointer
> may move, and the "src" pointer would then be invalidated.

So what? You already _have_ to know it points inside the strbuf, so you can't expect it to be valid after any serious strbuf operation.

Show 8 quoted lines
> > what is that for? Why can't the caller just use strbuf_detach? (He
> > already has to pass negative hint somehow, which should be a concious
> > action).
> 
>   The idea is to have a unified API to deal with both the cases where
> the filtering is known not to work in place by the caller, or for the
> cases where it could if enough space is allocated but that a realloc is
> needed.
this just makes it convoluted and opaque (as in "not transparent")
Show 12 quoted lines
> > > +	if ((size_t)hint >= sb->alloc) {
> > > +		void *tmp = strbuf_detach(sb, NULL);
> > > +		strbuf_grow(sb, hint);
> > > +		return tmp;
> > > +	}
> > > +
> > > +	return NULL;
> > > +}
> >
> > How can one know when it sb is safe to use after strbuf_end_filter?
> 
>   We could document it, that's not an issue.
The fact that you _have_to_ document is.
Show 5 quoted lines
> > It is for the first "if", for example. free() wont free the buf in sb.
> > Oh, right, one can check if returned pointer !NULL. Which just adds
> > more code to handle your API.
> 
>   I don't get that part. free(NULL) is totally ok.
Not that. One have to store the result of start_filter and check it
Show 6 quoted lines
> > What actually happens to sb? Is it detached? Is it reallocated?
> > When it is detached and when it is reallocated?
> 
>   It is detached if the filter does not works in place (caller says that
> with '-1' as a hint) or if it works in place but needs a buffer
> reallocation.
Too many if's. Ugly
>   Note that I did not created this semantics, it was how convert.c
> worked already, in a even more convoluted way before.
And why shouldn't these semantics kept to convert.c?
Previous: Pierre HabouzitNext: Pierre Habouzit
Message 4 of 8 in “strbuf `filter' API”
  1. Pierre HabouzitOct 5, 2007
  2. Alex RiesenOct 6, 2007
  3. Pierre HabouzitOct 7, 2007
  4. Alex RiesenOct 7, 2007
  5. Pierre HabouzitOct 7, 2007
  6. Alex RiesenOct 7, 2007
  7. Pierre HabouzitOct 8, 2007
  8. Alex RiesenOct 8, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.