12 Commits

Author SHA1 Message Date
Alejandro Colomar
01a0aac628 lib/: Rename XREALLOC() => xrealloc_T()
The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 21:22:45 -06:00
Alejandro Colomar
e010eb2d4e lib/: Rename REALLOC() => realloc_T()
The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 21:22:45 -06:00
Alejandro Colomar
d0a0c35cd8 lib/alloc/: REALLOC[F](): Move _Generic(3) to separate line
This should be more readable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 21:22:45 -06:00
Alejandro Colomar
9705effba5 lib/: Use compound literals to avoid casts
Casts are unsafe.

Compound literals also have the ability of converting values, but they
don't have the unwanted effects on safety --casts disable most useful
diagnostics--.

Compound literals are lvalues, which means their address can be taken,
and they can also be assigned to.  To avoid this, we force lvalue
conversion through a statement expression.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 21:22:45 -06:00
Alejandro Colomar
882fbdf99b lib/alloc/: reallocarray[f]_(): Add helper macros to handle n?:1
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 21:22:45 -06:00
Alejandro Colomar
2f18e7c0b6 lib/{alloc,search}/: Use typeas() to add support for arbitrary types
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 08:34:32 -06:00
Alejandro Colomar
97380c811a lib/: Use a consistent name for macro arguments representing a type name
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 08:34:32 -06:00
Alejandro Colomar
655ffcbe1b lib/, src/, tests/: Move x*() definitions to non-x* header files
Now that all of these are one-liners, they don't need a separate header
file.  Compact stuff.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-10-27 14:32:06 +01:00
Evgeny Grin (Karlson2k)
eb71706b1c */: Fix including <config.h> as system header
"config.h" is a locally generated header. It must be included as
'#include "config.h"'.
It is already included correctly in some sources files. This commit
unifies the way how "config.h" is included.

Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
2025-07-16 14:12:40 +02:00
Alejandro Colomar
afc4b574b7 lib/alloc/realloc*.h: Always reallocate at least 1 byte
glibc's realloc(3) is broken.  It was originally good (I believe) until
at some point, when it was changed to conform to C89, which had a bogus
specification that required that it returns NULL.  C99 fixed the mistake
from C89, and so glibc's realloc(3) is non-conforming to
C99/C11/POSIX.1-2008.  C17 broke again the definition of realloc(3).

Link: <https://github.com/shadow-maint/shadow/pull/1095>
Link: <https://nabijaczleweli.xyz/content/blogn_t/017-malloc0.html>
Link: <https://inbox.sourceware.org/libc-alpha/5gclfbrxfd7446gtwd2x2gfuquy7ukjdbrndphyfmfszxlft76@wwjz7spd4vd7/T/#t>
Co-developed-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Acked-by: Paul Eggert <eggert@cs.ucla.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-22 10:53:06 +02:00
Alejandro Colomar
12aa29b576 lib/alloc/realloc*.h: Rename macro parameter
This is in preparation for the following commit, which will need this
shorter parameter name to avoid breaking long lines.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-22 10:53:06 +02:00
Alejandro Colomar
3049bef9c3 lib/alloc/, lib/, src/, tests/: Organize the allocation APIs in a new subdirectory
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00