]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
static-destruct: Move static_destruct() logic to implementation file
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 14 May 2025 13:06:50 +0000 (15:06 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 14 May 2025 14:56:41 +0000 (16:56 +0200)
This will allow us to remove the memory-util.h include from
static-destruct.h as part of #37344.

src/basic/meson.build
src/basic/static-destruct.c [new file with mode: 0644]
src/basic/static-destruct.h

index a2ac978a20cd813fdc0f2acab52711b3c3628eb5..44b90c2e768050b43330c945835b7961a1cd65fe 100644 (file)
@@ -96,6 +96,7 @@ basic_sources = files(
         'socket-util.c',
         'sort-util.c',
         'stat-util.c',
+        'static-destruct.c',
         'strbuf.c',
         'string-table.c',
         'string-util.c',
diff --git a/src/basic/static-destruct.c b/src/basic/static-destruct.c
new file mode 100644 (file)
index 0000000..f8006c8
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "static-destruct.h"
+
+void static_destruct_impl(const StaticDestructor *start, const StaticDestructor *end) {
+        if (!start)
+                return;
+
+        for (const StaticDestructor *d = ALIGN_PTR(start); d < end; 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();
+                }
+}
index f167d6413ec81d918e8e49fa20607ede7e8c9255..aaafbbc478bb8436a28e19f5797f41b2f1a098cb 100644 (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);
 }