diff --git a/flake.nix b/flake.nix index f93c33e..4830232 100644 --- a/flake.nix +++ b/flake.nix @@ -297,6 +297,8 @@ ''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICrbBG+U07f7OKvOxYIGYCaNvyozzxQF+I9Fb5TYZErK yukkop vm-postgres'' ]; + + services.postgresql = let package = pkgs.postgresql_15; @@ -318,12 +320,16 @@ initialScript = pkgs.writeText "init-sql-script" '' CREATE EXTENSION "hemar"; - SELECT hemar.parse('{% zalupa %}'); - SELECT hemar.parse('{% zalupa %}'); + -- SELECT hemar.parse('{% zalupa %}'); + -- SELECT hemar.parse('{% zalupa %}'); + -- SELECT hemar.parse('zalupa {% her %} davalka')::JSON; + -- SELECT hemar.parse('zalupa {% her %} davalka')::JSON; + -- SELECT hemar.parse('zalupa {% her %} davalka')::JSON; + -- SELECT hemar.parse('zalupa {% her %} davalka')::JSON; ''; }; - environment.systemPackages = with pkgs; [ ]; + environment.systemPackages = with pkgs; [ gdb ]; programs.zsh.shellAliases = self.lib.sharedShellAliases // { conn = "sudo su postgres -c 'psql -p 64317'"; check = "journalctl -u postgresql"; diff --git a/package/c/hectic/hectic.c b/package/c/hectic/hectic.c index 7ee893c..e2b321c 100644 --- a/package/c/hectic/hectic.c +++ b/package/c/hectic/hectic.c @@ -139,7 +139,7 @@ void set_output_color_mode(ColorMode mode) { const char* mode_name = color_mode_to_string(mode); // Using fprintf since this might be called before logging is initialized - raise_message(LOG_LEVEL_INFO, __FILE__, __func__, __LINE__, "CONFIG: Setting output color mode to %s", mode_name); + raise_info__(__FILE__, __func__, __LINE__, "CONFIG: Setting output color mode to %s", mode_name); // Set the mode color_mode = mode; @@ -322,7 +322,7 @@ void logger_free(void) { log_rules = NULL; if (log_rules_arena) { arena_free__(__FILE__, __func__, __LINE__, log_rules_arena); - free(log_rules_arena); + arena_memory_free(log_rules_arena); log_rules_arena = NULL; } @@ -334,7 +334,7 @@ void logger_free(void) { // Free log file path if allocated if (log_file_path != NULL) { - free(log_file_path); + arena_memory_free(log_file_path); log_file_path = NULL; } @@ -421,8 +421,8 @@ char* raise_message( // ----------- PtrSet *ptrset_init__(POSITION_INFO_DECLARATION, Arena *arena) { - PtrSet *set = arena_alloc__(POSITION_INFO, arena, sizeof(PtrSet)); - set->data = arena_alloc__(POSITION_INFO, arena, 4 * sizeof(struct { void const *ptr; const char *type; const char *field_name; })); + PtrSet *set = arena_alloc__(file, func, line, arena, sizeof(PtrSet)); + set->data = arena_alloc__(file, func, line, arena, 4 * sizeof(struct { void const *ptr; const char *type; const char *field_name; })); set->size = 0; set->capacity = 4; return set; @@ -524,7 +524,7 @@ char *char_to_debug_str__(CTX_DECLARATION, const char *name, char c) { char *union_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *type, const char *name, const void *ptr, size_t active_variant, size_t count, ...) { if (count % 2 == 0) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "HECTICLIB ERROR: Union to debug str: count is even"); + raise_exception__(file, func, line, "HECTICLIB ERROR: Union to debug str: count is even"); assert(0); } @@ -572,16 +572,16 @@ char *union_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char * /* Private function */ char *debug_join_debug_strings_v(CTX_DECLARATION, int count, va_list args) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "DEBUG JOIN: Joining %d strings", count); + raise_trace__(file, func, line, "DEBUG JOIN: Joining %d strings", count); int total_len = 1; va_list args_copy; va_copy(args_copy, args); - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "DEBUG JOIN: Starting first pass"); + raise_trace__(file, func, line, "DEBUG JOIN: Starting first pass"); for (int i = 0; i < count; i++) { char *s = va_arg(args_copy, char*); int len = strlen(s); - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "DEBUG JOIN: String %d: [%s] %p len: %d", i, s, s, len); + raise_trace__(file, func, line, "DEBUG JOIN: String %d: [%s] %p len: %d", i, s, s, len); total_len += len; } va_end(args_copy); @@ -589,7 +589,7 @@ char *debug_join_debug_strings_v(CTX_DECLARATION, int count, va_list args) { char *joined = arena_alloc__(CTX(arena), total_len); joined[0] = '\0'; - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "DEBUG JOIN: concatenating strings"); + raise_trace__(file, func, line, "DEBUG JOIN: concatenating strings"); va_copy(args_copy, args); for (int i = 0; i < count; i++) { char *s = va_arg(args_copy, char*); @@ -604,7 +604,7 @@ char *debug_join_debug_strings_v(CTX_DECLARATION, int count, va_list args) { } char *struct_to_debug_str__(CTX_DECLARATION, const char *type, const char *name, const void *ptr, int count, ...) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "DEBUG STR: type: %s, name: %s, ptr: %p, count: %d", type, name, ptr, count); + raise_trace__(file, func, line, "DEBUG STR: type: %s, name: %s, ptr: %p, count: %d", type, name, ptr, count); va_list args; va_start(args, count); @@ -617,7 +617,7 @@ char *struct_to_debug_str__(CTX_DECLARATION, const char *type, const char *name, char *debug_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *s) { int indent = 0; size_t len = strlen(s) * 3; // Estimate for extra spaces, newlines, and indents - char *result = arena_alloc__(POSITION_INFO, arena, len); + char *result = arena_alloc__(file, func, line, arena, len); char *current = result; size_t remaining = len; @@ -676,7 +676,7 @@ char *debug_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const char if (remaining < 20) { size_t used = current - result; size_t new_len = len * 2; - result = arena_realloc__(POSITION_INFO, arena, result, len, new_len); + result = arena_realloc__(file, func, line, arena, result, len, new_len); current = result + used; remaining = new_len - used; len = new_len; @@ -701,7 +701,7 @@ char *debug_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const char Arena arena_init__(POSITION_INFO_DECLARATION, size_t size) { // Function entry logging - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA INIT: Creating arena (size: %zu bytes)", size); Arena arena; @@ -709,7 +709,7 @@ Arena arena_init__(POSITION_INFO_DECLARATION, size_t size) { // Check for allocation failure if (!arena.begin) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "ARENA INIT: Failed to allocate memory for arena (requested: %zu bytes)", size); exit(1); } @@ -719,19 +719,19 @@ Arena arena_init__(POSITION_INFO_DECLARATION, size_t size) { arena.capacity = size; // Success logging at LOG level - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "ARENA INIT: Arena initialized successfully (address: %p, capacity: %zu bytes)", arena.begin, size); return arena; } void* arena_alloc_or_null__(POSITION_INFO_DECLARATION, Arena *arena, size_t size, bool expand) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ARENA ALLOC: Requesting memory from arena (arena: %p, size: %zu bytes)", arena, size); if (arena->begin == 0) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA ALLOC: Arena not initialized, creating new arena"); - *arena = arena_init__(POSITION_INFO, 1024); + *arena = arena_init__(file, func, line, 1024); } // align size to 8 @@ -745,12 +745,12 @@ void* arena_alloc_or_null__(POSITION_INFO_DECLARATION, Arena *arena, size_t size // FIXME(yukkop): All pointers to the arena will be invalidated // We need to use a virtual memory allocator to avoid this issue size_t new_capacity = arena->capacity * 2 + size; - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA ALLOC: Expanding arena (old: %zu, new: %zu)", arena->capacity, new_capacity); void *new_mem = arena_memory_alloc(new_capacity); if (!new_mem) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA ALLOC: Failed to expand arena (requested: %zu bytes)", new_capacity); return NULL; } @@ -761,10 +761,10 @@ void* arena_alloc_or_null__(POSITION_INFO_DECLARATION, Arena *arena, size_t size arena->current = (char *)new_mem + used; arena->capacity = new_capacity; - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA ALLOC: Arena expanded successfully (address: %p, capacity: %zu)", new_mem, new_capacity); } else { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA ALLOC: Insufficient memory in arena (address: %p, capacity: %zu bytes, used: %zu bytes, requested: %zu bytes)", arena->begin, arena->capacity, used, size); return NULL; @@ -774,27 +774,27 @@ void* arena_alloc_or_null__(POSITION_INFO_DECLARATION, Arena *arena, size_t size void *mem = arena->current; arena->current = (char*)arena->current + size; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA ALLOC: Memory allocated (address: %p, size: %zu)", mem, size); return mem; } void* arena_alloc__(POSITION_INFO_DECLARATION, Arena *arena, size_t size) { // Function entry logging - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA ALLOC: Allocating memory (arena: %p, size: %zu bytes)", arena, size); - void *mem = arena_alloc_or_null__(POSITION_INFO, arena, size, false); + void *mem = arena_alloc_or_null__(file, func, line, arena, size, false); if (!mem) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA ALLOC: Allocation failed (arena: %p, requested: %zu bytes)", arena, size); - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "ARENA ALLOC: Arena out of memory (requested: %zu bytes)", size); exit(1); } // Success logging - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "ARENA ALLOC: Memory allocated successfully (address: %p, size: %zu bytes)", mem, size); return mem; } @@ -807,12 +807,12 @@ void* arena_realloc__(POSITION_INFO_DECLARATION, Arena *arena, void *ptr, size_t size, size_t new_size) { void *new_ptr = NULL; if (ptr == NULL) { - new_ptr = arena_alloc__(POSITION_INFO, arena, new_size); + new_ptr = arena_alloc__(file, func, line, arena, new_size); } else if (new_size <= size) { new_ptr = ptr; } else { // FIXME(yukkop): Must tries to expand the arena before allocating new memory - new_ptr = arena_alloc_or_null__(POSITION_INFO, arena, new_size, false); + new_ptr = arena_alloc_or_null__(file, func, line, arena, new_size, false); if (new_ptr) memcpy(new_ptr, ptr, size); } @@ -821,12 +821,12 @@ void* arena_realloc__(POSITION_INFO_DECLARATION, Arena *arena, void arena_reset__(POSITION_INFO_DECLARATION, Arena *arena) { // Function entry logging - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA RESET: Resetting arena (address: %p)", arena); // Check for NULL arena if (!arena) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA RESET: Attempted to reset NULL arena"); return; } @@ -835,26 +835,26 @@ void arena_reset__(POSITION_INFO_DECLARATION, Arena *arena) { arena->current = arena->begin; // Operation success logging - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "ARENA RESET: Arena reset successfully (address: %p, capacity: %zu bytes)", arena->begin, arena->capacity); } void arena_free__(POSITION_INFO_DECLARATION, Arena *arena) { // Function entry logging - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA FREE: Releasing arena memory (address: %p)", arena); // Check for NULL arena if (!arena) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA FREE: Attempted to free NULL arena"); return; } // Check for NULL begin pointer if (!arena->begin) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA FREE: Attempted to free arena with NULL memory block"); return; } @@ -866,7 +866,7 @@ void arena_free__(POSITION_INFO_DECLARATION, Arena *arena) { arena_memory_free(arena->begin); // Success logging - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "ARENA FREE: Arena released successfully (address: %p, capacity: %zu bytes, used: %zu bytes)", arena->begin, arena->capacity, used); @@ -881,13 +881,13 @@ void arena_free__(POSITION_INFO_DECLARATION, Arena *arena) { */ char* arena_strdup__(POSITION_INFO_DECLARATION, Arena *arena, const char *s) { // Function entry logging - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ARENA STRDUP: Duplicating string (arena: %p, source: %p, preview: %.20s%s)", arena, s, s ? s : "", s && strlen(s) > 20 ? "..." : ""); // Check for NULL string if (!s) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA STRDUP: Source string is NULL, returning NULL"); return NULL; } @@ -896,13 +896,13 @@ char* arena_strdup__(POSITION_INFO_DECLARATION, Arena *arena, const char *s) { size_t len = strlen(s) + 1; // Success case - char *result = (char*)arena_alloc__(POSITION_INFO, arena, len); + char *result = (char*)arena_alloc__(file, func, line, arena, len); // Copy the string memcpy(result, s, len); // Success logging - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA STRDUP: String duplicated successfully (result: %p, length: %zu bytes)", result, len); @@ -921,31 +921,31 @@ char* arena_strdup_fmt__(POSITION_INFO_DECLARATION, Arena *arena, const char *fm if (len < 0) return NULL; - char *temp = arena_alloc__(POSITION_INFO, DISPOSABLE_ARENA, len + 1); + char *temp = arena_alloc__(file, func, line, DISPOSABLE_ARENA, len + 1); va_start(args, fmt); vsnprintf(temp, len + 1, fmt, args); va_end(args); - return arena_strdup__(POSITION_INFO, arena, temp); + return arena_strdup__(file, func, line, arena, temp); } char* arena_strncpy__(POSITION_INFO_DECLARATION, Arena *arena, const char *start, size_t len) { // Function entry logging - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ARENA STRNCPY: Copying string (arena: %p, source: %p, length: %zu, preview: %.20s%s)", arena, start, len, start ? start : "", start && strlen(start) > 20 ? "..." : ""); // Check for NULL string if (!start) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA STRNCPY: Source string is NULL, returning NULL"); return NULL; } // Allocate memory for the string plus null terminator - char *result = (char*)arena_alloc__(POSITION_INFO, arena, len + 1); + char *result = (char*)arena_alloc__(file, func, line, arena, len + 1); if (!result) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA STRNCPY: Memory allocation failed"); return NULL; } @@ -955,7 +955,7 @@ char* arena_strncpy__(POSITION_INFO_DECLARATION, Arena *arena, const char *start result[len] = '\0'; // Success logging - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA STRNCPY: String copied successfully (result: %p, length: %zu bytes)", result, len + 1); @@ -968,19 +968,19 @@ char* arena_strncpy__(POSITION_INFO_DECLARATION, Arena *arena, const char *start char* arena_repstr__(POSITION_INFO_DECLARATION, Arena *arena, const char *src, size_t start, size_t len, const char *rep) { // Function entry logging - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ARENA REPSTR: Replacing substring (source: %p, start: %zu, length: %zu, replacement: %.20s%s)", src, start, len, rep, strlen(rep) > 20 ? "..." : ""); // Check inputs if (!src) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA REPSTR: Source string is NULL"); return NULL; } if (!rep) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA REPSTR: Replacement string is NULL"); return NULL; } @@ -991,22 +991,22 @@ char* arena_repstr__(POSITION_INFO_DECLARATION, Arena *arena, // Validate start and length if (start > (size_t)src_len) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ARENA REPSTR: Start position %zu exceeds source length %d", start, src_len); // Return a copy of the source string - return arena_strdup__(POSITION_INFO, arena, src); + return arena_strdup__(file, func, line, arena, src); } if (start + len > (size_t)src_len) { size_t old_len = len; len = src_len - start; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA REPSTR: Adjusted length from %zu to %zu to fit source bounds", old_len, len); } // Calculate new length and allocate memory int new_len = src_len - (int)len + rep_len; - char *new_str = (char*)arena_alloc__(POSITION_INFO, arena, new_len + 1); + char *new_str = (char*)arena_alloc__(file, func, line, arena, new_len + 1); // Perform the replacement operation memcpy(new_str, src, start); @@ -1014,7 +1014,7 @@ char* arena_repstr__(POSITION_INFO_DECLARATION, Arena *arena, strcpy(new_str + start + rep_len, src + start + len); // Success logging - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ARENA REPSTR: Replacement complete (result: %p, new length: %d)", new_str, new_len); return new_str; @@ -1026,12 +1026,12 @@ char* arena_repstr__(POSITION_INFO_DECLARATION, Arena *arena, void substr_clone__(POSITION_INFO_DECLARATION, const char * const src, char *dest, size_t from, size_t len) { // Log function entry at TRACE level - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "Function called with src=%p, dest=%p, from=%zu, len=%zu", src, dest, from, len); if (!src || !dest) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "Invalid NULL pointer: %s%s", (!src ? "src " : ""), (!dest ? "dest" : "")); @@ -1042,7 +1042,7 @@ void substr_clone__(POSITION_INFO_DECLARATION, const char * const src, char *des size_t srclen = strlen(src); if (from >= srclen) { // Log warning with context when 'from' is out of range - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "Out of range: 'from' index (%zu) exceeds source length (%zu)", from, srclen); dest[0] = '\0'; @@ -1053,7 +1053,7 @@ void substr_clone__(POSITION_INFO_DECLARATION, const char * const src, char *des if (from + len > srclen) { size_t old_len = len; len = srclen - from; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "Adjusted length from %zu to %zu to fit source bounds", old_len, len); } @@ -1063,7 +1063,7 @@ void substr_clone__(POSITION_INFO_DECLARATION, const char * const src, char *des dest[len] = '\0'; // Log success at TRACE level - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "Successfully copied %zu bytes: \"%.*s\"", len, (int)len, dest); } @@ -1073,25 +1073,25 @@ void substr_clone__(POSITION_INFO_DECLARATION, const char * const src, char *des // ---------- char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * const item, int indent_level) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "PRETTY: Starting JSON prettification (item: %p, indent: %d)", item, indent_level); if (!item) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "PRETTY: Invalid JSON object (NULL) provided for prettification"); return NULL; } if (!arena) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "PRETTY: Invalid arena (NULL) provided for prettification"); return NULL; } - char *out = arena_alloc__(POSITION_INFO, arena, 1024); + char *out = arena_alloc__(file, func, line, arena, 1024); if (!out) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "PRETTY: Memory allocation failed during JSON prettification"); return NULL; } @@ -1104,7 +1104,7 @@ char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * Json *child = item->value.child; int child_count = 0; - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "PRETTY: Processing JSON object children"); while (child) { @@ -1113,11 +1113,11 @@ char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * } ptr += sprintf(ptr, "\"%s\": ", child->key ? child->key : ""); - char *child_str = json_to_pretty_str__(POSITION_INFO, arena, child, indent_level + 1); + char *child_str = json_to_pretty_str__(file, func, line, arena, child, indent_level + 1); if (child_str) { ptr += sprintf(ptr, "%s", child_str); } else { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "PRETTY: Failed to prettify child element (key=%s)", child->key ? child->key : ""); } @@ -1135,7 +1135,7 @@ char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * ptr += sprintf(ptr, " "); } sprintf(ptr, "}"); - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "PRETTY: Object prettification complete with %d child elements", child_count); } else if (item->type == JSON_ARRAY) { ptr += sprintf(ptr, "[\n"); @@ -1143,7 +1143,7 @@ char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * Json *child = item->value.child; int child_count = 0; - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "PRETTY: Processing JSON array elements"); while (child) { @@ -1152,11 +1152,11 @@ char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * ptr += sprintf(ptr, " "); } - char *child_str = json_to_pretty_str__(POSITION_INFO, arena, child, indent_level + 1); + char *child_str = json_to_pretty_str__(file, func, line, arena, child, indent_level + 1); if (child_str) { ptr += sprintf(ptr, "%s", child_str); } else { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "PRETTY: Failed to prettify array element at index %d", child_count); } @@ -1173,7 +1173,7 @@ char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * ptr += sprintf(ptr, " "); } sprintf(ptr, "]"); - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "PRETTY: Array prettification complete with %d elements", child_count); } else if (item->type == JSON_STRING) { sprintf(ptr, "\"%s\"", item->value.string ? item->value.string : ""); @@ -1185,7 +1185,7 @@ char *json_to_pretty_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * sprintf(ptr, "null"); } - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "PRETTY: JSON %s prettified (length=%zu)", json_type_to_string(item->type), strlen(out)); @@ -1209,9 +1209,9 @@ static Json *json_parse_value__(POSITION_INFO_DECLARATION, const char **s, Arena /* Parse a JSON string (does not handle full escaping) */ static char *json_parse_string__(POSITION_INFO_DECLARATION, const char **s_ptr, Arena *arena) { const char *s = *s_ptr; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Entering json_parse_string__ at position: %p", s); + raise_debug__(file, func, line, "Entering json_parse_string__ at position: %p", s); if (*s != '"') { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Expected '\"' at start of string, got: %c", *s); + raise_debug__(file, func, line, "Expected '\"' at start of string, got: %c", *s); return NULL; } s++; // skip opening quote @@ -1223,43 +1223,43 @@ static char *json_parse_string__(POSITION_INFO_DECLARATION, const char **s_ptr, s++; } if (*s != '"') { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Unterminated string starting at: %p", start); + raise_debug__(file, func, line, "Unterminated string starting at: %p", start); return NULL; } size_t len = s - start; - char *str = arena_alloc__(POSITION_INFO, arena, len + 1); + char *str = arena_alloc__(file, func, line, arena, len + 1); if (!str) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Memory allocation failed in json_parse_string__"); + raise_debug__(file, func, line, "Memory allocation failed in json_parse_string__"); return NULL; } memcpy(str, start, len); str[len] = '\0'; *s_ptr = s + 1; // skip closing quote - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Parsed string: \"%s\" (length: %zu)", str, len); + raise_debug__(file, func, line, "Parsed string: \"%s\" (length: %zu)", str, len); return str; } /* Parse a number using strtod */ static double json_parse_number__(POSITION_INFO_DECLARATION, const char **s_ptr) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Parsing number at position: %p", *s_ptr); + raise_debug__(file, func, line, "Parsing number at position: %p", *s_ptr); char *end; double num = strtod(*s_ptr, &end); if (*s_ptr == end) - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "No valid number found at: %p", *s_ptr); + raise_debug__(file, func, line, "No valid number found at: %p", *s_ptr); *s_ptr = end; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Parsed number: %g", num); + raise_debug__(file, func, line, "Parsed number: %g", num); return num; } /* Parse a JSON array: [ value, value, ... ] */ static Json *json_parse_array__(POSITION_INFO_DECLARATION, const char **s, Arena *arena) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Entering json_parse_array__ at position: %p", *s); + raise_debug__(file, func, line, "Entering json_parse_array__ at position: %p", *s); if (**s != '[') return NULL; (*s)++; // skip '[' *s = skip_whitespace(*s); - Json *array = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *array = arena_alloc__(file, func, line, arena, sizeof(Json)); if (!array) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Memory allocation failed in json_parse_array__"); + raise_debug__(file, func, line, "Memory allocation failed in json_parse_array__"); return NULL; } memset(array, 0, sizeof(Json)); @@ -1267,13 +1267,13 @@ static Json *json_parse_array__(POSITION_INFO_DECLARATION, const char **s, Arena Json *last = NULL; if (**s == ']') { // empty array (*s)++; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Parsed empty array"); + raise_debug__(file, func, line, "Parsed empty array"); return array; } while (**s) { - Json *element = json_parse_value__(POSITION_INFO, s, arena); + Json *element = json_parse_value__(file, func, line, s, arena); if (!element) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Failed to parse array element"); + raise_debug__(file, func, line, "Failed to parse array element"); return NULL; } if (!array->value.child) @@ -1287,26 +1287,26 @@ static Json *json_parse_array__(POSITION_INFO_DECLARATION, const char **s, Arena *s = skip_whitespace(*s); } else if (**s == ']') { (*s)++; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Completed parsing array"); + raise_debug__(file, func, line, "Completed parsing array"); break; } else { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Unexpected character '%c' in array", **s); + raise_debug__(file, func, line, "Unexpected character '%c' in array", **s); return NULL; } } - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Completed parsing array"); + raise_debug__(file, func, line, "Completed parsing array"); return array; } /* Parse a JSON object: { "key": value, ... } */ static Json *json_parse_object__(POSITION_INFO_DECLARATION, const char **s, Arena *arena) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Entering json_parse_object__ at position: %p", *s); + raise_debug__(file, func, line, "Entering json_parse_object__ at position: %p", *s); if (**s != '{') return NULL; (*s)++; // skip '{' *s = skip_whitespace(*s); - Json *object = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *object = arena_alloc__(file, func, line, arena, sizeof(Json)); if (!object) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Memory allocation failed in json_parse_object__"); + raise_debug__(file, func, line, "Memory allocation failed in json_parse_object__"); return NULL; } memset(object, 0, sizeof(Json)); @@ -1314,25 +1314,25 @@ static Json *json_parse_object__(POSITION_INFO_DECLARATION, const char **s, Aren Json *last = NULL; if (**s == '}') { (*s)++; - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Parsed empty object"); + raise_debug__(file, func, line, "Parsed empty object"); return object; } while (**s) { - char *key = json_parse_string__(POSITION_INFO, s, arena); + char *key = json_parse_string__(file, func, line, s, arena); if (!key) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Failed to parse key in object"); + raise_debug__(file, func, line, "Failed to parse key in object"); return NULL; } *s = skip_whitespace(*s); if (**s != ':') { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Expected ':' after key \"%s\", got: %c", key, **s); + raise_debug__(file, func, line, "Expected ':' after key \"%s\", got: %c", key, **s); return NULL; } (*s)++; // skip ':' *s = skip_whitespace(*s); - Json *value = json_parse_value__(POSITION_INFO, s, arena); + Json *value = json_parse_value__(file, func, line, s, arena); if (!value) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Failed to parse value for key \"%s\"", key); + raise_debug__(file, func, line, "Failed to parse value for key \"%s\"", key); return NULL; } value->key = key; // assign key to the value @@ -1349,37 +1349,37 @@ static Json *json_parse_object__(POSITION_INFO_DECLARATION, const char **s, Aren (*s)++; break; } else { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Unexpected character '%c' in object", **s); + raise_debug__(file, func, line, "Unexpected character '%c' in object", **s); return NULL; } } - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Completed parsing object"); + raise_debug__(file, func, line, "Completed parsing object"); return object; } /* Full JSON value parser */ static Json *json_parse_value__(POSITION_INFO_DECLARATION, const char **s, Arena *arena) { *s = skip_whitespace(*s); - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Parsing JSON value at position: %p", *s); + raise_debug__(file, func, line, "Parsing JSON value at position: %p", *s); if (**s == '"') { - Json *item = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *item = arena_alloc__(file, func, line, arena, sizeof(Json)); if (!item) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Memory allocation failed in json_parse_value for string"); + raise_debug__(file, func, line, "Memory allocation failed in json_parse_value for string"); return NULL; } memset(item, 0, sizeof(Json)); item->type = JSON_STRING; - item->value.string = json_parse_string__(POSITION_INFO, s, arena); + item->value.string = json_parse_string__(file, func, line, s, arena); return item; } else if (strncmp(*s, "null", 4) == 0) { - Json *item = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *item = arena_alloc__(file, func, line, arena, sizeof(Json)); if (!item) return NULL; memset(item, 0, sizeof(Json)); item->type = JSON_NULL; *s += 4; return item; } else if (strncmp(*s, "true", 4) == 0) { - Json *item = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *item = arena_alloc__(file, func, line, arena, sizeof(Json)); if (!item) return NULL; memset(item, 0, sizeof(Json)); item->type = JSON_BOOL; @@ -1387,7 +1387,7 @@ static Json *json_parse_value__(POSITION_INFO_DECLARATION, const char **s, Arena *s += 4; return item; } else if (strncmp(*s, "false", 5) == 0) { - Json *item = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *item = arena_alloc__(file, func, line, arena, sizeof(Json)); if (!item) return NULL; memset(item, 0, sizeof(Json)); item->type = JSON_BOOL; @@ -1395,57 +1395,57 @@ static Json *json_parse_value__(POSITION_INFO_DECLARATION, const char **s, Arena *s += 5; return item; } else if ((**s == '-') || isdigit((unsigned char)**s)) { - Json *item = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *item = arena_alloc__(file, func, line, arena, sizeof(Json)); if (!item) { - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Memory allocation failed in json_parse_value for number"); + raise_debug__(file, func, line, "Memory allocation failed in json_parse_value for number"); return NULL; } memset(item, 0, sizeof(Json)); item->type = JSON_NUMBER; - item->value.number = json_parse_number__(POSITION_INFO, s); + item->value.number = json_parse_number__(file, func, line, s); return item; } else if (**s == '[') { - return json_parse_array__(POSITION_INFO, s, arena); + return json_parse_array__(file, func, line, s, arena); } else if (**s == '{') { - return json_parse_object__(POSITION_INFO, s, arena); + return json_parse_object__(file, func, line, s, arena); } - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, "Unrecognized JSON value at position: %p", *s); + raise_debug__(file, func, line, "Unrecognized JSON value at position: %p", *s); return NULL; } // FIXME(yukkop): **s changes in the function. Need to fix. Json *json_parse__(POSITION_INFO_DECLARATION, Arena *arena, const char **s) { // Function entry logging with DEBUG level - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "PARSE: Starting JSON parsing (input: %p)", *s); // Check input parameters if (!s || !*s) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "PARSE: Invalid input parameters (NULL pointer provided for JSON parsing)"); return NULL; } if (!arena) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "PARSE: Invalid arena (NULL) provided for JSON parsing"); return NULL; } // Show input preview for debugging with TRACE level - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "PARSE: Input preview: '%.20s%s'", *s, strlen(*s) > 20 ? "..." : ""); // Process JSON value - Json *result = json_parse_value__(POSITION_INFO, s, arena); + Json *result = json_parse_value__(file, func, line, s, arena); // Log parsing result if (!result) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "PARSE: Failed to parse JSON at position %p (context: '%.10s')", *s, *s && strlen(*s) > 0 ? *s : ""); } else { - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "PARSE: JSON parsing completed successfully (type: %s)", json_type_to_string(result->type)); } @@ -1453,7 +1453,7 @@ Json *json_parse__(POSITION_INFO_DECLARATION, Arena *arena, const char **s) { } char *json_to_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * const item) { - return json_to_str_with_opts__(POSITION_INFO, arena, item, JSON_NORAW); + return json_to_str_with_opts__(file, func, line, arena, item, JSON_NORAW); } /* Minimal JSON printer with raw output option. @@ -1461,27 +1461,27 @@ char *json_to_str__(POSITION_INFO_DECLARATION, Arena *arena, const Json * const */ char *json_to_str_with_opts__(POSITION_INFO_DECLARATION, Arena *arena, const Json * const item, JsonRawOpt raw) { // Function entry with DEBUG level - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "FORMAT: Starting JSON conversion to string (item: %p, raw_mode: %s)", item, raw == JSON_RAW ? "enabled" : "disabled"); // Check input parameters if (!item) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "FORMAT: Invalid JSON object (NULL) provided for string conversion"); return NULL; } if (!arena) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "FORMAT: Invalid arena (NULL) provided for string conversion"); return NULL; } // Allocate memory for the string - char *out = arena_alloc__(POSITION_INFO, arena, 1024); + char *out = arena_alloc__(file, func, line, arena, 1024); if (!out) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, + raise_exception__(file, func, line, "FORMAT: Memory allocation failed during JSON string conversion"); return NULL; } @@ -1497,16 +1497,16 @@ char *json_to_str_with_opts__(POSITION_INFO_DECLARATION, Arena *arena, const Jso Json *child = item->value.child; int child_count = 0; - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "FORMAT: Processing JSON object children"); while (child) { ptr += sprintf(ptr, "\"%s\":", child->key ? child->key : ""); - char *child_str = json_to_str_with_opts__(POSITION_INFO, arena, child, raw); + char *child_str = json_to_str_with_opts__(file, func, line, arena, child, raw); if (child_str) { ptr += sprintf(ptr, "%s", child_str); } else { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "FORMAT: Failed to stringify child element (key=%s)", child->key ? child->key : ""); } @@ -1519,7 +1519,7 @@ char *json_to_str_with_opts__(POSITION_INFO_DECLARATION, Arena *arena, const Jso } sprintf(ptr, "}"); - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "FORMAT: Object conversion complete with %d child elements", child_count); } else if (item->type == JSON_ARRAY) { ptr += sprintf(ptr, "["); @@ -1528,15 +1528,15 @@ char *json_to_str_with_opts__(POSITION_INFO_DECLARATION, Arena *arena, const Jso Json *child = item->value.child; int child_count = 0; - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "FORMAT: Processing JSON array elements"); while (child) { - char *child_str = json_to_str_with_opts__(POSITION_INFO, arena, child, raw); + char *child_str = json_to_str_with_opts__(file, func, line, arena, child, raw); if (child_str) { ptr += sprintf(ptr, "%s", child_str); } else { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "FORMAT: Failed to stringify array element at index %d", child_count); } @@ -1548,7 +1548,7 @@ char *json_to_str_with_opts__(POSITION_INFO_DECLARATION, Arena *arena, const Jso } sprintf(ptr, "]"); - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "FORMAT: Array conversion complete with %d elements", child_count); } else if (item->type == JSON_STRING) { type_name = "string"; @@ -1568,7 +1568,7 @@ char *json_to_str_with_opts__(POSITION_INFO_DECLARATION, Arena *arena, const Jso sprintf(ptr, "null"); } - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "FORMAT: JSON %s converted to string (length=%zu)", type_name, strlen(out)); @@ -1577,25 +1577,25 @@ char *json_to_str_with_opts__(POSITION_INFO_DECLARATION, Arena *arena, const Jso /* Retrieve an object item by key (case-sensitive) */ Json *json_get_object_item__(POSITION_INFO_DECLARATION, const Json * const object, const char * const key) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ACCESS: Searching for key \"%s\" in JSON object %p", key ? key : "", object); // Check input parameters if (!object) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ACCESS: Invalid object (NULL) passed to json_get_object_item"); return NULL; } if (!key) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ACCESS: Invalid key (NULL) passed to json_get_object_item"); return NULL; } if (object->type != JSON_OBJECT) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "ACCESS: JSON value is not an object (actual type: %d)", object->type); return NULL; } @@ -1608,7 +1608,7 @@ Json *json_get_object_item__(POSITION_INFO_DECLARATION, const Json * const objec debug_scan = debug_scan->next; } - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ACCESS: Object has %d key-value pairs", total_keys); // Perform key search @@ -1617,18 +1617,18 @@ Json *json_get_object_item__(POSITION_INFO_DECLARATION, const Json * const objec while (child) { if (child->key) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ACCESS: Comparing key \"%s\" with \"%s\" at position %d", child->key, key, position); if (strcmp(child->key, key) == 0) { - raise_message(LOG_LEVEL_LOG, POSITION_INFO, + raise_log__(file, func, line, "ACCESS: Found value for key \"%s\" (type: %s)", key, json_type_to_string(child->type)); return child; } } else { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "ACCESS: Skipping element at position %d with NULL key", position); } @@ -1636,19 +1636,19 @@ Json *json_get_object_item__(POSITION_INFO_DECLARATION, const Json * const objec position++; } - raise_message(LOG_LEVEL_DEBUG, POSITION_INFO, + raise_debug__(file, func, line, "ACCESS: Key \"%s\" not found in object (checked %d items)", key, position); return NULL; } char *json_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const JsonValue *self, JsonType active_variant, PtrSet *visited) { - char *child_str = json_to_debug_str__(POSITION_INFO, arena, "child", self->child, visited); - char *result = arena_alloc__(POSITION_INFO, arena, 1024); + char *child_str = json_to_debug_str__(file, func, line, arena, "child", self->child, visited); + char *result = arena_alloc__(file, func, line, arena, 1024); UNION_TO_DEBUG_STR(arena, result, JsonValue, name, self, visited, active_variant, 5, - JSON_STRING, string_to_debug_str__(POSITION_INFO, arena, "string", self->string), - JSON_NUMBER, float_to_debug_str__(POSITION_INFO, arena, "number", self->number), - JSON_BOOL, bool_to_debug_str__(POSITION_INFO, arena, "boolean", self->boolean), + JSON_STRING, string_to_debug_str__(file, func, line, arena, "string", self->string), + JSON_NUMBER, float_to_debug_str__(file, func, line, arena, "number", self->number), + JSON_BOOL, bool_to_debug_str__(file, func, line, arena, "boolean", self->boolean), JSON_OBJECT, child_str, JSON_ARRAY, child_str ); @@ -1656,35 +1656,35 @@ char *json_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const c } char* json_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const Json *self, PtrSet *visited) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "json_to_debug_str(, )"); + raise_trace__(file, func, line, "json_to_debug_str(, )"); - char *result = arena_alloc__(POSITION_INFO, arena, 1024); + char *result = arena_alloc__(file, func, line, arena, 1024); STRUCT_TO_DEBUG_STR(arena, result, Json, name, self, visited, 3, - enum_to_debug_str__(POSITION_INFO, arena, "type", self->type, json_type_to_string(self->type)), - string_to_debug_str__(POSITION_INFO, arena, "key", self->key), - json_value_to_debug_str__(POSITION_INFO, arena, "value", &self->value, self->type, visited), - json_to_debug_str__(POSITION_INFO, arena, "next", self->next, visited) + enum_to_debug_str__(file, func, line, arena, "type", self->type, json_type_to_string(self->type)), + string_to_debug_str__(file, func, line, arena, "key", self->key), + json_value_to_debug_str__(file, func, line, arena, "value", &self->value, self->type, visited), + json_to_debug_str__(file, func, line, arena, "next", self->next, visited) ); return result; } JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const char **s) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "DEBUG STR TO JSON: debug_str: %s", *s); + raise_trace__(file, func, line, "DEBUG STR TO JSON: debug_str: %s", *s); // Remove the unused 'start' variable - Json *json = arena_alloc__(POSITION_INFO, arena, sizeof(Json)); + Json *json = arena_alloc__(file, func, line, arena, sizeof(Json)); memset(json, 0, sizeof(Json)); // Extract the name/key const char *equal_sign = strstr(*s, "="); if (!equal_sign) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no equal sign found"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no equal sign found"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_EQUAL_SIGN_ERROR, "No equal sign found"); } - Slice full_name = slice_create__(POSITION_INFO, 1, *s, strlen(*s), 0, equal_sign - *s); + Slice full_name = slice_create__(file, func, line, 1, *s, strlen(*s), 0, equal_sign - *s); if (full_name.len == 0) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no name found"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no name found"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_LEFT_OPERAND_ERROR, "No left operand found"); } @@ -1704,7 +1704,7 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch const char *space = strchr(name_str, ' '); if (!space) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: missing struct name"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: missing struct name"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_STRUCT_NAME_ERROR, "Struct without name"); } @@ -1716,23 +1716,23 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch while (*name_end && !isspace(*name_end) && *name_end != '{') name_end++; if (name_end == name_str) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: missing struct variable name"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: missing struct variable name"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_STRUCT_NAME_ERROR, "Struct without variable name"); } size_t name_len = name_end - name_str; - json->key = arena_strncpy__(POSITION_INFO, arena, name_str, name_len); + json->key = arena_strncpy__(file, func, line, arena, name_str, name_len); // Find struct body const char *body_start = strchr(name_end, '{'); if (!body_start) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no start found for struct"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no start found for struct"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_START_ERROR, "Struct without start"); } const char *body_end = strrchr(body_start, '}'); if (!body_end) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no end found for struct"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no end found for struct"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_END_ERROR, "Struct without end"); } @@ -1751,7 +1751,7 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch const char *space = strchr(name_str, ' '); if (!space) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: missing union name"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: missing union name"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_STRUCT_NAME_ERROR, "Union without name"); } @@ -1763,18 +1763,18 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch while (*name_end && !isspace(*name_end) && *name_end != '{') name_end++; size_t name_len = name_end - name_str; - json->key = arena_strncpy__(POSITION_INFO, arena, name_str, name_len); + json->key = arena_strncpy__(file, func, line, arena, name_str, name_len); // Find body const char *body_start = strchr(name_end, '{'); if (!body_start) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no start found for union"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no start found for union"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_START_ERROR, "Union without start"); } const char *body_end = strrchr(body_start, '}'); if (!body_end) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no end found for union"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no end found for union"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_END_ERROR, "Union without end"); } @@ -1791,7 +1791,7 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch // Find enum value (typically at the end) const char *value_start = strrchr(*s, ' '); if (!value_start) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: missing enum value"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: missing enum value"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_LEFT_OPERAND_ERROR, "Invalid enum format"); } @@ -1801,12 +1801,12 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch if (space) { size_t name_len = space - name_str; - json->key = arena_strncpy__(POSITION_INFO, arena, name_str, name_len); + json->key = arena_strncpy__(file, func, line, arena, name_str, name_len); } // Extract value as string value_start = skip_whitespace(value_start + 1); - json->value.string = arena_strdup__(POSITION_INFO, arena, value_start); + json->value.string = arena_strdup__(file, func, line, arena, value_start); // Move pointer to the end *s += strlen(*s); @@ -1822,19 +1822,19 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch while (name_end > name_str && isspace(*(name_end-1))) name_end--; size_t name_len = name_end - name_str; - json->key = arena_strncpy__(POSITION_INFO, arena, name_str, name_len); + json->key = arena_strncpy__(file, func, line, arena, name_str, name_len); } // Find array body const char *body_start = strchr(*s, '['); if (!body_start) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no start found for array"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no start found for array"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_START_ERROR, "Array without start"); } const char *body_end = strrchr(body_start, ']'); if (!body_end) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: no end found for array"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: no end found for array"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_NO_END_ERROR, "Array without end"); } @@ -1869,12 +1869,12 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch const char *end_quote = strchr(value, '"'); if (!end_quote) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "DEBUG STR TO JSON: unterminated string"); + raise_exception__(file, func, line, "DEBUG STR TO JSON: unterminated string"); return RESULT_ERROR(JsonResult, DEBUG_TO_JSON_PARSE_LEFT_OPERAND_ERROR, "Unterminated string"); } size_t str_len = end_quote - value; - json->value.string = arena_strncpy__(POSITION_INFO, arena, value, str_len); + json->value.string = arena_strncpy__(file, func, line, arena, value, str_len); *s = end_quote + 1; } else if (isdigit(*value) || *value == '-' || *value == '+') { @@ -1895,7 +1895,7 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch while (*end && !isspace(*end) && *end != ',' && *end != '}' && *end != ']') end++; size_t str_len = end - value; - json->value.string = arena_strncpy__(POSITION_INFO, arena, value, str_len); + json->value.string = arena_strncpy__(file, func, line, arena, value, str_len); *s = end; } @@ -1904,7 +1904,7 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch while (*name_end && !isspace(*name_end) && *name_end != '=') name_end++; size_t name_len = name_end - name_str; - json->key = arena_strncpy__(POSITION_INFO, arena, name_str, name_len); + json->key = arena_strncpy__(file, func, line, arena, name_str, name_len); } return RESULT_SOME(JsonResult, *json); @@ -1917,13 +1917,13 @@ JsonResult debug_str_to_json__(POSITION_INFO_DECLARATION, Arena *arena, const ch // Create a slice from an array with boundary check. Slice slice_create__(POSITION_INFO_DECLARATION, size_t isize, const void *array, size_t array_len, size_t start, size_t len) { // Function entry logging - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "SLICE: Creating slice (source: %p, array_length: %zu, start: %zu, length: %zu, item_size: %zu)", array, array_len, start, len, isize); // Boundary check if (start + len > array_len) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "SLICE: Slice boundaries exceed array length (start: %zu, length: %zu, array_length: %zu)", start, len, array_len); return (Slice){NULL, 0, isize}; @@ -1933,7 +1933,7 @@ Slice slice_create__(POSITION_INFO_DECLARATION, size_t isize, const void *array, Slice result = (Slice){ (char *)array + start * isize, len, isize }; // Success logging - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "SLICE: Slice created successfully (data: %p, length: %zu, item_size: %zu)", result.data, result.len, result.isize); @@ -1943,13 +1943,13 @@ Slice slice_create__(POSITION_INFO_DECLARATION, size_t isize, const void *array, // Return a subslice from an existing slice. Slice slice_subslice__(POSITION_INFO_DECLARATION, Slice s, size_t start, size_t len) { // Function entry logging - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "SLICE: Creating subslice (source: %p, source_length: %zu, start: %zu, length: %zu)", s.data, s.len, start, len); // Boundary check if (start + len > s.len) { - raise_message(LOG_LEVEL_WARN, POSITION_INFO, + raise_warn__(file, func, line, "SLICE: Subslice boundaries exceed source slice length (start: %zu, length: %zu, source_length: %zu)", start, len, s.len); return (Slice){NULL, 0, s.isize}; @@ -1959,7 +1959,7 @@ Slice slice_subslice__(POSITION_INFO_DECLARATION, Slice s, size_t start, size_t Slice result = (Slice){(char*)s.data + start * s.isize, len, s.isize}; // Success logging - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, + raise_trace__(file, func, line, "SLICE: Subslice created successfully (data: %p, length: %zu, item_size: %zu)", result.data, result.len, result.isize); @@ -1967,8 +1967,8 @@ Slice slice_subslice__(POSITION_INFO_DECLARATION, Slice s, size_t start, size_t } int* arena_slice_copy__(POSITION_INFO_DECLARATION, Arena *arena, Slice s) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "arena_slice_copy(, )"); - int *copy = (void*) arena_alloc__(POSITION_INFO, arena, s.len * sizeof(int)); + raise_trace__(file, func, line, "arena_slice_copy(, )"); + int *copy = (void*) arena_alloc__(file, func, line, arena, s.len * sizeof(int)); if (copy) memcpy(copy, s.data, s.len * s.isize); return copy; @@ -2033,7 +2033,7 @@ char* slice_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, Slice slice) *pos++ = '}'; // Closing brace for the structure *pos = '\0'; - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "slice_to_debug_str: %s", buffer); + raise_trace__(file, func, line, "slice_to_debug_str: %s", buffer); return buffer; } @@ -2255,12 +2255,12 @@ void logger_print_rules() { char *log_rules_to_debug_str__(CTX_DECLARATION, char *name, LogRule *self, PtrSet *visited) { char *result = arena_alloc(arena, MEM_KiB); STRUCT_TO_DEBUG_STR(arena, result, LogRule, name, self, visited, 6, - enum_to_debug_str__(POSITION_INFO, arena, "level", self->level, log_level_to_string(self->level)), - string_to_debug_str__(POSITION_INFO, arena, "file_pattern", self->file_pattern), - string_to_debug_str__(POSITION_INFO, arena, "function_pattern", self->function_pattern), - int_to_debug_str__(POSITION_INFO, arena, "line_start", self->line_start), - int_to_debug_str__(POSITION_INFO, arena, "line_end", self->line_end), - log_rules_to_debug_str__(POSITION_INFO, arena, "next", self->next, visited) + enum_to_debug_str__(file, func, line, arena, "level", self->level, log_level_to_string(self->level)), + string_to_debug_str__(file, func, line, arena, "file_pattern", self->file_pattern), + string_to_debug_str__(file, func, line, arena, "function_pattern", self->function_pattern), + int_to_debug_str__(file, func, line, arena, "line_start", self->line_start), + int_to_debug_str__(file, func, line, arena, "line_end", self->line_end), + log_rules_to_debug_str__(file, func, line, arena, "next", self->next, visited) ); return result; } @@ -2279,7 +2279,7 @@ View string_to_view(const char *str) { } View *string_to_view_ptr__(POSITION_INFO_DECLARATION, Arena *arena, const char *str) { - View *view = arena_alloc__(POSITION_INFO, arena, sizeof(View)); + View *view = arena_alloc__(file, func, line, arena, sizeof(View)); const View tmp = string_to_view(str); *(void **)&view->data = (void *)tmp.data; *(size_t *)&view->len = tmp.len; @@ -2294,28 +2294,28 @@ View *string_to_view_ptr__(POSITION_INFO_DECLARATION, Arena *arena, const char * // Look at package\c\hectic\docs\templater.md TemplateConfig template_default_config__(POSITION_INFO_DECLARATION, Arena *arena) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "TEMPLATE: Default config"); + raise_trace__(file, func, line, "TEMPLATE: Default config"); TemplateConfig config = { .Syntax = { .Braces = { - .open = string_to_view_ptr__(POSITION_INFO, arena, "{%"), - .close = string_to_view_ptr__(POSITION_INFO, arena, "%}") + .open = string_to_view_ptr__(file, func, line, arena, "{%"), + .close = string_to_view_ptr__(file, func, line, arena, "%}") }, .Section = { - .control = string_to_view_ptr__(POSITION_INFO, arena, "for "), - .source = string_to_view_ptr__(POSITION_INFO, arena, "in "), - .begin = string_to_view_ptr__(POSITION_INFO, arena, "do ") + .control = string_to_view_ptr__(file, func, line, arena, "for "), + .source = string_to_view_ptr__(file, func, line, arena, "in "), + .begin = string_to_view_ptr__(file, func, line, arena, "do ") }, .Interpolate = { - .invoke = string_to_view_ptr__(POSITION_INFO, arena, "") + .invoke = string_to_view_ptr__(file, func, line, arena, "") }, .Include = { - .invoke = string_to_view_ptr__(POSITION_INFO, arena, "include ") + .invoke = string_to_view_ptr__(file, func, line, arena, "include ") }, .Execute = { - .invoke = string_to_view_ptr__(POSITION_INFO, arena, "exec ") + .invoke = string_to_view_ptr__(file, func, line, arena, "exec ") }, - .nesting = string_to_view_ptr__(POSITION_INFO, arena, "->") + .nesting = string_to_view_ptr__(file, func, line, arena, "->") } }; @@ -2325,11 +2325,11 @@ TemplateConfig template_default_config__(POSITION_INFO_DECLARATION, Arena *arena #define CHECK_CONFIG_STR(field, name) \ do { \ if (config->Syntax.field->data == NULL) { \ - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "VALIDATE: " name " is NULL"); \ + raise_exception__(file, func, line, "VALIDATE: " name " is NULL"); \ return false; \ } \ if (config->Syntax.field->len > TEMPLATE_MAX_PREFIX_LEN) { \ - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "VALIDATE: " name " is too long"); \ + raise_exception__(file, func, line, "VALIDATE: " name " is too long"); \ return false; \ } \ } while (0) @@ -2337,7 +2337,7 @@ do { \ bool template_validate_config__(POSITION_INFO_DECLARATION, const TemplateConfig *config) { raise_trace("VALIDATE: config %p", config); if (!config) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "VALIDATE: Config is NULL"); + raise_exception__(file, func, line, "VALIDATE: Config is NULL"); return false; } @@ -2358,7 +2358,7 @@ bool template_validate_config__(POSITION_INFO_DECLARATION, const TemplateConfig #define TEMPLATE_ASSERT_SYNTAX(pattern, message_arg, code_arg) \ if (strncmp(*s, pattern, strlen(pattern)) == 0) { \ - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "PARSE: " message_arg); \ + raise_exception__(file, func, line, "PARSE: " message_arg); \ return RESULT_ERROR(TemplateResult, code_arg, message_arg); \ } @@ -2383,7 +2383,7 @@ TemplateValue init_template_value__(POSITION_INFO_DECLARATION, TemplateNodeType value.include.key = NULL; break; default: - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "INIT: Unknown node type"); + raise_exception__(file, func, line, "INIT: Unknown node type"); exit(1); } return value; @@ -2393,16 +2393,16 @@ TemplateNode init_template_node__(POSITION_INFO_DECLARATION, Arena *arena, Templ TemplateNode node; node.next = NULL; node.type = type; - node.value = arena_alloc__(POSITION_INFO, arena, sizeof(TemplateValue)); - *node.value = init_template_value__(POSITION_INFO, type); + node.value = arena_alloc__(file, func, line, arena, sizeof(TemplateValue)); + *node.value = init_template_value__(file, func, line, type); return node; } TemplateResult init_template_result__(POSITION_INFO_DECLARATION, Arena *arena, TemplateNodeType type) { TemplateResult result; result.type = RESULT_SOME; - result.Result.some = arena_alloc__(POSITION_INFO, arena, sizeof(TemplateNode)); - *result.Result.some = init_template_node__(POSITION_INFO, arena, type); + result.Result.some = arena_alloc__(file, func, line, arena, sizeof(TemplateNode)); + *result.Result.some = init_template_node__(file, func, line, arena, type); return result; } @@ -2417,9 +2417,9 @@ TemplateNode new_template_node__(TemplateNodeType type, TemplateValue *value) { TemplateResult template_parse__(POSITION_INFO_DECLARATION, Arena *arena, const char **s, const TemplateConfig *config, bool inner_parse); TemplateResult template_parse_interpolation__(POSITION_INFO_DECLARATION, Arena *arena, const char **s_ptr, const TemplateConfig *config) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Interpolation"); + raise_trace__(file, func, line, "PARSE: Interpolation"); - TemplateResult result = init_template_result__(POSITION_INFO, arena, TEMPLATE_NODE_INTERPOLATE); + TemplateResult result = init_template_result__(file, func, line, arena, TEMPLATE_NODE_INTERPOLATE); const char **s = s_ptr; @@ -2440,7 +2440,7 @@ TemplateResult template_parse_interpolation__(POSITION_INFO_DECLARATION, Arena * size_t key_len = *s - key_start; - char *key = arena_strncpy__(POSITION_INFO, arena, key_start, key_len); + char *key = arena_strncpy__(file, func, line, arena, key_start, key_len); result.Result.some->value->interpolate.key = key; @@ -2451,9 +2451,9 @@ TemplateResult template_parse_interpolation__(POSITION_INFO_DECLARATION, Arena * } TemplateResult template_parse_section__(POSITION_INFO_DECLARATION, Arena *arena, const char **s_ptr, const TemplateConfig *config) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Section"); + raise_trace__(file, func, line, "PARSE: Section"); - TemplateResult result = init_template_result__(POSITION_INFO, arena, TEMPLATE_NODE_SECTION); + TemplateResult result = init_template_result__(file, func, line, arena, TEMPLATE_NODE_SECTION); const char **s = s_ptr; @@ -2474,7 +2474,7 @@ TemplateResult template_parse_section__(POSITION_INFO_DECLARATION, Arena *arena, } size_t iterator_len = *s - iterator_start; - result.Result.some->value->section.iterator = arena_strncpy__(POSITION_INFO, arena, iterator_start, iterator_len); + result.Result.some->value->section.iterator = arena_strncpy__(file, func, line, arena, iterator_start, iterator_len); // Find the collection name *s = skip_whitespace(*s); @@ -2490,13 +2490,13 @@ TemplateResult template_parse_section__(POSITION_INFO_DECLARATION, Arena *arena, } size_t collection_len = *s - collection_start; - result.Result.some->value->section.collection = arena_strncpy__(POSITION_INFO, arena, collection_start, collection_len); + result.Result.some->value->section.collection = arena_strncpy__(file, func, line, arena, collection_start, collection_len); // Skip to the body *s = skip_whitespace(*s); // Parse the body - TemplateResult body_result = template_parse__(POSITION_INFO, arena, s, config, true); + TemplateResult body_result = template_parse__(file, func, line, arena, s, config, true); if (body_result.type == RESULT_ERROR) { return body_result; } @@ -2506,7 +2506,7 @@ TemplateResult template_parse_section__(POSITION_INFO_DECLARATION, Arena *arena, // Skip to the end of the section *s = skip_whitespace(*s); if (strncmp(*s, config->Syntax.Braces.close->data, config->Syntax.Braces.close->len) != 0) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "PARSE: Expected section end"); + raise_exception__(file, func, line, "PARSE: Expected section end"); return RESULT_ERROR(TemplateResult, TEMPLATE_ERROR_UNEXPECTED_SECTION_END, "Expected section end"); } *s_ptr = *s + config->Syntax.Braces.close->len; @@ -2515,9 +2515,9 @@ TemplateResult template_parse_section__(POSITION_INFO_DECLARATION, Arena *arena, } TemplateResult template_parse_include__(POSITION_INFO_DECLARATION, Arena *arena, const char **s_ptr, const TemplateConfig *config) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Include"); + raise_trace__(file, func, line, "PARSE: Include"); - TemplateResult result = init_template_result__(POSITION_INFO, arena, TEMPLATE_NODE_INCLUDE); + TemplateResult result = init_template_result__(file, func, line, arena, TEMPLATE_NODE_INCLUDE); const char **s = s_ptr; @@ -2536,12 +2536,12 @@ TemplateResult template_parse_include__(POSITION_INFO_DECLARATION, Arena *arena, } size_t include_len = *s - include_start; - result.Result.some->value->include.key = arena_strncpy__(POSITION_INFO, arena, include_start, include_len); + result.Result.some->value->include.key = arena_strncpy__(file, func, line, arena, include_start, include_len); // Skip to the end of the include *s = skip_whitespace(*s); if (strncmp(*s, config->Syntax.Braces.close->data, config->Syntax.Braces.close->len) != 0) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "PARSE: Expected include end"); + raise_exception__(file, func, line, "PARSE: Expected include end"); return RESULT_ERROR(TemplateResult, TEMPLATE_ERROR_UNEXPECTED_INCLUDE_END, "Expected include end"); } *s_ptr = *s + config->Syntax.Braces.close->len; @@ -2550,9 +2550,9 @@ TemplateResult template_parse_include__(POSITION_INFO_DECLARATION, Arena *arena, } TemplateResult template_parse_execute__(POSITION_INFO_DECLARATION, Arena *arena, const char **s_ptr, const TemplateConfig *config) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Execute"); + raise_trace__(file, func, line, "PARSE: Execute"); - TemplateResult result = init_template_result__(POSITION_INFO, arena, TEMPLATE_NODE_EXECUTE); + TemplateResult result = init_template_result__(file, func, line, arena, TEMPLATE_NODE_EXECUTE); const char **s = s_ptr; @@ -2572,11 +2572,11 @@ TemplateResult template_parse_execute__(POSITION_INFO_DECLARATION, Arena *arena, } size_t code_len = *s - code_start; - result.Result.some->value->execute.code = arena_strncpy__(POSITION_INFO, arena, code_start, code_len); + result.Result.some->value->execute.code = arena_strncpy__(file, func, line, arena, code_start, code_len); // Skip to the end of the execute if (strncmp(*s, config->Syntax.Braces.close->data, config->Syntax.Braces.close->len) != 0) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "PARSE: Expected execute end"); + raise_exception__(file, func, line, "PARSE: Expected execute end"); return RESULT_ERROR(TemplateResult, TEMPLATE_ERROR_UNEXPECTED_EXECUTE_END, "Expected execute end"); } *s_ptr = *s + config->Syntax.Braces.close->len; @@ -2585,22 +2585,22 @@ TemplateResult template_parse_execute__(POSITION_INFO_DECLARATION, Arena *arena, } TemplateResult template_parse__(POSITION_INFO_DECLARATION, Arena *arena, const char **s, const TemplateConfig *config, bool inner_parse) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Iteration start"); + raise_trace__(file, func, line, "PARSE: Iteration start"); - if (!template_validate_config__(POSITION_INFO, config)) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "PARSE: Invalid config"); + if (!template_validate_config__(file, func, line, config)) { + raise_exception__(file, func, line, "PARSE: Invalid config"); return RESULT_ERROR(TemplateResult, TEMPLATE_ERROR_INVALID_CONFIG, "Invalid config"); } if (!arena) { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "PARSE: Arena is NULL"); + raise_exception__(file, func, line, "PARSE: Arena is NULL"); return RESULT_ERROR(TemplateResult, TEMPLATE_ERROR_OUT_OF_MEMORY, "Out of memory"); } const char *start = *s; - TemplateNode *root = arena_alloc__(POSITION_INFO, arena, sizeof(TemplateNode)); - *root = init_template_node__(POSITION_INFO, arena, TEMPLATE_NODE_TEXT); + TemplateNode *root = arena_alloc__(file, func, line, arena, sizeof(TemplateNode)); + *root = init_template_node__(file, func, line, arena, TEMPLATE_NODE_TEXT); TemplateNode *current = root; bool current_node_filled = false; @@ -2611,31 +2611,31 @@ TemplateResult template_parse__(POSITION_INFO_DECLARATION, Arena *arena, const c while (*s && **s != '\0') { // Check for closing brace if this is inner parse if (inner_parse && strncmp(*s, config->Syntax.Braces.close->data, config->Syntax.Braces.close->len) == 0) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Found closing brace in inner parse"); + raise_trace__(file, func, line, "PARSE: Found closing brace in inner parse"); break; } if (strncmp(*s, config->Syntax.Braces.open->data, open_brace_len) == 0) { if (start != *s) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Text node: %s", arena_strncpy__(POSITION_INFO, DISPOSABLE_ARENA, start, *s - start)); + raise_trace__(file, func, line, "PARSE: Text node: %s", arena_strncpy__(POSITION_INFO, DISPOSABLE_ARENA, start, *s - start)); if (current_node_filled) { - TemplateNode *new_node = arena_alloc__(POSITION_INFO, arena, sizeof(TemplateNode)); - *new_node = init_template_node__(POSITION_INFO, arena, TEMPLATE_NODE_TEXT); + TemplateNode *new_node = arena_alloc__(file, func, line, arena, sizeof(TemplateNode)); + *new_node = init_template_node__(file, func, line, arena, TEMPLATE_NODE_TEXT); current->next = new_node; current = new_node; } else { current->type = TEMPLATE_NODE_TEXT; - *current->value = init_template_value__(POSITION_INFO, TEMPLATE_NODE_TEXT); + *current->value = init_template_value__(file, func, line, TEMPLATE_NODE_TEXT); } - current->value->text.content = arena_strncpy__(POSITION_INFO, arena, start, *s - start); + current->value->text.content = arena_strncpy__(file, func, line, arena, start, *s - start); current_node_filled = true; } // Determine tag type by prefix TemplateResult current_result; { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Found tag"); + raise_trace__(file, func, line, "PARSE: Found tag"); const char *tag_prefix = *s + open_brace_len; tag_prefix = skip_whitespace(tag_prefix); @@ -2668,23 +2668,23 @@ TemplateResult template_parse__(POSITION_INFO_DECLARATION, Arena *arena, const c } if (matched_type == 1) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Section tag"); - current_result = template_parse_section__(POSITION_INFO, arena, s, config); + raise_trace__(file, func, line, "PARSE: Section tag"); + current_result = template_parse_section__(file, func, line, arena, s, config); start = *s; } else if (matched_type == 2) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Interpolation tag"); - current_result = template_parse_interpolation__(POSITION_INFO, arena, s, config); + raise_trace__(file, func, line, "PARSE: Interpolation tag"); + current_result = template_parse_interpolation__(file, func, line, arena, s, config); start = *s; } else if (matched_type == 3) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Include tag"); - current_result = template_parse_include__(POSITION_INFO, arena, s, config); + raise_trace__(file, func, line, "PARSE: Include tag"); + current_result = template_parse_include__(file, func, line, arena, s, config); start = *s; } else if (matched_type == 4) { - raise_message(LOG_LEVEL_TRACE, POSITION_INFO, "PARSE: Execute tag"); - current_result = template_parse_execute__(POSITION_INFO, arena, s, config); + raise_trace__(file, func, line, "PARSE: Execute tag"); + current_result = template_parse_execute__(file, func, line, arena, s, config); start = *s; } else { - raise_message(LOG_LEVEL_EXCEPTION, POSITION_INFO, "PARSE: Unknown tag prefix: %s", slice_create__(POSITION_INFO, 1, (char *)tag_prefix, strlen(tag_prefix), 0, TEMPLATE_MAX_PREFIX_LEN)); + raise_exception__(file, func, line, "PARSE: Unknown tag prefix: %s", slice_create__(POSITION_INFO, 1, (char *)tag_prefix, strlen(tag_prefix), 0, TEMPLATE_MAX_PREFIX_LEN)); return RESULT_ERROR(TemplateResult, TEMPLATE_ERROR_UNKNOWN_TAG, "Unknown tag prefix"); } @@ -2693,7 +2693,7 @@ TemplateResult template_parse__(POSITION_INFO_DECLARATION, Arena *arena, const c if (current_node_filled) { // SAFETY(yukkop): NO init necessary here - TemplateNode *new_node = arena_alloc__(POSITION_INFO, arena, sizeof(TemplateNode)); + TemplateNode *new_node = arena_alloc__(file, func, line, arena, sizeof(TemplateNode)); *new_node = *current_result.Result.some; current->next = new_node; current = new_node; @@ -2711,24 +2711,24 @@ TemplateResult template_parse__(POSITION_INFO_DECLARATION, Arena *arena, const c // Add text node if there is any text after the last tag if (start != *s) { if (current_node_filled) { - TemplateNode *new_node = arena_alloc__(POSITION_INFO, arena, sizeof(TemplateNode)); - *new_node = init_template_node__(POSITION_INFO, arena, TEMPLATE_NODE_TEXT); + TemplateNode *new_node = arena_alloc__(file, func, line, arena, sizeof(TemplateNode)); + *new_node = init_template_node__(file, func, line, arena, TEMPLATE_NODE_TEXT); current->next = new_node; current = new_node; } else { current->type = TEMPLATE_NODE_TEXT; - *current->value = init_template_value__(POSITION_INFO, TEMPLATE_NODE_TEXT); + *current->value = init_template_value__(file, func, line, TEMPLATE_NODE_TEXT); } - current->value->text.content = arena_strncpy__(POSITION_INFO, arena, start, *s - start); + current->value->text.content = arena_strncpy__(file, func, line, arena, start, *s - start); current_node_filled = true; } // Set null when node is not filled if (!current_node_filled && current == root) { root->type = TEMPLATE_NODE_TEXT; - *root->value = init_template_value__(POSITION_INFO, TEMPLATE_NODE_TEXT); - root->value->text.content = arena_strncpy__(POSITION_INFO, arena, "", 0); + *root->value = init_template_value__(file, func, line, TEMPLATE_NODE_TEXT); + root->value->text.content = arena_strncpy__(file, func, line, arena, "", 0); } return RESULT_SOME(TemplateResult, *root); @@ -2755,9 +2755,9 @@ char *template_node_type_to_string(TemplateNodeType type) { char *template_section_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const TemplateSectionValue *self, PtrSet *visited) { char *result = arena_alloc(arena, MEM_KiB); STRUCT_TO_DEBUG_STR(arena, result, TemplateSectionValue, name, self, visited, 3, - string_to_debug_str__(POSITION_INFO, arena, "iterator", self->iterator), - string_to_debug_str__(POSITION_INFO, arena, "collection", self->collection), - template_node_to_debug_str__(POSITION_INFO, arena, "body", self->body, visited) + string_to_debug_str__(file, func, line, arena, "iterator", self->iterator), + string_to_debug_str__(file, func, line, arena, "collection", self->collection), + template_node_to_debug_str__(file, func, line, arena, "body", self->body, visited) ); return result; } @@ -2765,7 +2765,7 @@ char *template_section_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *ar char *template_interpolate_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const TemplateInterpolateValue *self, PtrSet *visited) { char *result = arena_alloc(arena, MEM_KiB); STRUCT_TO_DEBUG_STR(arena, result, TemplateInterpolateValue, name, self, visited, 1, - string_to_debug_str__(POSITION_INFO, arena, "key", self->key) + string_to_debug_str__(file, func, line, arena, "key", self->key) ); return result; } @@ -2773,7 +2773,7 @@ char *template_interpolate_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena char *template_execute_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const TemplateExecuteValue *self, PtrSet *visited) { char *result = arena_alloc(arena, MEM_KiB); STRUCT_TO_DEBUG_STR(arena, result, TemplateExecuteValue, name, self, visited, 1, - string_to_debug_str__(POSITION_INFO, arena, "code", self->code) + string_to_debug_str__(file, func, line, arena, "code", self->code) ); return result; } @@ -2781,7 +2781,7 @@ char *template_execute_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *ar char *template_include_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const TemplateIncludeValue *self, PtrSet *visited) { char *result = arena_alloc(arena, MEM_KiB); STRUCT_TO_DEBUG_STR(arena, result, TemplateIncludeValue, name, self, visited, 1, - string_to_debug_str__(POSITION_INFO, arena, "key", self->key) + string_to_debug_str__(file, func, line, arena, "key", self->key) ); return result; } @@ -2789,7 +2789,7 @@ char *template_include_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *ar char *template_text_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const TemplateTextValue *self, PtrSet *visited) { char *result = arena_alloc(arena, MEM_KiB); STRUCT_TO_DEBUG_STR(arena, result, TemplateTextValue, name, self, visited, 1, - string_to_debug_str__(POSITION_INFO, arena, "content", self->content) + string_to_debug_str__(file, func, line, arena, "content", self->content) ); return result; } @@ -2798,11 +2798,11 @@ char *template_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, con char *result = arena_alloc(arena, MEM_KiB); UNION_TO_DEBUG_STR(arena, result, TemplateValue, name, self, visited, active_variant, 5, - TEMPLATE_NODE_SECTION, template_section_value_to_debug_str__(POSITION_INFO, arena, "section", &self->section, visited), - TEMPLATE_NODE_INTERPOLATE, template_interpolate_value_to_debug_str__(POSITION_INFO, arena, "interpolate", &self->interpolate, visited), - TEMPLATE_NODE_EXECUTE, template_execute_value_to_debug_str__(POSITION_INFO, arena, "execute", &self->execute, visited), - TEMPLATE_NODE_INCLUDE, template_include_value_to_debug_str__(POSITION_INFO, arena, "include", &self->include, visited), - TEMPLATE_NODE_TEXT, template_text_value_to_debug_str__(POSITION_INFO, arena, "text", &self->text, visited) + TEMPLATE_NODE_SECTION, template_section_value_to_debug_str__(file, func, line, arena, "section", &self->section, visited), + TEMPLATE_NODE_INTERPOLATE, template_interpolate_value_to_debug_str__(file, func, line, arena, "interpolate", &self->interpolate, visited), + TEMPLATE_NODE_EXECUTE, template_execute_value_to_debug_str__(file, func, line, arena, "execute", &self->execute, visited), + TEMPLATE_NODE_INCLUDE, template_include_value_to_debug_str__(file, func, line, arena, "include", &self->include, visited), + TEMPLATE_NODE_TEXT, template_text_value_to_debug_str__(file, func, line, arena, "text", &self->text, visited) ); return result; } @@ -2810,19 +2810,19 @@ char *template_value_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, con char *template_node_to_debug_str__(POSITION_INFO_DECLARATION, Arena *arena, const char *name, const TemplateNode *self, PtrSet *visited) { char *result = arena_alloc(arena, MEM_KiB); STRUCT_TO_DEBUG_STR(arena, result, TemplateNode, name, self, visited, 3, - enum_to_debug_str__(POSITION_INFO, arena, "type", self->type, template_node_type_to_string(self->type)), - template_value_to_debug_str__(POSITION_INFO, arena, "value", self->value, self->type, visited), - template_node_to_debug_str__(POSITION_INFO, arena, "next", self->next, visited) + enum_to_debug_str__(file, func, line, arena, "type", self->type, template_node_type_to_string(self->type)), + template_value_to_debug_str__(file, func, line, arena, "value", self->value, self->type, visited), + template_node_to_debug_str__(file, func, line, arena, "next", self->next, visited) ); return result; } char *template_node_to_json_str__(POSITION_INFO_DECLARATION, Arena *arena, const TemplateNode *node, int depth) { - if (!node) return arena_strncpy__(POSITION_INFO, arena, "", 0); + if (!node) return arena_strncpy__(file, func, line, arena, "", 0); if (depth > TEMPLATE_NODE_MAX_DEBUG_DEPTH) { - return arena_strncpy__(POSITION_INFO, arena, "...", 3); + return arena_strncpy__(file, func, line, arena, "...", 3); } // Use a temporary buffer on the stack for building the string @@ -2846,7 +2846,7 @@ char *template_node_to_json_str__(POSITION_INFO_DECLARATION, Arena *arena, const APPEND("\"content\":{\"iterator\":\"%s\",\"collection\":\"%s\"}", node->value->section.iterator, node->value->section.collection); - char *body_str = template_node_to_json_str__(POSITION_INFO, arena, node->value->section.body, depth + 1); + char *body_str = template_node_to_json_str__(file, func, line, arena, node->value->section.body, depth + 1); if (body_str) { APPEND(",\"body\":[%s]", body_str); } @@ -2870,7 +2870,7 @@ char *template_node_to_json_str__(POSITION_INFO_DECLARATION, Arena *arena, const APPEND("}"); if (node->next) { - char *next_str = template_node_to_json_str__(POSITION_INFO, arena, node->next, depth + 1); + char *next_str = template_node_to_json_str__(file, func, line, arena, node->next, depth + 1); if (next_str) { APPEND(",%s", next_str); } @@ -2881,7 +2881,7 @@ char *template_node_to_json_str__(POSITION_INFO_DECLARATION, Arena *arena, const } // Copy the final string to arena-allocated memory - char *result = arena_strncpy__(POSITION_INFO, arena, temp_buf, len); + char *result = arena_strncpy__(file, func, line, arena, temp_buf, len); return result; } diff --git a/package/c/hectic/hectic.h b/package/c/hectic/hectic.h index 2d5ca7a..66dfcd1 100644 --- a/package/c/hectic/hectic.h +++ b/package/c/hectic/hectic.h @@ -298,6 +298,48 @@ char* raise_message(LogLevel level, const char *file, const char *func, int line #define PRECOMPILED_LOG_LEVEL LOG_LEVEL_TRACE // default level #endif +#if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_TRACE +#define raise_trace__(...) ((void)0) // log removed at compile time +#else +#define raise_trace__(file, func, line, ...) raise_message(LOG_LEVEL_TRACE, file, func, line, ##__VA_ARGS__) +#endif + +#if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_DEBUG +#define raise_debug__(...) ((void)0) +#else +#define raise_debug__(file, func, line, ...) raise_message(LOG_LEVEL_DEBUG, file, func, line, ##__VA_ARGS__) +#endif + +#if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_LOG +#define raise_log__(...) ((void)0) +#else +#define raise_log__(file, func, line, ...) raise_message(LOG_LEVEL_LOG, file, func, line, ##__VA_ARGS__) +#endif + +#if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_INFO +#define raise_info__(...) ((void)0) +#else +#define raise_info__(file, func, line, ...) raise_message(LOG_LEVEL_INFO, file, func, line, ##__VA_ARGS__) +#endif + +#if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_NOTICE +#define raise_notice__(...) ((void)0) +#else +#define raise_notice__(file, func, line, ...) raise_message(LOG_LEVEL_NOTICE, file, func, line, ##__VA_ARGS__) +#endif + +#if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_WARN +#define raise_warn__(...) ((void)0) +#else +#define raise_warn__(file, func, line, ...) raise_message(LOG_LEVEL_WARN, file, func, line, ##__VA_ARGS__) +#endif + +#if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_EXCEPTION +#define raise_exception__(...) ((void)0) +#else +#define raise_exception__(fine, func, line, ...) raise_message(LOG_LEVEL_EXCEPTION, file, func, line, ##__VA_ARGS__) +#endif + #if PRECOMPILED_LOG_LEVEL > LOG_LEVEL_TRACE #define raise_trace(...) ((void)0) // log removed at compile time #else diff --git a/package/c/hectic/test/06-templater.c b/package/c/hectic/test/06-templater.c index d04c106..56f6e60 100755 --- a/package/c/hectic/test/06-templater.c +++ b/package/c/hectic/test/06-templater.c @@ -171,6 +171,19 @@ static void simplest_test_template_parse(Arena *arena, TemplateConfig *config) { "]") == 0); } +static void simplest_interpolation_that_crash_db_test_template_parse(Arena *arena, TemplateConfig *config) { + const char *template_str = "zalupa {% her %} davalka"; + + template_parse(arena, &template_str, config); + arena_reset(arena); + template_parse(arena, &template_str, config); + template_parse(arena, &template_str, config); + arena_reset(arena); + template_parse(arena, &template_str, config); + template_parse(arena, &template_str, config); + template_parse(arena, &template_str, config); +} + static void simplest_interpolation_test_template_parse(Arena *arena, TemplateConfig *config) { const char *template_str = "{% name %} {% name2 %}"; @@ -345,12 +358,16 @@ int main(void) { printf("%sTest 3: simplest_interpolation_test_template_parse passed%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_RESET)); arena_reset(&arena); + simplest_interpolation_that_crash_db_test_template_parse(&arena, &config); + printf("%sTest 4: simplest_interpolation_that_crash_db_test_template_parse passed%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_RESET)); + arena_reset(&arena); + simplest_separator_test_template_parse(&arena, &config); - printf("%sTest 4: simplest_separator_test_template_parse passed%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_RESET)); + printf("%sTest 5: simplest_separator_test_template_parse passed%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_RESET)); arena_reset(&arena); simplest_execute_test_template_parse(&arena, &config); - printf("%sTest 5: simplest_execute_test_template_parse passed%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_RESET)); + printf("%sTest 6: simplest_execute_test_template_parse passed%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_RESET)); arena_reset(&arena); logger_free(); diff --git a/package/c/hemar/hemar.c b/package/c/hemar/hemar.c index 9053e7c..b903672 100755 --- a/package/c/hemar/hemar.c +++ b/package/c/hemar/hemar.c @@ -14,6 +14,9 @@ #include "utils/memutils.h" #include "utils/regproc.h" #include + +#define PRECOMPILED_LOG_LEVEL LOG_LEVEL_EXCEPTION + #include "hectic.h" #ifdef PG_MODULE_MAGIC @@ -27,9 +30,10 @@ static MemoryContext HemarContext = NULL; #define INIT \ MemoryContext oldctx; \ oldctx = MemoryContextSwitchTo(HemarContext); \ - logger_init(); \ + /* logger_init(); \ + logger_level(LOG_LEVEL_TRACE); \ logger_set_file(LOG_FILE); \ - logger_set_output_mode(LOG_OUTPUT_BOTH); \ + logger_set_output_mode(LOG_OUTPUT_BOTH);*/ \ Arena arena = arena_init(MEM_MiB); @@ -37,6 +41,7 @@ static MemoryContext HemarContext = NULL; /*DISPOSABLE_ARENA_FREE*/; \ /*arena_free(&arena);*/ \ /*logger_free();*/ \ + arena_reset(&arena); \ MemoryContextSwitchTo(oldctx); \ MemoryContextReset(HemarContext); @@ -65,7 +70,7 @@ Datum pg_template_parse(PG_FUNCTION_ARGS) { text *template_text = PG_GETARG_TEXT_PP(0); const char *template_str = text_to_cstring(template_text); - raise_notice("%s", template_str); + raise_notice("template_str: %s", template_str); TemplateResult template_result; TemplateConfig config = template_default_config(&arena);