From: Jeff King <peff@peff.net>
To: Brandon Casey <drafnel@gmail.com>
Cc: Jakub Narebski <jnareb@gmail.com>, git@vger.kernel.org
Subject: Re: Fwd: permission to re-license strbuf subsystem as LGPL
Date: Sat, 24 Sep 2011 02:05:40 -0400 [thread overview]
Message-ID: <20110924060540.GA13974@sigill.intra.peff.net> (raw)
In-Reply-To: <CA+sFfMdt-95rfaZmiYAHx02Ukjt_WN-kLJr410AzZfGHYkSv5w@mail.gmail.com>
On Fri, Sep 23, 2011 at 05:50:27PM -0500, Brandon Casey wrote:
> Hmm, I forgot about bstring. I think strbuf is a little smaller in
> scope than bstring, perhaps less ambitious. Less abstraction, and
> less protection too. With strbuf, you never forget that you're
> dealing with C char arrays. The data structures are pretty similar,
> but I don't think strbuf will ever have a function like
>
> bconcat(bstring1, bstring2)
>
> instead, you'd just do
>
> strbuf_add(strbuf1, strbuf2.buf, strbuf2.len)
I think it's spelled:
strbuf_addbuf(strbuf1, strbuf2);
in the current code.
> The benefit, of course, of a bconcat function is that either bstring1
> or bstring2 can be NULL (like if a previous bstring2 = bfromcstr()
> initialization failed). This allows you to perform a sequence of
> bstring operations and only check errors at the end.
There is no error checking with strbufs at all. The only thing that can
fail is malloc, and in that case, we always die().
It wouldn't be too hard to make it return errors (or set a global error
flag), and have any failed mallocs just leave the strbuf unchanged.
Because strbufs are always in a consistent state, it would be safe to
do:
global_strbuf_error_flag = 0;
strbuf_addbuf(strbuf1, strbuf2);
strbuf_addbuf(strbuf3, strbuf1);
strbuf_addbuf(strbuf3, strbuf4);
if (global_strbuf_error_flag)
...
The contents of the strbufs would be indeterminant, but you would never
have violated any memory constraints.
-Peff
next prev parent reply other threads:[~2011-09-24 6:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CA+sFfMeRDQiqGhO9Y=k3tEnzdXjMx59huFE_fx6Y14cJxj1J=Q@mail.gmail.com>
2011-09-23 15:01 ` Fwd: permission to re-license strbuf subsystem as LGPL Brandon Casey
2011-09-23 15:36 ` Michael Witten
2011-09-23 17:12 ` Fwd: " Jakub Narebski
2011-09-23 22:50 ` Brandon Casey
2011-09-24 6:05 ` Jeff King [this message]
2011-09-23 22:16 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110924060540.GA13974@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=drafnel@gmail.com \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).