Commit 3e91fcdd authored by kenton@google.com's avatar kenton@google.com

Work around GCC 4.3.0 x86_64 compiler bug (seen on Fedora 9).

Details:

For each message type, protoc generates an array of byte offsets of each of
the fields within the message class.  These offsets are later used by the
reflection implementation.  Prior to this revision, the offset arrays were
allocated as global variables.  Since they were just arrays of ints, they
should have been initialized at compile time.  Unfortunately, GCC 4.3.0
incorrectly decides that they cannot be initialized at compile time because
the values used to initialize the array have type ptrdiff_t, and GCC 4.3.0
does not recognize that it can convert ptrdiff_t to int at compile time.  This
bug did not seem to exist in previous versions of GCC.  Google's compiler
team has submitted a fix for this bug back to the GCC project, but we will
have to work around it anyway since Fedora 9 shipped with GCC 4.3.0.
parent 580cf3c4
......@@ -508,8 +508,6 @@ GenerateClassDefinition(io::Printer* printer) {
if (descriptor_->field_count() > 0) {
printer->Print(vars,
"static const int _offsets_[$field_count$];\n"
"\n"
"::google::protobuf::uint32 _has_bits_[($field_count$ + 31) / 32];\n");
} else {
// Zero-size arrays aren't technically allowed, and MSVC in particular
......@@ -517,8 +515,6 @@ GenerateClassDefinition(io::Printer* printer) {
// other code compile. Since this is an uncommon case, we'll just declare
// them with size 1 and waste some space. Oh well.
printer->Print(
"static const int _offsets_[1];\n"
"\n"
"::google::protobuf::uint32 _has_bits_[1];\n");
}
......@@ -598,13 +594,16 @@ GenerateDescriptorInitializer(io::Printer* printer, int index) {
printer->Print(vars,
"$classname$::default_instance_ = new $classname$();\n");
// Generate the offsets.
GenerateOffsets(printer);
// Construct the reflection object.
printer->Print(vars,
"$classname$_reflection_ =\n"
" new ::google::protobuf::internal::GeneratedMessageReflection(\n"
" $classname$_descriptor_,\n"
" $classname$::default_instance_,\n"
" $classname$::_offsets_,\n"
" $classname$_offsets_,\n"
" GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, _has_bits_[0]),\n"
" GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET("
"$classname$, _unknown_fields_),\n");
......@@ -672,9 +671,6 @@ GenerateClassMethods(io::Printer* printer) {
extension_generators_[i]->GenerateDefinition(printer);
}
GenerateOffsets(printer);
printer->Print("\n");
GenerateStructors(printer);
printer->Print("\n");
......@@ -718,7 +714,7 @@ GenerateClassMethods(io::Printer* printer) {
void MessageGenerator::
GenerateOffsets(io::Printer* printer) {
printer->Print(
"const int $classname$::_offsets_[$field_count$] = {\n",
"static const int $classname$_offsets_[$field_count$] = {\n",
"classname", classname_,
"field_count", SimpleItoa(max(1, descriptor_->field_count())));
printer->Indent();
......
This diff is collapsed.
......@@ -169,8 +169,6 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message
::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > file_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[1];
::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -325,8 +323,6 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag
::google::protobuf::FileOptions* options_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[8];
::google::protobuf::uint32 _has_bits_[(8 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -414,8 +410,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto
::google::protobuf::int32 end_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[2];
::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -558,8 +552,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message {
::google::protobuf::MessageOptions* options_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[7];
::google::protobuf::uint32 _has_bits_[(7 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -748,8 +740,6 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa
::google::protobuf::FieldOptions* options_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[8];
::google::protobuf::uint32 _has_bits_[(8 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -850,8 +840,6 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag
::google::protobuf::EnumOptions* options_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[3];
::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -949,8 +937,6 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M
::google::protobuf::EnumValueOptions* options_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[3];
::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -1051,8 +1037,6 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes
::google::protobuf::ServiceOptions* options_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[3];
::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -1163,8 +1147,6 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess
::google::protobuf::MethodOptions* options_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[4];
::google::protobuf::uint32 _has_bits_[(4 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -1379,8 +1361,6 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message {
::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[5];
::google::protobuf::uint32 _has_bits_[(5 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -1553,8 +1533,6 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message {
::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[2];
::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -1752,8 +1730,6 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message {
::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[3];
::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -1919,8 +1895,6 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message {
::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[1];
::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -2086,8 +2060,6 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message {
::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[1];
::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -2253,8 +2225,6 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message {
::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[1];
::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -2420,8 +2390,6 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message {
::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[1];
::google::protobuf::uint32 _has_bits_[(1 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -2512,8 +2480,6 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu
bool is_extension_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[2];
::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......@@ -2641,8 +2607,6 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag
static const ::std::string _default_string_value_;
friend void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
const ::google::protobuf::FileDescriptor* file);
static const int _offsets_[6];
::google::protobuf::uint32 _has_bits_[(6 + 31) / 32];
// WHY DOES & HAVE LOWER PRECEDENCE THAN != !?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment