mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 16:35:40 +02:00
Convert jsonpull to C++ with shared_ptr and std::vector/std::string
Replace the manual malloc/realloc/free memory management in jsonpull with std::shared_ptr ownership. Each json_object now owns its children through std::vector<json_object_ptr>; raw back-pointers to parent and parser remain valid by structural invariant and are cleared on json_disconnect so detached subtrees can outlive their parser. Strings become std::string, child arrays become std::vector, and the old union becomes a struct so non-trivial members can coexist while preserving the existing o->value.xxx access paths. The old jsonpull.c is replaced by jsonpull.cpp, json_stringify now returns std::string, and all callers across tippecanoe, tile-join, tippecanoe-decode, tippecanoe-json-tool, tippecanoe-overzoom and the unit tests are updated to use json_object_ptr / json_pull_ptr. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+7
-9
@@ -42,10 +42,10 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
|
||||
|
||||
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, const char *arg, char **argv) {
|
||||
if (*arg == '{') {
|
||||
json_pull *jp = json_begin_string(arg);
|
||||
json_object *o = json_read_tree(jp);
|
||||
json_pull_ptr jp = json_begin_string(arg);
|
||||
json_object_ptr o = json_read_tree(jp);
|
||||
|
||||
if (o == NULL) {
|
||||
if (o == nullptr) {
|
||||
fprintf(stderr, "%s: -E%s: %s\n", *argv, arg, jp->error);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
@@ -55,9 +55,9 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < o->value.object.length; i++) {
|
||||
json_object *k = o->value.object.keys[i];
|
||||
json_object *v = o->value.object.values[i];
|
||||
for (size_t i = 0; i < o->value.object.keys.size(); i++) {
|
||||
json_object_ptr k = o->value.object.keys[i];
|
||||
json_object_ptr v = o->value.object.values[i];
|
||||
|
||||
if (k->type != JSON_STRING) {
|
||||
fprintf(stderr, "%s: -E%s: key %zu not a string\n", *argv, arg, i);
|
||||
@@ -68,11 +68,9 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
set_attribute_accum(attribute_accum, k->value.string.string, v->value.string.string);
|
||||
set_attribute_accum(attribute_accum, k->value.string.string.c_str(), v->value.string.string.c_str());
|
||||
}
|
||||
|
||||
json_free(o);
|
||||
json_end(jp);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user