From: Ondřej Surý Date: Fri, 20 Mar 2026 01:15:17 +0000 (+0100) Subject: Add MOVE_OWNERSHIP() macro for transferring pointer ownership X-Git-Tag: v9.20.22~12^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8feefb9874a1e05da863c312a78bb68981160b2a;p=thirdparty%2Fbind9.git Add MOVE_OWNERSHIP() macro for transferring pointer ownership 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) --- diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 2e842f305d4..0a92afe2726 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -41,6 +41,13 @@ *** 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