From 8feefb9874a1e05da863c312a78bb68981160b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 20 Mar 2026 02:15:17 +0100 Subject: [PATCH] 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) --- lib/isc/include/isc/util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 2e842f305d..0a92afe272 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