diff options
Diffstat (limited to 'upb/json')
-rw-r--r-- | upb/json/parser.c | 91 | ||||
-rw-r--r-- | upb/json/parser.h | 3 | ||||
-rw-r--r-- | upb/json/parser.rl | 19 | ||||
-rw-r--r-- | upb/json/printer.c | 16 | ||||
-rw-r--r-- | upb/json/printer.h | 3 |
5 files changed, 63 insertions, 69 deletions
diff --git a/upb/json/parser.c b/upb/json/parser.c index f16af48..a808616 100644 --- a/upb/json/parser.c +++ b/upb/json/parser.c @@ -21,12 +21,11 @@ ** - handling of keys/escape-sequences/etc that span input buffers. */ -#include <stdio.h> -#include <stdint.h> #include <assert.h> -#include <string.h> -#include <stdlib.h> #include <errno.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> #include "upb/json/parser.h" @@ -1150,11 +1149,11 @@ static void end_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -#line 1246 "upb/json/parser.rl" +#line 1245 "upb/json/parser.rl" -#line 1158 "upb/json/parser.c" +#line 1157 "upb/json/parser.c" static const char _json_actions[] = { 0, 1, 0, 1, 2, 1, 3, 1, 5, 1, 6, 1, 7, 1, 8, 1, @@ -1303,7 +1302,7 @@ static const int json_en_value_machine = 27; static const int json_en_main = 1; -#line 1249 "upb/json/parser.rl" +#line 1248 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -1325,7 +1324,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -#line 1329 "upb/json/parser.c" +#line 1328 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -1400,118 +1399,118 @@ _match: switch ( *_acts++ ) { case 0: -#line 1161 "upb/json/parser.rl" +#line 1160 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 1: -#line 1162 "upb/json/parser.rl" +#line 1161 "upb/json/parser.rl" { p--; {stack[top++] = cs; cs = 10; goto _again;} } break; case 2: -#line 1166 "upb/json/parser.rl" +#line 1165 "upb/json/parser.rl" { start_text(parser, p); } break; case 3: -#line 1167 "upb/json/parser.rl" +#line 1166 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 4: -#line 1173 "upb/json/parser.rl" +#line 1172 "upb/json/parser.rl" { start_hex(parser); } break; case 5: -#line 1174 "upb/json/parser.rl" +#line 1173 "upb/json/parser.rl" { hexdigit(parser, p); } break; case 6: -#line 1175 "upb/json/parser.rl" +#line 1174 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hex(parser)); } break; case 7: -#line 1181 "upb/json/parser.rl" +#line 1180 "upb/json/parser.rl" { CHECK_RETURN_TOP(escape(parser, p)); } break; case 8: -#line 1187 "upb/json/parser.rl" +#line 1186 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 9: -#line 1190 "upb/json/parser.rl" +#line 1189 "upb/json/parser.rl" { {stack[top++] = cs; cs = 19; goto _again;} } break; case 10: -#line 1192 "upb/json/parser.rl" +#line 1191 "upb/json/parser.rl" { p--; {stack[top++] = cs; cs = 27; goto _again;} } break; case 11: -#line 1197 "upb/json/parser.rl" +#line 1196 "upb/json/parser.rl" { start_member(parser); } break; case 12: -#line 1198 "upb/json/parser.rl" +#line 1197 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_membername(parser)); } break; case 13: -#line 1201 "upb/json/parser.rl" +#line 1200 "upb/json/parser.rl" { end_member(parser); } break; case 14: -#line 1207 "upb/json/parser.rl" +#line 1206 "upb/json/parser.rl" { start_object(parser); } break; case 15: -#line 1210 "upb/json/parser.rl" +#line 1209 "upb/json/parser.rl" { end_object(parser); } break; case 16: -#line 1216 "upb/json/parser.rl" +#line 1215 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_array(parser)); } break; case 17: -#line 1220 "upb/json/parser.rl" +#line 1219 "upb/json/parser.rl" { end_array(parser); } break; case 18: -#line 1225 "upb/json/parser.rl" +#line 1224 "upb/json/parser.rl" { start_number(parser, p); } break; case 19: -#line 1226 "upb/json/parser.rl" +#line 1225 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; case 20: -#line 1228 "upb/json/parser.rl" +#line 1227 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_stringval(parser)); } break; case 21: -#line 1229 "upb/json/parser.rl" +#line 1228 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_stringval(parser)); } break; case 22: -#line 1231 "upb/json/parser.rl" +#line 1230 "upb/json/parser.rl" { CHECK_RETURN_TOP(parser_putbool(parser, true)); } break; case 23: -#line 1233 "upb/json/parser.rl" +#line 1232 "upb/json/parser.rl" { CHECK_RETURN_TOP(parser_putbool(parser, false)); } break; case 24: -#line 1235 "upb/json/parser.rl" +#line 1234 "upb/json/parser.rl" { /* null value */ } break; case 25: -#line 1237 "upb/json/parser.rl" +#line 1236 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_subobject(parser)); } break; case 26: -#line 1238 "upb/json/parser.rl" +#line 1237 "upb/json/parser.rl" { end_subobject(parser); } break; case 27: -#line 1243 "upb/json/parser.rl" +#line 1242 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -#line 1515 "upb/json/parser.c" +#line 1514 "upb/json/parser.c" } } @@ -1524,7 +1523,7 @@ _again: _out: {} } -#line 1270 "upb/json/parser.rl" +#line 1269 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -1565,13 +1564,13 @@ static void json_parser_reset(upb_json_parser *p) { /* Emit Ragel initialization of the parser. */ -#line 1569 "upb/json/parser.c" +#line 1568 "upb/json/parser.c" { cs = json_start; top = 0; } -#line 1310 "upb/json/parser.rl" +#line 1309 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -1597,12 +1596,12 @@ static void free_json_parsermethod(upb_refcounted *r) { upb_value val = upb_inttable_iter_value(&i); upb_strtable *t = upb_value_getptr(val); upb_strtable_uninit(t); - free(t); + upb_gfree(t); } upb_inttable_uninit(&method->name_tables); - free(r); + upb_gfree(r); } static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { @@ -1619,7 +1618,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { } /* TODO(haberman): handle malloc failure. */ - t = malloc(sizeof(*t)); + t = upb_gmalloc(sizeof(*t)); upb_strtable_init(t, UPB_CTYPE_CONSTPTR); upb_inttable_insertptr(&m->name_tables, md, upb_value_ptr(t)); @@ -1632,7 +1631,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { size_t field_len = upb_fielddef_getjsonname(f, buf, len); if (field_len > len) { size_t len2; - buf = realloc(buf, field_len); + buf = upb_grealloc(buf, 0, field_len); len = field_len; len2 = upb_fielddef_getjsonname(f, buf, len); UPB_ASSERT_VAR(len2, len == len2); @@ -1651,7 +1650,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { } } - free(buf); + upb_gfree(buf); } /* Public API *****************************************************************/ @@ -1691,7 +1690,7 @@ upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md, const void* owner) { static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod, free_json_parsermethod}; - upb_json_parsermethod *ret = malloc(sizeof(*ret)); + upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret)); upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner); ret->msg = md; diff --git a/upb/json/parser.h b/upb/json/parser.h index 1d67dc4..bcc2c84 100644 --- a/upb/json/parser.h +++ b/upb/json/parser.h @@ -8,7 +8,6 @@ #ifndef UPB_JSON_PARSER_H_ #define UPB_JSON_PARSER_H_ -#include "upb/env.h" #include "upb/sink.h" #ifdef __cplusplus @@ -30,7 +29,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, * constructed. This hint may be an overestimate for some build configurations. * But if the parser library is upgraded without recompiling the application, * it may be an underestimate. */ -#define UPB_JSON_PARSER_SIZE 4104 +#define UPB_JSON_PARSER_SIZE 4112 #ifdef __cplusplus diff --git a/upb/json/parser.rl b/upb/json/parser.rl index 3e1ea94..b67f08d 100644 --- a/upb/json/parser.rl +++ b/upb/json/parser.rl @@ -19,12 +19,11 @@ ** - handling of keys/escape-sequences/etc that span input buffers. */ -#include <stdio.h> -#include <stdint.h> #include <assert.h> -#include <string.h> -#include <stdlib.h> #include <errno.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> #include "upb/json/parser.h" @@ -1332,12 +1331,12 @@ static void free_json_parsermethod(upb_refcounted *r) { upb_value val = upb_inttable_iter_value(&i); upb_strtable *t = upb_value_getptr(val); upb_strtable_uninit(t); - free(t); + upb_gfree(t); } upb_inttable_uninit(&method->name_tables); - free(r); + upb_gfree(r); } static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { @@ -1354,7 +1353,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { } /* TODO(haberman): handle malloc failure. */ - t = malloc(sizeof(*t)); + t = upb_gmalloc(sizeof(*t)); upb_strtable_init(t, UPB_CTYPE_CONSTPTR); upb_inttable_insertptr(&m->name_tables, md, upb_value_ptr(t)); @@ -1367,7 +1366,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { size_t field_len = upb_fielddef_getjsonname(f, buf, len); if (field_len > len) { size_t len2; - buf = realloc(buf, field_len); + buf = upb_grealloc(buf, 0, field_len); len = field_len; len2 = upb_fielddef_getjsonname(f, buf, len); UPB_ASSERT_VAR(len2, len == len2); @@ -1386,7 +1385,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { } } - free(buf); + upb_gfree(buf); } /* Public API *****************************************************************/ @@ -1426,7 +1425,7 @@ upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md, const void* owner) { static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod, free_json_parsermethod}; - upb_json_parsermethod *ret = malloc(sizeof(*ret)); + upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret)); upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner); ret->msg = md; diff --git a/upb/json/printer.c b/upb/json/printer.c index 230aa0d..cc50417 100644 --- a/upb/json/printer.c +++ b/upb/json/printer.c @@ -5,8 +5,6 @@ #include "upb/json/printer.h" -#include <stdlib.h> -#include <stdio.h> #include <string.h> #include <stdint.h> @@ -39,22 +37,22 @@ typedef struct { void freestrpc(void *ptr) { strpc *pc = ptr; - free(pc->ptr); - free(pc); + upb_gfree(pc->ptr); + upb_gfree(pc); } /* Convert fielddef name to JSON name and return as a string piece. */ strpc *newstrpc(upb_handlers *h, const upb_fielddef *f, bool preserve_fieldnames) { /* TODO(haberman): handle malloc failure. */ - strpc *ret = malloc(sizeof(*ret)); + strpc *ret = upb_gmalloc(sizeof(*ret)); if (preserve_fieldnames) { - ret->ptr = upb_strdup(upb_fielddef_name(f)); + ret->ptr = upb_gstrdup(upb_fielddef_name(f)); ret->len = strlen(ret->ptr); } else { size_t len; ret->len = upb_fielddef_getjsonname(f, NULL, 0); - ret->ptr = malloc(ret->len); + ret->ptr = upb_gmalloc(ret->len); len = upb_fielddef_getjsonname(f, ret->ptr, ret->len); UPB_ASSERT_VAR(len, len == ret->len); ret->len--; /* NULL */ @@ -566,10 +564,10 @@ static void set_enum_hd(upb_handlers *h, const upb_fielddef *f, bool preserve_fieldnames, upb_handlerattr *attr) { - EnumHandlerData *hd = malloc(sizeof(EnumHandlerData)); + EnumHandlerData *hd = upb_gmalloc(sizeof(EnumHandlerData)); hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f); hd->keyname = newstrpc(h, f, preserve_fieldnames); - upb_handlers_addcleanup(h, hd, free); + upb_handlers_addcleanup(h, hd, upb_gfree); upb_handlerattr_sethandlerdata(attr, hd); } diff --git a/upb/json/printer.h b/upb/json/printer.h index 36a24e9..548af0a 100644 --- a/upb/json/printer.h +++ b/upb/json/printer.h @@ -7,7 +7,6 @@ #ifndef UPB_JSON_TYPED_PRINTER_H_ #define UPB_JSON_TYPED_PRINTER_H_ -#include "upb/env.h" #include "upb/sink.h" #ifdef __cplusplus @@ -23,7 +22,7 @@ UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer) /* upb::json::Printer *********************************************************/ -#define UPB_JSON_PRINTER_SIZE 168 +#define UPB_JSON_PRINTER_SIZE 176 #ifdef __cplusplus |