infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
infix.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "common/compat_c23.h"
Include dependency graph for infix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  infix_type_t
 The central structure for describing any data type in the FFI system. More...
 
struct  infix_struct_member_t
 Describes a single member of an aggregate type (struct or union). More...
 
struct  infix_function_argument_t
 Describes a single argument to a function, pairing an optional name with its type. More...
 
struct  infix_error_details_t
 A structure holding detailed information about the last error that occurred on the current thread. More...
 

Macros

#define INFIX_MAJOR   0
 
#define INFIX_MINOR   1
 
#define INFIX_PATCH   0
 
#define _DEFAULT_SOURCE
 
#define _POSIX_C_SOURCE   200809L
 
#define infix_malloc   malloc
 A macro for the memory allocation function used by the library.
 
#define infix_calloc   calloc
 A macro for the zero-initializing memory allocation function.
 
#define infix_realloc   realloc
 A macro for the memory reallocation function.
 
#define infix_free   free
 A macro for the memory deallocation function.
 
#define infix_memcpy   memcpy
 A macro for copying memory from a source to a destination pointer.
 
#define infix_memset   memset
 A macro for setting a block of memory to a specific value.
 

Typedefs

typedef struct infix_type_t infix_type
 The central structure for describing any data type in the FFI system.
 
typedef struct infix_struct_member_t infix_struct_member
 Describes a single member of an aggregate type (struct or union).
 
typedef struct infix_function_argument_t infix_function_argument
 Describes a single argument of a function type, including its optional name.
 
typedef struct infix_forward_t infix_forward_t
 An opaque handle to a JIT-compiled forward-call trampoline.
 
typedef struct infix_reverse_t infix_reverse_t
 An opaque handle to the context of a reverse-call trampoline (callback).
 
typedef infix_reverse_t infix_context_t
 A clear alias for infix_reverse_t, intended for use in callback handler signatures.
 
typedef struct infix_arena_t infix_arena_t
 An opaque handle to a memory arena for fast, temporary allocations.
 
typedef struct infix_library_t infix_library_t
 An opaque handle to a shared library.
 
typedef struct infix_registry_t infix_registry_t
 An opaque handle to a named type registry.
 
typedef void(* infix_unbound_cif_func) (void *, void *, void **)
 The signature for a generic "unbound" forward-call trampoline.
 
typedef void(* infix_cif_func) (void *, void **)
 The signature for a "bound" forward-call trampoline.
 
typedef void(* infix_closure_handler_fn) (infix_context_t *context, void *return_value, void **args)
 The signature for a generic "closure" handler.
 

Enumerations

enum  infix_type_category {
  INFIX_TYPE_PRIMITIVE , INFIX_TYPE_POINTER , INFIX_TYPE_STRUCT , INFIX_TYPE_UNION ,
  INFIX_TYPE_ARRAY , INFIX_TYPE_REVERSE_TRAMPOLINE , INFIX_TYPE_ENUM , INFIX_TYPE_COMPLEX ,
  INFIX_TYPE_VECTOR , INFIX_TYPE_NAMED_REFERENCE , INFIX_TYPE_VOID
}
 Enumerates the fundamental categories of types supported by the FFI system. More...
 
enum  infix_primitive_type_id {
  INFIX_PRIMITIVE_BOOL , INFIX_PRIMITIVE_UINT8 , INFIX_PRIMITIVE_SINT8 , INFIX_PRIMITIVE_UINT16 ,
  INFIX_PRIMITIVE_SINT16 , INFIX_PRIMITIVE_UINT32 , INFIX_PRIMITIVE_SINT32 , INFIX_PRIMITIVE_UINT64 ,
  INFIX_PRIMITIVE_SINT64 , INFIX_PRIMITIVE_UINT128 , INFIX_PRIMITIVE_SINT128 , INFIX_PRIMITIVE_FLOAT ,
  INFIX_PRIMITIVE_DOUBLE , INFIX_PRIMITIVE_LONG_DOUBLE
}
 Enumerates the specific primitive C types supported by the FFI system. More...
 
