| 1 |
/* |
| 2 |
* Copyright © 2020 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include "config.h" |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
|
| 12 |
static inline void* |
| 13 |
_steal(void *ptr) { |
| 14 |
void **original = (void**)ptr; |
| 15 |
void *swapped = *original; |
| 16 |
*original = NULL; |
| 17 |
return swapped; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Resets the pointer content and resets the data to NULL. |
| 22 |
*/ |
| 23 |
#ifdef _WIN32 |
| 24 |
#define steal(ptr_) \ |
| 25 |
_steal(ptr_) |
| 26 |
#else |
| 27 |
#define steal(ptr_) \ |
| 28 |
(__typeof__(*(ptr_)))_steal(ptr_) |
| 29 |
#endif |