]> 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 11:05:30 +0000 (12:05 +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.

(cherry picked from commit 0f3be0beb8e461428466172d4b7b800933038adb)

lib/isc/include/isc/util.h

index 2e842f305d4e8d03fcf4274e6e618837ef927798..0a92afe27269d497dd0b21ce7714d0272404725d 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