Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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>
36 #include <google/protobuf/pyext/descriptor.h> 37 #include <google/protobuf/pyext/descriptor.h>
37 #include <google/protobuf/pyext/descriptor_database.h> 38 #include <google/protobuf/pyext/descriptor_database.h>
38 #include <google/protobuf/pyext/descriptor_pool.h> 39 #include <google/protobuf/pyext/descriptor_pool.h>
39 #include <google/protobuf/pyext/message.h> 40 #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
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();
76 cpool->descriptor_options = 85 cpool->descriptor_options =
77 new hash_map<const void*, PyObject *>(); 86 new hash_map<const void*, PyObject *>();
78 87
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
86 return cpool; 88 return cpool;
87 } 89 }
88 90
89 // Create a Python DescriptorPool, using the given pool as an underlay: 91 // Create a Python DescriptorPool, using the given pool as an underlay:
90 // new messages will be added to a custom pool, not to the underlay. 92 // new messages will be added to a custom pool, not to the underlay.
91 // 93 //
92 // Ownership of the underlay is not transferred, its pointer should 94 // Ownership of the underlay is not transferred, its pointer should
93 // stay alive. 95 // stay alive.
94 static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay( 96 static PyDescriptorPool* PyDescriptorPool_NewWithUnderlay(
95 const DescriptorPool* underlay) { 97 const DescriptorPool* underlay) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 144 }
143 DescriptorDatabase* database = NULL; 145 DescriptorDatabase* database = NULL;
144 if (py_database && py_database != Py_None) { 146 if (py_database && py_database != Py_None) {
145 database = new PyDescriptorDatabase(py_database); 147 database = new PyDescriptorDatabase(py_database);
146 } 148 }
147 return reinterpret_cast<PyObject*>( 149 return reinterpret_cast<PyObject*>(
148 PyDescriptorPool_NewWithDatabase(database)); 150 PyDescriptorPool_NewWithDatabase(database));
149 } 151 }
150 152
151 static void Dealloc(PyDescriptorPool* self) { 153 static void Dealloc(PyDescriptorPool* self) {
154 typedef PyDescriptorPool::ClassesByMessageMap::iterator iterator;
152 descriptor_pool_map.erase(self->pool); 155 descriptor_pool_map.erase(self->pool);
153 Py_CLEAR(self->py_message_factory); 156 for (iterator it = self->classes_by_descriptor->begin();
157 it != self->classes_by_descriptor->end(); ++it) {
158 Py_DECREF(it->second);
159 }
160 delete self->classes_by_descriptor;
154 for (hash_map<const void*, PyObject*>::iterator it = 161 for (hash_map<const void*, PyObject*>::iterator it =
155 self->descriptor_options->begin(); 162 self->descriptor_options->begin();
156 it != self->descriptor_options->end(); ++it) { 163 it != self->descriptor_options->end(); ++it) {
157 Py_DECREF(it->second); 164 Py_DECREF(it->second);
158 } 165 }
159 delete self->descriptor_options; 166 delete self->descriptor_options;
167 delete self->message_factory;
160 delete self->database; 168 delete self->database;
161 delete self->pool; 169 delete self->pool;
162 Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self)); 170 Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
163 } 171 }
164 172
165 PyObject* FindMessageByName(PyDescriptorPool* self, PyObject* arg) { 173 PyObject* FindMessageByName(PyDescriptorPool* self, PyObject* arg) {
166 Py_ssize_t name_size; 174 Py_ssize_t name_size;
167 char* name; 175 char* name;
168 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { 176 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
169 return NULL; 177 return NULL;
170 } 178 }
171 179
172 const Descriptor* message_descriptor = 180 const Descriptor* message_descriptor =
173 self->pool->FindMessageTypeByName(string(name, name_size)); 181 self->pool->FindMessageTypeByName(string(name, name_size));
174 182
175 if (message_descriptor == NULL) { 183 if (message_descriptor == NULL) {
176 PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name); 184 PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name);
177 return NULL; 185 return NULL;
178 } 186 }
179 187
180 return PyMessageDescriptor_FromDescriptor(message_descriptor); 188 return PyMessageDescriptor_FromDescriptor(message_descriptor);
181 } 189 }
182 190
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 }
183 206
184 207 // Retrieve the message class added to our database.
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 }
185 220
186 PyObject* FindFileByName(PyDescriptorPool* self, PyObject* arg) { 221 PyObject* FindFileByName(PyDescriptorPool* self, PyObject* arg) {
187 Py_ssize_t name_size; 222 Py_ssize_t name_size;
188 char* name; 223 char* name;
189 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { 224 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
190 return NULL; 225 return NULL;
191 } 226 }
192 227
193 const FileDescriptor* file_descriptor = 228 const FileDescriptor* file_descriptor =
194 self->pool->FindFileByName(string(name, name_size)); 229 self->pool->FindFileByName(string(name, name_size));
195 if (file_descriptor == NULL) { 230 if (file_descriptor == NULL) {
196 PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", name); 231 PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s",
232 name);
197 return NULL; 233 return NULL;
198 } 234 }
235
199 return PyFileDescriptor_FromDescriptor(file_descriptor); 236 return PyFileDescriptor_FromDescriptor(file_descriptor);
200 } 237 }
201 238
202 PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) { 239 PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) {
203 Py_ssize_t name_size; 240 Py_ssize_t name_size;
204 char* name; 241 char* name;
205 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { 242 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
206 return NULL; 243 return NULL;
207 } 244 }
208 245
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 const OneofDescriptor* oneof_descriptor = 298 const OneofDescriptor* oneof_descriptor =
262 self->pool->FindOneofByName(string(name, name_size)); 299 self->pool->FindOneofByName(string(name, name_size));
263 if (oneof_descriptor == NULL) { 300 if (oneof_descriptor == NULL) {
264 PyErr_Format(PyExc_KeyError, "Couldn't find oneof %.200s", name); 301 PyErr_Format(PyExc_KeyError, "Couldn't find oneof %.200s", name);
265 return NULL; 302 return NULL;
266 } 303 }
267 304
268 return PyOneofDescriptor_FromDescriptor(oneof_descriptor); 305 return PyOneofDescriptor_FromDescriptor(oneof_descriptor);
269 } 306 }
270 307
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
305 PyObject* FindFileContainingSymbol(PyDescriptorPool* self, PyObject* arg) { 308 PyObject* FindFileContainingSymbol(PyDescriptorPool* self, PyObject* arg) {
306 Py_ssize_t name_size; 309 Py_ssize_t name_size;
307 char* name; 310 char* name;
308 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) { 311 if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
309 return NULL; 312 return NULL;
310 } 313 }
311 314
312 const FileDescriptor* file_descriptor = 315 const FileDescriptor* file_descriptor =
313 self->pool->FindFileContainingSymbol(string(name, name_size)); 316 self->pool->FindFileContainingSymbol(string(name, name_size));
314 if (file_descriptor == NULL) { 317 if (file_descriptor == NULL) {
315 PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name); 318 PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name);
316 return NULL; 319 return NULL;
317 } 320 }
318 321
319 return PyFileDescriptor_FromDescriptor(file_descriptor); 322 return PyFileDescriptor_FromDescriptor(file_descriptor);
320 } 323 }
321 324
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
367 // These functions should not exist -- the only valid way to create 325 // These functions should not exist -- the only valid way to create
368 // descriptors is to call Add() or AddSerializedFile(). 326 // descriptors is to call Add() or AddSerializedFile().
369 // But these AddDescriptor() functions were created in Python and some people 327 // But these AddDescriptor() functions were created in Python and some people
370 // call them, so we support them for now for compatibility. 328 // call them, so we support them for now for compatibility.
371 // However we do check that the existing descriptor already exists in the pool, 329 // However we do check that the existing descriptor already exists in the pool,
372 // which appears to always be true for existing calls -- but then why do people 330 // which appears to always be true for existing calls -- but then why do people
373 // call a function that will just be a no-op? 331 // call a function that will just be a no-op?
374 // TODO(amauryfa): Need to investigate further. 332 // TODO(amauryfa): Need to investigate further.
375 333
376 PyObject* AddFileDescriptor(PyDescriptorPool* self, PyObject* descriptor) { 334 PyObject* AddFileDescriptor(PyDescriptorPool* self, PyObject* descriptor) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (enum_descriptor != 372 if (enum_descriptor !=
415 self->pool->FindEnumTypeByName(enum_descriptor->full_name())) { 373 self->pool->FindEnumTypeByName(enum_descriptor->full_name())) {
416 PyErr_Format(PyExc_ValueError, 374 PyErr_Format(PyExc_ValueError,
417 "The enum descriptor %s does not belong to this pool", 375 "The enum descriptor %s does not belong to this pool",
418 enum_descriptor->full_name().c_str()); 376 enum_descriptor->full_name().c_str());
419 return NULL; 377 return NULL;
420 } 378 }
421 Py_RETURN_NONE; 379 Py_RETURN_NONE;
422 } 380 }
423 381
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
440 // The code below loads new Descriptors from a serialized FileDescriptorProto. 382 // The code below loads new Descriptors from a serialized FileDescriptorProto.
441 383
442 384
443 // Collects errors that occur during proto file building to allow them to be 385 // Collects errors that occur during proto file building to allow them to be
444 // propagated in the python exception instead of only living in ERROR logs. 386 // propagated in the python exception instead of only living in ERROR logs.
445 class BuildFileErrorCollector : public DescriptorPool::ErrorCollector { 387 class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
446 public: 388 public:
447 BuildFileErrorCollector() : error_message(""), had_errors(false) {} 389 BuildFileErrorCollector() : error_message(""), had_errors(false) {}
448 390
449 void AddError(const string& filename, const string& element_name, 391 void AddError(const string& filename, const string& element_name,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 "Adds a serialized FileDescriptorProto to this pool." }, 471 "Adds a serialized FileDescriptorProto to this pool." },
530 472
531 // TODO(amauryfa): Understand why the Python implementation differs from 473 // TODO(amauryfa): Understand why the Python implementation differs from
532 // this one, ask users to use another API and deprecate these functions. 474 // this one, ask users to use another API and deprecate these functions.
533 { "AddFileDescriptor", (PyCFunction)AddFileDescriptor, METH_O, 475 { "AddFileDescriptor", (PyCFunction)AddFileDescriptor, METH_O,
534 "No-op. Add() must have been called before." }, 476 "No-op. Add() must have been called before." },
535 { "AddDescriptor", (PyCFunction)AddDescriptor, METH_O, 477 { "AddDescriptor", (PyCFunction)AddDescriptor, METH_O,
536 "No-op. Add() must have been called before." }, 478 "No-op. Add() must have been called before." },
537 { "AddEnumDescriptor", (PyCFunction)AddEnumDescriptor, METH_O, 479 { "AddEnumDescriptor", (PyCFunction)AddEnumDescriptor, METH_O,
538 "No-op. Add() must have been called before." }, 480 "No-op. Add() must have been called before." },
539 { "AddExtensionDescriptor", (PyCFunction)AddExtensionDescriptor, METH_O,
540 "No-op. Add() must have been called before." },
541 481
542 { "FindFileByName", (PyCFunction)FindFileByName, METH_O, 482 { "FindFileByName", (PyCFunction)FindFileByName, METH_O,
543 "Searches for a file descriptor by its .proto name." }, 483 "Searches for a file descriptor by its .proto name." },
544 { "FindMessageTypeByName", (PyCFunction)FindMessageByName, METH_O, 484 { "FindMessageTypeByName", (PyCFunction)FindMessageByName, METH_O,
545 "Searches for a message descriptor by full name." }, 485 "Searches for a message descriptor by full name." },
546 { "FindFieldByName", (PyCFunction)FindFieldByName, METH_O, 486 { "FindFieldByName", (PyCFunction)FindFieldByName, METH_O,
547 "Searches for a field descriptor by full name." }, 487 "Searches for a field descriptor by full name." },
548 { "FindExtensionByName", (PyCFunction)FindExtensionByName, METH_O, 488 { "FindExtensionByName", (PyCFunction)FindExtensionByName, METH_O,
549 "Searches for extension descriptor by full name." }, 489 "Searches for extension descriptor by full name." },
550 { "FindEnumTypeByName", (PyCFunction)FindEnumTypeByName, METH_O, 490 { "FindEnumTypeByName", (PyCFunction)FindEnumTypeByName, METH_O,
551 "Searches for enum type descriptor by full name." }, 491 "Searches for enum type descriptor by full name." },
552 { "FindOneofByName", (PyCFunction)FindOneofByName, METH_O, 492 { "FindOneofByName", (PyCFunction)FindOneofByName, METH_O,
553 "Searches for oneof descriptor by full name." }, 493 "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." },
558 494
559 { "FindFileContainingSymbol", (PyCFunction)FindFileContainingSymbol, METH_O, 495 { "FindFileContainingSymbol", (PyCFunction)FindFileContainingSymbol, METH_O,
560 "Gets the FileDescriptor containing the specified symbol." }, 496 "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." },
565 {NULL} 497 {NULL}
566 }; 498 };
567 499
568 } // namespace cdescriptor_pool 500 } // namespace cdescriptor_pool
569 501
570 PyTypeObject PyDescriptorPool_Type = { 502 PyTypeObject PyDescriptorPool_Type = {
571 PyVarObject_HEAD_INIT(&PyType_Type, 0) 503 PyVarObject_HEAD_INIT(&PyType_Type, 0)
572 FULL_MODULE_NAME ".DescriptorPool", // tp_name 504 FULL_MODULE_NAME ".DescriptorPool", // tp_name
573 sizeof(PyDescriptorPool), // tp_basicsize 505 sizeof(PyDescriptorPool), // tp_basicsize
574 0, // tp_itemsize 506 0, // tp_itemsize
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 if (it == descriptor_pool_map.end()) { 584 if (it == descriptor_pool_map.end()) {
653 PyErr_SetString(PyExc_KeyError, "Unknown descriptor pool"); 585 PyErr_SetString(PyExc_KeyError, "Unknown descriptor pool");
654 return NULL; 586 return NULL;
655 } 587 }
656 return it->second; 588 return it->second;
657 } 589 }
658 590
659 } // namespace python 591 } // namespace python
660 } // namespace protobuf 592 } // namespace protobuf
661 } // namespace google 593 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698