changed std allocation to rjp allocations
This commit is contained in:
parent
d68bea08f4
commit
cd5ddd950b
@ -94,7 +94,8 @@ void rjp_free_value(RJP_value* root);
|
||||
//initialize an empty json handle (outputting to string would result in '{}')
|
||||
RJP_value* rjp_init_json(void);
|
||||
|
||||
char* rjp_alloc(size_t nbytes);
|
||||
void* rjp_alloc(size_t nbytes);
|
||||
void* rjp_calloc(size_t num, size_t nbytes);
|
||||
void rjp_free(void* dest);
|
||||
|
||||
//add a member to a json object
|
||||
|
||||
18
src/input.c
18
src/input.c
@ -58,10 +58,10 @@ static int _rjp__is_whitespace(char c){
|
||||
void _rjp__add_element(RJP_array* j){
|
||||
++j->num_elements;
|
||||
if(!j->elements){
|
||||
j->elements = calloc(1, sizeof(RJP_array_element));
|
||||
j->elements = rjp_calloc(1, sizeof(RJP_array_element));
|
||||
j->last = j->elements;
|
||||
}else{
|
||||
j->last->next = calloc(1, sizeof(RJP_array_element));
|
||||
j->last->next = rjp_calloc(1, sizeof(RJP_array_element));
|
||||
j->last = j->last->next;
|
||||
}
|
||||
}
|
||||
@ -69,13 +69,13 @@ void _rjp__add_element(RJP_array* j){
|
||||
void _rjp__add_member(RJP_object* j, char* str, size_t len){
|
||||
++j->num_members;
|
||||
if(!j->members){
|
||||
j->members = calloc(1, sizeof(RJP_object_member));
|
||||
j->members = rjp_calloc(1, sizeof(RJP_object_member));
|
||||
j->last = j->members;
|
||||
}else{
|
||||
j->last->next = calloc(1, sizeof(RJP_object_member));
|
||||
j->last->next = rjp_calloc(1, sizeof(RJP_object_member));
|
||||
j->last = j->last->next;
|
||||
}
|
||||
j->last->name.value = malloc(len + 1);
|
||||
j->last->name.value = rjp_alloc(len + 1);
|
||||
strncpy(j->last->name.value, str, len);
|
||||
j->last->name.value[len] = 0;
|
||||
j->last->name.length = len;
|
||||
@ -83,10 +83,10 @@ void _rjp__add_member(RJP_object* j, char* str, size_t len){
|
||||
void _rjp__add_member_no_alloc(RJP_object* j, char* str, size_t len){
|
||||
++j->num_members;
|
||||
if(!j->members){
|
||||
j->members = calloc(1, sizeof(RJP_object_member));
|
||||
j->members = rjp_calloc(1, sizeof(RJP_object_member));
|
||||
j->last = j->members;
|
||||
}else{
|
||||
j->last->next = calloc(1, sizeof(RJP_object_member));
|
||||
j->last->next = rjp_calloc(1, sizeof(RJP_object_member));
|
||||
j->last = j->last->next;
|
||||
}
|
||||
j->last->name.value = str;
|
||||
@ -104,7 +104,7 @@ static RJP_value* _rjp__add_element_to_array(RJP_value* curr, RJP_state* state,
|
||||
//Assign object characteristics to previously allocated RJP_value
|
||||
static RJP_value* _rjp__add_object(RJP_value* curr, RJP_state* state){
|
||||
if(!curr){
|
||||
curr = calloc(1, sizeof(RJP_value));
|
||||
curr = rjp_calloc(1, sizeof(RJP_value));
|
||||
curr->type = json_object;
|
||||
return curr;
|
||||
}
|
||||
@ -351,7 +351,7 @@ RJP_value* rjp_parse(const char* str){
|
||||
char* new_string = _rjp__parse_string(root, str, &vallen, &row, &column);
|
||||
if(!new_string){
|
||||
if(vallen == 0){
|
||||
new_string = calloc(1, 1);
|
||||
new_string = rjp_calloc(1, 1);
|
||||
}else{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -6,13 +6,16 @@
|
||||
#include <stdio.h> //sprintf
|
||||
|
||||
RJP_value* rjp_init_json(void){
|
||||
RJP_value* ret = calloc(1, sizeof(RJP_value));
|
||||
RJP_value* ret = rjp_calloc(1, sizeof(RJP_value));
|
||||
ret->type = json_object;
|
||||
return ret;
|
||||
}
|
||||
char* rjp_alloc(size_t nbytes){
|
||||
void* rjp_alloc(size_t nbytes){
|
||||
return malloc(nbytes);
|
||||
}
|
||||
void* rjp_calloc(size_t num, size_t nbytes){
|
||||
return calloc(num, nbytes);
|
||||
}
|
||||
void rjp_free(void* data){
|
||||
free(data);
|
||||
}
|
||||
@ -173,7 +176,7 @@ char* rjp_to_json(RJP_value* root){
|
||||
size_t len = _rjp__object_strlen(root);
|
||||
if(!len)
|
||||
return NULL;
|
||||
char* tmp = malloc(len + 1);
|
||||
char* tmp = rjp_alloc(len + 1);
|
||||
tmp[len] = 0;
|
||||
size_t pos = 1;
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ char* _rjp__parse_string(RJP_value* root, const char* str, int* len, int* row, i
|
||||
if(*len == 0){
|
||||
return NULL;
|
||||
}
|
||||
new_string = malloc(*len + 1);
|
||||
new_string = rjp_alloc(*len + 1);
|
||||
new_string[*len] = 0;
|
||||
for(int i = 0;*str != '"';++i,++str){
|
||||
if(*str == '\\'){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user