From: Dmitry V. Levin Date: Thu, 16 Mar 2017 13:46:36 +0000 (+0000) Subject: tests: add TAIL_ALLOC_OBJECT_{CONST,VAR}_PTR to tests.h X-Git-Tag: v4.17~161 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72b7cfb3bf534c69cfa980fd6f4336e5a14d752b;p=strace tests: add TAIL_ALLOC_OBJECT_{CONST,VAR}_PTR to tests.h Introduce a new macros for the most widespread use of tail_alloc. * tests/tests.h (TAIL_ALLOC_OBJECT_CONST_PTR, TAIL_ALLOC_OBJECT_VAR_PTR): New macros. --- diff --git a/tests/tests.h b/tests/tests.h index 7a398c18..d077c5c8 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -71,6 +71,22 @@ void *tail_alloc(const size_t) void *tail_memdup(const void *, const size_t) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((2)); +/* + * Allocate an object of the specified type at the end + * of a mapped memory region. + * Assign its address to the specified constant pointer. + */ +#define TAIL_ALLOC_OBJECT_CONST_PTR(type_name, type_ptr) \ + type_name *const type_ptr = tail_alloc(sizeof(*type_ptr)) + +/* + * Allocate an object of the specified type at the end + * of a mapped memory region. + * Assign its address to the specified variable pointer. + */ +#define TAIL_ALLOC_OBJECT_VAR_PTR(type_name, type_ptr) \ + type_name *type_ptr = tail_alloc(sizeof(*type_ptr)) + /* * Fill memory (pointed by ptr, having size bytes) with different bytes (with * values starting with start and resetting every period) in order to catch