mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-22 04:18:01 +00:00
At least don't talk about allocation sizes in the public API
This commit is contained in:
parent
d630aa917e
commit
68e0784cc3
15
jsonpull.c
15
jsonpull.c
@ -13,6 +13,8 @@ static void json_error(char *s, ...) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#define SIZE_FOR(i) (((i) + 31) & ~31)
|
||||
|
||||
static json_object *add_object(json_type type, json_object *parent) {
|
||||
json_object *o = malloc(sizeof(struct json_object));
|
||||
o->type = type;
|
||||
@ -21,13 +23,11 @@ static json_object *add_object(json_type type, json_object *parent) {
|
||||
o->keys = NULL;
|
||||
o->values = NULL;
|
||||
o->length = 0;
|
||||
o->__allocated = 0;
|
||||
|
||||
if (parent != NULL) {
|
||||
if (parent->type == JSON_ARRAY) {
|
||||
if (parent->length >= parent->__allocated) {
|
||||
parent->__allocated += 20;
|
||||
parent->array = realloc(parent->array, parent->__allocated * sizeof(json_object *));
|
||||
if (SIZE_FOR(parent->length + 1) != SIZE_FOR(parent->length)) {
|
||||
parent->array = realloc(parent->array, SIZE_FOR(parent->length + 1) * sizeof(json_object *));
|
||||
}
|
||||
|
||||
parent->array[parent->length++] = o;
|
||||
@ -44,10 +44,9 @@ static json_object *add_object(json_type type, json_object *parent) {
|
||||
json_error("Hash key is not a string");
|
||||
}
|
||||
|
||||
if (parent->length >= parent->__allocated) {
|
||||
parent->__allocated += 20;
|
||||
parent->keys = realloc(parent->keys, parent->__allocated * sizeof(json_object *));
|
||||
parent->values = realloc(parent->values, parent->__allocated * sizeof(json_object *));
|
||||
if (SIZE_FOR(parent->length + 1) != SIZE_FOR(parent->length)) {
|
||||
parent->keys = realloc(parent->keys, SIZE_FOR(parent->length + 1) * sizeof(json_object *));
|
||||
parent->values = realloc(parent->values, SIZE_FOR(parent->length + 1) * sizeof(json_object *));
|
||||
}
|
||||
|
||||
parent->keys[parent->length] = o;
|
||||
|
@ -1,9 +1,3 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef enum json_type {
|
||||
JSON_HASH, JSON_ARRAY, JSON_NUMBER, JSON_STRING, JSON_TRUE, JSON_FALSE, JSON_NULL,
|
||||
} json_type;
|
||||
@ -19,7 +13,6 @@ typedef struct json_object {
|
||||
struct json_object **keys;
|
||||
struct json_object **values;
|
||||
int length;
|
||||
int __allocated;
|
||||
} json_object;
|
||||
|
||||
json_object *json_parse(FILE *f, json_object *current);
|
||||
|
Loading…
Reference in New Issue
Block a user