Commit 5db5c26a authored by Gaël Delalleau's avatar Gaël Delalleau Committed by Jie Luo

Fix a Python extension crash in the descriptor's nested types container code (#6455)

parent f38b6ed0
......@@ -650,6 +650,13 @@ class GeneratedDescriptorTest(unittest.TestCase):
del enum
self.assertEqual('FOO', next(values_iter).name)
def testDescriptorNestedTypesContainer(self):
message_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
nested_message_descriptor = unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR
self.assertEqual(len(message_descriptor.nested_types), 3)
self.assertFalse(None in message_descriptor.nested_types)
self.assertTrue(nested_message_descriptor in message_descriptor.nested_types)
def testServiceDescriptor(self):
service_descriptor = unittest_pb2.DESCRIPTOR.services_by_name['TestService']
self.assertEqual(service_descriptor.name, 'TestService')
......
......@@ -639,6 +639,7 @@ int Find(PyContainer* self, PyObject* item) {
// the .proto file definition.
const void* descriptor_ptr = PyDescriptor_AsVoidPtr(item);
if (descriptor_ptr == NULL) {
PyErr_Clear();
// Not a descriptor, it cannot be in the list.
return -1;
}
......
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