Skip to content

Commit 52d1367

Browse files
authored
Merge pull request #16 from Ultimaker/CURA-13047_post_upgrade_slice_crash
[CURA-13047] 'findFieldByName' now gives null on Windows, but the name exists
2 parents 367c697 + c1581eb commit 52d1367

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/PythonMessage.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,29 @@ MessagePtr Arcus::PythonMessage::getSharedMessage() const
4040
return _shared_message;
4141
}
4242

43+
// Instead of `_descriptor->FindFieldByName(field_name)`.
44+
const google::protobuf::FieldDescriptor* findFieldByNameHack(const google::protobuf::Descriptor* _descriptor, const std::string_view field_name)
45+
{
46+
for (int ii = 0; ii < _descriptor->field_count(); ++ii)
47+
{
48+
auto candidate = _descriptor->field(ii);
49+
if (field_name.compare(candidate->name()) == 0)
50+
{
51+
return candidate;
52+
}
53+
}
54+
return nullptr;
55+
}
56+
4357
bool Arcus::PythonMessage::__hasattr__(const std::string& field_name) const
4458
{
45-
auto field = _descriptor->FindFieldByName(field_name);
59+
auto field = findFieldByNameHack(_descriptor, field_name);
4660
return bool(field);
4761
}
4862

4963
PyObject* Arcus::PythonMessage::__getattr__(const std::string& field_name) const
5064
{
51-
auto field = _descriptor->FindFieldByName(field_name);
65+
auto field = findFieldByNameHack(_descriptor, field_name);
5266
if (! field)
5367
{
5468
PyErr_SetString(PyExc_AttributeError, field_name.c_str());
@@ -101,7 +115,7 @@ PyObject* Arcus::PythonMessage::__getattr__(const std::string& field_name) const
101115

102116
void Arcus::PythonMessage::__setattr__(const std::string& field_name, PyObject* value)
103117
{
104-
auto field = _descriptor->FindFieldByName(field_name);
118+
auto field = findFieldByNameHack(_descriptor, field_name);
105119
if (! field)
106120
{
107121
PyErr_SetString(PyExc_AttributeError, field_name.c_str());
@@ -177,7 +191,7 @@ void Arcus::PythonMessage::__setattr__(const std::string& field_name, PyObject*
177191

178192
PythonMessage* Arcus::PythonMessage::addRepeatedMessage(const std::string& field_name)
179193
{
180-
auto field = _descriptor->FindFieldByName(field_name);
194+
auto field = findFieldByNameHack(_descriptor, field_name);
181195
if (! field)
182196
{
183197
PyErr_SetString(PyExc_AttributeError, field_name.c_str());
@@ -190,7 +204,7 @@ PythonMessage* Arcus::PythonMessage::addRepeatedMessage(const std::string& field
190204

191205
int PythonMessage::repeatedMessageCount(const std::string& field_name) const
192206
{
193-
auto field = _descriptor->FindFieldByName(field_name);
207+
auto field = findFieldByNameHack(_descriptor, field_name);
194208
if (! field)
195209
{
196210
PyErr_SetString(PyExc_AttributeError, field_name.c_str());
@@ -202,7 +216,7 @@ int PythonMessage::repeatedMessageCount(const std::string& field_name) const
202216

203217
PythonMessage* Arcus::PythonMessage::getMessage(const std::string& field_name)
204218
{
205-
auto field = _descriptor->FindFieldByName(field_name);
219+
auto field = findFieldByNameHack(_descriptor, field_name);
206220
if (! field)
207221
{
208222
PyErr_SetString(PyExc_AttributeError, field_name.c_str());
@@ -213,7 +227,7 @@ PythonMessage* Arcus::PythonMessage::getMessage(const std::string& field_name)
213227

214228
PythonMessage* Arcus::PythonMessage::getRepeatedMessage(const std::string& field_name, int index)
215229
{
216-
auto field = _descriptor->FindFieldByName(field_name);
230+
auto field = findFieldByNameHack(_descriptor, field_name);
217231
if (! field)
218232
{
219233
PyErr_SetString(PyExc_AttributeError, field_name.c_str());

0 commit comments

Comments
 (0)