From a6a34a933b6c4eacb5868ec490c64d65820b1832 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Mon, 24 Mar 2025 20:33:43 -0600 Subject: [PATCH] remove array function added to config, still needs testing --- src/std/config.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/std/config.c b/src/std/config.c index 7ad6868..00e94bb 100644 --- a/src/std/config.c +++ b/src/std/config.c @@ -312,6 +312,10 @@ void ARC_Config_GroupDataHashtableDestroyKeyValueFn(void *key, void *value){ free(typeData); } +//private empty function to avoid removing references or data freed from an array +void ARC_ConfigType_EmptyDestroyFn(void *type){ +} + // -> EQUAL SEMICOLON void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config *config){ //skip whitespace and check for group name @@ -341,8 +345,25 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config ARC_String_Create(&variableString, NULL, 0); ARC_ParserData_HelperRecurseStringAdd(&variableString, childTagToken); + //check if the value is an array + childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 5); + ARC_Bool isArray = (ARC_Bool)(ARC_Vector_GetSize(childTagToken->tagTokens) != 0); + //check if removing if(config->load == ARC_False){ + if(isArray == ARC_True){ + ARC_ConfigTypeData *removingType = ARC_Hashtable_Get(config->currentGroup, (void *)variableString->data); + ARC_Array *array = (ARC_Array *)removingType->data; + + for(uint32_t index = 0; index < array->size; index++){ + removingType->destroyFn(array->data + index); + } + + removingType->destroyFn = ARC_ConfigType_EmptyDestroyFn; + ARC_Hashtable_Remove(config->currentGroup, (void *)variableString->data); + return; + } + ARC_Hashtable_Remove(config->currentGroup, (void *)variableString->data); ARC_String_Destroy(variableString); return; @@ -364,10 +385,6 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config nameVariableCStr[variableString->length] = '\0'; ARC_String_Destroy(variableString); - //check if the value is an array - childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 5); - ARC_Bool isArray = (ARC_Bool)(ARC_Vector_GetSize(childTagToken->tagTokens) != 0); - //get childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 9); @@ -438,8 +455,11 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config memcpy(array->data, typeVectorArray.data, typeVectorArray.size); } + //set the type data as an array + typeData->data = array; + //add the array to the group hashtable - ARC_Hashtable_Add(config->currentGroup, (void *)nameVariableCStr, (void *)array); + ARC_Hashtable_Add(config->currentGroup, (void *)nameVariableCStr, (void *)typeData); //cleanup ARC_VectorInline_Destroy(typeVector);