spa: utils: cleanup: fix __has_attribute() usage

Unknown preprocessor symbols are replaced with 0 in preprocessor
conditionals, so if `__has_attribute()` is not supported, then
the condition will be the following:

  if 0 && 0(__cleanup__)

which is syntactically incorrect.

So split the condition and only check `__has_attribute()` if
it exists.

Fixes: 65d949558b ("spa: utils: add scope based resource cleanup")
Fixes #4962
This commit is contained in:
Barnabás Pőcze 2025-11-02 19:06:39 +01:00
parent 62022ce623
commit d3368ee0d5

View file

@ -46,9 +46,13 @@ __extension__ ({ \
/* ========================================================================== */ /* ========================================================================== */
#if defined(__has_attribute) && __has_attribute(__cleanup__) #ifdef __has_attribute
#if __has_attribute(__cleanup__)
#define spa_cleanup(func) __attribute__((__cleanup__(func))) #define spa_cleanup(func) __attribute__((__cleanup__(func)))
#endif
#endif
#ifdef spa_cleanup
#define SPA_DEFINE_AUTO_CLEANUP(name, type, ...) \ #define SPA_DEFINE_AUTO_CLEANUP(name, type, ...) \
typedef __typeof__(type) _spa_auto_cleanup_type_ ## name; \ typedef __typeof__(type) _spa_auto_cleanup_type_ ## name; \