File tree 2 files changed +29
-9
lines changed
2 files changed +29
-9
lines changed Original file line number Diff line number Diff line change 4
4
#include "object.h"
5
5
6
6
object_t * object_create () {
7
- object_t * object = malloc ( sizeof (object_t ));
7
+ object_t * object = calloc ( 1 , sizeof (object_t ));
8
8
9
9
return object ;
10
10
}
11
11
12
12
void object_free (object_t * object ) {
13
+ if (!object ) {
14
+ return ;
15
+ }
16
+
17
+ if (object -> temporary ) {
18
+ free (object -> temporary );
19
+ object -> temporary = NULL ;
20
+ }
21
+
13
22
free (object );
14
23
}
15
24
16
25
cJSON * object_convertToJSON (object_t * object ) {
17
- cJSON * item = cJSON_CreateObject ();
26
+ if (!object ) {
27
+ return NULL ;
28
+ }
18
29
19
- return item ;
20
- fail :
21
- cJSON_Delete (item );
22
- return NULL ;
30
+ if (!object -> temporary ) {
31
+ return cJSON_Parse ("null" );
32
+ }
33
+
34
+ return cJSON_Parse (object -> temporary );
23
35
}
24
36
25
- object_t * object_parseFromJSON (char * jsonString ){
26
- object_t * object = NULL ;
37
+ object_t * object_parseFromJSON (cJSON * json ){
38
+ if (!json ) {
39
+ goto end ;
40
+ }
27
41
42
+ object_t * object = object_create ();
43
+ if (!object ) {
44
+ goto end ;
45
+ }
46
+ object -> temporary = cJSON_Print (json );
28
47
return object ;
48
+
29
49
end :
30
50
return NULL ;
31
51
}
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ object_t *object_create();
20
20
21
21
void object_free (object_t * object );
22
22
23
- object_t * object_parseFromJSON (char * jsonString );
23
+ object_t * object_parseFromJSON (cJSON * json );
24
24
25
25
cJSON * object_convertToJSON (object_t * object );
26
26
You can’t perform that action at this time.
0 commit comments