34 #include <google/protobuf/pyext/descriptor_database.h>
38 #include <google/protobuf/stubs/logging.h>
39 #include <google/protobuf/stubs/common.h>
40 #include <google/protobuf/descriptor.pb.h>
41 #include <google/protobuf/pyext/message.h>
42 #include <google/protobuf/pyext/scoped_pyobject_ptr.h>
49 : py_database_(py_database) {
50 Py_INCREF(py_database_);
53 PyDescriptorDatabase::~PyDescriptorDatabase() { Py_DECREF(py_database_); }
59 if (py_descriptor == NULL) {
60 if (PyErr_ExceptionMatches(PyExc_KeyError)) {
69 if (py_descriptor == Py_None) {
76 message->message->GetDescriptor() == filedescriptor_descriptor) {
86 PyObject_CallMethod(py_descriptor,
"SerializeToString", NULL));
87 if (serialized_pb == NULL) {
89 <<
"DescriptorDatabase method did not return a FileDescriptorProto";
95 if (PyBytes_AsStringAndSize(serialized_pb.
get(), &
str, &
len) < 0) {
97 <<
"DescriptorDatabase method did not return a FileDescriptorProto";
102 if (!file_proto.ParseFromArray(
str,
len)) {
104 <<
"DescriptorDatabase method did not return a FileDescriptorProto";
124 PyObject_CallMethod(py_database_,
"FindFileContainingSymbol",
"s#",
125 symbol_name.c_str(), symbol_name.size()));
132 bool PyDescriptorDatabase::FindFileContainingExtension(
136 PyObject_GetAttrString(py_database_,
"FindFileContainingExtension"));
137 if (py_method == NULL) {
152 bool PyDescriptorDatabase::FindAllExtensionNumbers(
155 PyObject_GetAttrString(py_database_,
"FindAllExtensionNumbers"));
156 if (py_method == NULL) {
164 if (py_list == NULL) {
168 Py_ssize_t
size = PyList_Size(py_list.
get());
170 for (Py_ssize_t
i = 0 ;
i <
size; ++
i) {
172 item_value = PyLong_AsLong(item.
get());
173 if (item_value < 0) {
175 <<
"FindAllExtensionNumbers method did not return "
176 <<
"valid extension numbers.";
180 output->push_back(item_value);