| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#pragma once |
| 21 |
|
| 22 |
#include <stdlib.h> |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#define _CLEANUP_FUNC(func) __attribute__((cleanup (func))) |
| 27 |
|
| 28 |
#define _PF_AUTOPTR_FUNC_NAME(TypeName) pf_autoptr_cleanup_ ## TypeName |
| 29 |
#define _PF_AUTOPTR_TYPENAME(TypeName) TypeName ## _pf_autoptr |
| 30 |
|
| 31 |
#define PF_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, cleanup) \ |
| 32 |
typedef TypeName *_PF_AUTOPTR_TYPENAME (TypeName); \ |
| 33 |
static __attribute__((__unused__)) inline void \ |
| 34 |
_PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName **_ptr) \ |
| 35 |
{ if (_ptr) (cleanup) (*_ptr); } |
| 36 |
|
| 37 |
#define PF_DEFINE_AUTO_CLEAN_FUNC(TypeName, cleanup) \ |
| 38 |
static __attribute__((__unused__)) inline void \ |
| 39 |
_PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName *_ptr) \ |
| 40 |
{ cleanup (_ptr); } |
| 41 |
|
| 42 |
static inline void |
| 43 |
autoptr_cleanup_generic_free (void *p) |
| 44 |
{ |
| 45 |
void **pp = (void **) p; |
| 46 |
|
| 47 |
free (*pp); |
| 48 |
} |
| 49 |
|
| 50 |
#define pf_autofree _CLEANUP_FUNC (autoptr_cleanup_generic_free) |
| 51 |
#define pf_autoptr(TypeName) \ |
| 52 |
_CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) \ |
| 53 |
_PF_AUTOPTR_TYPENAME (TypeName) |
| 54 |
#define pf_auto(TypeName) \ |
| 55 |
_CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) TypeName |
| 56 |
|
| 57 |
PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus, sd_bus_unref) |
| 58 |
PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus_message, sd_bus_message_unref) |
| 59 |
PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus_slot, sd_bus_slot_unref) |
| 60 |
|
| 61 |
PF_DEFINE_AUTO_CLEAN_FUNC (sd_bus_error, sd_bus_error_free) |