macro: make TAKE_PTR() side-effect free

This commit is contained in:
Lennart Poettering 2021-11-03 15:56:34 +01:00
parent 7950211df3
commit b7759c8f0a

View File

@ -257,8 +257,9 @@
* resets it to NULL. See: https://doc.rust-lang.org/std/option/enum.Option.html#method.take */
#define TAKE_PTR(ptr) \
({ \
typeof(ptr) _ptr_ = (ptr); \
(ptr) = NULL; \
typeof(ptr) *_pptr_ = &(ptr); \
typeof(ptr) _ptr_ = *_pptr_; \
*_pptr_ = NULL; \
_ptr_; \
})