enum  infix_aggregate_category_t { INFIX_AGGREGATE_STRUCT , INFIX_AGGREGATE_UNION }
 Distinguishes between struct and union for named references. More...
 
enum  infix_status {
  INFIX_SUCCESS = 0 , INFIX_ERROR_ALLOCATION_FAILED , INFIX_ERROR_INVALID_ARGUMENT , INFIX_ERROR_UNSUPPORTED_ABI ,
  INFIX_ERROR_LAYOUT_FAILED , INFIX_ERROR_PROTECTION_FAILED , INFIX_ERROR_
}
 An enumeration of all possible success or failure codes from the public API. More...
 
enum  infix_error_category_t {
  INFIX_CATEGORY_NONE , INFIX_CATEGORY_GENERAL , INFIX_CATEGORY_ALLOCATION , INFIX_CATEGORY_PARSER ,
  INFIX_CATEGORY_ABI
}
 Broad categories for errors that can occur in the library. More...
 
enum  infix_error_code_t {
  INFIX_CODE_SUCCESS = 0 , INFIX_CODE_UNKNOWN , INFIX_CODE_OUT_OF_MEMORY = 100 , INFIX_CODE_EXECUTABLE_MEMORY_FAILURE ,
  INFIX_CODE_PROTECTION_FAILURE , INFIX_CODE_UNEXPECTED_TOKEN = 200 , INFIX_CODE_UNTERMINATED_AGGREGATE , INFIX_CODE_INVALID_KEYWORD ,
  INFIX_CODE_MISSING_RETURN_TYPE , INFIX_CODE_INTEGER_OVERFLOW , INFIX_CODE_RECURSION_DEPTH_EXCEEDED , INFIX_CODE_EMPTY_MEMBER_NAME ,
  INFIX_CODE_UNSUPPORTED_ABI = 300 , INFIX_CODE_TYPE_TOO_LARGE , INFIX_CODE_UNRESOLVED_NAMED_TYPE , INFIX_CODE_INVALID_MEMBER_TYPE ,
  INFIX_CODE_LIBRARY_NOT_FOUND = 400 , INFIX_CODE_SYMBOL_NOT_FOUND , INFIX_CODE_LIBRARY_LOAD_FAILED
}
 Specific error codes providing detailed information about a failure. More...
 

Functions

c23_nodiscard infix_registry_tinfix_registry_create (void)
 Creates a new, empty type registry.
 
void infix_registry_destroy (infix_registry_t *registry)
 Frees a type registry and all type definitions and metadata contained within it.
 
c23_nodiscard infix_status infix_register_types (infix_registry_t *, const char *)
 Parses a string of definitions and populates a type registry.
 
c23_nodiscard infix_status infix_forward_create (infix_forward_t **, const char *, void *, infix_registry_t *)
 Generates a bound forward-call trampoline from a signature string.
 
c23_nodiscard infix_status infix_forward_create_unbound (infix_forward_t **, const char *, infix_registry_t *)
 Generates an unbound forward-call trampoline from a signature string.
 
c23_nodiscard infix_status infix_reverse_create_callback (infix_reverse_t **, const char *, void *, infix_registry_t *)
 Generates a type-safe reverse-call trampoline (callback) from a signature string.
 
c23_nodiscard infix_status infix_reverse_create_closure (infix_reverse_t **, const char *, infix_closure_handler_fn, void *, infix_registry_t *)
 Generates a low-level reverse-call trampoline (closure) from a signature string.
 
c23_nodiscard infix_status infix_signature_parse (const char *, infix_arena_t **, infix_type **, infix_function_argument **, size_t *, size_t *, infix_registry_t *)
 Parses a full function signature string into its constituent infix_type parts.
 
c23_nodiscard infix_status infix_type_from_signature (infix_type **, infix_arena_t **, const char *, infix_registry_t *)
 Parses a signature string representing a single data type.
 
c23_nodiscard infix_library_tinfix_library_open (const char *)
 Opens a dynamic library and returns a handle to it.
 
void infix_library_close (infix_library_t *)
 Closes a dynamic library handle and unloads it.
 
