Skip to content

Commit

Permalink
Merge pull request armink#4 from zbcfscc/master
Browse files Browse the repository at this point in the history
Add delete API for struct object and JSON object.
  • Loading branch information
armink authored Jul 20, 2016
2 parents 5c85d98 + 17c5971 commit dbc1c6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions demo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@ int main(void) {
printf("Converted OK!\n");
}

s2j_delete_json_obj(json_student);
s2j_delete_struct_obj(converted_student_obj);

return 0;
}
8 changes: 8 additions & 0 deletions struct2json/inc/s2j.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extern "C" {
#define s2j_create_json_obj(json_obj) \
S2J_CREATE_JSON_OBJECT(json_obj)

/* Delete JSON object */
#define s2j_delete_json_obj(json_obj) \
S2J_DELETE_JSON_OBJECT(json_obj)

/* Set basic type element for JSON object */
#define s2j_json_set_basic_element(to_json, from_struct, type, element) \
S2J_JSON_SET_BASIC_ELEMENT(to_json, from_struct, type, element)
Expand All @@ -60,6 +64,10 @@ extern "C" {
#define s2j_create_struct_obj(struct_obj, type) \
S2J_CREATE_STRUCT_OBJECT(struct_obj, type)

/* Delete structure object */
#define s2j_delete_struct_obj(struct_obj) \
S2J_DELETE_STRUCT_OBJECT(struct_obj)

/* Get basic type element for structure object */
#define s2j_struct_get_basic_element(to_struct, from_json, type, element) \
S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element)
Expand Down
6 changes: 6 additions & 0 deletions struct2json/inc/s2jdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ typedef struct {
#define S2J_CREATE_JSON_OBJECT(json_obj) \
cJSON *json_obj = cJSON_CreateObject();

#define S2J_DELETE_JSON_OBJECT(json_obj) \
cJSON_Delete(json_obj);

#define S2J_JSON_SET_BASIC_ELEMENT(to_json, from_struct, type, _element) \
S2J_JSON_SET_##type##_ELEMENT(to_json, from_struct, _element)

Expand All @@ -116,6 +119,9 @@ typedef struct {
type *struct_obj = s2jHook.malloc_fn(sizeof(type)); \
if (struct_obj) memset(struct_obj, 0, sizeof(type));

#define S2J_DELETE_STRUCT_OBJECT(struct_obj) \
s2jHook.free_fn(struct_obj);

#define S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, _element) \
S2J_STRUCT_GET_##type##_ELEMENT(to_struct, from_json, _element)

Expand Down

0 comments on commit dbc1c6c

Please sign in to comment.