From 927926c845392d686ab8a021732ca4e8c556b5dd Mon Sep 17 00:00:00 2001 From: PengZheng Date: Thu, 18 Jan 2024 14:27:22 +0800 Subject: [PATCH] Remove unnecessary recursions caused by type reference by name. --- libs/dfi/src/dyn_type.c | 7 +++---- libs/dfi/src/json_serializer.c | 24 +++++++++++------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/libs/dfi/src/dyn_type.c b/libs/dfi/src/dyn_type.c index 92fb4fe5f..d9ce0206f 100644 --- a/libs/dfi/src/dyn_type.c +++ b/libs/dfi/src/dyn_type.c @@ -629,11 +629,10 @@ static void dynType_deepFree(const dyn_type* type, void* loc, bool alsoDeleteSel if (loc != NULL) { const dyn_type* subType = NULL; char* text = NULL; + while (type->type == DYN_TYPE_REF) { + type = type->ref.ref; + } switch (type->type) { - case DYN_TYPE_REF: - //NOTE: do not recursively forward asloDeleteSelf, because this is already handled in this function) - dynType_deepFree(type->ref.ref, loc, false); - break; case DYN_TYPE_COMPLEX : dynType_freeComplexType(type, loc); break; diff --git a/libs/dfi/src/json_serializer.c b/libs/dfi/src/json_serializer.c index 6c97d625e..c271a0277 100644 --- a/libs/dfi/src/json_serializer.c +++ b/libs/dfi/src/json_serializer.c @@ -61,7 +61,11 @@ int jsonSerializer_deserialize(const dyn_type* type, const char* input, size_t l } int jsonSerializer_deserializeJson(const dyn_type* type, json_t* input, void** out) { - return jsonSerializer_createType(type, input, out); + const dyn_type* real = type; + while (real->type == DYN_TYPE_REF) { + real = real->ref.ref; + } + return jsonSerializer_createType(real, input, out); } static int jsonSerializer_createType(const dyn_type* type, json_t* val, void** result) { @@ -203,10 +207,7 @@ static int jsonSerializer_parseAny(const dyn_type* type, void* loc, json_t* val) celix_err_pushf("Error cannot deserialize pointer to pointer"); } break; - case 'l': - status = jsonSerializer_parseAny(type->ref.ref, loc, val); - break; - case 'P' : + //case 'P' : default : status = ERROR; celix_err_pushf("Error provided type '%c' not supported for JSON\n", c); @@ -273,7 +274,11 @@ static int jsonSerializer_parseEnum(const dyn_type* type, const char* enum_name, } int jsonSerializer_serializeJson(const dyn_type* type, const void* input, json_t** out) { - return jsonSerializer_writeAny(type, (void*)input /*TODO update static function to take const void**/, out); + const dyn_type* real = type; + while (real->type == DYN_TYPE_REF) { + real = real->ref.ref; + } + return jsonSerializer_writeAny(real, (void*)input /*TODO update static function to take const void**/, out); } static int jsonSerializer_writeAny(const dyn_type *type, void* input, json_t **out) { @@ -363,13 +368,6 @@ static int jsonSerializer_writeAny(const dyn_type *type, void* input, json_t **o case '[' : status = jsonSerializer_writeSequence(type, input, &val); break; - case 'P' : - status = ERROR; - celix_err_pushf("Untyped pointer not supported for serialization."); - break; - case 'l': - status = jsonSerializer_writeAny(type->ref.ref, input, out); - break; default : celix_err_pushf("Unsupported descriptor '%c'", descriptor); status = ERROR;