c23_nodiscard void * infix_library_get_symbol (infix_library_t *, const char *)
 Retrieves the memory address of a symbol (function or global variable).
 
infix_status infix_read_global (infix_library_t *, const char *, const char *, void *)
 Reads the value of a global variable from a loaded library.
 
infix_status infix_write_global (infix_library_t *, const char *, const char *, void *)
 Writes a value to a global variable in a loaded library.
 
c23_nodiscard infix_status infix_forward_create_manual (infix_forward_t **, infix_type *, infix_type **, size_t, size_t, void *)
 Generates a bound forward-call trampoline for a given function signature.
 
c23_nodiscard infix_status infix_forward_create_unbound_manual (infix_forward_t **, infix_type *, infix_type **, size_t, size_t)
 Generates an unbound forward-call trampoline for a given function signature.
 
c23_nodiscard infix_status infix_reverse_create_callback_manual (infix_reverse_t **, infix_type *, infix_type **, size_t, size_t, void *)
 Generates a type-safe reverse-call trampoline (callback) from infix_type objects.
 
c23_nodiscard infix_status infix_reverse_create_closure_manual (infix_reverse_t **, infix_type *, infix_type **, size_t, size_t, infix_closure_handler_fn, void *)
 Generates a generic reverse-call trampoline (closure) from infix_type objects.
 
void infix_forward_destroy (infix_forward_t *)
 Frees a forward trampoline and its associated executable memory.
 
void infix_reverse_destroy (infix_reverse_t *)
 Frees a reverse trampoline, its JIT-compiled stub, and its context.
 
c23_nodiscard infix_typeinfix_type_create_primitive (infix_primitive_type_id)
 Creates an infix_type descriptor for a primitive C type.
 
c23_nodiscard infix_typeinfix_type_create_pointer (void)
 Creates an infix_type descriptor for a generic void* pointer.
 
c23_nodiscard infix_status infix_type_create_pointer_to (infix_arena_t *, infix_type **, infix_type *)
 Creates an infix_type for a pointer to a specific type from an arena.
 
c23_nodiscard infix_typeinfix_type_create_void (void)
 Creates an infix_type descriptor for the void type.
 
c23_nodiscard infix_status infix_type_create_struct (infix_arena_t *, infix_type **, infix_struct_member *, size_t)
 Creates a new infix_type for a struct from an arena.
 
c23_nodiscard infix_status infix_type_create_packed_struct (infix_arena_t *, infix_type **, size_t, size_t, infix_struct_member *, size_t)
 Creates a new infix_type for a packed struct from an arena.
 
c23_nodiscard infix_status infix_type_create_union (infix_arena_t *, infix_type **, infix_struct_member *, size_t)
 Creates a new infix_type for a union from an arena.
 
c23_nodiscard infix_status infix_type_create_array (infix_arena_t *, infix_type **, infix_type *, size_t)
 Creates a new infix_type for a fixed-size array from an arena.
 
c23_nodiscard infix_status infix_type_create_enum (infix_arena_t *, infix_type **, infix_type *)
 Creates a new infix_type for an enum from an arena.
 
c23_nodiscard infix_status infix_type_create_named_reference (infix_arena_t *, infix_type **, const char *, infix_aggregate_category_t)
 Creates a new infix_type for a named reference from an arena.
 
c23_nodiscard infix_status infix_type_create_complex (infix_arena_t *, infix_type **, infix_type *)
 Creates a new infix_type for a _Complex number from an arena.
 
c23_nodiscard infix_status infix_type_create_vector (infix_arena_t *, infix_type **, infix_type *, size_t)
 Creates a new infix_type for a SIMD vector from an arena.
 
infix_struct_member infix_type_create_member (const char *, infix_type *, size_t)
 A factory function to create an infix_struct_member.
 
c23_nodiscard infix_arena_tinfix_arena_create (size_t)
 Creates and initializes a new memory arena.
 
void infix_arena_destroy (infix_arena_t *)
 Frees an entire memory arena and all objects allocated within it.
 
