]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add MOVE_OWNERSHIP() macro for transferring pointer ownership
authorOndřej Surý <ondrej@isc.org>
Fri, 20 Mar 2026 01:15:17 +0000 (02:15 +0100)
committerOndřej Surý <ondrej@isc.org>
Mon, 23 Mar 2026 10:06:28 +0000 (11:06 +0100)
A helper macro that returns the current value of a pointer and sets
it to NULL in one expression, useful for transferring ownership in
designated initializers.

lib/isc/include/isc/util.h

index 5564bb71995d08411fa60c5fbdd8a398c6c5d175..702fd5aef3e4dd2ca4109752e9c99a216a0d8ac2 100644 (file)
  *** General Macros.
  ***/
 
+#define MOVE_OWNERSHIP(source)                             \
+       ({                                                 \
+               __typeof__(source) __ownership = (source); \
+               (source) = NULL;                           \
+               __ownership;                               \
+       })
+
 /*%
  * Legacy way how to hide unused function arguments, don't use in
  * the new code, rather use the ISC_ATTR_UNUSED macro that expands