| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 // Implements the DescriptorPool, which collects all descriptors. | 31 // Implements the DescriptorPool, which collects all descriptors. |
| 32 | 32 |
| 33 #include <Python.h> | 33 #include <Python.h> |
| 34 | 34 |
| 35 #include <google/protobuf/descriptor.pb.h> | 35 #include <google/protobuf/descriptor.pb.h> |
| 36 #include <google/protobuf/dynamic_message.h> | |
| 37 #include <google/protobuf/pyext/descriptor.h> | 36 #include <google/protobuf/pyext/descriptor.h> |
| 38 #include <google/protobuf/pyext/descriptor_database.h> | 37 #include <google/protobuf/pyext/descriptor_database.h> |
| 39 #include <google/protobuf/pyext/descriptor_pool.h> | 38 #include <google/protobuf/pyext/descriptor_pool.h> |
| 40 #include <google/protobuf/pyext/message.h> | 39 #include <google/protobuf/pyext/message.h> |
| 40 #include <google/protobuf/pyext/message_factory.h> |
| 41 #include <google/protobuf/pyext/scoped_pyobject_ptr.h> | 41 #include <google/protobuf/pyext/scoped_pyobject_ptr.h> |
| 42 | 42 |
| 43 #if PY_MAJOR_VERSION >= 3 | 43 #if PY_MAJOR_VERSION >= 3 |
| 44 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize | 44 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize |
| 45 #if PY_VERSION_HEX < 0x03030000 | 45 #if PY_VERSION_HEX < 0x03030000 |
| 46 #error "Python 3.0 - 3.2 are not supported." | 46 #error "Python 3.0 - 3.2 are not supported." |
| 47 #endif | 47 #endif |
| 48 #define PyString_AsStringAndSize(ob, charpp, sizep) \ | 48 #define PyString_AsStringAndSize(ob, charpp, sizep) \ |
| 49 (PyUnicode_Check(ob)? \ | 49 (PyUnicode_Check(ob)? \ |
| 50 ((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ | 50 ((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 66 static PyDescriptorPool* _CreateDescriptorPool() { | 66 static PyDescriptorPool* _CreateDescriptorPool() { |
| 67 PyDescriptorPool* cpool = PyObject_New( | 67 PyDescriptorPool* cpool = PyObject_New( |
| 68 PyDescriptorPool, &PyDescriptorPool_Type); | 68 PyDescriptorPool, &PyDescriptorPool_Type); |
| 69 if (cpool == NULL) { | 69 if (cpool == NULL) { |
| 70 return NULL; | 70 return NULL; |
| 71 } | 71 } |
| 72 | 72 |
| 73 cpool->underlay = NULL; | 73 cpool->underlay = NULL; |
| 74 cpool->database = NULL; | 74 cpool->database = NULL; |
| 75 | 75 |
| 76 DynamicMessageFactory* message_factory = new DynamicMessageFactory(); | |
| 77 // This option might be the default some day. | |
| 78 message_factory->SetDelegateToGeneratedFactory(true); | |
| 79 cpool->message_factory = message_factory; | |
| 80 | |
| 81 // TODO(amauryfa): Rewrite the SymbolDatabase in C so that it uses the same | |
| 82 // storage. | |
| 83 cpool->classes_by_descriptor = | |
| 84 new PyDescriptorPool::ClassesByMessageMap(); | |
| 85 cpool->descriptor_options = | 76 cpool->descriptor_options = |
| 86 new hash_map<const void*, PyObject *>(); | 77 new hash_map<const void*, PyObject *>(); |
| 87 | 78 |
| 79 cpool->py_message_factory = message_factory::NewMessageFactory( |
| 80 &PyMessageFactory_Type, cpool); |
| 81 if (cpool->py_message_factory == NULL) { |
| 82 Py_DECREF(cpool); |
| 83 return NULL; |
| 84 } |
| 85 |
| 88 return cpool; | 86 return cpool; |
| 89 } | 87 } |
| 90 | 88 |
| 91 // Create a Python DescriptorPool, using the given pool as an underlay: | 89 // Create a Python DescriptorPool, using the given pool as an underlay: |
| 92 // new messages will be added to a custom pool, not to the underlay. | 90 // new messages will be added to a custom pool, not to the underlay. |
| 93 // | 91 // |
| 94 // Ownership of the underlay is not transferred, its pointer should | 92 // Ownership of the underlay is not transferred, its pointer should |
| 95 // stay alive. | 93 // stay alive. |
| 96 static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay( | 94 static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay( |
| 97 const DescriptorPool* underlay) { | 95 const DescriptorPool* underlay) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 142 } |
| 145 DescriptorDatabase* database = NULL; | 143 DescriptorDatabase* database = NULL; |
| 146 if (py_database && py_database != Py_None) { | 144 if (py_database && py_database != Py_None) { |
| 147 database = new PyDescriptorDatabase(py_database); | 145 database = new PyDescriptorDatabase(py_database); |
| 148 } | 146 } |
| 149 return reinterpret_cast<PyObject*>( | 147 return reinterpret_cast<PyObject*>( |
| 150 PyDescriptorPool_NewWithDatabase(database)); | 148 PyDescriptorPool_NewWithDatabase(database)); |
| 151 } | 149 } |
| 152 | 150 |
| 153 static void Dealloc(PyDescriptorPool* self) { | 151 static void Dealloc(PyDescriptorPool* self) { |
| 154 typedef PyDescriptorPool::ClassesByMessageMap::iterator iterator; | |
| 155 descriptor_pool_map.erase(self->pool); | 152 descriptor_pool_map.erase(self->pool); |
| 156 for (iterator it = self->classes_by_descriptor->begin(); | 153 Py_CLEAR(self->py_message_factory); |
| 157 it != self->classes_by_descriptor->end(); ++it) { | |
| 158 Py_DECREF(it->second); | |
| 159 } | |
| 160 delete self->classes_by_descriptor; | |
| 161 for (hash_map<const void*, PyObject*>::iterator it = | 154 for (hash_map<const void*, PyObject*>::iterator it = |
| 162 self->descriptor_options->begin(); | 155 self->descriptor_options->begin(); |
| 163 it != self->descriptor_options->end(); ++it) { | 156 it != self->descriptor_options->end(); ++it) { |
| 164 Py_DECREF(it->second); | 157 Py_DECREF(it->second); |
| 165 } | 158 } |
| 166 delete self->descriptor_options; | 159 delete self->descriptor_options; |
| 167 delete self->message_factory; | |
| 168 delete self->database; | 160 delete self->database; |
| 169 delete self->pool; | 161 delete self->pool; |
| 170 Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self)); | 162 Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self)); |
| 171 } | 163 } |
| 172 | 164 |
| 173 PyObject* FindMessageByName(PyDescriptorPool* self, PyObject* arg) { | 165 PyObject* FindMessageByName(PyDescriptorPool* self, PyObject* arg) { |
| 174 Py_ssize_t name_size; | 166 Py_ssize_t name_size; |
| 175 char* name; | 167 char* name; |
| 176 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { | 168 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { |
| 177 return NULL; | 169 return NULL; |
| 178 } | 170 } |
| 179 | 171 |
| 180 const Descriptor* message_descriptor = | 172 const Descriptor* message_descriptor = |
| 181 self->pool->FindMessageTypeByName(string(name, name_size)); | 173 self->pool->FindMessageTypeByName(string(name, name_size)); |
| 182 | 174 |
| 183 if (message_descriptor == NULL) { | 175 if (message_descriptor == NULL) { |
| 184 PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name); | 176 PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name); |
| 185 return NULL; | 177 return NULL; |
| 186 } | 178 } |
| 187 | 179 |
| 188 return PyMessageDescriptor_FromDescriptor(message_descriptor); | 180 return PyMessageDescriptor_FromDescriptor(message_descriptor); |
| 189 } | 181 } |
| 190 | 182 |
| 191 // Add a message class to our database. | |
| 192 int RegisterMessageClass(PyDescriptorPool* self, | |
| 193 const Descriptor* message_descriptor, | |
| 194 CMessageClass* message_class) { | |
| 195 Py_INCREF(message_class); | |
| 196 typedef PyDescriptorPool::ClassesByMessageMap::iterator iterator; | |
| 197 std::pair<iterator, bool> ret = self->classes_by_descriptor->insert( | |
| 198 std::make_pair(message_descriptor, message_class)); | |
| 199 if (!ret.second) { | |
| 200 // Update case: DECREF the previous value. | |
| 201 Py_DECREF(ret.first->second); | |
| 202 ret.first->second = message_class; | |
| 203 } | |
| 204 return 0; | |
| 205 } | |
| 206 | 183 |
| 207 // Retrieve the message class added to our database. | 184 |
| 208 CMessageClass* GetMessageClass(PyDescriptorPool* self, | |
| 209 const Descriptor* message_descriptor) { | |
| 210 typedef PyDescriptorPool::ClassesByMessageMap::iterator iterator; | |
| 211 iterator ret = self->classes_by_descriptor->find(message_descriptor); | |
| 212 if (ret == self->classes_by_descriptor->end()) { | |
| 213 PyErr_Format(PyExc_TypeError, "No message class registered for '%s'", | |
| 214 message_descriptor->full_name().c_str()); | |
| 215 return NULL; | |
| 216 } else { | |
| 217 return ret->second; | |
| 218 } | |
| 219 } | |
| 220 | 185 |
| 221 PyObject* FindFileByName(PyDescriptorPool* self, PyObject* arg) { | 186 PyObject* FindFileByName(PyDescriptorPool* self, PyObject* arg) { |
| 222 Py_ssize_t name_size; | 187 Py_ssize_t name_size; |
| 223 char* name; | 188 char* name; |
| 224 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { | 189 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { |
| 225 return NULL; | 190 return NULL; |
| 226 } | 191 } |
| 227 | 192 |
| 228 const FileDescriptor* file_descriptor = | 193 const FileDescriptor* file_descriptor = |
| 229 self->pool->FindFileByName(string(name, name_size)); | 194 self->pool->FindFileByName(string(name, name_size)); |
| 230 if (file_descriptor == NULL) { | 195 if (file_descriptor == NULL) { |
| 231 PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", | 196 PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", name); |
| 232 name); | |
| 233 return NULL; | 197 return NULL; |
| 234 } | 198 } |
| 235 | |
| 236 return PyFileDescriptor_FromDescriptor(file_descriptor); | 199 return PyFileDescriptor_FromDescriptor(file_descriptor); |
| 237 } | 200 } |
| 238 | 201 |
| 239 PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) { | 202 PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) { |
| 240 Py_ssize_t name_size; | 203 Py_ssize_t name_size; |
| 241 char* name; | 204 char* name; |
| 242 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { | 205 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { |
| 243 return NULL; | 206 return NULL; |
| 244 } | 207 } |
| 245 | 208 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 const OneofDescriptor* oneof_descriptor = | 261 const OneofDescriptor* oneof_descriptor = |
| 299 self->pool->FindOneofByName(string(name, name_size)); | 262 self->pool->FindOneofByName(string(name, name_size)); |
| 300 if (oneof_descriptor == NULL) { | 263 if (oneof_descriptor == NULL) { |
| 301 PyErr_Format(PyExc_KeyError, "Couldn't find oneof %.200s", name); | 264 PyErr_Format(PyExc_KeyError, "Couldn't find oneof %.200s", name); |
| 302 return NULL; | 265 return NULL; |
| 303 } | 266 } |
| 304 | 267 |
| 305 return PyOneofDescriptor_FromDescriptor(oneof_descriptor); | 268 return PyOneofDescriptor_FromDescriptor(oneof_descriptor); |
| 306 } | 269 } |
| 307 | 270 |
| 271 PyObject* FindServiceByName(PyDescriptorPool* self, PyObject* arg) { |
| 272 Py_ssize_t name_size; |
| 273 char* name; |
| 274 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { |
| 275 return NULL; |
| 276 } |
| 277 |
| 278 const ServiceDescriptor* service_descriptor = |
| 279 self->pool->FindServiceByName(string(name, name_size)); |
| 280 if (service_descriptor == NULL) { |
| 281 PyErr_Format(PyExc_KeyError, "Couldn't find service %.200s", name); |
| 282 return NULL; |
| 283 } |
| 284 |
| 285 return PyServiceDescriptor_FromDescriptor(service_descriptor); |
| 286 } |
| 287 |
| 288 PyObject* FindMethodByName(PyDescriptorPool* self, PyObject* arg) { |
| 289 Py_ssize_t name_size; |
| 290 char* name; |
| 291 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { |
| 292 return NULL; |
| 293 } |
| 294 |
| 295 const MethodDescriptor* method_descriptor = |
| 296 self->pool->FindMethodByName(string(name, name_size)); |
| 297 if (method_descriptor == NULL) { |
| 298 PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name); |
| 299 return NULL; |
| 300 } |
| 301 |
| 302 return PyMethodDescriptor_FromDescriptor(method_descriptor); |
| 303 } |
| 304 |
| 308 PyObject* FindFileContainingSymbol(PyDescriptorPool* self, PyObject* arg) { | 305 PyObject* FindFileContainingSymbol(PyDescriptorPool* self, PyObject* arg) { |
| 309 Py_ssize_t name_size; | 306 Py_ssize_t name_size; |
| 310 char* name; | 307 char* name; |
| 311 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { | 308 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { |
| 312 return NULL; | 309 return NULL; |
| 313 } | 310 } |
| 314 | 311 |
| 315 const FileDescriptor* file_descriptor = | 312 const FileDescriptor* file_descriptor = |
| 316 self->pool->FindFileContainingSymbol(string(name, name_size)); | 313 self->pool->FindFileContainingSymbol(string(name, name_size)); |
| 317 if (file_descriptor == NULL) { | 314 if (file_descriptor == NULL) { |
| 318 PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name); | 315 PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name); |
| 319 return NULL; | 316 return NULL; |
| 320 } | 317 } |
| 321 | 318 |
| 322 return PyFileDescriptor_FromDescriptor(file_descriptor); | 319 return PyFileDescriptor_FromDescriptor(file_descriptor); |
| 323 } | 320 } |
| 324 | 321 |
| 322 PyObject* FindExtensionByNumber(PyDescriptorPool* self, PyObject* args) { |
| 323 PyObject* message_descriptor; |
| 324 int number; |
| 325 if (!PyArg_ParseTuple(args, "Oi", &message_descriptor, &number)) { |
| 326 return NULL; |
| 327 } |
| 328 const Descriptor* descriptor = PyMessageDescriptor_AsDescriptor( |
| 329 message_descriptor); |
| 330 if (descriptor == NULL) { |
| 331 return NULL; |
| 332 } |
| 333 |
| 334 const FieldDescriptor* extension_descriptor = |
| 335 self->pool->FindExtensionByNumber(descriptor, number); |
| 336 if (extension_descriptor == NULL) { |
| 337 PyErr_Format(PyExc_KeyError, "Couldn't find extension %d", number); |
| 338 return NULL; |
| 339 } |
| 340 |
| 341 return PyFieldDescriptor_FromDescriptor(extension_descriptor); |
| 342 } |
| 343 |
| 344 PyObject* FindAllExtensions(PyDescriptorPool* self, PyObject* arg) { |
| 345 const Descriptor* descriptor = PyMessageDescriptor_AsDescriptor(arg); |
| 346 if (descriptor == NULL) { |
| 347 return NULL; |
| 348 } |
| 349 |
| 350 std::vector<const FieldDescriptor*> extensions; |
| 351 self->pool->FindAllExtensions(descriptor, &extensions); |
| 352 |
| 353 ScopedPyObjectPtr result(PyList_New(extensions.size())); |
| 354 if (result == NULL) { |
| 355 return NULL; |
| 356 } |
| 357 for (int i = 0; i < extensions.size(); i++) { |
| 358 PyObject* extension = PyFieldDescriptor_FromDescriptor(extensions[i]); |
| 359 if (extension == NULL) { |
| 360 return NULL; |
| 361 } |
| 362 PyList_SET_ITEM(result.get(), i, extension); // Steals the reference. |
| 363 } |
| 364 return result.release(); |
| 365 } |
| 366 |
| 325 // These functions should not exist -- the only valid way to create | 367 // These functions should not exist -- the only valid way to create |
| 326 // descriptors is to call Add() or AddSerializedFile(). | 368 // descriptors is to call Add() or AddSerializedFile(). |
| 327 // But these AddDescriptor() functions were created in Python and some people | 369 // But these AddDescriptor() functions were created in Python and some people |
| 328 // call them, so we support them for now for compatibility. | 370 // call them, so we support them for now for compatibility. |
| 329 // However we do check that the existing descriptor already exists in the pool, | 371 // However we do check that the existing descriptor already exists in the pool, |
| 330 // which appears to always be true for existing calls -- but then why do people | 372 // which appears to always be true for existing calls -- but then why do people |
| 331 // call a function that will just be a no-op? | 373 // call a function that will just be a no-op? |
| 332 // TODO(amauryfa): Need to investigate further. | 374 // TODO(amauryfa): Need to investigate further. |
| 333 | 375 |
| 334 PyObject* AddFileDescriptor(PyDescriptorPool* self, PyObject* descriptor) { | 376 PyObject* AddFileDescriptor(PyDescriptorPool* self, PyObject* descriptor) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 if (enum_descriptor != | 414 if (enum_descriptor != |
| 373 self->pool->FindEnumTypeByName(enum_descriptor->full_name())) { | 415 self->pool->FindEnumTypeByName(enum_descriptor->full_name())) { |
| 374 PyErr_Format(PyExc_ValueError, | 416 PyErr_Format(PyExc_ValueError, |
| 375 "The enum descriptor %s does not belong to this pool", | 417 "The enum descriptor %s does not belong to this pool", |
| 376 enum_descriptor->full_name().c_str()); | 418 enum_descriptor->full_name().c_str()); |
| 377 return NULL; | 419 return NULL; |
| 378 } | 420 } |
| 379 Py_RETURN_NONE; | 421 Py_RETURN_NONE; |
| 380 } | 422 } |
| 381 | 423 |
| 424 PyObject* AddExtensionDescriptor(PyDescriptorPool* self, PyObject* descriptor) { |
| 425 const FieldDescriptor* extension_descriptor = |
| 426 PyFieldDescriptor_AsDescriptor(descriptor); |
| 427 if (!extension_descriptor) { |
| 428 return NULL; |
| 429 } |
| 430 if (extension_descriptor != |
| 431 self->pool->FindExtensionByName(extension_descriptor->full_name())) { |
| 432 PyErr_Format(PyExc_ValueError, |
| 433 "The extension descriptor %s does not belong to this pool", |
| 434 extension_descriptor->full_name().c_str()); |
| 435 return NULL; |
| 436 } |
| 437 Py_RETURN_NONE; |
| 438 } |
| 439 |
| 382 // The code below loads new Descriptors from a serialized FileDescriptorProto. | 440 // The code below loads new Descriptors from a serialized FileDescriptorProto. |
| 383 | 441 |
| 384 | 442 |
| 385 // Collects errors that occur during proto file building to allow them to be | 443 // Collects errors that occur during proto file building to allow them to be |
| 386 // propagated in the python exception instead of only living in ERROR logs. | 444 // propagated in the python exception instead of only living in ERROR logs. |
| 387 class BuildFileErrorCollector : public DescriptorPool::ErrorCollector { | 445 class BuildFileErrorCollector : public DescriptorPool::ErrorCollector { |
| 388 public: | 446 public: |
| 389 BuildFileErrorCollector() : error_message(""), had_errors(false) {} | 447 BuildFileErrorCollector() : error_message(""), had_errors(false) {} |
| 390 | 448 |
| 391 void AddError(const string& filename, const string& element_name, | 449 void AddError(const string& filename, const string& element_name, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 "Adds a serialized FileDescriptorProto to this pool." }, | 529 "Adds a serialized FileDescriptorProto to this pool." }, |
| 472 | 530 |
| 473 // TODO(amauryfa): Understand why the Python implementation differs from | 531 // TODO(amauryfa): Understand why the Python implementation differs from |
| 474 // this one, ask users to use another API and deprecate these functions. | 532 // this one, ask users to use another API and deprecate these functions. |
| 475 { "AddFileDescriptor", (PyCFunction)AddFileDescriptor, METH_O, | 533 { "AddFileDescriptor", (PyCFunction)AddFileDescriptor, METH_O, |
| 476 "No-op. Add() must have been called before." }, | 534 "No-op. Add() must have been called before." }, |
| 477 { "AddDescriptor", (PyCFunction)AddDescriptor, METH_O, | 535 { "AddDescriptor", (PyCFunction)AddDescriptor, METH_O, |
| 478 "No-op. Add() must have been called before." }, | 536 "No-op. Add() must have been called before." }, |
| 479 { "AddEnumDescriptor", (PyCFunction)AddEnumDescriptor, METH_O, | 537 { "AddEnumDescriptor", (PyCFunction)AddEnumDescriptor, METH_O, |
| 480 "No-op. Add() must have been called before." }, | 538 "No-op. Add() must have been called before." }, |
| 539 { "AddExtensionDescriptor", (PyCFunction)AddExtensionDescriptor, METH_O, |
| 540 "No-op. Add() must have been called before." }, |
| 481 | 541 |
| 482 { "FindFileByName", (PyCFunction)FindFileByName, METH_O, | 542 { "FindFileByName", (PyCFunction)FindFileByName, METH_O, |
| 483 "Searches for a file descriptor by its .proto name." }, | 543 "Searches for a file descriptor by its .proto name." }, |
| 484 { "FindMessageTypeByName", (PyCFunction)FindMessageByName, METH_O, | 544 { "FindMessageTypeByName", (PyCFunction)FindMessageByName, METH_O, |
| 485 "Searches for a message descriptor by full name." }, | 545 "Searches for a message descriptor by full name." }, |
| 486 { "FindFieldByName", (PyCFunction)FindFieldByName, METH_O, | 546 { "FindFieldByName", (PyCFunction)FindFieldByName, METH_O, |
| 487 "Searches for a field descriptor by full name." }, | 547 "Searches for a field descriptor by full name." }, |
| 488 { "FindExtensionByName", (PyCFunction)FindExtensionByName, METH_O, | 548 { "FindExtensionByName", (PyCFunction)FindExtensionByName, METH_O, |
| 489 "Searches for extension descriptor by full name." }, | 549 "Searches for extension descriptor by full name." }, |
| 490 { "FindEnumTypeByName", (PyCFunction)FindEnumTypeByName, METH_O, | 550 { "FindEnumTypeByName", (PyCFunction)FindEnumTypeByName, METH_O, |
| 491 "Searches for enum type descriptor by full name." }, | 551 "Searches for enum type descriptor by full name." }, |
| 492 { "FindOneofByName", (PyCFunction)FindOneofByName, METH_O, | 552 { "FindOneofByName", (PyCFunction)FindOneofByName, METH_O, |
| 493 "Searches for oneof descriptor by full name." }, | 553 "Searches for oneof descriptor by full name." }, |
| 554 { "FindServiceByName", (PyCFunction)FindServiceByName, METH_O, |
| 555 "Searches for service descriptor by full name." }, |
| 556 { "FindMethodByName", (PyCFunction)FindMethodByName, METH_O, |
| 557 "Searches for method descriptor by full name." }, |
| 494 | 558 |
| 495 { "FindFileContainingSymbol", (PyCFunction)FindFileContainingSymbol, METH_O, | 559 { "FindFileContainingSymbol", (PyCFunction)FindFileContainingSymbol, METH_O, |
| 496 "Gets the FileDescriptor containing the specified symbol." }, | 560 "Gets the FileDescriptor containing the specified symbol." }, |
| 561 { "FindExtensionByNumber", (PyCFunction)FindExtensionByNumber, METH_VARARGS, |
| 562 "Gets the extension descriptor for the given number." }, |
| 563 { "FindAllExtensions", (PyCFunction)FindAllExtensions, METH_O, |
| 564 "Gets all known extensions of the given message descriptor." }, |
| 497 {NULL} | 565 {NULL} |
| 498 }; | 566 }; |
| 499 | 567 |
| 500 } // namespace cdescriptor_pool | 568 } // namespace cdescriptor_pool |
| 501 | 569 |
| 502 PyTypeObject PyDescriptorPool_Type = { | 570 PyTypeObject PyDescriptorPool_Type = { |
| 503 PyVarObject_HEAD_INIT(&PyType_Type, 0) | 571 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 504 FULL_MODULE_NAME ".DescriptorPool", // tp_name | 572 FULL_MODULE_NAME ".DescriptorPool", // tp_name |
| 505 sizeof(PyDescriptorPool), // tp_basicsize | 573 sizeof(PyDescriptorPool), // tp_basicsize |
| 506 0, // tp_itemsize | 574 0, // tp_itemsize |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 if (it == descriptor_pool_map.end()) { | 652 if (it == descriptor_pool_map.end()) { |
| 585 PyErr_SetString(PyExc_KeyError, "Unknown descriptor pool"); | 653 PyErr_SetString(PyExc_KeyError, "Unknown descriptor pool"); |
| 586 return NULL; | 654 return NULL; |
| 587 } | 655 } |
| 588 return it->second; | 656 return it->second; |
| 589 } | 657 } |
| 590 | 658 |
| 591 } // namespace python | 659 } // namespace python |
| 592 } // namespace protobuf | 660 } // namespace protobuf |
| 593 } // namespace google | 661 } // namespace google |
| OLD | NEW |