Skip to content

Commit 61cc14b

Browse files
committed
TEST try without OPAL_OBJECT
Signed-off-by: Wenduo Wang <[email protected]>
1 parent eafc65b commit 61cc14b

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

opal/util/json/opal_json.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,19 @@ struct opal_json_internal_t {
3030
};
3131
typedef struct opal_json_internal_t opal_json_internal_t;
3232

33-
static void opal_json_internal_reset(opal_json_internal_t *json)
33+
static void opal_json_internal_free(opal_json_internal_t *json)
3434
{
35-
json->parent.type = OPAL_JSON_TYPE_COUNT;
36-
json->value = NULL;
37-
}
35+
if (NULL == json) {
36+
return;
37+
}
3838

39-
static void opal_json_internal_destruct(opal_json_internal_t *json)
40-
{
4139
/* The root JSON object will release the memory of its children */
4240
if (json->value && NULL == json->value->parent) {
4341
json_value_free(json->value);
4442
}
45-
opal_json_internal_reset(json);
46-
}
4743

48-
OBJ_CLASS_INSTANCE(opal_json_internal_t, opal_json_t, opal_json_internal_reset,
49-
opal_json_internal_destruct);
44+
free(json);
45+
}
5046

5147
static inline int opal_json_internal_translate_type(json_type type, opal_json_type *out)
5248
{
@@ -84,11 +80,13 @@ static inline int opal_json_internal_translate_type(json_type type, opal_json_ty
8480

8581
static int opal_json_internal_new(const json_value *in, opal_json_internal_t **out)
8682
{
87-
int ret = OPAL_SUCCESS;
88-
*out = OBJ_NEW(opal_json_internal_t);
83+
*out = malloc(sizeof(opal_json_internal_t));
84+
if (NULL == *out) {
85+
return OPAL_ERROR;
86+
}
87+
8988
(*out)->value = (json_value *) in;
90-
ret = opal_json_internal_translate_type(in->type, &(*out)->parent.type);
91-
return ret;
89+
return opal_json_internal_translate_type(in->type, &(*out)->parent.type);
9290
}
9391

9492
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)
109107
if (OPAL_SUCCESS == ret) {
110108
*json = (opal_json_t *) out;
111109
} else if (out) {
112-
OBJ_RELEASE(out);
110+
opal_json_internal_free(out);
113111
}
114112

115113
return ret;
@@ -181,17 +179,15 @@ int opal_json_get_key(const opal_json_t *json, const char *key, opal_json_t **ou
181179
if (OPAL_SUCCESS == ret) {
182180
*out = (opal_json_t *) result;
183181
} else if (result) {
184-
OBJ_RELEASE(result);
182+
opal_json_internal_free(result);
185183
}
186184

187185
return ret;
188186
}
189187

190188
void opal_json_free(opal_json_t *json)
191189
{
192-
if (json) {
193-
OBJ_RELEASE(json);
194-
}
190+
opal_json_internal_free((struct opal_json_internal_t *) json);
195191
}
196192

197193
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
213209
if (OPAL_SUCCESS == ret) {
214210
*out = (opal_json_t *) result;
215211
} else if (result) {
216-
OBJ_RELEASE(result);
212+
opal_json_internal_free(result);
217213
}
218214

219215
return ret;

opal/util/json/opal_json.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ typedef enum {
6464
} opal_json_type;
6565

6666
struct opal_json_t {
67-
opal_object_t super;
6867
opal_json_type type;
6968
};
7069
typedef struct opal_json_t opal_json_t;
7170

72-
OBJ_CLASS_INSTANCE(opal_json_t, opal_object_t, NULL, NULL);
73-
7471
/**
7572
* Load JSON from a string.
7673
*

0 commit comments

Comments
 (0)