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

Re: [GSoC][RFC][PATCH 2/2] STRBUF_INIT_CONST: Adapting strbuf_* functions

From
Robear Selwans <rwagih.rw@gmail.com>
Date
Feb 19, 2020, 01:43 UTC
Message-ID
<CALH1-Xr3HVZzDn2-9EvmdiBWmxWQ-zfExM2LNJyR1wR+dgxRSQ@mail.gmail.com>
In-Reply-To
<xmqq36b7k4i6.fsf@gitster-ct.c.googlers.com>
On Tue, Feb 18, 2020 at 10:46 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
> Abhishek Kumar <abhishekkumar8222@gmail.com> writes:
> >> STRBUF_INIT_CONST: a new way to initialize strbuf
> > Use imperative mood and be more specific in the commit title -
> > `strbuf: Teach strbuf to initialize immutable strings`
> s/T/t/;
I don't get what you mean by that.
Show 6 quoted lines
> Also, isn't "if (sb->alloc < sb->len)" too loose a check for the new
> feature?  AFAICS in 1/2, a strbuf that is still borrowing a const
> string always has sb->alloc==0.  Other instances of strbuf that
> happens to satisify the above condition, e.g. (sb->len == 5 &&
> sb->alloc == 1), is an error.  If we are to check the condition
> about sb->len, shouldn't we diagnose such a case as an error, no?

AFAIK after reading the documentation for `strbuf`, there is no other case where `sb->len > sb->alloc` as `alloc` needs to always be more than `len`. I'd like to be corrected if mistaken, though.

> As Peff, I am a bit hesitant about leaving a strbuf that hasn't been
> made mutable around, though.

Yeah, I started to get that when I read Peff's reply. I think I'll go with the approach that Peff suggested, where the constant string is copied to a stack array and so is made mutable to a degree. Since this is a different way, I guess I'll make that from scratch instead of editing the existing one.

Previous: Junio C HamanoNext: Jeff King
Message 4 of 8 in “Re: [GSoC][RFC][PATCH 2/2] STRBUF_INIT_CONST: Adapting strbuf_* functions”
  1. Abhishek KumarFeb 18, 2020
  2. Robear SelwansFeb 18, 2020
  3. Junio C HamanoFeb 18, 2020
  4. Robear SelwansFeb 19, 2020
  5. Jeff KingFeb 19, 2020
  6. Junio C HamanoFeb 19, 2020
  7. Robear SelwansFeb 19, 2020
  8. Junio C HamanoFeb 19, 2020

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.