Trying to fix error when freeing act quotation in while symbol
@@ -253,7 +253,6 @@ "_sort_j" #
"_sort_current" # "_sort_next" # "_sort_i" # - ) "sort" :: ;;; gsub
@@ -439,7 +439,7 @@ {
if (token == NULL || token->value == NULL) return; free(token->value); - // token->value = NULL; + // token->value = NULL; free(token); // Free the token itself }@@ -745,7 +745,7 @@ }
} else { - // copy->value = NULL; + copy->value = NULL; } // Copy the file position if it exists@@ -821,8 +821,6 @@ }
// Copy basic fields copy->type = item->type; - copy->is_operator = item->is_operator; - copy->quotation_size = item->quotation_size; // Copy the union field based on the type switch (item->type)@@ -849,13 +847,15 @@ }
break; case HEX_TYPE_QUOTATION: - if (item->data.quotation_value && item->quotation_size > 0) + copy->quotation_size = item->quotation_size; + copy->is_operator = item->is_operator; + if (item->data.quotation_value) { copy->data.quotation_value = (hex_item_t **)malloc(item->quotation_size * sizeof(hex_item_t *)); if (!copy->data.quotation_value) { - hex_free_item(ctx, copy); hex_error(ctx, "[copy item] Failed to allocate memory for quotation array"); + hex_free_item(ctx, copy); return NULL; }@@ -865,8 +865,8 @@ copy->data.quotation_value[i] = hex_copy_item(ctx, item->data.quotation_value[i]); // Recursively copy each item
if (!copy->data.quotation_value[i]) { // Cleanup on failure - hex_free_item(ctx, copy); hex_error(ctx, "[copy item] Failed to copy quotation item"); + hex_free_item(ctx, copy); return NULL; } }@@ -882,7 +882,6 @@ copy->data.fn_value = item->data.fn_value; // Copy function pointer for native symbols
break; case HEX_TYPE_USER_SYMBOL: - // User symbols do not have a function pointer, so no additional copying here break; default:@@ -898,14 +897,14 @@ {
copy->token = hex_copy_token(ctx, item->token); if (!copy->token) { - hex_free_item(ctx, copy); hex_error(ctx, "[copy item] Failed to copy token"); + hex_free_item(ctx, copy); return NULL; } } else { - copy->token = NULL; + // copy->token = NULL; } return copy;@@ -3289,7 +3288,7 @@ case HEX_TYPE_INVALID:
fprintf(stream, "<invalid>"); break; default: - fprintf(stream, "<unknown>"); + fprintf(stream, "<unknown:%d>", item.type); break; } }@@ -3400,7 +3399,7 @@ case HEX_TYPE_INVALID:
fprintf(stream, "<invalid>"); break; default: - fprintf(stream, "<unknown>"); + fprintf(stream, "<unknown:%d>", item->type); break; } }@@ -5973,7 +5972,6 @@ return 1;
} } HEX_POP(ctx, evalResult); - ; if (evalResult->type == HEX_TYPE_INTEGER && evalResult->data.int_value == 0) { HEX_FREE(ctx, evalResult);@@ -5985,8 +5983,8 @@ for (size_t i = 0; i < act->quotation_size; i++)
{ if (hex_push(ctx, act->data.quotation_value[i]) != 0) { - HEX_FREE(ctx, action); HEX_FREE(ctx, act); + HEX_FREE(ctx, action); HEX_FREE(ctx, condition); return 1; }
@@ -12,7 +12,7 @@ {
if (token == NULL || token->value == NULL) return; free(token->value); - // token->value = NULL; + // token->value = NULL; free(token); // Free the token itself }@@ -394,8 +394,6 @@ }
// Copy basic fields copy->type = item->type; - copy->is_operator = item->is_operator; - copy->quotation_size = item->quotation_size; // Copy the union field based on the type switch (item->type)@@ -422,13 +420,15 @@ }
break; case HEX_TYPE_QUOTATION: - if (item->data.quotation_value && item->quotation_size > 0) + copy->quotation_size = item->quotation_size; + copy->is_operator = item->is_operator; + if (item->data.quotation_value) { copy->data.quotation_value = (hex_item_t **)malloc(item->quotation_size * sizeof(hex_item_t *)); if (!copy->data.quotation_value) { + hex_error(ctx, "[copy item] Failed to allocate memory for quotation array"); hex_free_item(ctx, copy); - hex_error(ctx, "[copy item] Failed to allocate memory for quotation array"); return NULL; }@@ -438,8 +438,8 @@ copy->data.quotation_value[i] = hex_copy_item(ctx, item->data.quotation_value[i]); // Recursively copy each item
if (!copy->data.quotation_value[i]) { // Cleanup on failure - hex_free_item(ctx, copy); hex_error(ctx, "[copy item] Failed to copy quotation item"); + hex_free_item(ctx, copy); return NULL; } }@@ -455,7 +455,6 @@ copy->data.fn_value = item->data.fn_value; // Copy function pointer for native symbols
break; case HEX_TYPE_USER_SYMBOL: - // User symbols do not have a function pointer, so no additional copying here break; default:@@ -471,8 +470,8 @@ {
copy->token = hex_copy_token(ctx, item->token); if (!copy->token) { - hex_free_item(ctx, copy); hex_error(ctx, "[copy item] Failed to copy token"); + hex_free_item(ctx, copy); return NULL; } }
@@ -2362,7 +2362,6 @@ return 1;
} } HEX_POP(ctx, evalResult); - ; if (evalResult->type == HEX_TYPE_INTEGER && evalResult->data.int_value == 0) { HEX_FREE(ctx, evalResult);@@ -2374,8 +2373,8 @@ for (size_t i = 0; i < act->quotation_size; i++)
{ if (hex_push(ctx, act->data.quotation_value[i]) != 0) { - HEX_FREE(ctx, action); HEX_FREE(ctx, act); + HEX_FREE(ctx, action); HEX_FREE(ctx, condition); return 1; }
@@ -133,7 +133,7 @@ case HEX_TYPE_INVALID:
fprintf(stream, "<invalid>"); break; default: - fprintf(stream, "<unknown>"); + fprintf(stream, "<unknown:%d>", item.type); break; } }@@ -244,7 +244,7 @@ case HEX_TYPE_INVALID:
fprintf(stream, "<invalid>"); break; default: - fprintf(stream, "<unknown>"); + fprintf(stream, "<unknown:%d>", item->type); break; } }