Debian Codegraph @

texk/web2c/mfluadir/otfcc/dep/extern/json-builder.c

raw
1
2 /* vim: set et ts=3 sw=3 sts=3 ft=c:
3 *
4 * Copyright (C) 2014 James McLaughlin. All rights reserved.
5 * https://github.com/udp/json-builder
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include "json-builder.h"
32 #include "emyg-dtoa/emyg-dtoa.h"
33
34 #include <string.h>
35 #include <assert.h>
36 #include <stdio.h>
37 #include <math.h>
38
39 #ifdef _MSC_VER
40 #define snprintf _snprintf
41 #endif
42
43 const static json_serialize_opts default_opts = {
44 json_serialize_mode_single_line, 0, 3 /* indent_size */
45 };
46
47 typedef struct json_builder_value {
48 json_value value;
49
50 int is_builder_value;
51
52 size_t additional_length_allocated;
53 size_t length_iterated;
54
55 } json_builder_value;
56
57 static int builderize(json_value *value) {
58 if (((json_builder_value *)value)->is_builder_value) return 1;
59
60 if (value->type == json_object) {
61 unsigned int i;
62
63 /* Values straight out of the parser have the names of object entries
64 * allocated in the same allocation as the values array itself. This is
65 * not desirable when manipulating values because the names would be easy
66 * to clobber.
67 */
68 for (i = 0; i < value->u.object.length; ++i) {
69 json_char *name_copy;
70 json_object_entry *entry = &value->u.object.values[i];
71
72 if (!(name_copy = (json_char *)malloc((entry->name_length + 1) * sizeof(json_char)))) return 0;
73
74 memcpy(name_copy, entry->name, entry->name_length + 1);
75 entry->name = name_copy;
76 }
77 }
78
79 ((json_builder_value *)value)->is_builder_value = 1;
80
81 return 1;
82 }
83
84 const size_t json_builder_extra = sizeof(json_builder_value) - sizeof(json_value);
85
86 /* These flags are set up from the opts before serializing to make the
87 * serializer conditions simpler.
88 */
89 const int f_spaces_around_brackets = (1 << 0);
90 const int f_spaces_after_commas = (1 << 1);
91 const int f_spaces_after_colons = (1 << 2);
92 const int f_tabs = (1 << 3);
93
94 static int get_serialize_flags(json_serialize_opts opts) {
95 int flags = 0;
96
97 if (opts.mode == json_serialize_mode_packed) return 0;
98
99 if (opts.mode == json_serialize_mode_multiline) {
100 if (opts.opts & json_serialize_opt_use_tabs) flags |= f_tabs;
101 } else {
102 if (!(opts.opts & json_serialize_opt_pack_brackets)) flags |= f_spaces_around_brackets;
103
104 if (!(opts.opts & json_serialize_opt_no_space_after_comma)) flags |= f_spaces_after_commas;
105 }
106
107 if (!(opts.opts & json_serialize_opt_no_space_after_colon)) flags |= f_spaces_after_colons;
108
109 return flags;
110 }
111
112 json_value *json_array_new(size_t length) {
113 json_value *value = (json_value *)calloc(1, sizeof(json_builder_value));
114
115 if (!value) return NULL;
116
117 ((json_builder_value *)value)->is_builder_value = 1;
118
119 value->type = json_array;
120
121 if (!(value->u.array.values = (json_value **)malloc(length * sizeof(json_value *)))) {
122 free(value);
123 return NULL;
124 }
125
126 ((json_builder_value *)value)->additional_length_allocated = length;
127
128 return value;
129 }
130
131 json_value *json_array_push(json_value *array, json_value *value) {
132 assert(array->type == json_array);
133
134 if (!builderize(array) || !builderize(value)) return NULL;
135
136 if (((json_builder_value *)array)->additional_length_allocated > 0) {
137 --((json_builder_value *)array)->additional_length_allocated;
138 } else {
139 json_value **values_new =
140 (json_value **)realloc(array->u.array.values, sizeof(json_value *) * (array->u.array.length + 1));
141
142 if (!values_new) return NULL;
143
144 array->u.array.values = values_new;
145 }
146
147 array->u.array.values[array->u.array.length] = value;
148 ++array->u.array.length;
149
150 value->parent = array;
151
152 return value;
153 }
154
155 json_value *json_object_new(size_t length) {
156 json_value *value = (json_value *)calloc(1, sizeof(json_builder_value));
157
158 if (!value) return NULL;
159
160 ((json_builder_value *)value)->is_builder_value = 1;
161
162 value->type = json_object;
163
164 if (!(value->u.object.values = (json_object_entry *)calloc(length, sizeof(*value->u.object.values)))) {
165 free(value);
166 return NULL;
167 }
168
169 ((json_builder_value *)value)->additional_length_allocated = length;
170
171 return value;
172 }
173
174 json_value *json_object_push(json_value *object, const json_char *name, json_value *value) {
175 return json_object_push_length(object, strlen(name), name, value);
176 }
177
178 json_value *json_object_push_length(json_value *object, unsigned int name_length, const json_char *name,
179 json_value *value) {
180 json_char *name_copy;
181
182 assert(object->type == json_object);
183
184 if (!(name_copy = (json_char *)malloc((name_length + 1) * sizeof(json_char)))) return NULL;
185
186 memcpy(name_copy, name, name_length * sizeof(json_char));
187 name_copy[name_length] = 0;
188
189 if (!json_object_push_nocopy(object, name_length, name_copy, value)) {
190 free(name_copy);
191 return NULL;
192 }
193
194 return value;
195 }
196
197 json_value *json_object_push_nocopy(json_value *object, unsigned int name_length, json_char *name, json_value *value) {
198 json_object_entry *entry;
199
200 assert(object->type == json_object);
201
202 if (!builderize(object) || !builderize(value)) return NULL;
203
204 if (((json_builder_value *)object)->additional_length_allocated > 0) {
205 --((json_builder_value *)object)->additional_length_allocated;
206 } else {
207 json_object_entry *values_new = (json_object_entry *)realloc(
208 object->u.object.values, sizeof(*object->u.object.values) * (object->u.object.length + 1));
209
210 if (!values_new) return NULL;
211
212 object->u.object.values = values_new;
213 }
214
215 entry = object->u.object.values + object->u.object.length;
216
217 entry->name_length = name_length;
218 entry->name = name;
219 entry->value = value;
220
221 ++object->u.object.length;
222
223 value->parent = object;
224
225 return value;
226 }
227
228 json_value *json_string_new(const json_char *buf) {
229 return json_string_new_length(strlen(buf), buf);
230 }
231
232 json_value *json_string_new_length(unsigned int length, const json_char *buf) {
233 json_value *value;
234 json_char *copy = (json_char *)malloc((length + 1) * sizeof(json_char));
235
236 if (!copy) return NULL;
237
238 memcpy(copy, buf, length * sizeof(json_char));
239 copy[length] = 0;
240
241 if (!(value = json_string_new_nocopy(length, copy))) {
242 free(copy);
243 return NULL;
244 }
245
246 return value;
247 }
248
249 json_value *json_string_new_nocopy(unsigned int length, json_char *buf) {
250 json_value *value = (json_value *)calloc(1, sizeof(json_builder_value));
251
252 if (!value) return NULL;
253
254 ((json_builder_value *)value)->is_builder_value = 1;
255
256 value->type = json_string;
257 value->u.string.length = length;
258 value->u.string.ptr = buf;
259
260 return value;
261 }
262
263 json_value *json_integer_new(json_int_t integer) {
264 json_value *value = (json_value *)calloc(1, sizeof(json_builder_value));
265
266 if (!value) return NULL;
267
268 ((json_builder_value *)value)->is_builder_value = 1;
269
270 value->type = json_integer;
271 value->u.integer = integer;
272
273 return value;
274 }
275
276 json_value *json_double_new(double dbl) {
277 json_value *value = (json_value *)calloc(1, sizeof(json_builder_value));
278
279 if (!value) return NULL;
280
281 ((json_builder_value *)value)->is_builder_value = 1;
282
283 value->type = json_double;
284 value->u.dbl = dbl;
285
286 return value;
287 }
288
289 json_value *json_boolean_new(int b) {
290 json_value *value = (json_value *)calloc(1, sizeof(json_builder_value));
291
292 if (!value) return NULL;
293
294 ((json_builder_value *)value)->is_builder_value = 1;
295
296 value->type = json_boolean;
297 value->u.boolean = b;
298
299 return value;
300 }
301
302 json_value *json_null_new(void) {
303 json_value *value = (json_value *)calloc(1, sizeof(json_builder_value));
304
305 if (!value) return NULL;
306
307 ((json_builder_value *)value)->is_builder_value = 1;
308
309 value->type = json_null;
310
311 return value;
312 }
313
314 void json_object_sort(json_value *object, json_value *proto) {
315 unsigned int i, out_index = 0;
316
317 if (!builderize(object)) return; /* TODO error */
318
319 assert(object->type == json_object);
320 assert(proto->type == json_object);
321
322 for (i = 0; i < proto->u.object.length; ++i) {
323 unsigned int j;
324 json_object_entry proto_entry = proto->u.object.values[i];
325
326 for (j = 0; j < object->u.object.length; ++j) {
327 json_object_entry entry = object->u.object.values[j];
328
329 if (entry.name_length != proto_entry.name_length) continue;
330
331 if (memcmp(entry.name, proto_entry.name, entry.name_length) != 0) continue;
332
333 object->u.object.values[j] = object->u.object.values[out_index];
334 object->u.object.values[out_index] = entry;
335
336 ++out_index;
337 }
338 }
339 }
340
341 json_value *json_object_merge(json_value *objectA, json_value *objectB) {
342 unsigned int i;
343
344 assert(objectA->type == json_object);
345 assert(objectB->type == json_object);
346 assert(objectA != objectB);
347
348 if (!builderize(objectA) || !builderize(objectB)) return NULL;
349
350 if (objectB->u.object.length <= ((json_builder_value *)objectA)->additional_length_allocated) {
351 ((json_builder_value *)objectA)->additional_length_allocated -= objectB->u.object.length;
352 } else {
353 json_object_entry *values_new;
354
355 unsigned int alloc = objectA->u.object.length + ((json_builder_value *)objectA)->additional_length_allocated +
356 objectB->u.object.length;
357
358 if (!(values_new = (json_object_entry *)realloc(objectA->u.object.values, sizeof(json_object_entry) * alloc))) {
359 return NULL;
360 }
361
362 objectA->u.object.values = values_new;
363 }
364
365 for (i = 0; i < objectB->u.object.length; ++i) {
366 json_object_entry *entry = &objectA->u.object.values[objectA->u.object.length + i];
367
368 *entry = objectB->u.object.values[i];
369 entry->value->parent = objectA;
370 }
371
372 objectA->u.object.length += objectB->u.object.length;
373
374 free(objectB->u.object.values);
375 free(objectB);
376
377 return objectA;
378 }
379
380 static size_t measure_string(unsigned int length, const json_char *str) {
381 unsigned int i;
382 size_t measured_length = 0;
383
384 for (i = 0; i < length; ++i) {
385 json_char c = str[i];
386
387 switch (c) {
388 case 0:
389 case 0xb:
390 measured_length += 6;
391 break;
392 case '"':
393 case '\\':
394 case '\b':
395 case '\f':
396 case '\n':
397 case '\r':
398 case '\t':
399
400 measured_length += 2;
401 break;
402
403 default:
404
405 ++measured_length;
406 break;
407 };
408 };
409
410 return measured_length;
411 }
412
413 #define PRINT_ESCAPED(c) \
414 do { \
415 *buf++ = '\\'; \
416 *buf++ = (c); \
417 } while (0);
418
419 static size_t serialize_string(json_char *buf, unsigned int length, const json_char *str) {
420 json_char *orig_buf = buf;
421 unsigned int i;
422
423 for (i = 0; i < length; ++i) {
424 json_char c = str[i];
425
426 switch (c) {
427 case 0:
428 *buf++ = '\\';
429 *buf++ = 'u';
430 *buf++ = '0';
431 *buf++ = '0';
432 *buf++ = '0';
433 *buf++ = '0';
434 continue;
435 case '"':
436 PRINT_ESCAPED('\"');
437 continue;
438 case '\\':
439 PRINT_ESCAPED('\\');
440 continue;
441 case '\b':
442 PRINT_ESCAPED('b');
443 continue;
444 case '\f':
445 PRINT_ESCAPED('f');
446 continue;
447 case '\n':
448 PRINT_ESCAPED('n');
449 continue;
450 case '\r':
451 PRINT_ESCAPED('r');
452 continue;
453 case '\t':
454 PRINT_ESCAPED('t');
455 continue;
456 case 0xb:
457 *buf++ = '\\';
458 *buf++ = 'u';
459 *buf++ = '0';
460 *buf++ = '0';
461 *buf++ = '0';
462 *buf++ = 'b';
463 continue;
464
465 default:
466
467 *buf++ = c;
468 break;
469 };
470 };
471
472 return buf - orig_buf;
473 }
474
475 size_t json_measure(json_value *value) {
476 return json_measure_ex(value, default_opts);
477 }
478
479 #define MEASURE_NEWLINE() \
480 do { \
481 ++newlines; \
482 indents += depth; \
483 } while (0);
484
485 size_t json_measure_ex(json_value *value, json_serialize_opts opts) {
486 size_t total = 1; /* null terminator */
487 size_t newlines = 0;
488 size_t depth = 0;
489 size_t indents = 0;
490 int flags;
491 int bracket_size, comma_size, colon_size;
492
493 flags = get_serialize_flags(opts);
494
495 /* to reduce branching
496 */
497 bracket_size = flags & f_spaces_around_brackets ? 2 : 1;
498 comma_size = flags & f_spaces_after_commas ? 2 : 1;
499 colon_size = flags & f_spaces_after_colons ? 2 : 1;
500
501 while (value) {
502 json_int_t integer;
503 json_object_entry *entry;
504
505 switch (value->type) {
506 case json_array:
507
508 if (((json_builder_value *)value)->length_iterated == 0) {
509 if (value->u.array.length == 0) {
510 total += 2; /* `[]` */
511 break;
512 }
513
514 total += bracket_size; /* `[` */
515
516 ++depth;
517 MEASURE_NEWLINE(); /* \n after [ */
518 }
519
520 if (((json_builder_value *)value)->length_iterated == value->u.array.length) {
521 --depth;
522 MEASURE_NEWLINE();
523 total += bracket_size; /* `]` */
524
525 ((json_builder_value *)value)->length_iterated = 0;
526 break;
527 }
528
529 if (((json_builder_value *)value)->length_iterated > 0) {
530 total += comma_size; /* `, ` */
531
532 MEASURE_NEWLINE();
533 }
534
535 ((json_builder_value *)value)->length_iterated++;
536 value = value->u.array.values[((json_builder_value *)value)->length_iterated - 1];
537 continue;
538
539 case json_object:
540
541 if (((json_builder_value *)value)->length_iterated == 0) {
542 if (value->u.object.length == 0) {
543 total += 2; /* `{}` */
544 break;
545 }
546
547 total += bracket_size; /* `{` */
548
549 ++depth;
550 MEASURE_NEWLINE(); /* \n after { */
551 }
552
553 if (((json_builder_value *)value)->length_iterated == value->u.object.length) {
554 --depth;
555 MEASURE_NEWLINE();
556 total += bracket_size; /* `}` */
557
558 ((json_builder_value *)value)->length_iterated = 0;
559 break;
560 }
561
562 if (((json_builder_value *)value)->length_iterated > 0) {
563 total += comma_size; /* `, ` */
564 MEASURE_NEWLINE();
565 }
566
567 entry = value->u.object.values + (((json_builder_value *)value)->length_iterated++);
568
569 total += 2 + colon_size; /* `"": ` */
570 total += measure_string(entry->name_length, entry->name);
571
572 value = entry->value;
573 continue;
574 #ifdef CARYLL_USE_PRE_SERIALIZED
575 case json_pre_serialized:
576
577 total += value->u.string.length;
578 break;
579 #endif
580 case json_string:
581 total += 2; /* `""` */
582 total += measure_string(value->u.string.length, value->u.string.ptr);
583 break;
584
585 case json_integer:
586
587 integer = value->u.integer;
588
589 if (integer < 0) {
590 total += 1; /* `-` */
591 integer = -integer;
592 }
593
594 ++total; /* first digit */
595
596 while (integer >= 10) {
597 ++total; /* another digit */
598 integer /= 10;
599 }
600
601 break;
602
603 case json_double: {
604 char buffer[256];
605 emyg_dtoa(value->u.dbl, buffer);
606 total += strlen(buffer);
607 break;
608 }
609
610 case json_boolean:
611
612 total += value->u.boolean ? 4 : /* `true` */
613 5; /* `false` */
614
615 break;
616
617 case json_null:
618
619 total += 4; /* `null` */
620 break;
621
622 default:
623 break;
624 };
625
626 value = value->parent;
627 }
628
629 if (opts.mode == json_serialize_mode_multiline) {
630 total += newlines * (((opts.opts & json_serialize_opt_CRLF) ? 2 : 1) + opts.indent_size);
631 total += indents * opts.indent_size;
632 }
633
634 return total;
635 }
636
637 void json_serialize(json_char *buf, json_value *value) {
638 json_serialize_ex(buf, value, default_opts);
639 }
640
641 #define PRINT_NEWLINE() \
642 do { \
643 if (opts.mode == json_serialize_mode_multiline) { \
644 if (opts.opts & json_serialize_opt_CRLF) *buf++ = '\r'; \
645 *buf++ = '\n'; \
646 for (i = 0; i < indent; ++i) \
647 *buf++ = indent_char; \
648 } \
649 } while (0);
650
651 #define PRINT_OPENING_BRACKET(c) \
652 do { \
653 *buf++ = (c); \
654 if (flags & f_spaces_around_brackets) *buf++ = ' '; \
655 } while (0);
656
657 #define PRINT_CLOSING_BRACKET(c) \
658 do { \
659 if (flags & f_spaces_around_brackets) *buf++ = ' '; \
660 *buf++ = (c); \
661 } while (0);
662
663 void json_serialize_ex(json_char *buf, json_value *value, json_serialize_opts opts) {
664 json_int_t integer, orig_integer;
665 json_object_entry *entry;
666 json_char *ptr;
667 int indent = 0;
668 char indent_char;
669 int i;
670 int flags;
671
672 flags = get_serialize_flags(opts);
673
674 indent_char = flags & f_tabs ? '\t' : ' ';
675
676 while (value) {
677 switch (value->type) {
678 case json_array:
679
680 if (((json_builder_value *)value)->length_iterated == 0) {
681 if (value->u.array.length == 0) {
682 *buf++ = '[';
683 *buf++ = ']';
684
685 break;
686 }
687
688 PRINT_OPENING_BRACKET('[');
689
690 indent += opts.indent_size;
691 PRINT_NEWLINE();
692 }
693
694 if (((json_builder_value *)value)->length_iterated == value->u.array.length) {
695 indent -= opts.indent_size;
696 PRINT_NEWLINE();
697 PRINT_CLOSING_BRACKET(']');
698
699 ((json_builder_value *)value)->length_iterated = 0;
700 break;
701 }
702
703 if (((json_builder_value *)value)->length_iterated > 0) {
704 *buf++ = ',';
705
706 if (flags & f_spaces_after_commas) *buf++ = ' ';
707
708 PRINT_NEWLINE();
709 }
710
711 ((json_builder_value *)value)->length_iterated++;
712 value = value->u.array.values[((json_builder_value *)value)->length_iterated - 1];
713 continue;
714
715 case json_object:
716
717 if (((json_builder_value *)value)->length_iterated == 0) {
718 if (value->u.object.length == 0) {
719 *buf++ = '{';
720 *buf++ = '}';
721
722 break;
723 }
724
725 PRINT_OPENING_BRACKET('{');
726
727 indent += opts.indent_size;
728 PRINT_NEWLINE();
729 }
730
731 if (((json_builder_value *)value)->length_iterated == value->u.object.length) {
732 indent -= opts.indent_size;
733 PRINT_NEWLINE();
734 PRINT_CLOSING_BRACKET('}');
735
736 ((json_builder_value *)value)->length_iterated = 0;
737 break;
738 }
739
740 if (((json_builder_value *)value)->length_iterated > 0) {
741 *buf++ = ',';
742
743 if (flags & f_spaces_after_commas) *buf++ = ' ';
744
745 PRINT_NEWLINE();
746 }
747
748 entry = value->u.object.values + (((json_builder_value *)value)->length_iterated++);
749
750 *buf++ = '\"';
751 buf += serialize_string(buf, entry->name_length, entry->name);
752 *buf++ = '\"';
753 *buf++ = ':';
754
755 if (flags & f_spaces_after_colons) *buf++ = ' ';
756
757 value = entry->value;
758 continue;
759 #ifdef CARYLL_USE_PRE_SERIALIZED
760 case json_pre_serialized:
761 memcpy(buf, value->u.string.ptr, value->u.string.length);
762 buf += value->u.string.length;
763 break;
764 #endif
765 case json_string:
766
767 *buf++ = '\"';
768 buf += serialize_string(buf, value->u.string.length, value->u.string.ptr);
769 *buf++ = '\"';
770 break;
771
772 case json_integer:
773
774 integer = value->u.integer;
775
776 if (integer < 0) {
777 *buf++ = '-';
778 integer = -integer;
779 }
780
781 orig_integer = integer;
782
783 ++buf;
784
785 while (integer >= 10) {
786 ++buf;
787 integer /= 10;
788 }
789
790 integer = orig_integer;
791 ptr = buf;
792
793 do {
794 *--ptr = "0123456789"[integer % 10];
795 } while ((integer /= 10) > 0);
796
797 break;
798
799 case json_double: {
800 char tmp[256];
801 emyg_dtoa(value->u.dbl, tmp);
802 memcpy(buf, tmp, strlen(tmp));
803 buf += strlen(tmp);
804 break;
805 }
806
807 case json_boolean:
808
809 if (value->u.boolean) {
810 memcpy(buf, "true", 4);
811 buf += 4;
812 } else {
813 memcpy(buf, "false", 5);
814 buf += 5;
815 }
816
817 break;
818
819 case json_null:
820
821 memcpy(buf, "null", 4);
822 buf += 4;
823 break;
824
825 default:
826 break;
827 };
828
829 value = value->parent;
830 }
831
832 *buf = 0;
833 }
834
835 void json_builder_free(json_value *value) {
836 json_value *cur_value;
837
838 if (!value) return;
839
840 value->parent = 0;
841
842 while (value) {
843 switch (value->type) {
844 case json_array:
845
846 if (!value->u.array.length) {
847 free(value->u.array.values);
848 break;
849 }
850
851 value = value->u.array.values[--value->u.array.length];
852 continue;
853
854 case json_object:
855
856 if (!value->u.object.length) {
857 free(value->u.object.values);
858 break;
859 }
860
861 --value->u.object.length;
862
863 if (((json_builder_value *)value)->is_builder_value) {
864 /* Names are allocated separately for builder values. In parser
865 * values, they are part of the same allocation as the values array
866 * itself.
867 */
868 free(value->u.object.values[value->u.object.length].name);
869 }
870
871 value = value->u.object.values[value->u.object.length].value;
872 continue;
873
874 case json_string:
875 #ifdef CARYLL_USE_PRE_SERIALIZED
876 case json_pre_serialized:
877 #endif
878 free(value->u.string.ptr);
879 break;
880
881 default:
882 break;
883 };
884
885 cur_value = value;
886 value = value->parent;
887 free(cur_value);
888 }
889 }