extern "C" {
#endif
+#ifdef _CONST
+# error _CONST can only be defined in the local header
+#endif
+#ifndef _DL_MODULE_PRIVATE
+# define _CONST const
+#else
+# define _CONST
+#endif
+
#ifdef __APPLE__
# define DL_EXTENSION ".dylib"
#elif defined (WIN32)
*/
typedef struct dl_module_s dl_module_t;
struct dl_module_s {
- dl_t *dl; //!< Dynamic loader handle.
+ dl_t * _CONST dl; //!< Dynamic loader handle.
- dl_module_t const *parent; //!< of this module.
+ dl_module_t const * _CONST parent; //!< of this module.
- dl_module_type_t type; //!< of this module.
+ dl_module_type_t _CONST type; //!< of this module.
- dl_module_common_t const *common; //!< Symbol exported by the module, containing its public
- //!< functions, name and behaviour control flags.
+ dl_module_common_t const * _CONST common; //!< Symbol exported by the module, containing its public
+ //!< functions, name and behaviour control flags.
- CONF_SECTION *conf; //!< The module's global configuration
- ///< (as opposed to the instance, configuration).
- ///< May be NULL.
- bool in_tree;
+ CONF_SECTION * _CONST conf; //!< The module's global configuration
+ ///< (as opposed to the instance, configuration).
+ ///< May be NULL.
+ bool _CONST in_tree;
};
/** A module/inst tuple
*/
typedef struct dl_module_instance_s dl_module_inst_t;
struct dl_module_instance_s {
- char const *name; //!< Instance name.
- dl_module_t const *module; //!< Module
- void *data; //!< Module instance's parsed configuration.
- CONF_SECTION *conf; //!< Module's instance configuration.
- dl_module_inst_t const *parent; //!< Parent module's instance (if any).
+ char const * _CONST name; //!< Instance name.
+ dl_module_t const * _CONST module; //!< Module
+ void * _CONST data; //!< Module instance's parsed configuration.
+ CONF_SECTION * _CONST conf; //!< Module's instance configuration.
+ dl_module_inst_t const * _CONST parent; //!< Parent module's instance (if any).
};
extern fr_table_num_sorted_t const dl_module_type_prefix[];
dl_module_loader_t *dl_module_loader_init(char const *lib_dir);
+#undef _CONST
+
#ifdef __cplusplus
}
#endif
unlang_module_fd_event_t fd_read; //!< Function to call when FD is readable.
unlang_module_fd_event_t fd_write; //!< Function to call when FD is writable.
unlang_module_fd_event_t fd_error; //!< Function to call when FD has errored.
- void const *inst; //!< Module instance to pass to callbacks.
+ dl_module_inst_t *dl_inst; //!< Module instance to pass to callbacks.
+ ///< Use dl_inst->data to get instance data.
void *thread; //!< Thread specific module instance.
void const *ctx; //!< ctx data to pass to callbacks.
fr_event_timer_t const *ev; //!< Event in this worker's event heap.
static void unlang_event_fd_read_handler(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx)
{
unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t);
- void *mutable_ctx;
- void *mutable_inst;
fr_assert(ev->fd == fd);
- memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx));
- memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst));
-
ev->fd_read(&(module_ctx_t){
- .instance = mutable_inst,
+ .dl_inst = ev->dl_inst,
+ .instance = ev->dl_inst->data,
.thread = ev->thread,
- .rctx = mutable_ctx },
+ .rctx = UNCONST(void *, ev->ctx) },
ev->request, fd);
}
static void unlang_module_event_timeout_handler(UNUSED fr_event_list_t *el, fr_time_t now, void *ctx)
{
unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t);
- void *mutable_ctx;
- void *mutable_inst;
-
- memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx));
- memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst));
ev->timeout(&(module_ctx_t){
- .instance = mutable_inst,
+ .dl_inst = ev->dl_inst,
+ .instance = ev->dl_inst->data,
.thread = ev->thread,
- .rctx = mutable_ctx
+ .rctx = UNCONST(void *, ev->ctx)
}, ev->request, now);
talloc_free(ev);
}
.request = request,
.fd = -1,
.timeout = callback,
- .inst = mc->instance->dl_inst->data,
+ .dl_inst = mc->instance->dl_inst,
.thread = state->thread,
.ctx = ctx
};
static void unlang_event_fd_write_handler(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *ctx)
{
unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t);
- void *mutable_ctx;
- void *mutable_inst;
-
fr_assert(ev->fd == fd);
- memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx));
- memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst));
-
ev->fd_write(&(module_ctx_t){
- .instance = mutable_inst,
+ .dl_inst = ev->dl_inst,
+ .instance = ev->dl_inst->data,
.thread = ev->thread,
- .rctx = mutable_ctx },
+ .rctx = UNCONST(void *, ev->ctx) },
ev->request, fd);
}
UNUSED int flags, UNUSED int fd_errno, void *ctx)
{
unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t);
- void *mutable_ctx;
- void *mutable_inst;
fr_assert(ev->fd == fd);
- memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx));
- memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst));
-
ev->fd_error(&(module_ctx_t){
- .instance = mutable_inst,
+ .dl_inst = ev->dl_inst,
+ .instance = ev->dl_inst->data,
.thread = ev->thread,
- .rctx = mutable_ctx
+ .rctx = UNCONST(void *, ev->ctx)
}, ev->request, fd);
}
ev->fd_read = read;
ev->fd_write = write;
ev->fd_error = error;
- ev->inst = mc->instance->dl_inst->data;
+ ev->dl_inst = mc->instance->dl_inst;
ev->thread = state->thread;
ev->ctx = ctx;
request->module = mc->instance->name;
safe_lock(mc->instance);
state->signal(&(module_ctx_t){
+ .dl_inst = mc->instance->dl_inst,
.instance = mc->instance->dl_inst->data,
.thread = state->thread->data,
.rctx = state->rctx
safe_lock(mc->instance);
ua = resume(&state->rcode,
&(module_ctx_t){
+ .dl_inst = mc->instance->dl_inst,
.instance = mc->instance->dl_inst->data,
.thread = state->thread->data,
.rctx = state->rctx,
safe_lock(mc->instance); /* Noop unless instance->mutex set */
ua = mc->method(&state->rcode,
&(module_ctx_t){
+ .dl_inst = mc->instance->dl_inst,
.instance = mc->instance->dl_inst->data,
.thread = state->thread->data
},