Affix
view release on metacpan or search on metacpan
infix/include/infix/infix.h view on Meta::CPAN
* @brief Parses a full function signature string into its constituent parts.
*
* This function provides a way to deconstruct a signature string into its components
* (`return_type`, `arg_types`, etc.) without generating a trampoline. It is useful
* for introspection and for preparing arguments for the Manual API.
*
* @param[in] signature The signature string to parse.
* @param[out] out_arena On success, receives a pointer to an arena holding all parsed types. The caller owns this and
* must free it with `infix_arena_destroy`.
* @param[out] out_ret_type On success, receives a pointer to the return type.
* @param[out] out_args On success, receives a pointer to the array of `infix_function_argument` structs.
* @param[out] out_num_args On success, receives the total number of arguments.
* @param[out] out_num_fixed_args On success, receives the number of fixed (non-variadic) arguments.
* @param[in] registry An optional type registry.
* @return `INFIX_SUCCESS` on success.
*/
INFIX_API INFIX_NODISCARD infix_status infix_signature_parse(
const char *, infix_arena_t **, infix_type **, infix_function_argument **, size_t *, size_t *, infix_registry_t *);
/**
* @brief Parses a signature string representing a single data type.
*
* This is the core function for introspection, allowing you to get a detailed,
* fully resolved memory layout for any C type described by a signature.
*
* @param[out] out_type On success, receives a pointer to the parsed type object.
* @param[out] out_arena On success, receives a pointer to the arena holding the type. The caller must free this with
* `infix_arena_destroy`.
* @param[in] signature The signature string of the data type (e.g., `"{id:int, name:*char}"`).
* @param[in] registry An optional type registry for resolving named types.
* @return `INFIX_SUCCESS` on success.
*/
INFIX_API INFIX_NODISCARD infix_status infix_type_from_signature(infix_type **,
infix_arena_t **,
const char *,
infix_registry_t *);
/** @} */ // end of high_level_api group
/**
* @defgroup exports_api Dynamic Library & Globals API
* @brief Cross-platform functions for loading shared libraries and accessing exported symbols.
* @{
*/
/**
* @brief Opens a dynamic library and returns a handle to it.
* @param[in] path The file path to the library (e.g., `./mylib.so`, `user32.dll`).
* @return A handle to the library, or `nullptr` on failure. The handle must be freed with `infix_library_close`.
*/
INFIX_API INFIX_NODISCARD infix_library_t * infix_library_open(const char *);
/**
* @brief Closes a dynamic library handle.
* @param[in] lib The library handle to close. Safe to call with `nullptr`.
*/
INFIX_API void infix_library_close(infix_library_t *);
/**
* @brief Retrieves the address of a symbol (function or variable) from a loaded library.
* @param[in] lib The library handle.
* @param[in] symbol_name The name of the symbol to look up.
* @return A pointer to the symbol's address, or `nullptr` if not found.
*/
INFIX_API INFIX_NODISCARD void * infix_library_get_symbol(infix_library_t *, const char *);
/**
* @brief Reads the value of a global variable from a library into a buffer.
*
* Uses the signature parser to determine the size of the variable to ensure the
* correct number of bytes are copied.
*
* @param[in] lib The library handle.
* @param[in] symbol_name The name of the global variable.
* @param[in] type_signature The `infix` signature string describing the variable's type.
* @param[out] buffer A pointer to the destination buffer to receive the data.
* @param[in] registry An optional registry for resolving named types in the signature.
* @return `INFIX_SUCCESS` on success, or an error code on failure.
*/
INFIX_API INFIX_NODISCARD infix_status
infix_read_global(infix_library_t *, const char *, const char *, void *, infix_registry_t *);
/**
* @brief Writes data from a buffer into a global variable in a library.
* @param[in] lib The library handle.
* @param[in] symbol_name The name of the global variable.
* @param[in] type_signature The `infix` signature string describing the variable's type.
* @param[in] buffer A pointer to the source buffer containing the data to write.
* @param[in] registry An optional registry for resolving named types in the signature.
* @return `INFIX_SUCCESS` on success, or an error code on failure.
*/
INFIX_API INFIX_NODISCARD infix_status
infix_write_global(infix_library_t *, const char *, const char *, void *, infix_registry_t *);
/** @} */ // end of exports_api group
/**
* @defgroup manual_api Manual API
* @brief A lower-level, programmatic API for creating trampolines from `infix_type` objects.
*
* This API is intended for performance-critical applications or language bindings that
* need to construct type information dynamically without the overhead of string parsing.
* All `infix_type` objects passed to these functions must be allocated from an `infix_arena_t`.
* @{
*/
/**
* @brief Creates a bound forward trampoline from `infix_type` objects.
* @param[out] out_trampoline Receives the created trampoline handle.
* @param[in] return_type The `infix_type` for the function's return value.
* @param[in] arg_types An array of `infix_type*` for the function's arguments.
* @param[in] num_args The number of arguments.
* @param[in] num_fixed_args The number of non-variadic arguments.
* @param[in] target_function The address of the C function to call.
* @return `INFIX_SUCCESS` on success.
*/
INFIX_API INFIX_NODISCARD infix_status
infix_forward_create_manual(infix_forward_t **, infix_type *, infix_type **, size_t, size_t, void *);
/**
* @brief Creates an unbound forward trampoline from `infix_type` objects.
* @param[out] out_trampoline Receives the created trampoline handle.
* @param[in] return_type The `infix_type` for the function's return value.
* @param[in] arg_types An array of `infix_type*` for the function's arguments.
* @param[in] num_args The number of arguments.
* @param[in] num_fixed_args The number of non-variadic arguments.
* @return `INFIX_SUCCESS` on success.
*/
INFIX_API INFIX_NODISCARD infix_status
infix_forward_create_unbound_manual(infix_forward_t **, infix_type *, infix_type **, size_t, size_t);
/**
* @brief Creates a type-safe reverse trampoline (callback) from `infix_type` objects.
* @param[out] out_context Receives the created context handle.
* @param[in] return_type The function's return type.
* @param[in] arg_types An array of argument types.
* @param[in] num_args The number of arguments.
* @param[in] num_fixed_args The number of non-variadic arguments.
* @param[in] user_callback_fn A pointer to the type-safe C handler function.
* @return `INFIX_SUCCESS` on success.
*/
INFIX_API INFIX_NODISCARD infix_status
infix_reverse_create_callback_manual(infix_reverse_t **, infix_type *, infix_type **, size_t, size_t, void *);
/**
* @brief Creates a generic reverse trampoline (closure) from `infix_type` objects.
* @param[out] out_context Receives the created context handle.
* @param[in] return_type The function's return type.
* @param[in] arg_types An array of argument types.
* @param[in] num_args The number of arguments.
* @param[in] num_fixed_args The number of non-variadic arguments.
* @param[in] user_callback_fn A pointer to the generic `infix_closure_handler_fn`.
* @param[in] user_data A `void*` pointer to application-specific state.
* @return `INFIX_SUCCESS` on success.
*/
INFIX_API INFIX_NODISCARD infix_status infix_reverse_create_closure_manual(
infix_reverse_t **, infix_type *, infix_type **, size_t, size_t, infix_closure_handler_fn, void *);
/**
* @brief Destroys a forward trampoline and frees all associated memory.
( run in 1.021 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )