static-destruct: Move static_destruct() logic to implementation file

This will allow us to remove the memory-util.h include from
static-destruct.h as part of #37344.
This commit is contained in:
Daan De Meyer
2025-05-14 16:56:41 +02:00
parent bdcd47a269
commit 02b6ac3a50
3 changed files with 26 additions and 18 deletions
+3 -18
View File
@@ -84,25 +84,10 @@ typedef struct StaticDestructor {
extern const StaticDestructor _weak_ __start_SYSTEMD_STATIC_DESTRUCT[];
extern const StaticDestructor _weak_ __stop_SYSTEMD_STATIC_DESTRUCT[];
void static_destruct_impl(const StaticDestructor *start, const StaticDestructor *end);
/* The function to destroy everything. (Note that this must be static inline, as it's key that it remains in
* the same linking unit as the variables we want to destroy.) */
static inline void static_destruct(void) {
if (!__start_SYSTEMD_STATIC_DESTRUCT)
return;
for (const StaticDestructor *d = ALIGN_PTR(__start_SYSTEMD_STATIC_DESTRUCT);
d < __stop_SYSTEMD_STATIC_DESTRUCT;
d = ALIGN_PTR(d + 1))
switch (d->type) {
case STATIC_DESTRUCTOR_SIMPLE:
d->simple.destroy(d->simple.data);
break;
case STATIC_DESTRUCTOR_ARRAY:
array_cleanup(&d->array);
break;
default:
assert_not_reached();
}
return static_destruct_impl(__start_SYSTEMD_STATIC_DESTRUCT, __stop_SYSTEMD_STATIC_DESTRUCT);
}