Re: [PATCH] strbuf_readlink semantics update.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Pierre Habouzit
Date: Wednesday, December 24, 2008 - 3:11 am

On Tue, Dec 23, 2008 at 06:16:01PM +0000, Linus Torvalds wrote:
=20

The "problem" is that the strbuf API usually works that way: functions
append things to a buffer, or do nothing, but always keep the buffer in
a state where you can append more stuff to it.

If read_file_or_gitlink or strbuf_readlink destroy the buffer, then you
break the second expectation people (should) have about the strbuf API.

The reason is that if you built things in the buffer, you really don't
want it to be undone just because the last bit you add went wrong for
some reason. Or if you have a buffer that is reused in a loop, you don't
want the buffer you allocated to be dropped just because one error
occurred.


Alternatively, we could pass a flag to tell function performing reads
(fread, read, readlink, whatever) that those should destroy the buffer
on error or just report it. I don't really know. It sounds like
over-engineering though.


--=20
=C2=B7O=C2=B7  Pierre Habouzit
=C2=B7=C2=B7O                                                madcoder@debia=
n.org
OOO                                                http://www.madism.org
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/5] Be careful about lstat()-vs-readlink(), Linus Torvalds, (Wed Dec 17, 11:42 am)
[PATCH 1/5] Add generic 'strbuf_readlink()' helper function, Linus Torvalds, (Wed Dec 17, 11:42 am)
[PATCH 3/5] Make 'index_path()' use 'strbuf_readlink()', Linus Torvalds, (Wed Dec 17, 11:43 am)
Re: [PATCH 4/5] Make 'diff_populate_filespec()' use the ne ..., Olivier Galibert, (Thu Dec 18, 10:56 am)
[PATCH] diff.c: fix pointer type warning, René Scharfe, (Fri Dec 19, 3:10 pm)
Re: [PATCH] diff.c: fix pointer type warning, Junio C Hamano, (Fri Dec 19, 4:09 pm)
[PATCH] strbuf_readlink semantics update., Pierre Habouzit, (Tue Dec 23, 3:05 am)
Re: [PATCH] strbuf_readlink semantics update., Pierre Habouzit, (Tue Dec 23, 3:21 am)
Re: [PATCH] strbuf_readlink semantics update., Linus Torvalds, (Tue Dec 23, 11:16 am)
Re: [PATCH] strbuf_readlink semantics update., Pierre Habouzit, (Wed Dec 24, 3:11 am)
Re: [PATCH] strbuf_readlink semantics update., René Scharfe, (Wed Dec 24, 8:20 am)
Re: [PATCH] strbuf_readlink semantics update., Junio C Hamano, (Thu Dec 25, 12:23 am)
Re: [PATCH] strbuf_readlink semantics update., Pierre Habouzit, (Sun Jan 4, 5:21 am)