From a084e2bc8066ce2fed852bf04e5168e289bf834b Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sat, 19 Aug 2023 12:43:39 +0200 Subject: Libunit: added macros that enhance type safety. nxt_min() nxt_max() Return the minimum/maximum of two values. nxt_swap() Swap the values of two variables passed by their addresses. nxt_sizeof_array() Return the size (in bytes) of an array. nxt_nitems() Return the number of elements in an array. nxt_memberof() Expand to a member of a structure. It uses a compound literal for the object. nxt_sizeof_incomplete() Calculate the size of an incomplete type, as if sizeof() could be applied to it. nxt_sizeof_fam0() Calculate the size of each element of a FAM of a structure. nxt_sizeof_fam() Calculate the size of a FAM of a structure. nxt_offsetof_fam() Calculate the offset of the nth element of the FAM from the start of the containing structure. nxt_sizeof_struct() Calculate the total size of a structure containing a FAM. This value is the one that should be used for allocating the structure. Suggested-by: Andrew Clayton nxt_is_near_end() Evaluate to true if the member is near the end of a structure. This is only designed to be used with FAMs, to make sure that the FAM is near the end of the structure (a zero-length array near the end of the structure would still pass this test, but it's a reasonable assertion to do. Suggested-by: David Laight nxt_is_zero_sizeof() Evaluate to true if the size of 'x' is 0. nxt_is_same_type() Evaluate to true if the both arguments are compatible types. nxt_is_same_typeof() Evaluate to true if the types of both arguments are compatible. nxt_is_array() Evaluate to true if the argument is an array. nxt_must_be() It's like static_assert(3), but implemented as an expression. It's necessary for writing the must_be_array() macro. It's always evaluates to (int) 0. nxt_must_be_array() Statically assert that the argument is an array. It is an expression that always evaluates to (int) 0. nxt_must_be_zero_sizeof() Statically assert that the argument has a size of 0. nxt_must_be_near_end() Statically assert that a member of a structure is near the end of it. Suggested-by: David Laight nxt_must_be_fam() Statically assert that the argument is a flexible array member (FAM). It's an expression that always evaluates to (int) 0. Link: Link: Link: Link: Link: Cc: Andrew Clayton Cc: Zhidao Hong Signed-off-by: Alejandro Colomar Signed-off-by: Alejandro Colomar --- auto/make | 2 ++ 1 file changed, 2 insertions(+) (limited to 'auto') diff --git a/auto/make b/auto/make index abfd41ad..88c4fb2b 100644 --- a/auto/make +++ b/auto/make @@ -406,6 +406,7 @@ libunit-install: $NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC test -d \$(DESTDIR)$NXT_INCLUDEDIR \ || install -d \$(DESTDIR)$NXT_INCLUDEDIR install -p -m u=rw,go=r src/nxt_unit.h \ + src/nxt_unit_cdefs.h \ src/nxt_unit_field.h \ src/nxt_unit_request.h \ src/nxt_unit_response.h \ @@ -423,6 +424,7 @@ libunit-uninstall: rm -f \$(DESTDIR)$NXT_PKGCONFIGDIR/unit.pc @rmdir -p \$(DESTDIR)$NXT_PKGCONFIGDIR 2>/dev/null || true rm -f \$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit.h \ + \$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_cdefs.h \ \$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_field.h \ \$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_request.h \ \$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_response.h \ -- cgit