47#if defined(INFIX_OS_OPENBSD)
51#elif defined(INFIX_COMPILER_MSVC)
53#define INFIX_TLS __declspec(thread)
54#elif defined(INFIX_OS_WINDOWS) && defined(INFIX_COMPILER_CLANG)
57#define INFIX_TLS __declspec(thread)
58#elif defined(INFIX_COMPILER_GCC)
61#define INFIX_TLS __thread
62#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
64#define INFIX_TLS _Thread_local
67#warning "Compiler does not support thread-local storage; error handling will not be thread-safe."
72#if defined(INFIX_COMPILER_MSVC)
73#define _INFIX_SAFE_STRNCPY(dest, src, count) strncpy_s(dest, sizeof(dest), src, count)
75#define _INFIX_SAFE_STRNCPY(dest, src, count) \
77 strncpy(dest, src, (count)); \
78 (dest)[(sizeof(dest)) - 1] = '\0'; \
112 return "An unknown error occurred";
114 return "A required pointer argument was NULL";
116 return "A type registry was required but not provided";
118 return "A native exception was thrown across the FFI boundary";
120 return "Out of memory";
122 return "Failed to allocate executable memory";
124 return "Failed to change memory protection flags";
126 return "Invalid alignment requested (must be power of two > 0)";
128 return "Unexpected token or character";
130 return "Unterminated aggregate (missing '}', '>', ']', or ')')'";
132 return "Invalid type keyword";
134 return "Function signature missing '->' or return type";
136 return "Integer overflow detected during layout calculation";
138 return "Type definition is too deeply nested";
140 return "Named type was declared with empty angle brackets";
142 return "The provided signature string was empty";
144 return "The current platform ABI is not supported";
146 return "A data type was too large to be handled by the ABI";
148 return "Named type not found in registry or is an undefined forward declaration";
150 return "Aggregate contains an illegal member type (e.g., a struct with a void member)";
152 return "The requested dynamic library could not be found";
154 return "The requested symbol was not found in the library";
156 return "Loading the dynamic library failed";
158 return "An unknown or unspecified error occurred";
184 size_t sig_len = strlen(signature);
185 const size_t radius = 20;
187 size_t start = (position > radius) ? (position - radius) : 0;
188 size_t end = (position + radius < sig_len) ? (position + radius) : sig_len;
190 const char * start_indicator = (
start > 0) ?
"... " :
"";
191 const char * end_indicator = (
end < sig_len) ?
" ..." :
"";
192 size_t start_indicator_len = (
start > 0) ? 4 : 0;
204 size_t caret_pos = position -
start + start_indicator_len;
205 snprintf(pointer,
sizeof(pointer),
"%*s^", (
int)caret_pos,
"");
211 written = snprintf(
p, remaining,
"\n\n %s\n %s", snippet, pointer);
212 if (written < 0 || (
size_t)written >= remaining) {
219 remaining -= written;
clock_t start
Definition 901_call_overhead.c:48
clock_t end
Definition 901_call_overhead.c:48
char * p
Definition 904_registry_benchmark.c:25
static const char * _get_error_message_for_code(infix_error_code_t code)
Definition error.c:107
void _infix_set_error(infix_error_category_t category, infix_error_code_t code, size_t position)
Sets the thread-local error state with detailed information.
Definition error.c:175
INFIX_TLS const char * g_infix_last_signature_context
A thread-local pointer to the full signature string being parsed.
Definition error.c:99
void _infix_set_system_error(infix_error_category_t category, infix_error_code_t code, long system_code, const char *msg)
Sets the thread-local error state for a system-level error.
Definition error.c:244
#define _INFIX_SAFE_STRNCPY(dest, src, count)
Definition error.c:75
void _infix_clear_error(void)
Clears the thread-local error state.
Definition error.c:268
static INFIX_TLS infix_error_details_t g_infix_last_error
The thread-local variable that stores the details of the last error.
Definition error.c:89
#define INFIX_TLS
Definition error.c:68
INFIX_API infix_error_details_t infix_get_last_error(void)
Retrieves detailed information about the last error that occurred on the current thread.
Definition error.c:281
infix_error_code_t
Enumerates specific error codes.
Definition infix.h:1360
infix_error_category_t
Enumerates the high-level categories of errors that can occur.
Definition infix.h:1350
@ INFIX_CODE_PROTECTION_FAILURE
Definition infix.h:1371
@ INFIX_CODE_SUCCESS
Definition infix.h:1362
@ INFIX_CODE_LIBRARY_NOT_FOUND
Definition infix.h:1392
@ INFIX_CODE_INVALID_MEMBER_TYPE
Definition infix.h:1388
@ INFIX_CODE_MISSING_REGISTRY
Definition infix.h:1365
@ INFIX_CODE_UNRESOLVED_NAMED_TYPE
Definition infix.h:1387
@ INFIX_CODE_INVALID_ALIGNMENT
Definition infix.h:1372
@ INFIX_CODE_INTEGER_OVERFLOW
Definition infix.h:1379
@ INFIX_CODE_TYPE_TOO_LARGE
Definition infix.h:1386
@ INFIX_CODE_EMPTY_SIGNATURE
Definition infix.h:1382
@ INFIX_CODE_UNEXPECTED_TOKEN
Definition infix.h:1375
@ INFIX_CODE_MISSING_RETURN_TYPE
Definition infix.h:1378
@ INFIX_CODE_EMPTY_MEMBER_NAME
Definition infix.h:1381
@ INFIX_CODE_EXECUTABLE_MEMORY_FAILURE
Definition infix.h:1370
@ INFIX_CODE_UNKNOWN
Definition infix.h:1363
@ INFIX_CODE_SYMBOL_NOT_FOUND
Definition infix.h:1393
@ INFIX_CODE_RECURSION_DEPTH_EXCEEDED
Definition infix.h:1380
@ INFIX_CODE_UNSUPPORTED_ABI
Definition infix.h:1385
@ INFIX_CODE_UNTERMINATED_AGGREGATE
Definition infix.h:1376
@ INFIX_CODE_LIBRARY_LOAD_FAILED
Definition infix.h:1394
@ INFIX_CODE_NATIVE_EXCEPTION
Definition infix.h:1366
@ INFIX_CODE_NULL_POINTER
Definition infix.h:1364
@ INFIX_CODE_INVALID_KEYWORD
Definition infix.h:1377
@ INFIX_CODE_OUT_OF_MEMORY
Definition infix.h:1369
@ INFIX_CATEGORY_PARSER
Definition infix.h:1354
@ INFIX_CATEGORY_NONE
Definition infix.h:1351
size_t position
Definition infix.h:1403
infix_error_category_t category
Definition infix.h:1401
char message[256]
Definition infix.h:1405
long system_error_code
Definition infix.h:1404
infix_error_code_t code
Definition infix.h:1402
#define INFIX_API
Symbol visibility macro.
Definition infix.h:114
The public interface for the infix FFI library.
Internal data structures, function prototypes, and constants.
Provides detailed, thread-local information about the last error that occurred.
Definition infix.h:1400