summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-12-16 14:32:14 -0800
committerJoshua Haberman <jhaberman@gmail.com>2018-12-16 14:32:14 -0800
commit377871f10403c7b4e1cc6f769b9443b5197aecc8 (patch)
tree7c97aac20d9ecddf69d5a213d958c9bdfc123646 /upb
parent380558922b661499f4eb43b0463b5a73e5fe87b7 (diff)
Got test_decoder working!
Diffstat (limited to 'upb')
-rw-r--r--upb/def.c51
-rw-r--r--upb/def.h10
-rw-r--r--upb/upb.h1
3 files changed, 57 insertions, 5 deletions
diff --git a/upb/def.c b/upb/def.c
index ba6de50..047684e 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -643,7 +643,7 @@ uint32_t upb_msgdef_submsgfieldcount(const upb_msgdef *m) {
const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) {
upb_value val;
return upb_inttable_lookup32(&m->itof, i, &val) ?
- upb_value_getptr(val) : NULL;
+ upb_value_getconstptr(val) : NULL;
}
const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
@@ -1128,12 +1128,14 @@ static bool create_fielddef(
if (m) {
/* direct message field. */
+ upb_value v, packed_v;
+
f = (upb_fielddef*)&m->fields[m->field_count++];
f->msgdef = m;
f->is_extension_ = false;
- upb_value packed_v = pack_def(f, UPB_DEFTYPE_FIELD);
- upb_value v = upb_value_constptr(f);
+ packed_v = pack_def(f, UPB_DEFTYPE_FIELD);
+ v = upb_value_constptr(f);
if (!upb_strtable_insert3(&m->ntof, name.data, name.size, packed_v, alloc)) {
upb_status_seterrf(ctx->status, "duplicate field name (%s)", shortname);
@@ -1580,5 +1582,48 @@ bool upb_symtab_addfile(upb_symtab *s,
return ok;
}
+/* Include here since we want most of this file to be stdio-free. */
+#include <stdio.h>
+
+bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) {
+ /* Since this function should never fail (it would indicate a bug in upb) we
+ * print errors to stderr instead of returning error status to the user. */
+ upb_def_init **deps = init->deps;
+ google_protobuf_FileDescriptorProto *file;
+ upb_arena arena;
+ upb_status status = UPB_STATUS_INIT;
+
+ if (upb_strtable_lookup(&s->files, init->filename, NULL)) {
+ return true;
+ }
+
+ for (; *deps; deps++) {
+ if (!_upb_symtab_loaddefinit(s, *deps)) goto err;
+ }
+
+ upb_arena_init(&arena);
+ file = google_protobuf_FileDescriptorProto_parsenew(init->descriptor, &arena);
+
+ if (!file) {
+ upb_status_seterrf(
+ &status,
+ "Failed to parse compiled-in descriptor for file '%s'. This should "
+ "never happen.",
+ init->filename);
+ goto err;
+ }
+
+ if (!upb_symtab_addfile(s, file, &status)) goto err;
+
+ upb_arena_uninit(&arena);
+ return true;
+
+err:
+ fprintf(stderr, "Error loading compiled-in descriptor: %s\n",
+ upb_status_errmsg(&status));
+ upb_arena_uninit(&arena);
+ return false;
+}
+
#undef CHK
#undef CHK_OOM
diff --git a/upb/def.h b/upb/def.h
index 4fe6d04..e6fdf21 100644
--- a/upb/def.h
+++ b/upb/def.h
@@ -659,7 +659,6 @@ const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i);
const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i);
const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i);
-
UPB_END_EXTERN_C
#ifdef __cplusplus
@@ -707,6 +706,15 @@ bool upb_symtab_addfile(upb_symtab *s,
const google_protobuf_FileDescriptorProto* file,
upb_status *status);
+/* For generated code only: loads a generated descriptor. */
+typedef struct upb_def_init {
+ struct upb_def_init **deps;
+ const char *filename;
+ upb_stringview descriptor;
+} upb_def_init;
+
+bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init);
+
UPB_END_EXTERN_C
#ifdef __cplusplus
diff --git a/upb/upb.h b/upb/upb.h
index 020022b..2fb7a88 100644
--- a/upb/upb.h
+++ b/upb/upb.h
@@ -463,7 +463,6 @@ struct upb_alloc {
UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
UPB_ASSERT(alloc);
- UPB_ASSERT(size < 65535);
return alloc->func(alloc, NULL, 0, size);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback