summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Fallin <cfallin@c1f.net>2014-12-11 18:58:04 -0800
committerChris Fallin <cfallin@c1f.net>2014-12-12 14:49:12 -0800
commitb3f6daf83d8adf0040a1bf9401342c811502f690 (patch)
tree2b51257e4b9cebfc3640d98cda45f9b8be36fdb2
parent56913be6bb57f81dbbf7baf9cc9a0a2cd1a36493 (diff)
Amalgamated distribution (upb.c/upb.h) tool.
There are a number of tweaks to get this to work: - The #include dependence graph wasn't quite complete, and I had to add a few #includes to get the tool to work. - I had to change a number of symbol names to avoid conflicts between 'static' definitions in different .c files. This could be avoided if the tool were smart enough to rename static symbols to have unique prefixes instead, but (i) this requires semantic understanding of C, and (ii) the macro-defined static functions (e.g., handlers for primitive types in several places) would probably trip this up. Verified that the resulting upb.h/upb.c compiles and doesn't have any unresolved references.
-rw-r--r--Makefile12
-rwxr-xr-xtools/amalgamate.py47
-rw-r--r--upb/handlers.c24
-rw-r--r--upb/handlers.h1
-rw-r--r--upb/json/parser.c99
-rw-r--r--upb/json/parser.rl29
-rw-r--r--upb/json/printer.c4
-rw-r--r--upb/pb/decoder.c12
-rw-r--r--upb/pb/encoder.c6
-rw-r--r--upb/pb/textprinter.c59
-rw-r--r--upb/refcounted.c4
-rw-r--r--upb/symtab.c2
-rw-r--r--upb/table.int.h2
13 files changed, 185 insertions, 116 deletions
diff --git a/Makefile b/Makefile
index 96bb1a7..8913752 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@
# Threading:
# * -DUPB_THREAD_UNSAFE: remove all thread-safety.
-.PHONY: all lib clean tests test benchmark descriptorgen
+.PHONY: all lib clean tests test benchmark descriptorgen amalgamate
.PHONY: clean_leave_profile
# Prevents the deletion of intermediate files.
@@ -462,3 +462,13 @@ $(RUBYEXT): upb/bindings/ruby/upb.c upb/bindings/ruby/Makefile
rubytest: $(RUBYEXT) upb/descriptor/descriptor.pb
RUBYLIB="upb/bindings/ruby" ruby tests/bindings/ruby/upb.rb
+
+# Amalgamated source (upb.c/upb.h) ############################################
+
+AMALGAMATE_SRCS=$(upb_SRCS) $(upb_descriptor_SRCS) $(upb_pb_SRCS) $(upb_json_SRCS)
+
+amalgamate: upb.c upb.h
+
+upb.c upb.h: $(AMALGAMATE_SRCS)
+ $(E) AMALGAMATE $@
+ $(Q) ./tools/amalgamate.py "" "" $^
diff --git a/tools/amalgamate.py b/tools/amalgamate.py
new file mode 100755
index 0000000..6fd8033
--- /dev/null
+++ b/tools/amalgamate.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+
+import sys
+import re
+
+INCLUDE_RE = re.compile('^#include "([^"]*)"$')
+
+def parse_include(line):
+ match = INCLUDE_RE.match(line)
+ return match.groups()[0] if match else None
+
+class Amalgamator:
+ def __init__(self, include_path, output_path):
+ self.include_path = include_path
+ self.included = set()
+ self.output_h = open(output_path + "upb.h", "w")
+ self.output_c = open(output_path + "upb.c", "w")
+
+ self.output_c.write("// Amalgamated source file\n")
+ self.output_c.write('#include "upb.h"\n')
+
+ self.output_h.write("// Amalgamated source file\n")
+
+ def _process_file(self, infile_name, outfile):
+ for line in open(infile_name):
+ include = parse_include(line)
+ if include is not None and include.startswith("upb"):
+ if include not in self.included:
+ self.included.add(include)
+ self._add_header(self.include_path + include)
+ else:
+ outfile.write(line)
+
+ def _add_header(self, filename):
+ self._process_file(filename, self.output_h)
+
+ def add_src(self, filename):
+ self._process_file(filename, self.output_c)
+
+# ---- main ----
+
+include_path = sys.argv[1]
+output_path = sys.argv[2]
+amalgamator = Amalgamator(include_path, output_path)
+
+for filename in sys.argv[3:]:
+ amalgamator.add_src(filename.strip())
diff --git a/upb/handlers.c b/upb/handlers.c
index 90df8a6..c0fd271 100644
--- a/upb/handlers.c
+++ b/upb/handlers.c
@@ -120,7 +120,7 @@ static int32_t trygetsel(upb_handlers *h, const upb_fielddef *f,
return sel;
}
-static upb_selector_t getsel(upb_handlers *h, const upb_fielddef *f,
+static upb_selector_t handlers_getsel(upb_handlers *h, const upb_fielddef *f,
upb_handlertype_t type) {
int32_t sel = trygetsel(h, f, type);
assert(sel >= 0);
@@ -129,7 +129,7 @@ static upb_selector_t getsel(upb_handlers *h, const upb_fielddef *f,
static const void **returntype(upb_handlers *h, const upb_fielddef *f,
upb_handlertype_t type) {
- return &h->table[getsel(h, f, type)].attr.return_closure_type_;
+ return &h->table[handlers_getsel(h, f, type)].attr.return_closure_type_;
}
static bool doset(upb_handlers *h, int32_t sel, const upb_fielddef *f,
@@ -213,18 +213,18 @@ const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f,
if (upb_fielddef_isseq(f) &&
type != UPB_HANDLER_STARTSEQ &&
type != UPB_HANDLER_ENDSEQ &&
- h->table[sel = getsel(h, f, UPB_HANDLER_STARTSEQ)].func) {
+ h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)].func) {
ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
}
if (type == UPB_HANDLER_STRING &&
- h->table[sel = getsel(h, f, UPB_HANDLER_STARTSTR)].func) {
+ h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSTR)].func) {
ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
}
// The effective type of the submessage; not used yet.
// if (type == SUBMESSAGE &&
- // h->table[sel = getsel(h, f, UPB_HANDLER_STARTSUBMSG)].func) {
+ // h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSUBMSG)].func) {
// ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
// }
@@ -237,7 +237,7 @@ const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f,
// the return closure type of this handler's attr.
bool checkstart(upb_handlers *h, const upb_fielddef *f, upb_handlertype_t type,
upb_status *status) {
- upb_selector_t sel = getsel(h, f, type);
+ upb_selector_t sel = handlers_getsel(h, f, type);
if (h->table[sel].func) return true;
const void *closure_type = effective_closure_type(h, f, type);
const upb_handlerattr *attr = &h->table[sel].attr;
@@ -444,14 +444,18 @@ bool upb_handlers_freeze(upb_handlers *const*handlers, int n, upb_status *s) {
if (upb_fielddef_issubmsg(f)) {
bool hashandler = false;
- if (upb_handlers_gethandler(h, getsel(h, f, UPB_HANDLER_STARTSUBMSG)) ||
- upb_handlers_gethandler(h, getsel(h, f, UPB_HANDLER_ENDSUBMSG))) {
+ if (upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_STARTSUBMSG)) ||
+ upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_ENDSUBMSG))) {
hashandler = true;
}
if (upb_fielddef_isseq(f) &&
- (upb_handlers_gethandler(h, getsel(h, f, UPB_HANDLER_STARTSEQ)) ||
- upb_handlers_gethandler(h, getsel(h, f, UPB_HANDLER_ENDSEQ)))) {
+ (upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)) ||
+ upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_ENDSEQ)))) {
hashandler = true;
}
diff --git a/upb/handlers.h b/upb/handlers.h
index ca28cff..2267d98 100644
--- a/upb/handlers.h
+++ b/upb/handlers.h
@@ -23,6 +23,7 @@
#define UPB_HANDLERS_H
#include "upb/def.h"
+#include "upb/table.int.h"
#ifdef __cplusplus
namespace upb {
diff --git a/upb/json/parser.c b/upb/json/parser.c
index 78fc6c0..fe2b586 100644
--- a/upb/json/parser.c
+++ b/upb/json/parser.c
@@ -33,7 +33,7 @@
#include "upb/json/parser.h"
-#define CHECK_RETURN(x) if (!(x)) return false
+#define PARSER_CHECK_RETURN(x) if (!(x)) return false
static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
upb_handlertype_t type) {
@@ -43,7 +43,7 @@ static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
return sel;
}
-static upb_selector_t getsel(upb_json_parser *p) {
+static upb_selector_t parser_getsel(upb_json_parser *p) {
return getsel_for_handlertype(
p, upb_handlers_getprimitivehandlertype(p->top->f));
}
@@ -153,7 +153,7 @@ static void end_array(upb_json_parser *p) {
static void clear_member(upb_json_parser *p) { p->top->f = NULL; }
-static bool putbool(upb_json_parser *p, bool val) {
+static bool parser_putbool(upb_json_parser *p, bool val) {
if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) {
upb_status_seterrf(p->status,
"Boolean value specified for non-bool field: %s",
@@ -161,7 +161,7 @@ static bool putbool(upb_json_parser *p, bool val) {
return false;
}
- bool ok = upb_sink_putbool(&p->top->sink, getsel(p), val);
+ bool ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val);
UPB_ASSERT_VAR(ok, ok);
return true;
}
@@ -297,7 +297,8 @@ static bool end_text(upb_json_parser *p, const char *ptr, bool is_num) {
// This is a string field (as opposed to a member name).
upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
if (upb_fielddef_type(p->top->f) == UPB_TYPE_BYTES) {
- CHECK_RETURN(base64_push(p, sel, p->accumulated, p->accumulated_len));
+ PARSER_CHECK_RETURN(base64_push(p, sel, p->accumulated,
+ p->accumulated_len));
} else {
upb_sink_putstring(&p->top->sink, sel, p->accumulated, p->accumulated_len, NULL);
}
@@ -313,7 +314,7 @@ static bool end_text(upb_json_parser *p, const char *ptr, bool is_num) {
int32_t int_val = 0;
if (upb_enumdef_ntoi(enumdef, p->accumulated, p->accumulated_len,
&int_val)) {
- upb_selector_t sel = getsel(p);
+ upb_selector_t sel = parser_getsel(p);
upb_sink_putint32(&p->top->sink, sel, int_val);
} else {
upb_status_seterrmsg(p->status, "Enum value name unknown");
@@ -379,7 +380,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putint32(&p->top->sink, getsel(p), val);
+ upb_sink_putint32(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_INT64: {
@@ -387,7 +388,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putint64(&p->top->sink, getsel(p), val);
+ upb_sink_putint64(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_UINT32: {
@@ -395,7 +396,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > UINT32_MAX || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putuint32(&p->top->sink, getsel(p), val);
+ upb_sink_putuint32(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_UINT64: {
@@ -403,7 +404,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > UINT64_MAX || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putuint64(&p->top->sink, getsel(p), val);
+ upb_sink_putuint64(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_DOUBLE: {
@@ -411,7 +412,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putdouble(&p->top->sink, getsel(p), val);
+ upb_sink_putdouble(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_FLOAT: {
@@ -419,7 +420,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putfloat(&p->top->sink, getsel(p), val);
+ upb_sink_putfloat(&p->top->sink, parser_getsel(p), val);
break;
}
default:
@@ -505,11 +506,11 @@ static void hex(upb_json_parser *p, const char *end) {
// What follows is the Ragel parser itself. The language is specified in Ragel
// and the actions call our C functions above.
-#line 595 "upb/json/parser.rl"
+#line 596 "upb/json/parser.rl"
-#line 513 "upb/json/parser.c"
+#line 514 "upb/json/parser.c"
static const char _json_actions[] = {
0, 1, 0, 1, 2, 1, 3, 1,
4, 1, 5, 1, 6, 1, 7, 1,
@@ -662,7 +663,7 @@ static const int json_en_value_machine = 27;
static const int json_en_main = 1;
-#line 598 "upb/json/parser.rl"
+#line 599 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) {
@@ -679,7 +680,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const char *pe = buf + size;
-#line 683 "upb/json/parser.c"
+#line 684 "upb/json/parser.c"
{
int _klen;
unsigned int _trans;
@@ -754,114 +755,114 @@ _match:
switch ( *_acts++ )
{
case 0:
-#line 516 "upb/json/parser.rl"
+#line 517 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 1:
-#line 517 "upb/json/parser.rl"
+#line 518 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 10; goto _again;} }
break;
case 2:
-#line 521 "upb/json/parser.rl"
+#line 522 "upb/json/parser.rl"
{ start_text(parser, p); }
break;
case 3:
-#line 522 "upb/json/parser.rl"
+#line 523 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p, false)); }
break;
case 4:
-#line 528 "upb/json/parser.rl"
+#line 529 "upb/json/parser.rl"
{ start_hex(parser, p); }
break;
case 5:
-#line 529 "upb/json/parser.rl"
+#line 530 "upb/json/parser.rl"
{ hex(parser, p); }
break;
case 6:
-#line 535 "upb/json/parser.rl"
+#line 536 "upb/json/parser.rl"
{ escape(parser, p); }
break;
case 7:
-#line 538 "upb/json/parser.rl"
+#line 539 "upb/json/parser.rl"
{ {cs = stack[--top]; goto _again;} }
break;
case 8:
-#line 539 "upb/json/parser.rl"
+#line 540 "upb/json/parser.rl"
{ {stack[top++] = cs; cs = 19; goto _again;} }
break;
case 9:
-#line 541 "upb/json/parser.rl"
+#line 542 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 27; goto _again;} }
break;
case 10:
-#line 546 "upb/json/parser.rl"
+#line 547 "upb/json/parser.rl"
{ start_member(parser); }
break;
case 11:
-#line 547 "upb/json/parser.rl"
+#line 548 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_member(parser)); }
break;
case 12:
-#line 550 "upb/json/parser.rl"
+#line 551 "upb/json/parser.rl"
{ clear_member(parser); }
break;
case 13:
-#line 556 "upb/json/parser.rl"
+#line 557 "upb/json/parser.rl"
{ start_object(parser); }
break;
case 14:
-#line 559 "upb/json/parser.rl"
+#line 560 "upb/json/parser.rl"
{ end_object(parser); }
break;
case 15:
-#line 565 "upb/json/parser.rl"
+#line 566 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_array(parser)); }
break;
case 16:
-#line 569 "upb/json/parser.rl"
+#line 570 "upb/json/parser.rl"
{ end_array(parser); }
break;
case 17:
-#line 574 "upb/json/parser.rl"
+#line 575 "upb/json/parser.rl"
{ start_number(parser, p); }
break;
case 18:
-#line 575 "upb/json/parser.rl"
+#line 576 "upb/json/parser.rl"
{ end_number(parser, p); }
break;
case 19:
-#line 577 "upb/json/parser.rl"
+#line 578 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_stringval(parser)); }
break;
case 20:
-#line 578 "upb/json/parser.rl"
+#line 579 "upb/json/parser.rl"
{ end_stringval(parser); }
break;
case 21:
-#line 580 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(putbool(parser, true)); }
+#line 581 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(parser_putbool(parser, true)); }
break;
case 22:
-#line 582 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(putbool(parser, false)); }
+#line 583 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(parser_putbool(parser, false)); }
break;
case 23:
-#line 584 "upb/json/parser.rl"
+#line 585 "upb/json/parser.rl"
{ /* null value */ }
break;
case 24:
-#line 586 "upb/json/parser.rl"
+#line 587 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_subobject(parser)); }
break;
case 25:
-#line 587 "upb/json/parser.rl"
+#line 588 "upb/json/parser.rl"
{ end_subobject(parser); }
break;
case 26:
-#line 592 "upb/json/parser.rl"
+#line 593 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
-#line 865 "upb/json/parser.c"
+#line 866 "upb/json/parser.c"
}
}
@@ -874,7 +875,7 @@ _again:
_out: {}
}
-#line 614 "upb/json/parser.rl"
+#line 615 "upb/json/parser.rl"
if (p != pe) {
upb_status_seterrf(parser->status, "Parse error at %s\n", p);
@@ -915,13 +916,13 @@ void upb_json_parser_reset(upb_json_parser *p) {
int top;
// Emit Ragel initialization of the parser.
-#line 919 "upb/json/parser.c"
+#line 920 "upb/json/parser.c"
{
cs = json_start;
top = 0;
}
-#line 654 "upb/json/parser.rl"
+#line 655 "upb/json/parser.rl"
p->current_state = cs;
p->parser_top = top;
p->text_begin = NULL;
diff --git a/upb/json/parser.rl b/upb/json/parser.rl
index 8ceca77..abc76c8 100644
--- a/upb/json/parser.rl
+++ b/upb/json/parser.rl
@@ -31,7 +31,7 @@
#include "upb/json/parser.h"
-#define CHECK_RETURN(x) if (!(x)) return false
+#define PARSER_CHECK_RETURN(x) if (!(x)) return false
static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
upb_handlertype_t type) {
@@ -41,7 +41,7 @@ static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
return sel;
}
-static upb_selector_t getsel(upb_json_parser *p) {
+static upb_selector_t parser_getsel(upb_json_parser *p) {
return getsel_for_handlertype(
p, upb_handlers_getprimitivehandlertype(p->top->f));
}
@@ -151,7 +151,7 @@ static void end_array(upb_json_parser *p) {
static void clear_member(upb_json_parser *p) { p->top->f = NULL; }
-static bool putbool(upb_json_parser *p, bool val) {
+static bool parser_putbool(upb_json_parser *p, bool val) {
if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) {
upb_status_seterrf(p->status,
"Boolean value specified for non-bool field: %s",
@@ -159,7 +159,7 @@ static bool putbool(upb_json_parser *p, bool val) {
return false;
}
- bool ok = upb_sink_putbool(&p->top->sink, getsel(p), val);
+ bool ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val);
UPB_ASSERT_VAR(ok, ok);
return true;
}
@@ -295,7 +295,8 @@ static bool end_text(upb_json_parser *p, const char *ptr, bool is_num) {
// This is a string field (as opposed to a member name).
upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
if (upb_fielddef_type(p->top->f) == UPB_TYPE_BYTES) {
- CHECK_RETURN(base64_push(p, sel, p->accumulated, p->accumulated_len));
+ PARSER_CHECK_RETURN(base64_push(p, sel, p->accumulated,
+ p->accumulated_len));
} else {
upb_sink_putstring(&p->top->sink, sel, p->accumulated, p->accumulated_len, NULL);
}
@@ -311,7 +312,7 @@ static bool end_text(upb_json_parser *p, const char *ptr, bool is_num) {
int32_t int_val = 0;
if (upb_enumdef_ntoi(enumdef, p->accumulated, p->accumulated_len,
&int_val)) {
- upb_selector_t sel = getsel(p);
+ upb_selector_t sel = parser_getsel(p);
upb_sink_putint32(&p->top->sink, sel, int_val);
} else {
upb_status_seterrmsg(p->status, "Enum value name unknown");
@@ -377,7 +378,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putint32(&p->top->sink, getsel(p), val);
+ upb_sink_putint32(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_INT64: {
@@ -385,7 +386,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putint64(&p->top->sink, getsel(p), val);
+ upb_sink_putint64(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_UINT32: {
@@ -393,7 +394,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > UINT32_MAX || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putuint32(&p->top->sink, getsel(p), val);
+ upb_sink_putuint32(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_UINT64: {
@@ -401,7 +402,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (val > UINT64_MAX || errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putuint64(&p->top->sink, getsel(p), val);
+ upb_sink_putuint64(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_DOUBLE: {
@@ -409,7 +410,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putdouble(&p->top->sink, getsel(p), val);
+ upb_sink_putdouble(&p->top->sink, parser_getsel(p), val);
break;
}
case UPB_TYPE_FLOAT: {
@@ -417,7 +418,7 @@ static void end_number(upb_json_parser *p, const char *ptr) {
if (errno == ERANGE || end != myend)
assert(false);
else
- upb_sink_putfloat(&p->top->sink, getsel(p), val);
+ upb_sink_putfloat(&p->top->sink, parser_getsel(p), val);
break;
}
default:
@@ -577,9 +578,9 @@ static void hex(upb_json_parser *p, const char *end) {
>{ CHECK_RETURN_TOP(start_stringval(parser)); }
%{ end_stringval(parser); }
| "true"
- %{ CHECK_RETURN_TOP(putbool(parser, true)); }
+ %{ CHECK_RETURN_TOP(parser_putbool(parser, true)); }
| "false"
- %{ CHECK_RETURN_TOP(putbool(parser, false)); }
+ %{ CHECK_RETURN_TOP(parser_putbool(parser, false)); }
| "null"
%{ /* null value */ }
| object
diff --git a/upb/json/printer.c b/upb/json/printer.c
index 28f3e4a..b996ccf 100644
--- a/upb/json/printer.c
+++ b/upb/json/printer.c
@@ -421,7 +421,7 @@ static size_t repeated_bytes(void *closure, const void *handler_data,
return len;
}
-void sethandlers(const void *closure, upb_handlers *h) {
+void printer_sethandlers(const void *closure, upb_handlers *h) {
UPB_UNUSED(closure);
upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
@@ -541,5 +541,5 @@ upb_sink *upb_json_printer_input(upb_json_printer *p) {
const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
const void *owner) {
- return upb_handlers_newfrozen(md, owner, sethandlers, NULL);
+ return upb_handlers_newfrozen(md, owner, printer_sethandlers, NULL);
}
diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c
index d774ebd..ec8c03f 100644
--- a/upb/pb/decoder.c
+++ b/upb/pb/decoder.c
@@ -402,7 +402,7 @@ static double as_double(uint64_t n) { double d; memcpy(&d, &n, 8); return d; }
static float as_float(uint32_t n) { float f; memcpy(&f, &n, 4); return f; }
// Pushes a frame onto the decoder stack.
-static bool push(upb_pbdecoder *d, uint64_t end) {
+static bool decoder_push(upb_pbdecoder *d, uint64_t end) {
upb_pbdecoder_frame *fr = d->top;
if (end > fr->end_ofs) {
@@ -426,14 +426,14 @@ static bool pushtagdelim(upb_pbdecoder *d, uint32_t arg) {
// field number) prior to hitting any enclosing submessage end, pushing our
// existing delim end prevents us from continuing to parse values from a
// corrupt proto that doesn't give us an END tag in time.
- if (!push(d, d->top->end_ofs))
+ if (!decoder_push(d, d->top->end_ofs))
return false;
d->top->groupnum = arg;
return true;
}
// Pops a frame from the decoder stack.
-static void pop(upb_pbdecoder *d) { d->top--; }
+static void decoder_pop(upb_pbdecoder *d) { d->top--; }
NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d,
uint64_t expected) {
@@ -493,7 +493,7 @@ have_tag:
break;
case UPB_WIRE_TYPE_END_GROUP:
if (fieldnum == -d->top->groupnum) {
- pop(d);
+ decoder_pop(d);
} else if (fieldnum == d->top->groupnum) {
return DECODE_ENDGROUP;
} else {
@@ -730,12 +730,12 @@ size_t upb_pbdecoder_decode(void *closure, const void *hd, const char *buf,
)
VMCASE(OP_POP,
assert(d->top > d->stack);
- pop(d);
+ decoder_pop(d);
)
VMCASE(OP_PUSHLENDELIM,
uint32_t len;
CHECK_RETURN(decode_v32(d, &len));
- CHECK_SUSPEND(push(d, offset(d) + len));
+ CHECK_SUSPEND(decoder_push(d, offset(d) + len));
set_delim_end(d);
)
VMCASE(OP_SETDELIM,
diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c
index 4681c20..d2c22e9 100644
--- a/upb/pb/encoder.c
+++ b/upb/pb/encoder.c
@@ -109,7 +109,7 @@ static bool reserve(upb_pb_encoder *e, size_t bytes) {
// Call when "bytes" bytes have been writte at e->ptr. The caller *must* have
// previously called reserve() with at least this many bytes.
-static void advance(upb_pb_encoder *e, size_t bytes) {
+static void encoder_advance(upb_pb_encoder *e, size_t bytes) {
assert((e->limit - e->ptr) >= bytes);
e->ptr += bytes;
}
@@ -137,7 +137,7 @@ static bool encode_bytes(upb_pb_encoder *e, const void *data, size_t len) {
}
memcpy(e->ptr, data, len);
- advance(e, len);
+ encoder_advance(e, len);
return true;
}
@@ -274,7 +274,7 @@ static bool encode_varint(upb_pb_encoder *e, uint64_t val) {
return false;
}
- advance(e, upb_vencode64(val, e->ptr));
+ encoder_advance(e, upb_vencode64(val, e->ptr));
return true;
}
diff --git a/upb/pb/textprinter.c b/upb/pb/textprinter.c
index 610d8a1..8ceed68 100644
--- a/upb/pb/textprinter.c
+++ b/upb/pb/textprinter.c
@@ -110,7 +110,7 @@ bool putf(upb_textprinter *p, const char *fmt, ...) {
/* handlers *******************************************************************/
-static bool startmsg(void *c, const void *hd) {
+static bool textprinter_startmsg(void *c, const void *hd) {
UPB_UNUSED(hd);
upb_textprinter *p = c;
if (p->indent_depth_ == 0) {
@@ -119,7 +119,7 @@ static bool startmsg(void *c, const void *hd) {
return true;
}
-static bool endmsg(void *c, const void *hd, upb_status *s) {
+static bool textprinter_endmsg(void *c, const void *hd, upb_status *s) {
UPB_UNUSED(hd);
UPB_UNUSED(s);
upb_textprinter *p = c;
@@ -130,7 +130,8 @@ static bool endmsg(void *c, const void *hd, upb_status *s) {
}
#define TYPE(name, ctype, fmt) \
- static bool put ## name(void *closure, const void *handler_data, ctype val) {\
+ static bool textprinter_put ## name(void *closure, const void *handler_data, \
+ ctype val) { \
upb_textprinter *p = closure; \
const upb_fielddef *f = handler_data; \
CHECK(indent(p)); \
@@ -141,7 +142,8 @@ static bool endmsg(void *c, const void *hd, upb_status *s) {
return false; \
}
-static bool putbool(void *closure, const void *handler_data, bool val) {
+static bool textprinter_putbool(void *closure, const void *handler_data,
+ bool val) {
upb_textprinter *p = closure;
const upb_fielddef *f = handler_data;
CHECK(indent(p));
@@ -162,8 +164,11 @@ TYPE(uint64, uint64_t, "%" PRIu64)
TYPE(float, float, "%." STRINGIFY_MACROVAL(FLT_DIG) "g")
TYPE(double, double, "%." STRINGIFY_MACROVAL(DBL_DIG) "g")
+#undef TYPE
+
// Output a symbolic value from the enum if found, else just print as int32.
-static bool putenum(void *closure, const void *handler_data, int32_t val) {
+static bool textprinter_putenum(void *closure, const void *handler_data,
+ int32_t val) {
upb_textprinter *p = closure;
const upb_fielddef *f = handler_data;
const upb_enumdef *enum_def = upb_downcast_enumdef(upb_fielddef_subdef(f));
@@ -173,13 +178,13 @@ static bool putenum(void *closure, const void *handler_data, int32_t val) {
putf(p, "%s: %s", upb_fielddef_name(f), label);
endfield(p);
} else {
- if (!putint32(closure, handler_data, val))
+ if (!textprinter_putint32(closure, handler_data, val))
return false;
}
return true;
}
-static void *startstr(void *closure, const void *handler_data,
+static void *textprinter_startstr(void *closure, const void *handler_data,
size_t size_hint) {
const upb_fielddef *f = handler_data;
UPB_UNUSED(size_hint);
@@ -189,7 +194,7 @@ static void *startstr(void *closure, const void *handler_data,
return p;
}
-static bool endstr(void *closure, const void *handler_data) {
+static bool textprinter_endstr(void *closure, const void *handler_data) {
UPB_UNUSED(handler_data);
upb_textprinter *p = closure;
putf(p, "\"");
@@ -197,8 +202,8 @@ static bool endstr(void *closure, const void *handler_data) {
return true;
}
-static size_t putstr(void *closure, const void *hd, const char *buf,
- size_t len, const upb_bufhandle *handle) {
+static size_t textprinter_putstr(void *closure, const void *hd, const char *buf,
+ size_t len, const upb_bufhandle *handle) {
UPB_UNUSED(handle);
upb_textprinter *p = closure;
const upb_fielddef *f = hd;
@@ -208,7 +213,7 @@ err:
return 0;
}
-static void *startsubmsg(void *closure, const void *handler_data) {
+static void *textprinter_startsubmsg(void *closure, const void *handler_data) {
upb_textprinter *p = closure;
const char *name = handler_data;
CHECK(indent(p));
@@ -219,7 +224,7 @@ err:
return UPB_BREAK;
}
-static bool endsubmsg(void *closure, const void *handler_data) {
+static bool textprinter_endsubmsg(void *closure, const void *handler_data) {
UPB_UNUSED(handler_data);
upb_textprinter *p = closure;
p->indent_depth_--;
@@ -253,8 +258,8 @@ static void onmreg(const void *c, upb_handlers *h) {
UPB_UNUSED(c);
const upb_msgdef *m = upb_handlers_msgdef(h);
- upb_handlers_setstartmsg(h, startmsg, NULL);
- upb_handlers_setendmsg(h, endmsg, NULL);
+ upb_handlers_setstartmsg(h, textprinter_startmsg, NULL);
+ upb_handlers_setendmsg(h, textprinter_endmsg, NULL);
upb_msg_iter i;
for(upb_msg_begin(&i, m); !upb_msg_done(&i); upb_msg_next(&i)) {
@@ -263,31 +268,31 @@ static void onmreg(const void *c, upb_handlers *h) {
upb_handlerattr_sethandlerdata(&attr, f);
switch (upb_fielddef_type(f)) {
case UPB_TYPE_INT32:
- upb_handlers_setint32(h, f, putint32, &attr);
+ upb_handlers_setint32(h, f, textprinter_putint32, &attr);
break;
case UPB_TYPE_INT64:
- upb_handlers_setint64(h, f, putint64, &attr);
+ upb_handlers_setint64(h, f, textprinter_putint64, &attr);
break;
case UPB_TYPE_UINT32:
- upb_handlers_setuint32(h, f, putuint32, &attr);
+ upb_handlers_setuint32(h, f, textprinter_putuint32, &attr);
break;
case UPB_TYPE_UINT64:
- upb_handlers_setuint64(h, f, putuint64, &attr);
+ upb_handlers_setuint64(h, f, textprinter_putuint64, &attr);
break;
case UPB_TYPE_FLOAT:
- upb_handlers_setfloat(h, f, putfloat, &attr);
+ upb_handlers_setfloat(h, f, textprinter_putfloat, &attr);
break;
case UPB_TYPE_DOUBLE:
- upb_handlers_setdouble(h, f, putdouble, &attr);
+ upb_handlers_setdouble(h, f, textprinter_putdouble, &attr);
break;
case UPB_TYPE_BOOL:
- upb_handlers_setbool(h, f, putbool, &attr);
+ upb_handlers_setbool(h, f, textprinter_putbool, &attr);
break;
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
- upb_handlers_setstartstr(h, f, startstr, &attr);
- upb_handlers_setstring(h, f, putstr, &attr);
- upb_handlers_setendstr(h, f, endstr, &attr);
+ upb_handlers_setstartstr(h, f, textprinter_startstr, &attr);
+ upb_handlers_setstring(h, f, textprinter_putstr, &attr);
+ upb_handlers_setendstr(h, f, textprinter_endstr, &attr);
break;
case UPB_TYPE_MESSAGE: {
const char *name =
@@ -295,12 +300,12 @@ static void onmreg(const void *c, upb_handlers *h) {
? shortname(upb_msgdef_fullname(upb_fielddef_msgsubdef(f)))
: upb_fielddef_name(f);
upb_handlerattr_sethandlerdata(&attr, name);
- upb_handlers_setstartsubmsg(h, f, startsubmsg, &attr);
- upb_handlers_setendsubmsg(h, f, endsubmsg, &attr);
+ upb_handlers_setstartsubmsg(h, f, textprinter_startsubmsg, &attr);
+ upb_handlers_setendsubmsg(h, f, textprinter_endsubmsg, &attr);
break;
}
case UPB_TYPE_ENUM:
- upb_handlers_setint32(h, f, putenum, &attr);
+ upb_handlers_setint32(h, f, textprinter_putenum, &attr);
break;
}
}
diff --git a/upb/refcounted.c b/upb/refcounted.c
index ca97d9f..40e6e89 100644
--- a/upb/refcounted.c
+++ b/upb/refcounted.c
@@ -399,7 +399,7 @@ static upb_refcounted *pop(tarjan *t) {
return r;
}
-static void newgroup(tarjan *t) {
+static void tarjan_newgroup(tarjan *t) {
uint32_t *group = malloc(sizeof(*group));
if (!group) oom(t);
// Push group and empty group leader (we'll fill in leader later).
@@ -493,7 +493,7 @@ static void do_tarjan(const upb_refcounted *obj, tarjan *t) {
push(t, obj);
visit(obj, tarjan_visit, t);
if (lowlink(t, obj) == idx(t, obj)) {
- newgroup(t);
+ tarjan_newgroup(t);
while (pop(t) != obj)
;
}
diff --git a/upb/symtab.c b/upb/symtab.c
index 2f2b444..f172aaa 100644
--- a/upb/symtab.c
+++ b/upb/symtab.c
@@ -43,9 +43,9 @@ static void upb_symtab_free(upb_refcounted *r) {
free(s);
}
-static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free};
upb_symtab *upb_symtab_new(const void *owner) {
+ static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free};
upb_symtab *s = malloc(sizeof(*s));
upb_refcounted_init(UPB_UPCAST(s), &vtbl, owner);
upb_strtable_init(&s->symtab, UPB_CTYPE_PTR);
diff --git a/upb/table.int.h b/upb/table.int.h
index 56891d7..049ad3a 100644
--- a/upb/table.int.h
+++ b/upb/table.int.h
@@ -26,7 +26,7 @@
#include <assert.h>
#include <stdint.h>
#include <string.h>
-#include "upb.h"
+#include "upb/upb.h"
#ifdef __cplusplus
extern "C" {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback