mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-27 13:31:02 +08:00
Merge pull request #256 from protobuf-c/issue/251
Fix "Bad enums with multiple oneofs" (#251)
This commit is contained in:
commit
0973be46d2
39
Makefile.am
39
Makefile.am
@ -178,6 +178,19 @@ t/test-full.pb.cc t/test-full.pb.h: @PROTOC@ $(top_srcdir)/t/test-full.proto
|
||||
t/generated-code2/test-full-cxx-output.inc: t/generated-code2/cxx-generate-packed-data$(EXEEXT)
|
||||
$(AM_V_GEN)$(top_builddir)/t/generated-code2/cxx-generate-packed-data$(EXEEXT) > $(top_builddir)/t/generated-code2/test-full-cxx-output.inc
|
||||
|
||||
BUILT_SOURCES += \
|
||||
t/test.pb-c.c t/test.pb-c.h \
|
||||
t/test-full.pb-c.c t/test-full.pb-c.h \
|
||||
t/test-optimized.pb-c.c t/test-optimized.pb-c.h \
|
||||
t/test-full.pb.cc t/test-full.pb.h \
|
||||
t/generated-code2/test-full-cxx-output.inc
|
||||
|
||||
t_version_version_SOURCES = \
|
||||
t/version/version.c
|
||||
t_version_version_LDADD = \
|
||||
protobuf-c/libprotobuf-c.la
|
||||
|
||||
# Issue #220
|
||||
check_PROGRAMS += \
|
||||
t/issue220/issue220
|
||||
TESTS += \
|
||||
@ -194,17 +207,23 @@ BUILT_SOURCES += \
|
||||
EXTRA_DIST += \
|
||||
t/issue220/issue220.proto
|
||||
|
||||
BUILT_SOURCES += \
|
||||
t/test.pb-c.c t/test.pb-c.h \
|
||||
t/test-full.pb-c.c t/test-full.pb-c.h \
|
||||
t/test-optimized.pb-c.c t/test-optimized.pb-c.h \
|
||||
t/test-full.pb.cc t/test-full.pb.h \
|
||||
t/generated-code2/test-full-cxx-output.inc
|
||||
|
||||
t_version_version_SOURCES = \
|
||||
t/version/version.c
|
||||
t_version_version_LDADD = \
|
||||
# Issue #251
|
||||
check_PROGRAMS += \
|
||||
t/issue251/issue251
|
||||
TESTS += \
|
||||
t/issue251/issue251
|
||||
t_issue251_issue251_SOURCES = \
|
||||
t/issue251/issue251.c \
|
||||
t/issue251/issue251.pb-c.c
|
||||
t_issue251_issue251_LDADD = \
|
||||
protobuf-c/libprotobuf-c.la
|
||||
t/issue251/issue251.pb-c.c t/issue251/issue251.pb-c.h: $(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) $(top_srcdir)/t/issue251/issue251.proto
|
||||
$(AM_V_GEN)@PROTOC@ --plugin=$(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/issue251/issue251.proto
|
||||
BUILT_SOURCES += \
|
||||
t/issue251/issue251.pb-c.c t/issue251/issue251.pb-c.h
|
||||
EXTRA_DIST += \
|
||||
t/issue251/issue251.proto
|
||||
|
||||
endif # CROSS_COMPILING
|
||||
|
||||
endif # BUILD_COMPILER
|
||||
|
@ -148,9 +148,10 @@ GenerateStructDefinition(io::Printer* printer) {
|
||||
}
|
||||
|
||||
// Generate the case enums for unions
|
||||
vars["opt_comma"] = ",";
|
||||
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
|
||||
const OneofDescriptor *oneof = descriptor_->oneof_decl(i);
|
||||
vars["opt_comma"] = ",";
|
||||
|
||||
vars["oneofname"] = FullNameToUpper(oneof->name());
|
||||
vars["foneofname"] = FullNameToC(oneof->full_name());
|
||||
|
||||
@ -167,7 +168,7 @@ GenerateStructDefinition(io::Printer* printer) {
|
||||
}
|
||||
printer->Print(vars, "$ucclassname$__$oneofname$_$fieldname$ = $fieldnum$$opt_comma$\n");
|
||||
}
|
||||
printer->Print(vars, " PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE($ucclassname$)\n");
|
||||
printer->Print(vars, " PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE($ucclassname$__$oneofname$)\n");
|
||||
printer->Outdent();
|
||||
printer->Print(vars, "} $foneofname$Case;\n\n");
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ int main(void)
|
||||
{
|
||||
assert(_MESSAGE_TYPE1__FLAG_IS_INT_SIZE == INT_MAX);
|
||||
assert(_MESSAGE_TYPE2__ANOTHER_FLAG_IS_INT_SIZE == INT_MAX);
|
||||
assert(_TOP_LEVEL_IS_INT_SIZE == INT_MAX);
|
||||
assert(_TOP_LEVEL__SUBMESSAGES_IS_INT_SIZE == INT_MAX);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
1
t/issue251/.gitignore
vendored
Normal file
1
t/issue251/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
issue251
|
12
t/issue251/issue251.c
Normal file
12
t/issue251/issue251.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "t/issue251/issue251.pb-c.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/*
|
||||
* The problem in #251 caused invalid code to be generated in the
|
||||
* .pb-c.h file, so there's nothing for us to do here.
|
||||
*/
|
||||
return EXIT_SUCCESS;
|
||||
}
|
11
t/issue251/issue251.proto
Normal file
11
t/issue251/issue251.proto
Normal file
@ -0,0 +1,11 @@
|
||||
message two_oneofs {
|
||||
oneof first_oneof {
|
||||
bool a = 10;
|
||||
bool b = 11;
|
||||
}
|
||||
|
||||
oneof second_oneof {
|
||||
bool c = 20;
|
||||
bool d = 21;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user