Properly populate field presence flag on messages according to syntax flag.

pull/13171/head
Josh Haberman 9 years ago
parent bc53c1bc46
commit ba4b6f5c84
  1. 20
      travis.sh
  2. 28
      upb/descriptor/reader.c

@ -1,5 +1,10 @@
#!/bin/bash #!/bin/bash
install_protoc() {
sudo apt-get install protobuf-compiler
protoc --version || true
}
# Bare build: no dependencies installed, no JIT enabled. # Bare build: no dependencies installed, no JIT enabled.
bare_install() { bare_install() {
: :
@ -21,7 +26,8 @@ barejit_script() {
# Build with Google protobuf support and tests (with JIT). # Build with Google protobuf support and tests (with JIT).
withprotobuf_install() { withprotobuf_install() {
sudo apt-get update -qq sudo apt-get update -qq
sudo apt-get install protobuf-compiler libprotobuf-dev sudo apt-get install libprotobuf-dev
install_protoc
} }
withprotobuf_script() { withprotobuf_script() {
make -j12 tests googlepbtests WITH_JIT=yes make -j12 tests googlepbtests WITH_JIT=yes
@ -66,9 +72,13 @@ lua_script() {
# don't want the test to be brittle. # don't want the test to be brittle.
genfiles_install() { genfiles_install() {
sudo apt-get update -qq sudo apt-get update -qq
sudo apt-get install lua5.2 liblua5.2-dev protobuf-compiler sudo apt-get install lua5.2 liblua5.2-dev
} }
genfiles_script() { genfiles_script() {
# Avoid regenerating descriptor.pb, since its output can vary based on the
# version of protoc.
touch upb/descriptor/descriptor.pb
make -j12 genfiles USER_CPPFLAGS="$USER_CPPFLAGS `pkg-config lua5.2 --cflags`" make -j12 genfiles USER_CPPFLAGS="$USER_CPPFLAGS `pkg-config lua5.2 --cflags`"
# Will fail if any differences were observed. # Will fail if any differences were observed.
git diff --exit-code git diff --exit-code
@ -77,7 +87,8 @@ genfiles_script() {
# Tests the ndebug build. # Tests the ndebug build.
ndebug_install() { ndebug_install() {
sudo apt-get update -qq sudo apt-get update -qq
sudo apt-get install lua5.2 liblua5.2-dev protobuf-compiler libprotobuf-dev sudo apt-get install lua5.2 liblua5.2-dev libprotobuf-dev
install_protoc
} }
ndebug_script() { ndebug_script() {
# Override of USER_CPPFLAGS removes -UNDEBUG. # Override of USER_CPPFLAGS removes -UNDEBUG.
@ -89,7 +100,8 @@ ndebug_script() {
# A run that executes with coverage support and uploads to coveralls.io # A run that executes with coverage support and uploads to coveralls.io
coverage_install() { coverage_install() {
sudo apt-get update -qq sudo apt-get update -qq
sudo apt-get install protobuf-compiler libprotobuf-dev lua5.2 liblua5.2-dev sudo apt-get install libprotobuf-dev lua5.2 liblua5.2-dev
install_protoc
sudo pip install cpp-coveralls sudo pip install cpp-coveralls
} }
coverage_script() { coverage_script() {

@ -53,6 +53,9 @@ struct upb_descreader {
upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING];
int stack_len; int stack_len;
bool primitives_have_presence;
int file_start;
uint32_t number; uint32_t number;
char *name; char *name;
bool saw_number; bool saw_number;
@ -179,9 +182,12 @@ void upb_descreader_setscopename(upb_descreader *r, char *str) {
} }
/* Handlers for google.protobuf.FileDescriptorProto. */ /* Handlers for google.protobuf.FileDescriptorProto. */
static bool file_startmsg(void *r, const void *hd) { static bool file_startmsg(void *closure, const void *hd) {
upb_descreader *r = closure;
UPB_UNUSED(hd); UPB_UNUSED(hd);
upb_descreader_startcontainer(r); upb_descreader_startcontainer(r);
r->primitives_have_presence = true;
r->file_start = r->defs.len;
return true; return true;
} }
@ -210,9 +216,17 @@ static size_t file_onsyntax(void *closure, const void *hd, const char *buf,
UPB_UNUSED(handle); UPB_UNUSED(handle);
/* XXX: see comment at the top of the file. */ /* XXX: see comment at the top of the file. */
if (n == strlen("proto3") && memcmp(buf, "proto3", strlen("proto3")) == 0) { if (n == strlen("proto3") && memcmp(buf, "proto3", strlen("proto3")) == 0) {
/* TODO(haberman): set a flag in the scope so that all enclosing messages uint32_t i;
* will set field presence to false. */ /* Cover messages created previously. */
UPB_UNUSED(r); for (i = r->file_start; i < r->defs.len; i++) {
upb_msgdef *m = upb_dyncast_msgdef_mutable(r->defs.defs[i]);
if (m) {
upb_msgdef_setprimitiveshavepresence(m, false);
}
}
/* Cover messages created subsequently. */
r->primitives_have_presence = false;
} }
return n; return n;
} }
@ -511,10 +525,12 @@ static size_t field_ondefaultval(void *closure, const void *hd, const char *buf,
/* Handlers for google.protobuf.DescriptorProto (representing a message). */ /* Handlers for google.protobuf.DescriptorProto (representing a message). */
static bool msg_startmsg(void *closure, const void *hd) { static bool msg_startmsg(void *closure, const void *hd) {
upb_descreader *r = closure; upb_descreader *r = closure;
upb_msgdef *m;
UPB_UNUSED(hd); UPB_UNUSED(hd);
upb_deflist_push(&r->defs, m = upb_msgdef_new(&r->defs);
upb_msgdef_upcast_mutable(upb_msgdef_new(&r->defs))); upb_msgdef_setprimitiveshavepresence(m, r->primitives_have_presence);
upb_deflist_push(&r->defs, upb_msgdef_upcast_mutable(m));
upb_descreader_startcontainer(r); upb_descreader_startcontainer(r);
return true; return true;
} }

Loading…
Cancel
Save