string-buffer, string-buffer-reversed: Make OOM handling consistent

2025-02-09 Thread Bruno Haible via Gnulib discussion list
The out-of-memory handling in modules 'string-buffer' and 'xstring-buffer' is not consistent: An OOM situation that occurred while accumulating the string via functions without 'x' causes sb_xdupfree_c to return NULL, while an OOM during sb_xdupfree_c (that is

new modules string-buffer-reversed, xstring-buffer-reversed

2025-02-05 Thread Bruno Haible via Gnulib discussion list
The module 'string-buffer' supports creating a string piece by piece, from the start to the end. But in some cases, one needs to create a string piecemeal, from the end to the start. Same thing, just in the opposite direction. The C++ library authors would extend the 'string-

Re: string-buffer: Enable resource leak warnings from clang

2024-10-29 Thread Bruno Haible via Gnulib discussion list
A misindentation in this commit: > 2024-09-25 Bruno Haible > > string-buffer: Enable resource leak warnings from clang. > * m4/gnulib-common.m4 (gl_COMMON_BODY): Define the macros > _GL_ATTRIBUTE_CAPABILITY_TYPE, _GL_ATTRIBUTE_ACQ

string-buffer tests: Avoid test failure on native Windows

2024-09-26 Thread Bruno Haible
Michele Locati wrote: > I tried checking gnulib in a similar environment [4], and there we > have these failures: > ... > FAIL: test-string-buffer > > ../../gltests/test-string-buffer.c:159: assertion 'ret < 0' failed > FAIL test-string-

string-buffer: Add more API

2024-09-25 Thread Bruno Haible
While making use of the 'string-buffer' module in GNU gettext, I noticed that more API is needed, to cover the frequent use-cases. For code that is not performance-critical, the benefits of this module are: - You need to declare one variable instead of 3 variables. - It moves th

string-buffer: Enable resource leak warnings from clang

2024-09-25 Thread Bruno Haible
uisites are simple: - Use clang ≥ 15. - Use the warning option -Wthread-safety. 2024-09-25 Bruno Haible string-buffer: Enable resource leak warnings from clang. * m4/gnulib-common.m4 (gl_COMMON_BODY): Define the macros _GL_ATTRIBUTE_CAPABILITY_TYPE, _GL_A

string-buffer: Remove INT_MAX limitation

2024-09-24 Thread Bruno Haible
fails.) 2024-09-24 Bruno Haible string-buffer: Remove INT_MAX limitation. * lib/string-buffer.h (sb_appendvf, sb_appendf): Document that errno is set upon failure. * lib/string-buffer-printf.c: Include . (sb_appendvf): Call vsnzprintf instead of vsnprintf. E

string-buffer: Link to vasnprintf implementation only when needed

2024-09-24 Thread Bruno Haible
Some uses of the 'string-buffer' module don't need the *printf implementation. In order to eliminate it from linking, when linking statically, this patch splits up the module into two compilation units. (The alternative would be a separate module 'string-buffer-printf&#x

Re: string-buffer tests: Fix a gcc -Wformat warning

2023-09-04 Thread Bruno Haible
I did: > 2023-09-04 Bruno Haible > > string-buffer tests: Fix a gcc -Wformat warning. > * tests/test-string-buffer.c: Don't assume that wint_t has the same size > as 'int'. Oops, that doesn't even compile. Fix: 2023-09-04 Bruno Haible

string-buffer tests: Fix a gcc -Wformat warning

2023-09-04 Thread Bruno Haible
that has this. 2023-09-04 Bruno Haible string-buffer tests: Fix a gcc -Wformat warning. * tests/test-string-buffer.c: Don't assume that wint_t has the same size as 'int'. diff --git a/tests/test-string-buffer.c b/tests/test-string-buffer.c index 3d2

string-buffer: Improve GCC 11 allocation-deallocation checking

2021-08-07 Thread Bruno Haible
2021-08-07 Bruno Haible string-buffer: Improve GCC 11 allocation-deallocation checking. * lib/string-buffer.h: Include instead of . (sb_dupfree): Declare that deallocation must happen through 'free'. diff --git a/lib/string-buffer.h b/lib/string-buffer.h ind

Re: new module 'string-buffer'

2021-02-27 Thread Bruno Haible
oes not fail when an invalid format directive is encountered, the unit test failed. 2021-02-27 Bruno Haible string-buffer: Fixes. * modules/string-buffer (License): Change to LGPL. * tests/test-string-buffer.c (main): Add another sb_appendf call, that

Re: new module 'string-buffer'

2021-02-21 Thread Bruce Korb
I rolled my own. But gnulib cannot provide a drop-in replacement since it would require unportable stream hackery (worse that stdio-impl.h). The alternative is a string buffer module. Gnulib has some modules that sound good at first sight but don't fulfil the need: I wanted something

new module 'string-buffer'

2021-02-21 Thread Bruno Haible
-impl.h). The alternative is a string buffer module. Gnulib has some modules that sound good at first sight but don't fulfil the need: * scratch_buffer stores only one size_t in the struct; it requires the program to keep track how much of the buffer is already occupied. Also it doe

Re: string buffer

2012-06-17 Thread Bruno Haible
Pádraig Brady wrote: > Since there are lots of appending of strings here, > the approach taken in coreutils so far was > to append in a large buffer allocated up front, > or just to write to stdout. > > I guess something in between is more appropriate for a lib. > I.E. efficiently append to a stri