summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-01-29 08:26:00 -0800
committerGitHub <noreply@github.com>2019-01-29 08:26:00 -0800
commit2b62fbce6734eb672ae6ff6fcf258bfff4267ae8 (patch)
treec39dd54ef29a0b6610ebd4794b1646c83c66357a /upb
parentc7870e0f77d6331babfdb89f8c83e4e0279b5e70 (diff)
parent3d931557907307ecc19b74e8f3188301b149e99a (diff)
Merge pull request #145 from haberman/arrayapi
Generated code API changes for array and hazzers.
Diffstat (limited to 'upb')
-rw-r--r--upb/bindings/lua/upb/pb.c2
-rw-r--r--upb/bindings/lua/upb/table.c1
-rw-r--r--upb/decode.c14
-rw-r--r--upb/decode.h2
-rw-r--r--upb/def.c5
-rw-r--r--upb/def.h153
-rw-r--r--upb/descriptor/descriptor.upbdefs.c2
-rw-r--r--upb/descriptor/reader.c31
-rw-r--r--upb/encode.c6
-rw-r--r--upb/generated_util.h102
-rw-r--r--upb/handlers-inl.h2
-rw-r--r--upb/handlers.c1
-rw-r--r--upb/msg.c2
-rw-r--r--upb/msg.h20
-rw-r--r--upb/msgfactory.c2
-rw-r--r--upb/msgfactory.h6
-rw-r--r--upb/pb/decoder.int.h15
-rw-r--r--upb/structdefs.int.h196
-rw-r--r--upb/structs.int.h3
19 files changed, 315 insertions, 250 deletions
diff --git a/upb/bindings/lua/upb/pb.c b/upb/bindings/lua/upb/pb.c
index bca2ee8..b5284df 100644
--- a/upb/bindings/lua/upb/pb.c
+++ b/upb/bindings/lua/upb/pb.c
@@ -16,7 +16,7 @@ static int lupb_pb_decode(lua_State *L) {
const upb_msglayout *layout;
upb_msg *msg = lupb_msg_checkmsg2(L, 1, &layout);
const char *pb = lua_tolstring(L, 2, &len);
- upb_stringview buf = upb_stringview_make(pb, len);
+ upb_strview buf = upb_strview_make(pb, len);
upb_decode(buf, msg, layout);
/* TODO(haberman): check for error. */
diff --git a/upb/bindings/lua/upb/table.c b/upb/bindings/lua/upb/table.c
index 79120c7..3a9319d 100644
--- a/upb/bindings/lua/upb/table.c
+++ b/upb/bindings/lua/upb/table.c
@@ -21,7 +21,6 @@
#include "lauxlib.h"
#include "upb/bindings/lua/upb.h"
#include "upb/def.h"
-#include "upb/structdefs.int.h"
#include "upb/table.int.h"
static void lupbtable_setnum(lua_State *L, int tab, const char *key,
diff --git a/upb/decode.c b/upb/decode.c
index fc0e644..c54ee3c 100644
--- a/upb/decode.c
+++ b/upb/decode.c
@@ -112,14 +112,14 @@ static int64_t upb_zzdecode_64(uint64_t n) {
}
static bool upb_decode_string(const char **ptr, const char *limit,
- upb_stringview *val) {
+ upb_strview *val) {
uint32_t len;
CHK(upb_decode_varint32(ptr, limit, &len) &&
len < INT32_MAX &&
limit - *ptr >= (int32_t)len);
- *val = upb_stringview_make(*ptr, len);
+ *val = upb_strview_make(*ptr, len);
*ptr += len;
return true;
}
@@ -150,7 +150,7 @@ static bool upb_skip_unknownfielddata(upb_decstate *d, upb_decframe *frame,
return upb_decode_64bit(&d->ptr, frame->limit, &val);
}
case UPB_WIRE_TYPE_DELIMITED: {
- upb_stringview val;
+ upb_strview val;
return upb_decode_string(&d->ptr, frame->limit, &val);
}
case UPB_WIRE_TYPE_START_GROUP:
@@ -374,7 +374,7 @@ static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame,
return true;
}
-static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data,
+static bool upb_decode_fixedpacked(upb_array *arr, upb_strview data,
int elem_size) {
int elements = data.size / elem_size;
void *field_mem;
@@ -389,7 +389,7 @@ static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data,
static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
const char *field_start,
const upb_msglayout_field *field,
- upb_stringview val) {
+ upb_strview val) {
upb_array *arr = upb_getorcreatearr(frame, field);
#define VARINT_CASE(ctype, decode) { \
@@ -470,7 +470,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame,
const char *field_start,
const upb_msglayout_field *field) {
- upb_stringview val;
+ upb_strview val;
CHK(upb_decode_string(&d->ptr, frame->limit, &val));
@@ -584,7 +584,7 @@ static bool upb_decode_message(upb_decstate *d, const char *limit,
return true;
}
-bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l) {
+bool upb_decode(upb_strview buf, void *msg, const upb_msglayout *l) {
upb_decstate state;
state.ptr = buf.data;
diff --git a/upb/decode.h b/upb/decode.h
index 79774ed..dee4c0f 100644
--- a/upb/decode.h
+++ b/upb/decode.h
@@ -9,7 +9,7 @@
UPB_BEGIN_EXTERN_C
-bool upb_decode(upb_stringview buf, upb_msg *msg, const upb_msglayout *l);
+bool upb_decode(upb_strview buf, upb_msg *msg, const upb_msglayout *l);
UPB_END_EXTERN_C
diff --git a/upb/def.c b/upb/def.c
index 223fb1d..8adf8c1 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -4,7 +4,6 @@
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
-#include "upb/structdefs.int.h"
#include "upb/handlers.h"
typedef struct {
@@ -665,6 +664,8 @@ static void freefield(upb_refcounted *r) {
upb_fielddef_uninit_default(f);
if (f->subdef_is_symbolic)
upb_gfree(f->sub.name);
+ if (f->msg_is_symbolic)
+ upb_gfree(f->msg.name);
upb_def_uninit(upb_fielddef_upcast_mutable(f));
upb_gfree(f);
}
@@ -1022,7 +1023,7 @@ bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s) {
s, "cannot change field number after adding to a message");
return false;
}
- if (number == 0 || number > UPB_MAX_FIELDNUMBER) {
+ if (number == 0) {
upb_status_seterrf(s, "invalid field number (%u)", number);
return false;
}
diff --git a/upb/def.h b/upb/def.h
index 19b2a20..ea22e40 100644
--- a/upb/def.h
+++ b/upb/def.h
@@ -118,9 +118,24 @@ class upb::Def {
private:
UPB_DISALLOW_POD_OPS(Def, upb::Def)
+#else
+struct upb_def {
+ upb_refcounted base;
+
+ const char *fullname;
+ const upb_filedef* file;
+ char type; /* A upb_deftype_t (char to save space) */
+
+ /* Used as a flag during the def's mutable stage. Must be false unless
+ * it is currently being used by a function on the stack. This allows
+ * us to easily determine which defs were passed into the function's
+ * current invocation. */
+ bool came_from_user;
+#endif
};
-#endif /* __cplusplus */
+#define UPB_DEF_INIT(name, type, vtbl, refs, ref2s) \
+ { UPB_REFCOUNT_INIT(vtbl, refs, ref2s), name, NULL, type, false }
UPB_BEGIN_EXTERN_C
@@ -583,12 +598,57 @@ class upb::FieldDef {
private:
UPB_DISALLOW_POD_OPS(FieldDef, upb::FieldDef)
-};
-
+#else
+struct upb_fielddef {
+ upb_def base;
+
+ union {
+ int64_t sint;
+ uint64_t uint;
+ double dbl;
+ float flt;
+ void *bytes;
+ } defaultval;
+ union {
+ const upb_msgdef *def; /* If !msg_is_symbolic. */
+ char *name; /* If msg_is_symbolic. */
+ } msg;
+ union {
+ const upb_def *def; /* If !subdef_is_symbolic. */
+ char *name; /* If subdef_is_symbolic. */
+ } sub; /* The msgdef or enumdef for this field, if upb_hassubdef(f). */
+ bool subdef_is_symbolic;
+ bool msg_is_symbolic;
+ const upb_oneofdef *oneof;
+ bool default_is_string;
+ bool type_is_set_; /* False until type is explicitly set. */
+ bool is_extension_;
+ bool lazy_;
+ bool packed_;
+ upb_intfmt_t intfmt;
+ bool tagdelim;
+ upb_fieldtype_t type_;
+ upb_label_t label_;
+ uint32_t number_;
+ uint32_t selector_base; /* Used to index into a upb::Handlers table. */
+ uint32_t index_;
# endif /* defined(__cplusplus) */
+};
UPB_BEGIN_EXTERN_C
+extern const struct upb_refcounted_vtbl upb_fielddef_vtbl;
+
+#define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \
+ packed, name, num, msgdef, subdef, selector_base, \
+ index, defaultval, refs, ref2s) \
+ { \
+ UPB_DEF_INIT(name, UPB_DEF_FIELD, &upb_fielddef_vtbl, refs, ref2s), \
+ defaultval, {msgdef}, {subdef}, NULL, false, false, \
+ type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \
+ lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \
+ }
+
/* Native C API. */
upb_fielddef *upb_fielddef_new(const void *owner);
@@ -938,12 +998,45 @@ class upb::MessageDef {
private:
UPB_DISALLOW_POD_OPS(MessageDef, upb::MessageDef)
-};
+#else
+struct upb_msgdef {
+ upb_def base;
+
+ size_t selector_count;
+ uint32_t submsg_field_count;
+
+ /* Tables for looking up fields by number and name. */
+ upb_inttable itof; /* int to field */
+ upb_strtable ntof; /* name to field/oneof */
+
+ /* Is this a map-entry message? */
+ bool map_entry;
+
+ /* Whether this message has proto2 or proto3 semantics. */
+ upb_syntax_t syntax;
+ /* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
+ * non-well-known message. */
+ upb_wellknowntype_t well_known_type;
+
+ /* TODO(haberman): proper extension ranges (there can be multiple). */
#endif /* __cplusplus */
+};
UPB_BEGIN_EXTERN_C
+extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
+
+/* TODO: also support static initialization of the oneofs table. This will be
+ * needed if we compile in descriptors that contain oneofs. */
+#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
+ map_entry, syntax, well_known_type, refs, ref2s) \
+ { \
+ UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
+ selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \
+ well_known_type \
+ }
+
/* Returns NULL if memory allocation failed. */
upb_msgdef *upb_msgdef_new(const void *owner);
@@ -1122,12 +1215,24 @@ class upb::EnumDef {
private:
UPB_DISALLOW_POD_OPS(EnumDef, upb::EnumDef)
-};
+#else
+struct upb_enumdef {
+ upb_def base;
+ upb_strtable ntoi;
+ upb_inttable iton;
+ int32_t defaultval;
#endif /* __cplusplus */
+};
UPB_BEGIN_EXTERN_C
+extern const struct upb_refcounted_vtbl upb_enumdef_vtbl;
+
+#define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \
+ { UPB_DEF_INIT(name, UPB_DEF_ENUM, &upb_enumdef_vtbl, refs, ref2s), ntoi, \
+ iton, defaultval }
+
/* Native C API. */
upb_enumdef *upb_enumdef_new(const void *owner);
@@ -1276,12 +1381,25 @@ class upb::OneofDef {
private:
UPB_DISALLOW_POD_OPS(OneofDef, upb::OneofDef)
-};
-
+#else
+struct upb_oneofdef {
+ upb_refcounted base;
+
+ uint32_t index; /* Index within oneofs. */
+ const char *name;
+ upb_strtable ntof;
+ upb_inttable itof;
+ const upb_msgdef *parent;
#endif /* __cplusplus */
+};
UPB_BEGIN_EXTERN_C
+extern const struct upb_refcounted_vtbl upb_oneofdef_vtbl;
+
+#define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \
+ { UPB_REFCOUNT_INIT(&upb_oneofdef_vtbl, refs, ref2s), 0, name, ntof, itof }
+
/* Native C API. */
upb_oneofdef *upb_oneofdef_new(const void *owner);
@@ -1400,12 +1518,25 @@ class upb::FileDef {
private:
UPB_DISALLOW_POD_OPS(FileDef, upb::FileDef)
-};
+#else
+struct upb_filedef {
+ upb_refcounted base;
+
+ const char *name;
+ const char *package;
+ const char *phpprefix;
+ const char *phpnamespace;
+ upb_syntax_t syntax;
+ upb_inttable defs;
+ upb_inttable deps;
#endif
+};
UPB_BEGIN_EXTERN_C
+extern const struct upb_refcounted_vtbl upb_filedef_vtbl;
+
upb_filedef *upb_filedef_new(const void *owner);
/* Include upb_refcounted methods like upb_msgdef_ref(). */
@@ -1535,9 +1666,13 @@ class upb::SymbolTable {
private:
UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable)
-};
+#else
+struct upb_symtab {
+ upb_refcounted base;
+ upb_strtable symtab;
#endif /* __cplusplus */
+};
UPB_BEGIN_EXTERN_C
diff --git a/upb/descriptor/descriptor.upbdefs.c b/upb/descriptor/descriptor.upbdefs.c
index fa5bb3b..d91f674 100644
--- a/upb/descriptor/descriptor.upbdefs.c
+++ b/upb/descriptor/descriptor.upbdefs.c
@@ -7,8 +7,6 @@
* regenerated. */
#include "upb/def.h"
-#include "upb/structdefs.int.h"
-
static const upb_msgdef msgs[22];
static const upb_fielddef fields[107];
static const upb_enumdef enums[5];
diff --git a/upb/descriptor/reader.c b/upb/descriptor/reader.c
index 054ebd2..fd219fe 100644
--- a/upb/descriptor/reader.c
+++ b/upb/descriptor/reader.c
@@ -321,14 +321,21 @@ static void *file_startenum(void *closure, const void *hd) {
static void *file_startext(void *closure, const void *hd) {
upb_descreader *r = closure;
- bool ok;
r->f = upb_fielddef_new(r);
- ok = upb_filedef_addext(r->file, r->f, r, NULL);
UPB_UNUSED(hd);
- UPB_ASSERT(ok);
return r;
}
+static bool file_endext(void *closure, const void *hd) {
+ /* The current symtab code can't handle extensions, so we just discard
+ * them for now. */
+ upb_descreader *r = closure;
+ upb_fielddef_unref(r->f, r);
+ UPB_UNUSED(hd);
+ r->f = NULL;
+ return true;
+}
+
static size_t file_ondep(void *closure, const void *hd, const char *buf,
size_t n, const upb_bufhandle *handle) {
upb_descreader *r = closure;
@@ -702,13 +709,21 @@ static void *msg_startmsg(void *closure, const void *hd) {
static void *msg_startext(void *closure, const void *hd) {
upb_descreader *r = closure;
- upb_fielddef *f = upb_fielddef_new(&f);
- bool ok = upb_filedef_addext(r->file, f, &f, NULL);
+ r->f = upb_fielddef_new(r);
UPB_UNUSED(hd);
- UPB_ASSERT(ok);
return r;
}
+static bool msg_endext(void *closure, const void *hd) {
+ /* The current symtab code can't handle extensions, so we just discard
+ * them for now. */
+ upb_descreader *r = closure;
+ upb_fielddef_unref(r->f, r);
+ UPB_UNUSED(hd);
+ r->f = NULL;
+ return true;
+}
+
static void *msg_startfield(void *closure, const void *hd) {
upb_descreader *r = closure;
r->f = upb_fielddef_new(&r->f);
@@ -763,6 +778,8 @@ static void reghandlers(const void *closure, upb_handlers *h) {
upb_handlers_setstring(h, F(DescriptorProto, name), &msg_name, NULL);
upb_handlers_setstartsubmsg(h, F(DescriptorProto, extension), &msg_startext,
NULL);
+ upb_handlers_setendsubmsg(h, F(DescriptorProto, extension), &msg_endext,
+ NULL);
upb_handlers_setstartsubmsg(h, F(DescriptorProto, nested_type),
&msg_startmsg, NULL);
upb_handlers_setstartsubmsg(h, F(DescriptorProto, field),
@@ -786,6 +803,8 @@ static void reghandlers(const void *closure, upb_handlers *h) {
&file_startenum, NULL);
upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, extension),
&file_startext, NULL);
+ upb_handlers_setendsubmsg(h, F(FileDescriptorProto, extension),
+ &file_endext, NULL);
upb_handlers_setstring(h, F(FileDescriptorProto, dependency),
&file_ondep, NULL);
} else if (upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)) {
diff --git a/upb/encode.c b/upb/encode.c
index bff8262..b728353 100644
--- a/upb/encode.c
+++ b/upb/encode.c
@@ -207,8 +207,8 @@ do { ; } while(0)
VARINT_CASE(int64_t, upb_zzencode_64(*ptr));
case UPB_DESCRIPTOR_TYPE_STRING:
case UPB_DESCRIPTOR_TYPE_BYTES: {
- upb_stringview *start = arr->data;
- upb_stringview *ptr = start + arr->len;
+ upb_strview *start = arr->data;
+ upb_strview *ptr = start + arr->len;
do {
ptr--;
CHK(upb_put_bytes(e, ptr->data, ptr->size) &&
@@ -292,7 +292,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_64(val));
case UPB_DESCRIPTOR_TYPE_STRING:
case UPB_DESCRIPTOR_TYPE_BYTES: {
- upb_stringview view = *(upb_stringview*)field_mem;
+ upb_strview view = *(upb_strview*)field_mem;
if (skip_zero_value && view.size == 0) {
return true;
}
diff --git a/upb/generated_util.h b/upb/generated_util.h
new file mode 100644
index 0000000..bd47389
--- /dev/null
+++ b/upb/generated_util.h
@@ -0,0 +1,102 @@
+/*
+** Functions for use by generated code. These are not public and users must
+** not call them directly.
+*/
+
+#ifndef UPB_GENERATED_UTIL_H_
+#define UPB_GENERATED_UTIL_H_
+
+#include <stdint.h>
+#include "upb/structs.int.h"
+
+#define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs)
+
+UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs,
+ size_t *size) {
+ const upb_array *arr = *PTR_AT(msg, ofs, const upb_array*);
+ if (arr) {
+ if (size) *size = arr->size;
+ return arr->data;
+ } else {
+ if (size) *size = 0;
+ return NULL;
+ }
+}
+
+UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs,
+ size_t *size) {
+ upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
+ if (arr) {
+ if (size) *size = arr->size;
+ return arr->data;
+ } else {
+ if (size) *size = 0;
+ return NULL;
+ }
+}
+
+/* TODO(haberman): this is a mess. It will improve when upb_array no longer
+ * carries reflective state (type, elem_size). */
+UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
+ size_t elem_size,
+ upb_fieldtype_t type,
+ upb_arena *arena) {
+ upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
+
+ if (!arr) {
+ arr = upb_array_new(type, arena);
+ if (!arr) return NULL;
+ *PTR_AT(msg, ofs, upb_array*) = arr;
+ }
+
+ if (size > arr->size) {
+ size_t new_size = UPB_MAX(arr->size, 4);
+ size_t old_bytes = arr->size * elem_size;
+ size_t new_bytes;
+ upb_alloc *alloc = upb_arena_alloc(arr->arena);
+ while (new_size < size) new_size *= 2;
+ new_bytes = new_size * elem_size;
+ arr->data = upb_realloc(alloc, arr->data, old_bytes, new_bytes);
+ if (!arr->data) {
+ return NULL;
+ }
+ arr->size = new_size;
+ }
+
+ arr->len = size;
+ return arr->data;
+}
+
+UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs,
+ size_t elem_size,
+ upb_fieldtype_t type,
+ const void *value,
+ upb_arena *arena) {
+ upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
+ size_t i = arr ? arr->len : 0;
+ void *data =
+ _upb_array_resize_accessor(msg, ofs, i + 1, elem_size, type, arena);
+ if (!data) return false;
+ memcpy(PTR_AT(data, i * elem_size, char), value, elem_size);
+ return true;
+}
+
+UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) {
+ return (*PTR_AT(msg, idx / 8, const char) & (idx % 8)) != 0;
+}
+
+UPB_INLINE bool _upb_sethas(const void *msg, size_t idx) {
+ return (*PTR_AT(msg, idx / 8, char)) |= (1 << (idx % 8));
+}
+
+UPB_INLINE bool _upb_clearhas(const void *msg, size_t idx) {
+ return (*PTR_AT(msg, idx / 8, char)) &= ~(1 << (idx % 8));
+}
+
+UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) {
+ return *PTR_AT(msg, case_ofs, int32_t) == num;
+}
+
+#undef PTR_AT
+
+#endif /* UPB_GENERATED_UTIL_H_ */
diff --git a/upb/handlers-inl.h b/upb/handlers-inl.h
index afc1382..4a0494c 100644
--- a/upb/handlers-inl.h
+++ b/upb/handlers-inl.h
@@ -7,6 +7,8 @@
#define UPB_HANDLERS_INL_H_
#include <limits.h>
+#include "upb/upb.h"
+#include "upb/handlers.h"
/* C inline methods. */
diff --git a/upb/handlers.c b/upb/handlers.c
index 0022c32..33c43c3 100644
--- a/upb/handlers.c
+++ b/upb/handlers.c
@@ -4,7 +4,6 @@
*/
#include "upb/handlers.h"
-#include "upb/structdefs.int.h"
#include <string.h>
diff --git a/upb/msg.c b/upb/msg.c
index 29ba2e1..c6f0c17 100644
--- a/upb/msg.c
+++ b/upb/msg.c
@@ -51,7 +51,7 @@ static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
return sizeof(void*);
case UPB_TYPE_BYTES:
case UPB_TYPE_STRING:
- return sizeof(upb_stringview);
+ return sizeof(upb_strview);
}
UPB_UNREACHABLE();
}
diff --git a/upb/msg.h b/upb/msg.h
index c72e9f0..058f4a9 100644
--- a/upb/msg.h
+++ b/upb/msg.h
@@ -36,10 +36,12 @@ class MessageLayout;
#endif
-UPB_DECLARE_TYPE(upb::Array, upb_array)
UPB_DECLARE_TYPE(upb::Map, upb_map)
UPB_DECLARE_TYPE(upb::MapIterator, upb_mapiter)
+struct upb_array;
+typedef struct upb_array upb_array;
+
/* TODO(haberman): C++ accessors */
UPB_BEGIN_EXTERN_C
@@ -73,21 +75,21 @@ typedef struct upb_msglayout {
} upb_msglayout;
-/** upb_stringview ************************************************************/
+/** upb_strview ************************************************************/
typedef struct {
const char *data;
size_t size;
-} upb_stringview;
+} upb_strview;
-UPB_INLINE upb_stringview upb_stringview_make(const char *data, size_t size) {
- upb_stringview ret;
+UPB_INLINE upb_strview upb_strview_make(const char *data, size_t size) {
+ upb_strview ret;
ret.data = data;
ret.size = size;
return ret;
}
-#define UPB_STRINGVIEW_INIT(ptr, len) {ptr, len}
+#define UPB_STRVIEW_INIT(ptr, len) {ptr, len}
/** upb_msgval ****************************************************************/
@@ -107,7 +109,7 @@ typedef union {
const upb_msg* msg;
const upb_array* arr;
const void* ptr;
- upb_stringview str;
+ upb_strview str;
} upb_msgval;
#define ACCESSORS(name, membername, ctype) \
@@ -134,12 +136,12 @@ ACCESSORS(map, map, const upb_map*)
ACCESSORS(msg, msg, const upb_msg*)
ACCESSORS(ptr, ptr, const void*)
ACCESSORS(arr, arr, const upb_array*)
-ACCESSORS(str, str, upb_stringview)
+ACCESSORS(str, str, upb_strview)
#undef ACCESSORS
UPB_INLINE upb_msgval upb_msgval_makestr(const char *data, size_t size) {
- return upb_msgval_str(upb_stringview_make(data, size));
+ return upb_msgval_str(upb_strview_make(data, size));
}
diff --git a/upb/msgfactory.c b/upb/msgfactory.c
index 593c9dc..05f5975 100644
--- a/upb/msgfactory.c
+++ b/upb/msgfactory.c
@@ -32,7 +32,7 @@ static size_t upb_msgval_sizeof2(upb_fieldtype_t type) {
return sizeof(void*);
case UPB_TYPE_BYTES:
case UPB_TYPE_STRING:
- return sizeof(upb_stringview);
+ return sizeof(upb_strview);
}
UPB_UNREACHABLE();
}
diff --git a/upb/msgfactory.h b/upb/msgfactory.h
index 73a26ba..8b12461 100644
--- a/upb/msgfactory.h
+++ b/upb/msgfactory.h
@@ -5,6 +5,12 @@
#ifndef UPB_MSGFACTORY_H_
#define UPB_MSGFACTORY_H_
+#ifdef __cplusplus
+namespace upb {
+class MessageFactory;
+}
+#endif
+
UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory)
/** upb_msgfactory ************************************************************/
diff --git a/upb/pb/decoder.int.h b/upb/pb/decoder.int.h
index 4032570..c9ad551 100644
--- a/upb/pb/decoder.int.h
+++ b/upb/pb/decoder.int.h
@@ -9,17 +9,10 @@
#include "upb/handlers.h"
#include "upb/pb/decoder.h"
#include "upb/sink.h"
-#include "upb/structdefs.int.h"
#include "upb/table.int.h"
-/* C++ names are not actually used since this type isn't exposed to users. */
-#ifdef __cplusplus
-namespace upb {
-namespace pb {
-class MessageGroup;
-} /* namespace pb */
-} /* namespace upb */
-#endif
+#ifndef __cplusplus
+
UPB_DECLARE_DERIVED_TYPE(upb::pb::MessageGroup, upb::RefCounted,
mgroup, upb_refcounted)
@@ -82,7 +75,7 @@ typedef enum {
#define OP_MAX OP_HALT
-UPB_INLINE opcode getop(uint32_t instr) { return instr & 0xff; }
+UPB_INLINE opcode getop(uint32_t instr) { return (opcode)(instr & 0xff); }
/* Method group; represents a set of decoder methods that had their code
* emitted together, and must therefore be freed together. Immutable once
@@ -329,4 +322,6 @@ UPB_INLINE void upb_pbdecoder_unpackdispatch(uint64_t dispatch, uint64_t *ofs,
#define CHECK_RETURN(x) { int32_t ret = x; if (ret >= 0) return ret; }
+#endif /* __cplusplus */
+
#endif /* UPB_DECODER_INT_H_ */
diff --git a/upb/structdefs.int.h b/upb/structdefs.int.h
deleted file mode 100644
index cf8bd1d..0000000
--- a/upb/structdefs.int.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
-** This file contains definitions of structs that should be considered private
-** and NOT stable across versions of upb.
-**
-** The only reason they are declared here and not in .c files is to allow upb
-** and the application (if desired) to embed statically-initialized instances
-** of structures like defs.
-**
-** If you include this file, all guarantees of ABI compatibility go out the
-** window! Any code that includes this file needs to recompile against the
-** exact same version of upb that they are linking against.
-**
-** You also need to recompile if you change the value of the UPB_DEBUG_REFS
-** flag.
-*/
-
-#include "upb/def.h"
-
-#ifndef UPB_STATICINIT_H_
-#define UPB_STATICINIT_H_
-
-#ifdef __cplusplus
-/* Because of how we do our typedefs, this header can't be included from C++. */
-#error This file cannot be included from C++
-#endif
-
-/* upb_refcounted *************************************************************/
-
-
-/* upb_def ********************************************************************/
-
-struct upb_def {
- upb_refcounted base;
-
- const char *fullname;
- const upb_filedef* file;
- char type; /* A upb_deftype_t (char to save space) */
-
- /* Used as a flag during the def's mutable stage. Must be false unless
- * it is currently being used by a function on the stack. This allows
- * us to easily determine which defs were passed into the function's
- * current invocation. */
- bool came_from_user;
-};
-
-#define UPB_DEF_INIT(name, type, vtbl, refs, ref2s) \
- { UPB_REFCOUNT_INIT(vtbl, refs, ref2s), name, NULL, type, false }
-
-
-/* upb_fielddef ***************************************************************/
-
-struct upb_fielddef {
- upb_def base;
-
- union {
- int64_t sint;
- uint64_t uint;
- double dbl;
- float flt;
- void *bytes;
- } defaultval;
- union {
- const upb_msgdef *def; /* If !msg_is_symbolic. */
- char *name; /* If msg_is_symbolic. */
- } msg;
- union {
- const upb_def *def; /* If !subdef_is_symbolic. */
- char *name; /* If subdef_is_symbolic. */
- } sub; /* The msgdef or enumdef for this field, if upb_hassubdef(f). */
- bool subdef_is_symbolic;
- bool msg_is_symbolic;
- const upb_oneofdef *oneof;
- bool default_is_string;
- bool type_is_set_; /* False until type is explicitly set. */
- bool is_extension_;
- bool lazy_;
- bool packed_;
- upb_intfmt_t intfmt;
- bool tagdelim;
- upb_fieldtype_t type_;
- upb_label_t label_;
- uint32_t number_;
- uint32_t selector_base; /* Used to index into a upb::Handlers table. */
- uint32_t index_;
-};
-
-extern const struct upb_refcounted_vtbl upb_fielddef_vtbl;
-
-#define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \
- packed, name, num, msgdef, subdef, selector_base, \
- index, defaultval, refs, ref2s) \
- { \
- UPB_DEF_INIT(name, UPB_DEF_FIELD, &upb_fielddef_vtbl, refs, ref2s), \
- defaultval, {msgdef}, {subdef}, NULL, false, false, \
- type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \
- lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \
- }
-
-
-/* upb_msgdef *****************************************************************/
-
-struct upb_msgdef {
- upb_def base;
-
- size_t selector_count;
- uint32_t submsg_field_count;
-
- /* Tables for looking up fields by number and name. */
- upb_inttable itof; /* int to field */
- upb_strtable ntof; /* name to field/oneof */
-
- /* Is this a map-entry message? */
- bool map_entry;
-
- /* Whether this message has proto2 or proto3 semantics. */
- upb_syntax_t syntax;
-
- /* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
- * non-well-known message. */
- upb_wellknowntype_t well_known_type;
-
- /* TODO(haberman): proper extension ranges (there can be multiple). */
-};
-
-extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
-
-/* TODO: also support static initialization of the oneofs table. This will be
- * needed if we compile in descriptors that contain oneofs. */
-#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
- map_entry, syntax, well_known_type, refs, ref2s) \
- { \
- UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
- selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \
- well_known_type \
- }
-
-
-/* upb_enumdef ****************************************************************/
-
-struct upb_enumdef {
- upb_def base;
-
- upb_strtable ntoi;
- upb_inttable iton;
- int32_t defaultval;
-};
-
-extern const struct upb_refcounted_vtbl upb_enumdef_vtbl;
-
-#define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \
- { UPB_DEF_INIT(name, UPB_DEF_ENUM, &upb_enumdef_vtbl, refs, ref2s), ntoi, \
- iton, defaultval }
-
-
-/* upb_oneofdef ***************************************************************/
-
-struct upb_oneofdef {
- upb_refcounted base;
-
- uint32_t index; /* Index within oneofs. */
- const char *name;
- upb_strtable ntof;
- upb_inttable itof;
- const upb_msgdef *parent;
-};
-
-extern const struct upb_refcounted_vtbl upb_oneofdef_vtbl;
-
-#define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \
- { UPB_REFCOUNT_INIT(&upb_oneofdef_vtbl, refs, ref2s), 0, name, ntof, itof }
-
-
-/* upb_symtab *****************************************************************/
-
-struct upb_symtab {
- upb_refcounted base;
-
- upb_strtable symtab;
-};
-
-struct upb_filedef {
- upb_refcounted base;
-
- const char *name;
- const char *package;
- const char *phpprefix;
- const char *phpnamespace;
- upb_syntax_t syntax;
-
- upb_inttable defs;
- upb_inttable deps;
-};
-
-extern const struct upb_refcounted_vtbl upb_filedef_vtbl;
-
-#endif /* UPB_STATICINIT_H_ */
diff --git a/upb/structs.int.h b/upb/structs.int.h
index 6bc502e..1394dd4 100644
--- a/upb/structs.int.h
+++ b/upb/structs.int.h
@@ -5,6 +5,9 @@
#ifndef UPB_STRUCTS_H_
#define UPB_STRUCTS_H_
+#include "upb/def.h"
+#include "upb/msg.h"
+
struct upb_array {
upb_fieldtype_t type;
uint8_t element_size;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback