|
80 | 80 |
|
81 | 81 | static const google::protobuf::FieldDescriptor* GetFieldDescriptor(google::protobuf::Message* pMessage, const char* field_name)
|
82 | 82 | {
|
83 |
| - const google::protobuf::FieldDescriptor* descriptor = pMessage->GetDescriptor()->FindFieldByName(field_name); |
84 |
| - if (!descriptor) { |
85 |
| - BOOST_RAISE_EXCEPTION(PyExc_NameError, "Unable to find field '%s'.", field_name); |
| 83 | + const google::protobuf::Descriptor* descriptor = pMessage->GetDescriptor(); |
| 84 | + |
| 85 | + // For some reasons, FindFieldByName is causing a crash if the message has been initialized |
| 86 | + // by the server so let's look it up ourself... |
| 87 | + for (int iCurrentIndex=0; iCurrentIndex < descriptor->field_count(); iCurrentIndex++) |
| 88 | + { |
| 89 | + const google::protobuf::FieldDescriptor *field_descriptor = descriptor->field(iCurrentIndex); |
| 90 | + if (field_descriptor && strcmp(field_descriptor->name().c_str(), field_name) == 0) |
| 91 | + return field_descriptor; |
86 | 92 | }
|
87 |
| - return descriptor; |
| 93 | + return NULL; |
88 | 94 | }
|
89 | 95 |
|
90 | 96 | static const google::protobuf::EnumValueDescriptor* GetEnumValueDescriptor(google::protobuf::Message* pMessage, const char* field_name, int value)
|
|
105 | 111 | google::protobuf::Message* pMessage,
|
106 | 112 | T (google::protobuf::Reflection::*get_field_delegate)(const google::protobuf::Message& message, const google::protobuf::FieldDescriptor* field) const,
|
107 | 113 | const char* field_name)
|
108 |
| - { return (*pMessage->GetReflection().*get_field_delegate)(*pMessage, GetFieldDescriptor(pMessage, field_name)); } |
| 114 | + { |
| 115 | + const google::protobuf::FieldDescriptor* field_descriptor = GetFieldDescriptor(pMessage, field_name); |
| 116 | + if (!field_descriptor) |
| 117 | + BOOST_RAISE_EXCEPTION(PyExc_NameError, "Unable to find field '%s'.", field_name); |
| 118 | + |
| 119 | + return (*pMessage->GetReflection().*get_field_delegate)(*pMessage, field_descriptor); |
| 120 | + } |
109 | 121 |
|
110 | 122 | static int32 GetInt32(google::protobuf::Message* pMessage, const char* field_name)
|
111 | 123 | { return GetField<int32>(pMessage, &google::protobuf::Reflection::GetInt32, field_name); }
|
|
0 commit comments