diff options
author | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-10 14:33:52 -0600 |
---|---|---|
committer | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-14 12:05:59 -0600 |
commit | 3fd120db5c0f6e32740796a914945166d3d887fb (patch) | |
tree | c33be69d157a735e51d6de04cd4ed10dc5dae41d /src | |
parent | 980e58efc6828fb0fe2c83c64d6b76dc95b33813 (diff) | |
download | apk-tools-3fd120db5c0f6e32740796a914945166d3d887fb.tar.gz apk-tools-3fd120db5c0f6e32740796a914945166d3d887fb.tar.bz2 apk-tools-3fd120db5c0f6e32740796a914945166d3d887fb.tar.xz apk-tools-3fd120db5c0f6e32740796a914945166d3d887fb.zip |
applet: rework APK_DEFINE_APPLET to use constructor attribute
this allows the applet registration to work in a portable way, without having to
weird things with the linker.
ref #10794
Diffstat (limited to 'src')
-rw-r--r-- | src/apk.c | 1 | ||||
-rw-r--r-- | src/apk_applet.h | 6 | ||||
-rw-r--r-- | src/apk_defines.h | 1 | ||||
-rw-r--r-- | src/applet.c | 12 |
4 files changed, 3 insertions, 17 deletions
@@ -409,7 +409,6 @@ int main(int argc, char **argv) #ifdef TEST_MODE apk_string_array_init(&test_repos); #endif - apk_applet_register_builtin(); apk_argv = malloc(sizeof(char*[argc+2])); memcpy(apk_argv, argv, sizeof(char*[argc])); diff --git a/src/apk_applet.h b/src/apk_applet.h index c3d5978..0d63712 100644 --- a/src/apk_applet.h +++ b/src/apk_applet.h @@ -56,14 +56,10 @@ struct apk_applet { extern const struct apk_option_group optgroup_global, optgroup_commit, optgroup_signing; void apk_applet_register(struct apk_applet *); -void apk_applet_register_builtin(void); struct apk_applet *apk_applet_find(const char *name); void apk_applet_help(struct apk_applet *applet, struct apk_out *out); -typedef void (*apk_init_func_t)(void); - #define APK_DEFINE_APPLET(x) \ -static void __register_##x(void) { apk_applet_register(&x); } \ -static apk_init_func_t __regfunc_##x __attribute__((__section__("initapplets"))) __attribute((used)) = __register_##x; +__attribute__((constructor)) static void __register_##x(void) { apk_applet_register(&x); } #endif diff --git a/src/apk_defines.h b/src/apk_defines.h index 0a50284..fb8b682 100644 --- a/src/apk_defines.h +++ b/src/apk_defines.h @@ -223,6 +223,7 @@ APK_ARRAY(apk_string_array, char *); #define foreach_array_item(iter, array) \ for (iter = &(array)->item[0]; iter < &(array)->item[(array)->num]; iter++) +#define LIST_HEAD(name) struct list_head name = { &name, &name } #define LIST_END (void *) 0xe01 #define LIST_POISON1 (void *) 0xdeadbeef #define LIST_POISON2 (void *) 0xabbaabba diff --git a/src/applet.c b/src/applet.c index 1d47662..5585157 100644 --- a/src/applet.c +++ b/src/applet.c @@ -10,7 +10,7 @@ #include "apk_applet.h" #include "apk_print.h" -static struct list_head apk_applet_list; +static LIST_HEAD(apk_applet_list); #define apk_applet_foreach(iter) list_for_each_entry(iter, &apk_applet_list, node) @@ -20,16 +20,6 @@ void apk_applet_register(struct apk_applet *applet) list_add_tail(&applet->node, &apk_applet_list); } -void apk_applet_register_builtin(void) -{ - extern apk_init_func_t __start_initapplets[], __stop_initapplets[]; - apk_init_func_t *p; - - list_init(&apk_applet_list); - for (p = __start_initapplets; p < __stop_initapplets; p++) - (*p)(); -} - struct apk_applet *apk_applet_find(const char *name) { struct apk_applet *a; |