42#define INITIAL_REGISTRY_BUCKETS 61
54 while ((c = *str++)) {
55 hash = ((hash << 5) + hash) + c;
68 if (!registry || !name)
78 if (strcmp(current->
name, name) == 0) {
81 current = current->
next;
108 size_t name_len = strlen(name) + 1;
115 new_entry->
name = name_copy;
116 new_entry->
type =
nullptr;
121 registry->
buckets[index] = new_entry;
142 if (!registry->
arena) {
192 while (isspace((
unsigned char)*state->
p))
194 if (*state->
p ==
'#') {
195 while (*state->
p !=
'\n' && *state->
p !=
'\0')
213 const char * name_start = state->
p;
214 while (isalnum((
unsigned char)*state->
p) || *state->
p ==
'_' || *state->
p ==
':') {
215 if (*state->
p ==
':' && state->
p[1] !=
':')
217 if (*state->
p ==
':')
221 size_t len = state->
p - name_start;
222 if (len == 0 || len >= buf_size)
235 if (!registry || !definitions) {
246 const char * def_body_start;
249 struct def_info defs_found[256];
250 size_t num_defs_found = 0;
255 while (*state.
p !=
'\0') {
257 if (*state.
p ==
'\0')
260 if (*state.
p !=
'@') {
266 char name_buffer[256];
275 if (*state.
p ==
'=') {
291 if (num_defs_found >= 256) {
295 defs_found[num_defs_found].entry = entry;
296 defs_found[num_defs_found].def_body_start = state.
p;
300 const char * body_end = state.
p;
301 while (*body_end !=
'\0' && !(*body_end ==
';' && nest_level == 0)) {
302 if (*body_end ==
'{' || *body_end ==
'<' || *body_end ==
'(' || *body_end ==
'[')
304 if (*body_end ==
'}' || *body_end ==
'>' || *body_end ==
')' || *body_end ==
']')
308 defs_found[num_defs_found].def_body_len = body_end - state.
p;
312 else if (*state.
p ==
';') {
336 for (
size_t i = 0; i < num_defs_found; ++i) {
340 char * body_copy =
infix_malloc(defs_found[i].def_body_len + 1);
343 infix_memcpy(body_copy, defs_found[i].def_body_start, defs_found[i].def_body_len);
344 body_copy[defs_found[i].def_body_len] =
'\0';
365 entry->
type = permanent_type;
371 for (
size_t i = 0; i < num_defs_found; ++i) {
399 if (!type_ptr || !*type_ptr)
409 if (!entry || !entry->
type) {
415 *type_ptr = entry->
type;
infix_status status
Definition 103_unions.c:74
#define c23_nodiscard
Definition compat_c23.h:93
@ INFIX_CODE_UNRESOLVED_NAMED_TYPE
The type graph that contains an unresolved named reference.
Definition infix.h:1078
@ INFIX_CODE_UNEXPECTED_TOKEN
Parser ran into an invalid character at a given position.
Definition infix.h:1066
@ INFIX_CODE_UNKNOWN
An unknown or unspecified error occurred. This is a fallback code.
Definition infix.h:1058
@ INFIX_CODE_RECURSION_DEPTH_EXCEEDED
The parser exceeded the max nesting depth (e.g., {{{{...}}}}).
Definition infix.h:1072
@ INFIX_CODE_OUT_OF_MEMORY
Failure to allocate memory. Likely due to lack of system resources.
Definition infix.h:1061
@ INFIX_CATEGORY_ALLOCATION
An error related to memory allocation.
Definition infix.h:1042
@ INFIX_CATEGORY_GENERAL
A general or miscellaneous error.
Definition infix.h:1041
@ INFIX_CATEGORY_PARSER
An error that occurred while parsing a signature string.
Definition infix.h:1043
#define infix_free
A macro for the memory deallocation function.
Definition infix.h:280
void infix_arena_destroy(infix_arena_t *)
Frees an entire memory arena and all objects allocated within it.
Definition arena.c:68
#define infix_memcpy
A macro for copying memory from a source to a destination pointer.
Definition infix.h:290
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.
Definition arena.c:129
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.
Definition arena.c:86
#define infix_malloc
A macro for the memory allocation function used by the library.
Definition infix.h:250
c23_nodiscard infix_arena_t * infix_arena_create(size_t)
Creates and initializes a new memory arena.
Definition arena.c:41
infix_status
An enumeration of all possible success or failure codes from the public API.
Definition infix.h:351
@ INFIX_ERROR_ALLOCATION_FAILED
A memory allocation request failed.
Definition infix.h:353
@ INFIX_SUCCESS
The operation completed successfully.
Definition infix.h:352
@ INFIX_ERROR_INVALID_ARGUMENT
An invalid argument was provided to a function.
Definition infix.h:354
void infix_registry_destroy(infix_registry_t *registry)
Implementation for the public infix_registry_destroy function.
Definition type_registry.c:166
c23_nodiscard infix_status infix_register_types(infix_registry_t *registry, const char *definitions)
Implementation of the public infix_register_types function.
Definition type_registry.c:233
c23_nodiscard infix_registry_t * infix_registry_create(void)
Implementation for the public infix_registry_create function.
Definition type_registry.c:131
@ INFIX_TYPE_UNION
A user-defined union (union).
Definition infix.h:118
@ INFIX_TYPE_ARRAY
A fixed-size array.
Definition infix.h:119
@ INFIX_TYPE_POINTER
A generic void* pointer type.
Definition infix.h:116
@ INFIX_TYPE_NAMED_REFERENCE
A reference to a named type (e.g., struct<Node>).
Definition infix.h:124
@ INFIX_TYPE_REVERSE_TRAMPOLINE
A callback wrapper.
Definition infix.h:120
@ INFIX_TYPE_STRUCT
A user-defined structure (struct).
Definition infix.h:117
Declarations for internal-only functions, types, and constants.
void _infix_set_error(infix_error_category_t, infix_error_code_t, size_t)
Sets the thread-local error details for a library-internal error.
Definition error.c:44
c23_nodiscard infix_status _infix_parse_type_internal(infix_type **, infix_arena_t **, const char *, infix_registry_t *)
The core, non-resolving entry point for the signature parser.
Definition signature.c:1040
infix_type * _copy_type_graph_to_arena(infix_arena_t *, const infix_type *)
Performs a deep copy of a type graph from one arena to another.
Definition types.c:610
void _infix_clear_error(void)
Resets the thread-local error state. Called at the start of every public API function.
Definition error.c:76
Definition infix_internals.h:144
bool is_forward_declaration
Definition infix_internals.h:147
const char * name
Definition infix_internals.h:145
infix_type * type
Definition infix_internals.h:146
struct _infix_registry_entry_t * next
Definition infix_internals.h:148
Definition type_registry.c:183
infix_registry_t * registry
Definition type_registry.c:186
const char * start
Definition type_registry.c:185
const char * p
Definition type_registry.c:184
Definition infix_internals.h:130
infix_type * type
An infix_type describing the argument's type.
Definition infix.h:231
Definition infix_internals.h:158
size_t num_items
Definition infix_internals.h:161
infix_arena_t * arena
Definition infix_internals.h:159
_infix_registry_entry_t ** buckets
Definition infix_internals.h:162
size_t num_buckets
Definition infix_internals.h:160
infix_type * type
An infix_type describing the member's type.
Definition infix.h:221
The central structure for describing any data type in the FFI system.
Definition infix.h:161
struct infix_type_t::@0::@1 pointer_info
For INFIX_TYPE_POINTER.
union infix_type_t::@0 meta
Type-specific metadata.
struct infix_type_t::@0::@4 func_ptr_info
For INFIX_TYPE_REVERSE_TRAMPOLINE.
infix_struct_member * members
Array of members for the aggregate.
Definition infix.h:177
const char * name
Optional name of the aggregate.
Definition infix.h:176
infix_function_argument * args
Array of function arguments (name and type).
Definition infix.h:188
infix_type_category category
The fundamental category of the type.
Definition infix.h:162
struct infix_type_t::@0::@2 aggregate_info
For INFIX_TYPE_STRUCT and INFIX_TYPE_UNION.
struct infix_type_t::@0::@3 array_info
For INFIX_TYPE_ARRAY.
struct infix_type_t * pointee_type
The type this pointer points to.
Definition infix.h:172
struct infix_type_t * element_type
The type of elements in the array.
Definition infix.h:182
struct infix_type_t * return_type
Reverse trampoline return value.
Definition infix.h:187
size_t num_members
Number of members in the aggregate.
Definition infix.h:178
struct infix_type_t::@0::@8 named_reference
For INFIX_TYPE_NAMED_REFERENCE. This is an internal placeholder for a named type like @Point.
size_t num_args
The total number of fixed and variadic arguments.
Definition infix.h:189
static uint64_t _registry_hash_string(const char *str)
Definition type_registry.c:51
#define INITIAL_REGISTRY_BUCKETS
Definition type_registry.c:42
static _infix_registry_entry_t * _registry_lookup(infix_registry_t *registry, const char *name)
Definition type_registry.c:67
static _infix_registry_entry_t * _registry_insert(infix_registry_t *registry, const char *name)
Definition type_registry.c:96
static char * _registry_parser_parse_name(_registry_parser_state_t *state, char *buffer, size_t buf_size)
Definition type_registry.c:211
static void _registry_parser_skip_whitespace(_registry_parser_state_t *state)
Definition type_registry.c:190
c23_nodiscard infix_status _infix_resolve_type_graph(infix_type **type_ptr, infix_registry_t *registry)
Walks a type graph, replacing all @Name placeholders with their concrete definitions from a registry.
Definition type_registry.c:398