Fixed a memory leak and removed main function (again)
This commit is contained in:
parent
890876a490
commit
f1d8dbde97
@ -93,6 +93,7 @@ struct JSON_object_member{
|
||||
struct JSON_value* rjp_parse(const char* str);
|
||||
|
||||
//deallocate a json handle
|
||||
void rjp_free_json(char* json);
|
||||
void rjp_free(struct JSON_value* root);
|
||||
|
||||
struct JSON_object_member* rjp_get_members(struct JSON_object* j);
|
||||
|
||||
24
src/input.c
24
src/input.c
@ -59,7 +59,7 @@ void _rjp__add_element(struct JSON_array* j){
|
||||
j->last = j->last->next;
|
||||
}
|
||||
}
|
||||
//create member of the object as a linked list member and assign a name with no name allocation
|
||||
//create member of the object as a linked list member and assign a name with name allocation
|
||||
void _rjp__add_member(struct JSON_object* j, char* str, size_t len){
|
||||
++j->num_members;
|
||||
if(!j->members){
|
||||
@ -187,6 +187,9 @@ static void _rjp__free_object_recurse(struct JSON_value* root){
|
||||
free(m);
|
||||
}
|
||||
}
|
||||
void rjp_free_json(char* json){
|
||||
free(json);
|
||||
}
|
||||
//Same as recurse but also frees root node
|
||||
void rjp_free(struct JSON_value* root){
|
||||
if(!root)
|
||||
@ -263,7 +266,7 @@ struct JSON_value* rjp_parse(const char* str){
|
||||
syntax_error("Cannot have empty key name!", row, column);
|
||||
return NULL;
|
||||
}
|
||||
_rjp__add_member(&curr->object, new_string, keylen);
|
||||
_rjp__add_member_no_alloc(&curr->object, new_string, keylen);
|
||||
str += keylen;
|
||||
top->search_target = json_colon;
|
||||
//end of this object (object is empty)
|
||||
@ -423,20 +426,3 @@ enum JSON_type rjp_get_member_type(struct JSON_object_member* j){
|
||||
enum JSON_type rjp_get_value_type(struct JSON_value* j){
|
||||
return j->type;
|
||||
}
|
||||
|
||||
int main(){
|
||||
struct JSON_value* root = rjp_init_json();
|
||||
rjp_add_member(&root->object, 1, "intel_backlight", 0, (struct JSON_value){.integer = 4, .type = json_integer});
|
||||
rjp_add_member(&root->object, 1, "other_backlight", 0, (struct JSON_value){.integer = 14, .type = json_integer});
|
||||
struct JSON_value sub_object = rjp_object();
|
||||
rjp_add_member(&sub_object.object, 1, "sub_item", 0, rjp_array());
|
||||
rjp_add_member(&root->object, 1, "object", 0, sub_object);
|
||||
printf("%d\n", snprintf(NULL, 0, "%lf", 100.0));
|
||||
printf("%lf\n", 100.0);
|
||||
char* out = rjp_to_json(root);
|
||||
printf("%s\n", out);
|
||||
free(out);
|
||||
printf("\n");
|
||||
printf("%lu\n", _rjp__object_strlen(root));
|
||||
rjp_free(root);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user