diff options
| author | 2025-11-16 20:52:57 -0600 | |
|---|---|---|
| committer | 2025-11-16 20:52:57 -0600 | |
| commit | d026e93405655129e46debfca2124ee132e9b134 (patch) | |
| tree | 8adf037dd69c4226ef9a5d2a3dd8fa63eb783761 /include | |
| parent | [wip] plugin stuff (diff) | |
build config + more plugin stuff
Diffstat (limited to 'include')
| -rw-r--r-- | include/config.h.in | 54 | ||||
| -rw-r--r-- | include/connection.h | 4 | ||||
| -rw-r--r-- | include/macros.h | 12 | ||||
| -rw-r--r-- | include/pipeline.h | 29 |
4 files changed, 79 insertions, 20 deletions
diff --git a/include/config.h.in b/include/config.h.in new file mode 100644 index 0000000..49431a6 --- /dev/null +++ b/include/config.h.in @@ -0,0 +1,54 @@ +#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 +#mesondefine HAS_ATTR_FORMAT +#mesondefine HAS_RESTRICT + +#ifdef HAS_ATTR_WUR +#define ATTR_WUR __attribute__((warn_unused_result)) +#else +#define ATTR_WUR +#endif + +#ifdef HAS_ATTR_ALWAYS_INLINE +#define ATTR_ALWAYS_INLINE __attribute__((always_inline)) +#else +#define ATTR_ALWAYS_INLINE +#endif + +#ifdef HAS_ATTR_MALLOC +#define ATTR_MALLOC(_x) +#else +#define ATTR_MALLOC(_x) __attribute__((malloc _x)) +#endif + +#ifdef HAS_ATTR_FORMAT +#define ATTR_FORMAT(_x) __attribute__((format _x)) +#else +#define ATTR_FORMAT(_x) +#endif + +#ifdef HAS_RESTRICT +#define PTX_RESTRICT restrict +#else +#define PTX_RESTRICT +#endif + +/* meson doesn't support this one yet :( */ +#ifdef __has_attribute +# if __has_attribute(access) +# define ATTR_ACCESS(_x) __attribute__((access _x)) +# else +# define ATTR_ACCESS(_x) +# endif +#else +#define ATTR_ACCESS(_x) +#endif + +#endif /* include guard */ 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 */ |
