summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
Diffstat (limited to 'upb')
-rw-r--r--upb/def.c41
-rw-r--r--upb/def.h11
-rw-r--r--upb/symtab.c5
3 files changed, 34 insertions, 23 deletions
diff --git a/upb/def.c b/upb/def.c
index 4ed61be..2fdbf01 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -74,21 +74,17 @@ upb_deftype_t upb_def_type(const upb_def *d) { return d->type; }
const char *upb_def_fullname(const upb_def *d) { return d->fullname; }
const char *upb_def_name(const upb_def *d) {
- /* Return one past the last '.'. */
- const char *ret = d->fullname;
- const char *p = ret;
+ const char *p;
- if (ret == NULL) {
+ if (d->fullname == NULL) {
return NULL;
+ } else if ((p = strrchr(d->fullname, '.')) == NULL) {
+ /* No '.' in the name, return the full string. */
+ return d->fullname;
+ } else {
+ /* Return one past the last '.'. */
+ return p + 1;
}
-
- for (p = ret; *p; ++p) {
- if (*p == '.') {
- ret = p + 1;
- }
- }
-
- return ret;
}
bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) {
@@ -1527,12 +1523,6 @@ bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
return true;
}
-void upb_msgdef_setprimitiveshavepresence(upb_msgdef *m, bool have_presence) {
- assert(!upb_msgdef_isfrozen(m));
- assert(!m->base.file);
- m->syntax = have_presence ? UPB_SYNTAX_PROTO2 : UPB_SYNTAX_PROTO3;
-}
-
const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) {
upb_value val;
return upb_inttable_lookup32(&m->itof, i, &val) ?
@@ -1898,17 +1888,26 @@ const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i) {
}
bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s) {
- UPB_UNUSED(s);
+ name = upb_strdup(name);
+ if (!name) {
+ upb_status_seterrmsg(s, "Out of memory");
+ return false;
+ }
free((void*)f->name);
- f->name = upb_strdup(name);
+ f->name = name;
return true;
}
bool upb_filedef_setpackage(upb_filedef *f, const char *package,
upb_status *s) {
if (!upb_isident(package, strlen(package), true, s)) return false;
+ package = upb_strdup(package);
+ if (!package) {
+ upb_status_seterrmsg(s, "Out of memory");
+ return false;
+ }
free((void*)f->package);
- f->package = upb_strdup(package);
+ f->package = package;
return true;
}
diff --git a/upb/def.h b/upb/def.h
index 487729a..0fc6f41 100644
--- a/upb/def.h
+++ b/upb/def.h
@@ -921,7 +921,6 @@ bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
upb_status *s);
bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
upb_status *s);
-void upb_msgdef_setprimitiveshavepresence(upb_msgdef *m, bool have_presence);
/* Field lookup in a couple of different variations:
* - itof = int to field
@@ -1153,6 +1152,7 @@ class upb::OneofDef {
* by name once added to a message def. */
const char* name() const;
bool set_name(const char* name, Status* s);
+ bool set_name(const std::string& name, Status* s);
/* Returns the number of fields currently defined in the oneof. */
int field_count() const;
@@ -1306,7 +1306,8 @@ class upb::FileDef {
/* Get/set name of the file (eg. "foo/bar.proto"). */
const char* name() const;
- bool set_name(const char* fullname, Status* s);
+ bool set_name(const char* name, Status* s);
+ bool set_name(const std::string& name, Status* s);
/* Package name for definitions inside the file (eg. "foo.bar"). */
const char* package() const;
@@ -1900,6 +1901,9 @@ inline const char* OneofDef::name() const {
inline bool OneofDef::set_name(const char* name, Status* s) {
return upb_oneofdef_setname(this, name, s);
}
+inline bool OneofDef::set_name(const std::string& name, Status* s) {
+ return upb_oneofdef_setname(this, upb_safecstr(name), s);
+}
inline int OneofDef::field_count() const {
return upb_oneofdef_numfields(this);
}
@@ -1979,6 +1983,9 @@ inline const char* FileDef::name() const {
inline bool FileDef::set_name(const char* name, Status* s) {
return upb_filedef_setname(this, name, s);
}
+inline bool FileDef::set_name(const std::string& name, Status* s) {
+ return upb_filedef_setname(this, upb_safecstr(name), s);
+}
inline const char* FileDef::package() const {
return upb_filedef_package(this);
}
diff --git a/upb/symtab.c b/upb/symtab.c
index 58913b5..83f549e 100644
--- a/upb/symtab.c
+++ b/upb/symtab.c
@@ -427,6 +427,11 @@ bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status *status) {
n = upb_filedef_defcount(file);
defs = malloc(sizeof(*defs) * n);
+ if (defs == NULL) {
+ upb_status_seterrmsg(status, "Out of memory");
+ return false;
+ }
+
for (i = 0; i < n; i++) {
defs[i] = upb_filedef_mutabledef(file, i);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback