From 8a0a0b01ff00d51509cf7e9ee8ca7bd076ba7b28 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 2d507c3f7e..222dac56bc 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -47,6 +47,13 @@ *** General Macros. ***/ +#define MOVE_OWNERSHIP(source) \ + ({ \ + __typeof__(source) __ownership = (source); \ + (source) = NULL; \ + __ownership; \ + }) + /*% * Use this to hide unused function arguments. * \code