cleanup: add a scoped version of CLASS()

This will make it possible to use:

scoped_class() {
}

constructs to limit variables to certain scopes and still perform
auto-cleanup.

Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-07-11 15:47:48 +02:00
parent a6ed5691b2
commit 5c21c5f22d
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
1 changed files with 8 additions and 0 deletions

View File

@ -277,6 +277,14 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \
class_##_name##_t var __cleanup(class_##_name##_destructor) = \
class_##_name##_constructor
#define scoped_class(_name, var, args) \
for (CLASS(_name, var)(args); \
__guard_ptr(_name)(&var) || !__is_cond_ptr(_name); \
({ goto _label; })) \
if (0) { \
_label: \
break; \
} else
/*
* DEFINE_GUARD(name, type, lock, unlock):