spa: expose utils/cleanup.h for external users
Up until now, `spa/utils/cleanup.h` was not installed,
but 779f06865c
("pod: add spa_auto support for dynamic builder")
included it in a public header. So now `cleanup.h` also needs to
be installed like any other public header so as to not break
3rd party users.
For example, `xdg-desktop-portal-wlr` would break:
https://codesearch.debian.net/search?q=spa_pod_dynamic_builder_init&literal=1
This commit is contained in:
parent
bb120a070f
commit
15e14946fb
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
LIST=""
|
LIST=""
|
||||||
|
|
||||||
for i in $(find spa/include -name '*.h' -a -not -path 'spa/include/spa/utils/cleanup.h' | sed s#spa/include/##);
|
for i in $(find spa/include -name '*.h' | sed s#spa/include/##);
|
||||||
do
|
do
|
||||||
[ -f "$PREFIX/include/spa-0.2/$i" ] || LIST="$i $LIST"
|
[ -f "$PREFIX/include/spa-0.2/$i" ] || LIST="$i $LIST"
|
||||||
done
|
done
|
||||||
|
|
|
@ -15,7 +15,4 @@ spa_sections = [
|
||||||
spa_headers = 'spa' # used by doxygen
|
spa_headers = 'spa' # used by doxygen
|
||||||
install_subdir('spa',
|
install_subdir('spa',
|
||||||
install_dir : get_option('includedir') / spa_name,
|
install_dir : get_option('includedir') / spa_name,
|
||||||
exclude_files : [
|
|
||||||
'utils/cleanup.h',
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,10 +5,48 @@
|
||||||
#ifndef SPA_UTILS_CLEANUP_H
|
#ifndef SPA_UTILS_CLEANUP_H
|
||||||
#define SPA_UTILS_CLEANUP_H
|
#define SPA_UTILS_CLEANUP_H
|
||||||
|
|
||||||
#if !defined(__has_attribute) || !__has_attribute(__cleanup__)
|
#define spa_exchange(var, new_value) \
|
||||||
#error "attribute `cleanup` is required"
|
__extension__ ({ \
|
||||||
|
__typeof__(var) *_ptr = &(var); \
|
||||||
|
__typeof__(var) _old_value = *_ptr; \
|
||||||
|
*_ptr = (new_value); \
|
||||||
|
_old_value; \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* ========================================================================== */
|
||||||
|
|
||||||
|
#if __GNUC__ >= 10 || defined(__clang__)
|
||||||
|
#define spa_steal_ptr(ptr) ((__typeof__(*(ptr)) *) spa_exchange((ptr), NULL))
|
||||||
|
#else
|
||||||
|
#define spa_steal_ptr(ptr) spa_exchange((ptr), NULL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define spa_clear_ptr(ptr, destructor) \
|
||||||
|
__extension__ ({ \
|
||||||
|
__typeof__(ptr) _old_value = spa_steal_ptr(ptr); \
|
||||||
|
if (_old_value) \
|
||||||
|
destructor(_old_value); \
|
||||||
|
(void) 0; \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* ========================================================================== */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define spa_steal_fd(fd) spa_exchange((fd), -1)
|
||||||
|
|
||||||
|
#define spa_clear_fd(fd) \
|
||||||
|
__extension__ ({ \
|
||||||
|
int _old_value = spa_steal_fd(fd), _res = 0; \
|
||||||
|
if (_old_value >= 0) \
|
||||||
|
_res = close(_old_value); \
|
||||||
|
_res; \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* ========================================================================== */
|
||||||
|
|
||||||
|
#if defined(__has_attribute) && __has_attribute(__cleanup__)
|
||||||
|
|
||||||
#define spa_cleanup(func) __attribute__((__cleanup__(func)))
|
#define spa_cleanup(func) __attribute__((__cleanup__(func)))
|
||||||
|
|
||||||
#define SPA_DEFINE_AUTO_CLEANUP(name, type, ...) \
|
#define SPA_DEFINE_AUTO_CLEANUP(name, type, ...) \
|
||||||
|
@ -33,34 +71,10 @@ static inline void _spa_autoptr_cleanup_func_ ## name (__typeof__(type) **thing)
|
||||||
spa_cleanup(_spa_autoptr_cleanup_func_ ## name) \
|
spa_cleanup(_spa_autoptr_cleanup_func_ ## name) \
|
||||||
_spa_autoptr_cleanup_type_ ## name
|
_spa_autoptr_cleanup_type_ ## name
|
||||||
|
|
||||||
#define spa_exchange(var, new_value) \
|
|
||||||
__extension__ ({ \
|
|
||||||
__typeof__(var) *_ptr = &(var); \
|
|
||||||
__typeof__(var) _old_value = *_ptr; \
|
|
||||||
*_ptr = (new_value); \
|
|
||||||
_old_value; \
|
|
||||||
})
|
|
||||||
|
|
||||||
#if __GNUC__ >= 10 || defined(__clang__)
|
|
||||||
#define spa_steal_ptr(ptr) ((__typeof__(*(ptr)) *) spa_exchange((ptr), NULL))
|
|
||||||
#else
|
|
||||||
#define spa_steal_ptr(ptr) spa_exchange((ptr), NULL)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define spa_steal_fd(fd) spa_exchange((fd), -1)
|
|
||||||
|
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define spa_clear_ptr(ptr, destructor) \
|
|
||||||
__extension__ ({ \
|
|
||||||
__typeof__(ptr) _old_value = spa_steal_ptr(ptr); \
|
|
||||||
if (_old_value) \
|
|
||||||
destructor(_old_value); \
|
|
||||||
(void) 0; \
|
|
||||||
})
|
|
||||||
|
|
||||||
static inline void _spa_autofree_cleanup_func(void *p)
|
static inline void _spa_autofree_cleanup_func(void *p)
|
||||||
{
|
{
|
||||||
free(*(void **) p);
|
free(*(void **) p);
|
||||||
|
@ -69,16 +83,6 @@ static inline void _spa_autofree_cleanup_func(void *p)
|
||||||
|
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#define spa_clear_fd(fd) \
|
|
||||||
__extension__ ({ \
|
|
||||||
int _old_value = spa_steal_fd(fd), _res = 0; \
|
|
||||||
if (_old_value >= 0) \
|
|
||||||
_res = close(_old_value); \
|
|
||||||
_res; \
|
|
||||||
})
|
|
||||||
|
|
||||||
static inline void _spa_autoclose_cleanup_func(int *fd)
|
static inline void _spa_autoclose_cleanup_func(int *fd)
|
||||||
{
|
{
|
||||||
spa_clear_fd(*fd);
|
spa_clear_fd(*fd);
|
||||||
|
@ -101,4 +105,11 @@ SPA_DEFINE_AUTOPTR_CLEANUP(DIR, DIR, {
|
||||||
spa_clear_ptr(*thing, closedir);
|
spa_clear_ptr(*thing, closedir);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define SPA_DEFINE_AUTO_CLEANUP(name, type, ...)
|
||||||
|
#define SPA_DEFINE_AUTOPTR_CLEANUP(name, type, ...)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* SPA_UTILS_CLEANUP_H */
|
#endif /* SPA_UTILS_CLEANUP_H */
|
||||||
|
|
Loading…
Reference in New Issue