]> git.ipfire.org Git - thirdparty/shadow.git/commit
Simplify allocation APIs
authorAlejandro Colomar <alx@kernel.org>
Wed, 5 Apr 2023 19:17:38 +0000 (21:17 +0200)
committerSerge Hallyn <serge@hallyn.com>
Thu, 8 Jun 2023 14:05:39 +0000 (09:05 -0500)
commit09775d3718df216c75b62d73bbcc5aa060e0fc94
tree73732a20b85e0392a8343312b9c2650c6e023c68
parent065a752b426266462dc0e7d9ad5a9fe79e6be16a
Simplify allocation APIs

If we consider simple objects as arrays of size 1, we can considerably
simplify these APIs, merging the *ARRAY and the non-array variants.

That will produce more readable code, since lines will be shorter (by
not having ARRAY in the macro names, as all macros will consistently
handle arrays), and the allocated size will be also more explicit.

The syntax will now be of the form:

    p = MALLOC(42, foo_t);  // allocate 42 elements of type foo_t.
    p = MALLOC(1, bar_t);   // allocate 1 element of type foo_t.

The _array() allocation functions should _never_ be called directly, and
instead these macros should be used.

The non-array functions (e.g., malloc(3)) still have their place, but
are limited to allocating structures with flexible array members.  For
any other uses, the macros should be used.

Thus, we don't use any array or ARRAY variants in any code any more, and
they are only used as implementation details of these macros.

Link: <https://software.codidact.com/posts/285898/288023#answer-288023>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
40 files changed:
lib/alloc.h
lib/commonio.c
lib/getdef.c
lib/groupio.c
lib/groupmem.c
lib/gshadow.c
lib/nss.c
lib/run_part.c
lib/sgetgrent.c
lib/sgroupio.c
lib/sssd.c
lib/subordinateio.c
libmisc/addgrps.c
libmisc/agetpass.c
libmisc/copydir.c
libmisc/env.c
libmisc/find_new_uid.c
libmisc/idmapping.c
libmisc/list.c
libmisc/mail.c
libmisc/obscure.c
libmisc/prefix_flag.c
libmisc/setupenv.c
libmisc/utmp.c
libmisc/xgetXXbyYY.c
src/gpasswd.c
src/groupmems.c
src/groupmod.c
src/groups.c
src/id.c
src/login.c
src/newgrp.c
src/newusers.c
src/passwd.c
src/su.c
src/useradd.c
src/userdel.c
src/usermod.c
src/vipw.c
tests/libsubid/04_nss/libsubid_zzz.c