aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-11-16 20:52:57 -0600
committerLibravatar bigfoot547 <[email protected]>2025-11-16 20:52:57 -0600
commitd026e93405655129e46debfca2124ee132e9b134 (patch)
tree8adf037dd69c4226ef9a5d2a3dd8fa63eb783761
parent[wip] plugin stuff (diff)
build config + more plugin stuff
-rw-r--r--include/config.h.in (renamed from config.h.in)3
-rw-r--r--include/connection.h4
-rw-r--r--include/macros.h12
-rw-r--r--include/pipeline.h29
-rw-r--r--meson.build31
-rw-r--r--plugins/meson.build5
-rw-r--r--plugins/skibidi.c3
-rw-r--r--src/connection.c (renamed from connection.c)0
-rw-r--r--src/main.c (renamed from main.c)15
-rw-r--r--src/meson.build5
-rw-r--r--src/pipeline.c (renamed from pipeline.c)18
11 files changed, 71 insertions, 54 deletions
diff --git a/config.h.in b/include/config.h.in
index 59956d4..49431a6 100644
--- a/config.h.in
+++ b/include/config.h.in
@@ -1,6 +1,9 @@
#ifndef PTXMC_CONFIG_H_INCLUDED
#define PTXMC_CONFIG_H_INCLUDED
+#mesondefine PTX_IMPORT
+#mesondefine PTX_EXPORT
+
#mesondefine HAS_ATTR_WUR
#mesondefine HAS_ATTR_ALWAYS_INLINE
#mesondefine HAS_ATTR_MALLOC
diff --git a/include/connection.h b/include/connection.h
index 416e076..98f0eca 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -9,7 +9,7 @@ struct ptx_connection
ptx_pipeline_t *srv_read, *srv_write;
};
-struct ptx_connection *ptx_connection_new(void);
-void ptx_connection_free(struct ptx_connection *conn);
+PTX_API struct ptx_connection *ptx_connection_new(void) ATTR_WUR ATTR_MALLOC() ATTR_MALLOC((ptx_connection_free, 1));
+PTX_API void ptx_connection_free(struct ptx_connection *conn);
#endif /* include guard */
diff --git a/include/macros.h b/include/macros.h
new file mode 100644
index 0000000..3702df7
--- /dev/null
+++ b/include/macros.h
@@ -0,0 +1,12 @@
+#ifndef PTX_MACROS_H_INCLDUED
+#define PTX_MACROS_H_INCLDUED
+
+#include "config.h"
+
+#ifdef PTX_MODULE
+#define PTX_API PTX_IMPORT
+#else
+#define PTX_API PTX_EXPORT
+#endif
+
+#endif /* include guard */
diff --git a/include/pipeline.h b/include/pipeline.h
index d662b09..f8c51dc 100644
--- a/include/pipeline.h
+++ b/include/pipeline.h
@@ -5,7 +5,7 @@
#include <stddef.h>
#include <stdarg.h>
-#include "config.h"
+#include "macros.h"
#define PIPELINE_STAGE ATTR_WUR ATTR_ACCESS((read_only, 1))
#define PIPELINE_INIT ATTR_ACCESS((read_only, 1))
@@ -24,40 +24,33 @@ 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. */
-MODEXP ptx_pipeline_t *ptx_pipeline_new(size_t initial_size) ATTR_WUR ATTR_MALLOC() ATTR_MALLOC((ptx_pipeline_free, 1));
+PTX_API 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);
+PTX_API void ptx_pipeline_free(ptx_pipeline_t *pl);
/* adds `stage' with `name' to `pipeline' after `after'
* returns: number of stages added to pipeline (0 or 1), or -1 if there was an allocation or initialization error. */
-int ptx_pipeline_add_after(ptx_pipeline_t *pipeline, const struct ptx_pipeline_stage_funcs *stage, const char *name, const char *after, ...);
+PTX_API int ptx_pipeline_add_after(ptx_pipeline_t *pipeline, const struct ptx_pipeline_stage_funcs *stage, const char *name, const char *after, ...) ATTR_WUR;
/* adds `stage' with `name' to `pipeline' before `before'
* returns: number of stages added to pipeline (0 or 1), or -1 if there was an allocation or initialization error. */
-int ptx_pipeline_add_before(ptx_pipeline_t *pipeline, const struct ptx_pipeline_stage_funcs *stage, const char *name, const char *before, ...);
+PTX_API int ptx_pipeline_add_before(ptx_pipeline_t *pipeline, const struct ptx_pipeline_stage_funcs *stage, const char *name, const char *before, ...) ATTR_WUR;
/* TODO: could theoretically have versions of the above functions that don't defensively copy `name' */
/* returns: number of stages removed from pipeline */
-int ptx_pipeline_remove_stage(ptx_pipeline_t *pipeline, const char *name);
+PTX_API int ptx_pipeline_remove_stage(ptx_pipeline_t *pipeline, const char *name);
/* this pointer is guaranteed to be valid as long as the pipeline context is active (i.e., within this handler function)
* If you need to access user data of a stage from outside of a handler function, TODO */
-void **ptx_pipeline_ctx_get_user(const ptx_pipeline_ctx_t *ctx);
-const char *ptx_pipeline_ctx_get_name(const ptx_pipeline_ctx_t *ctx);
+PTX_API void **ptx_pipeline_ctx_get_user(const ptx_pipeline_ctx_t *ctx);
+PTX_API const char *ptx_pipeline_ctx_get_name(const ptx_pipeline_ctx_t *ctx);
-int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, const void *nextdata, size_t nextsize);
+PTX_API int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, const void *nextdata, size_t nextsize) ATTR_WUR;
-void ptx_pipeline_ctx_diag(const ptx_pipeline_ctx_t *ctx, int lvl, const char *fmt, ...) ATTR_FORMAT((printf, 3, 4)); /* TODO: pipeline stages should be able to send diagnostic messages */
+PTX_API void ptx_pipeline_ctx_diag(const ptx_pipeline_ctx_t *ctx, int lvl, const char *fmt, ...) ATTR_FORMAT((printf, 3, 4)); /* TODO: pipeline stages should be able to send diagnostic messages */
-int ptx_pipeline_handle(ptx_pipeline_t *pipeline, const void *data, size_t sz); /* TODO: diagnostic */
+PTX_API int ptx_pipeline_handle(ptx_pipeline_t *pipeline, const void *data, size_t sz); /* TODO: diagnostic */
#endif /* include guard */
diff --git a/meson.build b/meson.build
index 03d51a4..e144325 100644
--- a/meson.build
+++ b/meson.build
@@ -4,21 +4,40 @@ add_project_arguments('-D_XOPEN_SOURCE=700', language : [ 'c' ])
c_comp = meson.get_compiler('c')
conf_data = configuration_data()
+
+if not c_comp.has_function_attribute('visibility:default') \
+ or not c_comp.has_function_attribute('visibility:hidden')
+ error('Your platform isn\'t supported. Use a gcc-like compiler on linux.')
+else
+ conf_data.set('PTX_EXPORT', '__attribute__((visibility("default")))')
+ conf_data.set('PTX_IMPORT', 'extern')
+endif
+
conf_data.set('HAS_ATTR_WUR', c_comp.has_function_attribute('warn_unused_result'))
conf_data.set('HAS_ATTR_ALWAYS_INLINE', c_comp.has_function_attribute('always_inline'))
conf_data.set('HAS_ATTR_MALLOC', c_comp.has_function_attribute('malloc'))
conf_data.set('HAS_ATTR_FORMAT', c_comp.has_function_attribute('format'))
+
conf_data.set('HAS_RESTRICT', c_comp.has_type('int *restrict'))
-configure_file(input : 'config.h.in', output : 'config.h', configuration : conf_data)
+
+configure_file(input : 'include/config.h.in', output : 'config.h', configuration : conf_data)
conf_include = include_directories('.')
src_include = include_directories('include')
-executable('ptxmc',
- 'pipeline.c',
- 'connection.c',
- 'main.c',
+export_dynamic = []
+
+if c_comp.get_argument_syntax() == 'gcc'
+ if c_comp.has_argument('-fvisibility=hidden')
+ add_project_arguments('-fvisibility=hidden', language : 'c')
+ endif
+endif
+
+subdir('src')
+
+executable('ptxmc', prog_sources,
include_directories : [ conf_include, src_include ],
- link_args : [ '-rdynamic' ])
+ gnu_symbol_visibility : 'hidden',
+ export_dynamic : true)
subdir('plugins')
diff --git a/plugins/meson.build b/plugins/meson.build
index efa8e5d..59b5da0 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -1,2 +1,3 @@
-shared_library('m_skibidi', 'skibidi.c',
- include_directories : [ conf_include, src_include ])
+shared_module('m_skibidi', 'skibidi.c',
+ include_directories : [ conf_include, src_include ],
+ c_args : [ '-DMODULE=1' ])
diff --git a/plugins/skibidi.c b/plugins/skibidi.c
index 4fa4c33..d763058 100644
--- a/plugins/skibidi.c
+++ b/plugins/skibidi.c
@@ -1,7 +1,6 @@
-#define MODULE 1
#include "pipeline.h"
-__attribute__((visibility("default"))) int do_something(void)
+PTX_EXPORT int do_something(void)
{
return !!ptx_pipeline_new(4);
}
diff --git a/connection.c b/src/connection.c
index ecbb7fa..ecbb7fa 100644
--- a/connection.c
+++ b/src/connection.c
diff --git a/main.c b/src/main.c
index 273d797..83ed688 100644
--- a/main.c
+++ b/src/main.c
@@ -2,7 +2,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
-#include <dlfcn.h>
#include "pipeline.h"
@@ -122,19 +121,5 @@ 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/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..d1a3033
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,5 @@
+prog_sources = files(
+ 'pipeline.c',
+ 'connection.c',
+ 'main.c'
+)
diff --git a/pipeline.c b/src/pipeline.c
index a5ddbf2..8b54cca 100644
--- a/pipeline.c
+++ b/src/pipeline.c
@@ -47,7 +47,7 @@ static int ptx__pipeline_reserve(ptx_pipeline_t *pl, size_t req)
}
/* allocates a new pipeline, with space for `initial_size' new stages. */
-ATTR_WUR ptx_pipeline_t *ptx_pipeline_new(size_t initial_size)
+PTX_API ptx_pipeline_t *ptx_pipeline_new(size_t initial_size)
{
ptx_pipeline_t *pl = malloc(sizeof(ptx_pipeline_t));
if (!pl) return NULL;
@@ -77,7 +77,7 @@ static void ptx__cleanup_pipeline_stage(struct ptx__pipeline_stage_tag *stage)
}
/* 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)
+PTX_API void ptx_pipeline_free(ptx_pipeline_t *pl)
{
if (!pl) return;
@@ -192,7 +192,7 @@ static int ptx__pipeline_add_at(
/* adds `stage' with `name' to `pipeline' after `after' *
* returns: number of stages added to pipeline (0 or 1), or -1 if there was an allocation or initialization error. */
-int ptx_pipeline_add_after(
+PTX_API int ptx_pipeline_add_after(
ptx_pipeline_t *pipeline,
const struct ptx_pipeline_stage_funcs *stage,
const char *name,
@@ -224,7 +224,7 @@ int ptx_pipeline_add_after(
/* adds `stage' with `name' to `pipeline' before `before'
* returns: number of stages added to pipeline (0 or 1), or -1 if there was an allocation or initialization error. */
-int ptx_pipeline_add_before(
+PTX_API int ptx_pipeline_add_before(
ptx_pipeline_t *pipeline,
const struct ptx_pipeline_stage_funcs *stage,
const char *name,
@@ -255,7 +255,7 @@ int ptx_pipeline_add_before(
}
/* returns: number of stages removed from pipeline */
-int ptx_pipeline_remove_stage(ptx_pipeline_t *pipeline, const char *name)
+PTX_API int ptx_pipeline_remove_stage(ptx_pipeline_t *pipeline, const char *name)
{
assert(pipeline);
assert(!pipeline->handling);
@@ -270,19 +270,19 @@ int ptx_pipeline_remove_stage(ptx_pipeline_t *pipeline, const char *name)
return 1;
}
-void **ptx_pipeline_ctx_get_user(const ptx_pipeline_ctx_t *ctx)
+PTX_API void **ptx_pipeline_ctx_get_user(const ptx_pipeline_ctx_t *ctx)
{
assert(ctx);
return &ctx->pipeline->stages[ctx->curidx].user;
}
-const char *ptx_pipeline_ctx_get_name(const ptx_pipeline_ctx_t *ctx)
+PTX_API const char *ptx_pipeline_ctx_get_name(const ptx_pipeline_ctx_t *ctx)
{
assert(ctx);
return ctx->pipeline->stages[ctx->curidx].name;
}
-int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, const void *nextdata, size_t nextsize)
+PTX_API int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, const void *nextdata, size_t nextsize)
{
assert(ctx->curidx + 1 < ctx->pipeline->stages_len);
@@ -295,7 +295,7 @@ int ptx_pipeline_ctx_next(const ptx_pipeline_ctx_t *ctx, const void *nextdata, s
return (*new_ctx.pipeline->stages[new_ctx.curidx].impl.handler)(&new_ctx, nextdata, nextsize);
}
-int ptx_pipeline_handle(ptx_pipeline_t *pipeline, const void *data, size_t sz)
+PTX_API int ptx_pipeline_handle(ptx_pipeline_t *pipeline, const void *data, size_t sz)
{
assert(pipeline);
assert(!pipeline->handling);