diff options
| author | 2025-11-16 13:01:59 -0600 | |
|---|---|---|
| committer | 2025-11-16 13:07:20 -0600 | |
| commit | e6e7f4c8ad9bffd536182923c8e556ca028cec04 (patch) | |
| tree | 3b5409c06ab260116a95e919f9b2c5161c8d63e3 | |
| parent | add removal test and const-qualify data (diff) | |
[wip] plugin stuff
| -rw-r--r-- | include/connection.h (renamed from connection.h) | 0 | ||||
| -rw-r--r-- | include/pipeline.h (renamed from pipeline.h) | 9 | ||||
| -rw-r--r-- | main.c | 23 | ||||
| -rw-r--r-- | meson.build | 10 | ||||
| -rw-r--r-- | plugins/meson.build | 2 | ||||
| -rw-r--r-- | plugins/skibidi.c | 7 |
6 files changed, 43 insertions, 8 deletions
diff --git a/connection.h b/include/connection.h index 416e076..416e076 100644 --- a/connection.h +++ b/include/connection.h diff --git a/pipeline.h b/include/pipeline.h index c0feb56..d662b09 100644 --- a/pipeline.h +++ b/include/pipeline.h @@ -24,8 +24,15 @@ struct ptx_pipeline_stage_funcs { ptx_pipeline_cleanup_proc_t *cleanup; }; +#ifdef MODULE +#define MODEXP extern +#else +#define MODEXP \ +__attribute__((visibility("protected"))) +#endif + /* allocates a new pipeline, with space for `initial_size' new stages. */ -ptx_pipeline_t *ptx_pipeline_new(size_t initial_size) ATTR_WUR ATTR_MALLOC() ATTR_MALLOC((ptx_pipeline_free, 1)); +MODEXP ptx_pipeline_t *ptx_pipeline_new(size_t initial_size) ATTR_WUR ATTR_MALLOC() ATTR_MALLOC((ptx_pipeline_free, 1)); /* frees an existing pipeline stage. note that this will call the cleanup function in the stages as well. */ void ptx_pipeline_free(ptx_pipeline_t *pl); @@ -2,17 +2,18 @@ #include <stdbool.h> #include <stdint.h> #include <stdarg.h> +#include <dlfcn.h> #include "pipeline.h" #define UNUSED(_v) ((void)(_v)) -PIPELINE_STAGE int identity_stage_handle(const ptx_pipeline_ctx_t *ctx, const void *data, size_t sz) +PIPELINE_STAGE static int identity_stage_handle(const ptx_pipeline_ctx_t *ctx, const void *data, size_t sz) { return ptx_pipeline_ctx_next(ctx, data, sz); } -PIPELINE_INIT int debug_stage_init(const char *name, void **ppuser, va_list init_args) +PIPELINE_INIT static int debug_stage_init(const char *name, void **ppuser, va_list init_args) { static const char *const messages[] = { "no continue :(", "continue :)" }; @@ -26,12 +27,12 @@ PIPELINE_INIT int debug_stage_init(const char *name, void **ppuser, va_list init return 0; } -PIPELINE_CLEANUP void debug_stage_cleanup(const char *name, void *puser) +PIPELINE_CLEANUP static void debug_stage_cleanup(const char *name, void *puser) { printf("Debug stage %s (cleanup): %p\n", name, puser); } -PIPELINE_STAGE int debug_stage_handle(const ptx_pipeline_ctx_t *ctx, const void *data, size_t sz) +PIPELINE_STAGE static int debug_stage_handle(const ptx_pipeline_ctx_t *ctx, const void *data, size_t sz) { bool cont = !!(uintptr_t)(*ptx_pipeline_ctx_get_user(ctx)); printf("Debug stage %s:\n Data: %p\n Size: %zu\n", ptx_pipeline_ctx_get_name(ctx), data, sz); @@ -121,5 +122,19 @@ int main(void) { ptx_pipeline_free(pl); + void *mod; + if (!(mod = dlopen("plugins/libm_skibidi.so", RTLD_LAZY | RTLD_LOCAL))) { + printf("dlopen: %s\n", dlerror()); + return 1; + } + + int (*f)(void) = dlsym(mod, "do_something"); + if (!f) { + printf("dlsym: %s\n", dlerror()); + return 1; + } + + printf("f: %d\n", f()); + return 0; } diff --git a/meson.build b/meson.build index da4fe0e..03d51a4 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,5 @@ project('ptxmc', 'c', default_options : ['c_std=c11']) +add_project_arguments('-D_XOPEN_SOURCE=700', language : [ 'c' ]) c_comp = meson.get_compiler('c') @@ -11,10 +12,13 @@ conf_data.set('HAS_RESTRICT', c_comp.has_type('int *restrict')) configure_file(input : 'config.h.in', output : 'config.h', configuration : conf_data) conf_include = include_directories('.') +src_include = include_directories('include') executable('ptxmc', - 'main.c', 'pipeline.c', 'connection.c', - include_directories : conf_include, - c_args : [ '-D_XOPEN_SOURCE=700' ]) + 'main.c', + include_directories : [ conf_include, src_include ], + link_args : [ '-rdynamic' ]) + +subdir('plugins') diff --git a/plugins/meson.build b/plugins/meson.build new file mode 100644 index 0000000..efa8e5d --- /dev/null +++ b/plugins/meson.build @@ -0,0 +1,2 @@ +shared_library('m_skibidi', 'skibidi.c', + include_directories : [ conf_include, src_include ]) diff --git a/plugins/skibidi.c b/plugins/skibidi.c new file mode 100644 index 0000000..4fa4c33 --- /dev/null +++ b/plugins/skibidi.c @@ -0,0 +1,7 @@ +#define MODULE 1 +#include "pipeline.h" + +__attribute__((visibility("default"))) int do_something(void) +{ + return !!ptx_pipeline_new(4); +} |