c23_nodiscard void * infix_arena_alloc (infix_arena_t *, size_t, size_t)
 Allocates a block of memory from the arena with a specific alignment.
 
c23_nodiscard void * infix_arena_calloc (infix_arena_t *, size_t, size_t, size_t)
 Allocates a zero-initialized block of memory from the arena.
 
infix_error_details_t infix_get_last_error (void)
 Retrieves detailed information about the last error that occurred on the current thread.
 
Type Serialization
c23_nodiscard infix_status infix_type_print (char *, size_t, const infix_type *, infix_print_dialect_t)
 Serializes an infix_type object graph into a string representation.
 
c23_nodiscard infix_status infix_function_print (char *, size_t, const char *, const infix_type *, const infix_function_argument *, size_t, size_t, infix_print_dialect_t)
 Serializes a full function signature into a string representation.
 
Trampoline Introspection
c23_nodiscard infix_unbound_cif_func infix_forward_get_unbound_code (infix_forward_t *)
 Retrieves the executable code pointer from an unbound forward trampoline.
 
c23_nodiscard infix_cif_func infix_forward_get_code (infix_forward_t *)
 Retrieves the executable code pointer from a bound forward trampoline.
 
c23_nodiscard void * infix_reverse_get_code (const infix_reverse_t *)
 Retrieves the executable code pointer from a reverse trampoline.
 
c23_nodiscard void * infix_reverse_get_user_data (const infix_reverse_t *)
 Retrieves the user_data stored with a reverse trampoline.
 
c23_nodiscard size_t infix_forward_get_num_args (const infix_forward_t *)
 Retrieves the number of arguments for a forward trampoline.
 
c23_nodiscard size_t infix_forward_get_num_fixed_args (const infix_forward_t *)
 Retrieves the number of fixed (non-variadic) arguments for a forward trampoline.
 
c23_nodiscard const infix_typeinfix_forward_get_return_type (const infix_forward_t *)
 Retrieves the return type for a forward trampoline.
 
c23_nodiscard const infix_typeinfix_forward_get_arg_type (const infix_forward_t *, size_t)
 Retrieves the type of a specific argument for a forward trampoline.
 
c23_nodiscard size_t infix_reverse_get_num_args (const infix_reverse_t *)
 Retrieves the number of arguments for a reverse trampoline.
 
c23_nodiscard const infix_typeinfix_reverse_get_return_type (const infix_reverse_t *)
 Retrieves the return type for a reverse trampoline.
 
c23_nodiscard size_t infix_reverse_get_num_fixed_args (const infix_reverse_t *)
 Retrieves the number of fixed (non-variadic) arguments for a reverse trampoline.
 
c23_nodiscard const infix_typeinfix_reverse_get_arg_type (const infix_reverse_t *, size_t)
 Retrieves the type of a specific argument for a reverse trampoline.
 

Type Introspection

enum  infix_print_dialect_t { INFIX_DIALECT_SIGNATURE , INFIX_DIALECT_ITANIUM_MANGLING , INFIX_DIALECT_MSVC_MANGLING }
 Specifies the output format for type-to-string serialization functions. More...
 
c23_nodiscard infix_type_category infix_type_get_category (const infix_type *)
 Retrieves the fundamental category of an infix_type.
 
c23_nodiscard size_t infix_type_get_size (const infix_type *)
 Retrieves the size of an infix_type in bytes.
 
c23_nodiscard size_t infix_type_get_alignment (const infix_type *)
 Retrieves the alignment requirement of an infix_type in bytes.
 
c23_nodiscard size_t infix_type_get_member_count (const infix_type *)
 Retrieves the number of members in an aggregate type (struct or union).
 
c23_nodiscard const infix_struct_memberinfix_type_get_member (const infix_type *, size_t)
 Retrieves a specific member from an aggregate type by its index.
 
c23_nodiscard const char * infix_type_get_arg_name (const infix_type *, size_t)
 Retrieves the name of a function argument by its index.
 
c23_nodiscard const infix_typeinfix_type_get_arg_type (const infix_type *, size_t)
 Retrieves the type of a function argument by its index.
 

Macro Definition Documentation

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L