]> granicus.if.org Git - strace/commitdiff
tests: add TAIL_ALLOC_OBJECT_{CONST,VAR}_PTR to tests.h
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 16 Mar 2017 13:46:36 +0000 (13:46 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 16 Mar 2017 13:46:36 +0000 (13:46 +0000)
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.

tests/tests.h

index 7a398c18ebf55af7fa8a6726dc5488547eb10326..d077c5c8a6bb4710b776c6d0b601e1260b12e4aa 100644 (file)
@@ -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