This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 08/18] malloc: Add specialized dynarray for C strings


On 08/11/2017 04:50 PM, Adhemerval Zanella wrote:
> This patch adds an specialized dynarray to manage C strings using the
> dynarray internal implementation.  It uses some private fields from
> dynarray and thus it provided specific files to access and manage
> the internal string buffer.

There is a lot of complexity in this code to maintain the invariant that
the stored array is NUL-terminated.  It also means that the dynarray
functions must not be used directly.

std::string in C++ has a c_str() method which adds the null termination
on demand.  This means that char_array_str could fail due to memory
allocation, but I think it would simplify the code in general.  I tried
to write the dynarray functions in such a way that errors are sticky, so
one error check (char_array_str returns NULL) could cover all the
previous manipulations.

Thanks,
Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]