diff --git a/opal/util/json/opal_json.c b/opal/util/json/opal_json.c index 646b6fa2751..dd553e6e3b2 100644 --- a/opal/util/json/opal_json.c +++ b/opal/util/json/opal_json.c @@ -30,23 +30,19 @@ struct opal_json_internal_t { }; typedef struct opal_json_internal_t opal_json_internal_t; -static void opal_json_internal_reset(opal_json_internal_t *json) +static void opal_json_internal_free(opal_json_internal_t *json) { - json->parent.type = OPAL_JSON_TYPE_COUNT; - json->value = NULL; -} + if (NULL == json) { + return; + } -static void opal_json_internal_destruct(opal_json_internal_t *json) -{ /* The root JSON object will release the memory of its children */ if (json->value && NULL == json->value->parent) { json_value_free(json->value); } - opal_json_internal_reset(json); -} -OBJ_CLASS_INSTANCE(opal_json_internal_t, opal_json_t, opal_json_internal_reset, - opal_json_internal_destruct); + free(json); +} static inline int opal_json_internal_translate_type(json_type type, opal_json_type *out) { @@ -84,11 +80,13 @@ static inline int opal_json_internal_translate_type(json_type type, opal_json_ty static int opal_json_internal_new(const json_value *in, opal_json_internal_t **out) { - int ret = OPAL_SUCCESS; - *out = OBJ_NEW(opal_json_internal_t); + *out = malloc(sizeof(opal_json_internal_t)); + if (NULL == *out) { + return OPAL_ERROR; + } + (*out)->value = (json_value *) in; - ret = opal_json_internal_translate_type(in->type, &(*out)->parent.type); - return ret; + return opal_json_internal_translate_type(in->type, &(*out)->parent.type); } int opal_json_load(const char *str, const size_t len, opal_json_t **json) @@ -109,7 +107,7 @@ int opal_json_load(const char *str, const size_t len, opal_json_t **json) if (OPAL_SUCCESS == ret) { *json = (opal_json_t *) out; } else if (out) { - OBJ_RELEASE(out); + opal_json_internal_free(out); } return ret; @@ -181,7 +179,7 @@ int opal_json_get_key(const opal_json_t *json, const char *key, opal_json_t **ou if (OPAL_SUCCESS == ret) { *out = (opal_json_t *) result; } else if (result) { - OBJ_RELEASE(result); + opal_json_internal_free(result); } return ret; @@ -189,9 +187,7 @@ int opal_json_get_key(const opal_json_t *json, const char *key, opal_json_t **ou void opal_json_free(opal_json_t *json) { - if (json) { - OBJ_RELEASE(json); - } + opal_json_internal_free((struct opal_json_internal_t *) json); } int opal_json_get_index(const opal_json_t *json, const size_t index, opal_json_t **out) @@ -213,7 +209,7 @@ int opal_json_get_index(const opal_json_t *json, const size_t index, opal_json_t if (OPAL_SUCCESS == ret) { *out = (opal_json_t *) result; } else if (result) { - OBJ_RELEASE(result); + opal_json_internal_free(result); } return ret; diff --git a/opal/util/json/opal_json.h b/opal/util/json/opal_json.h index f258e93a054..69ad7ac0eab 100644 --- a/opal/util/json/opal_json.h +++ b/opal/util/json/opal_json.h @@ -64,13 +64,10 @@ typedef enum { } opal_json_type; struct opal_json_t { - opal_object_t super; opal_json_type type; }; typedef struct opal_json_t opal_json_t; -OBJ_CLASS_INSTANCE(opal_json_t, opal_object_t, NULL, NULL); - /** * Load JSON from a string. *