protobuf/python/google/protobuf/pyext/message.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
30 
31 // Author: anuraag@google.com (Anuraag Agrawal)
32 // Author: tibell@google.com (Johan Tibell)
33 
34 #include <google/protobuf/pyext/message.h>
35 
36 #include <structmember.h> // A Python header file.
37 
38 #include <cstdint>
39 #include <map>
40 #include <memory>
41 #include <string>
42 #include <vector>
43 
44 #include <google/protobuf/stubs/strutil.h>
45 
46 #ifndef PyVarObject_HEAD_INIT
47 #define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
48 #endif
49 #ifndef Py_TYPE
50 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
51 #endif
52 #include <google/protobuf/stubs/common.h>
53 #include <google/protobuf/stubs/logging.h>
54 #include <google/protobuf/io/coded_stream.h>
55 #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
56 #include <google/protobuf/descriptor.pb.h>
57 #include <google/protobuf/descriptor.h>
58 #include <google/protobuf/message.h>
59 #include <google/protobuf/text_format.h>
60 #include <google/protobuf/unknown_field_set.h>
61 #include <google/protobuf/pyext/descriptor.h>
62 #include <google/protobuf/pyext/descriptor_pool.h>
63 #include <google/protobuf/pyext/extension_dict.h>
64 #include <google/protobuf/pyext/field.h>
65 #include <google/protobuf/pyext/map_container.h>
66 #include <google/protobuf/pyext/message_factory.h>
67 #include <google/protobuf/pyext/repeated_composite_container.h>
68 #include <google/protobuf/pyext/repeated_scalar_container.h>
69 #include <google/protobuf/pyext/safe_numerics.h>
70 #include <google/protobuf/pyext/scoped_pyobject_ptr.h>
71 #include <google/protobuf/pyext/unknown_fields.h>
72 #include <google/protobuf/util/message_differencer.h>
73 #include <google/protobuf/io/strtod.h>
74 #include <google/protobuf/stubs/map_util.h>
75 
76 // clang-format off
77 #include <google/protobuf/port_def.inc>
78 // clang-format on
79 
80 #define PyString_AsString(ob) \
81  (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob))
82 #define PyString_AsStringAndSize(ob, charpp, sizep) \
83  (PyUnicode_Check(ob) ? ((*(charpp) = const_cast<char*>( \
84  PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL \
85  ? -1 \
86  : 0) \
87  : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
88 
89 namespace google {
90 namespace protobuf {
91 namespace python {
92 
94  public:
96  Message* lhs, Message* rhs,
97  const std::vector<const FieldDescriptor*>& fields) {
98  lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields);
99  }
100  static bool IsLazyField(const Reflection* reflection, const Message& message,
101  const FieldDescriptor* field) {
102  return reflection->IsLazyField(field) ||
103  reflection->IsLazyExtension(message, field);
104  }
105 };
106 
107 static PyObject* kDESCRIPTOR;
108 PyObject* EnumTypeWrapper_class;
109 static PyObject* PythonMessage_class;
110 static PyObject* kEmptyWeakref;
111 static PyObject* WKT_classes = NULL;
112 
113 namespace message_meta {
114 
115 namespace {
116 // Copied over from internal 'google/protobuf/stubs/strutil.h'.
117 inline void LowerString(std::string* s) {
118  std::string::iterator end = s->end();
119  for (std::string::iterator i = s->begin(); i != end; ++i) {
120  // tolower() changes based on locale. We don't want this!
121  if ('A' <= *i && *i <= 'Z') *i += 'a' - 'A';
122  }
123 }
124 } // namespace
125 
126 // Finalize the creation of the Message class.
127 static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
128  // For each field set: cls.<field>_FIELD_NUMBER = <number>
129  for (int i = 0; i < descriptor->field_count(); ++i) {
130  const FieldDescriptor* field_descriptor = descriptor->field(i);
131  ScopedPyObjectPtr property(NewFieldProperty(field_descriptor));
132  if (property == NULL) {
133  return -1;
134  }
135  if (PyObject_SetAttrString(cls, field_descriptor->name().c_str(),
136  property.get()) < 0) {
137  return -1;
138  }
139  }
140 
141  // For each enum set cls.<enum name> = EnumTypeWrapper(<enum descriptor>).
142  for (int i = 0; i < descriptor->enum_type_count(); ++i) {
143  const EnumDescriptor* enum_descriptor = descriptor->enum_type(i);
146  if (enum_type == NULL) {
147  return -1;
148  }
149  // Add wrapped enum type to message class.
150  ScopedPyObjectPtr wrapped(PyObject_CallFunctionObjArgs(
151  EnumTypeWrapper_class, enum_type.get(), NULL));
152  if (wrapped == NULL) {
153  return -1;
154  }
155  if (PyObject_SetAttrString(
156  cls, enum_descriptor->name().c_str(), wrapped.get()) == -1) {
157  return -1;
158  }
159 
160  // For each enum value add cls.<name> = <number>
161  for (int j = 0; j < enum_descriptor->value_count(); ++j) {
162  const EnumValueDescriptor* enum_value_descriptor =
163  enum_descriptor->value(j);
164  ScopedPyObjectPtr value_number(
165  PyLong_FromLong(enum_value_descriptor->number()));
166  if (value_number == NULL) {
167  return -1;
168  }
169  if (PyObject_SetAttrString(cls, enum_value_descriptor->name().c_str(),
170  value_number.get()) == -1) {
171  return -1;
172  }
173  }
174  }
175 
176  // For each extension set cls.<extension name> = <extension descriptor>.
177  //
178  // Extension descriptors come from
179  // <message descriptor>.extensions_by_name[name]
180  // which was defined previously.
181  for (int i = 0; i < descriptor->extension_count(); ++i) {
184  if (extension_field == NULL) {
185  return -1;
186  }
187 
188  // Add the extension field to the message class.
189  if (PyObject_SetAttrString(
190  cls, field->name().c_str(), extension_field.get()) == -1) {
191  return -1;
192  }
193  }
194 
195  return 0;
196 }
197 
198 static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
199  static const char* kwlist[] = {"name", "bases", "dict", 0};
200  PyObject *bases, *dict;
201  const char* name;
202 
203  // Check arguments: (name, bases, dict)
204  if (!PyArg_ParseTupleAndKeywords(
205  args, kwargs, "sO!O!:type", const_cast<char**>(kwlist), &name,
206  &PyTuple_Type, &bases, &PyDict_Type, &dict)) {
207  return NULL;
208  }
209 
210  // Check bases: only (), or (message.Message,) are allowed
211  if (!(PyTuple_GET_SIZE(bases) == 0 ||
212  (PyTuple_GET_SIZE(bases) == 1 &&
213  PyTuple_GET_ITEM(bases, 0) == PythonMessage_class))) {
214  PyErr_SetString(PyExc_TypeError,
215  "A Message class can only inherit from Message");
216  return NULL;
217  }
218 
219  // Check dict['DESCRIPTOR']
220  PyObject* py_descriptor = PyDict_GetItem(dict, kDESCRIPTOR);
221  if (py_descriptor == nullptr) {
222  PyErr_SetString(PyExc_TypeError, "Message class has no DESCRIPTOR");
223  return nullptr;
224  }
225  if (!PyObject_TypeCheck(py_descriptor, &PyMessageDescriptor_Type)) {
226  PyErr_Format(PyExc_TypeError, "Expected a message Descriptor, got %s",
227  py_descriptor->ob_type->tp_name);
228  return nullptr;
229  }
230  const Descriptor* message_descriptor =
231  PyMessageDescriptor_AsDescriptor(py_descriptor);
232  if (message_descriptor == nullptr) {
233  return nullptr;
234  }
235 
236  // Messages have no __dict__
237  ScopedPyObjectPtr slots(PyTuple_New(0));
238  if (PyDict_SetItemString(dict, "__slots__", slots.get()) < 0) {
239  return NULL;
240  }
241 
242  // Build the arguments to the base metaclass.
243  // We change the __bases__ classes.
244  ScopedPyObjectPtr new_args;
245 
246  if (WKT_classes == NULL) {
247  ScopedPyObjectPtr well_known_types(PyImport_ImportModule(
248  "google.protobuf.internal.well_known_types"));
249  GOOGLE_DCHECK(well_known_types != NULL);
250 
251  WKT_classes = PyObject_GetAttrString(well_known_types.get(), "WKTBASES");
252  GOOGLE_DCHECK(WKT_classes != NULL);
253  }
254 
255  PyObject* well_known_class = PyDict_GetItemString(
256  WKT_classes, message_descriptor->full_name().c_str());
257  if (well_known_class == NULL) {
258  new_args.reset(Py_BuildValue("s(OO)O", name, CMessage_Type,
259  PythonMessage_class, dict));
260  } else {
261  new_args.reset(Py_BuildValue("s(OOO)O", name, CMessage_Type,
262  PythonMessage_class, well_known_class, dict));
263  }
264 
265  if (new_args == NULL) {
266  return NULL;
267  }
268  // Call the base metaclass.
269  ScopedPyObjectPtr result(PyType_Type.tp_new(type, new_args.get(), NULL));
270  if (result == NULL) {
271  return NULL;
272  }
273  CMessageClass* newtype = reinterpret_cast<CMessageClass*>(result.get());
274 
275  // Cache the descriptor, both as Python object and as C++ pointer.
276  const Descriptor* descriptor =
277  PyMessageDescriptor_AsDescriptor(py_descriptor);
278  if (descriptor == NULL) {
279  return NULL;
280  }
281  Py_INCREF(py_descriptor);
282  newtype->py_message_descriptor = py_descriptor;
283  newtype->message_descriptor = descriptor;
284  // TODO(amauryfa): Don't always use the canonical pool of the descriptor,
285  // use the MessageFactory optionally passed in the class dict.
286  PyDescriptorPool* py_descriptor_pool =
287  GetDescriptorPool_FromPool(descriptor->file()->pool());
288  if (py_descriptor_pool == NULL) {
289  return NULL;
290  }
291  newtype->py_message_factory = py_descriptor_pool->py_message_factory;
292  Py_INCREF(newtype->py_message_factory);
293 
294  // Register the message in the MessageFactory.
295  // TODO(amauryfa): Move this call to MessageFactory.GetPrototype() when the
296  // MessageFactory is fully implemented in C++.
298  descriptor, newtype) < 0) {
299  return NULL;
300  }
301 
302  // Continue with type initialization: add other descriptors, enum values...
303  if (AddDescriptors(result.get(), descriptor) < 0) {
304  return NULL;
305  }
306  return result.release();
307 }
308 
309 static void Dealloc(PyObject* pself) {
310  CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
311  Py_XDECREF(self->py_message_descriptor);
312  Py_XDECREF(self->py_message_factory);
313  return PyType_Type.tp_dealloc(pself);
314 }
315 
316 static int GcTraverse(PyObject* pself, visitproc visit, void* arg) {
317  CMessageClass* self = reinterpret_cast<CMessageClass*>(pself);
318  Py_VISIT(self->py_message_descriptor);
319  Py_VISIT(self->py_message_factory);
320  return PyType_Type.tp_traverse(pself, visit, arg);
321 }
322 
323 static int GcClear(PyObject* pself) {
324  // It's important to keep the descriptor and factory alive, until the
325  // C++ message is fully destructed.
326  return PyType_Type.tp_clear(pself);
327 }
328 
329 // The _extensions_by_name dictionary is built on every access.
330 // TODO(amauryfa): Migrate all users to pool.FindAllExtensions()
331 static PyObject* GetExtensionsByName(CMessageClass *self, void *closure) {
332  if (self->message_descriptor == NULL) {
333  // This is the base Message object, simply raise AttributeError.
334  PyErr_SetString(PyExc_AttributeError,
335  "Base Message class has no DESCRIPTOR");
336  return NULL;
337  }
338 
339  const PyDescriptorPool* pool = self->py_message_factory->pool;
340 
341  std::vector<const FieldDescriptor*> extensions;
342  pool->pool->FindAllExtensions(self->message_descriptor, &extensions);
343 
344  ScopedPyObjectPtr result(PyDict_New());
345  for (int i = 0; i < extensions.size(); i++) {
348  if (extension == NULL) {
349  return NULL;
350  }
351  if (PyDict_SetItemString(result.get(), extensions[i]->full_name().c_str(),
352  extension.get()) < 0) {
353  return NULL;
354  }
355  }
356  return result.release();
357 }
358 
359 // The _extensions_by_number dictionary is built on every access.
360 // TODO(amauryfa): Migrate all users to pool.FindExtensionByNumber()
361 static PyObject* GetExtensionsByNumber(CMessageClass *self, void *closure) {
362  if (self->message_descriptor == NULL) {
363  // This is the base Message object, simply raise AttributeError.
364  PyErr_SetString(PyExc_AttributeError,
365  "Base Message class has no DESCRIPTOR");
366  return NULL;
367  }
368 
369  const PyDescriptorPool* pool = self->py_message_factory->pool;
370 
371  std::vector<const FieldDescriptor*> extensions;
372  pool->pool->FindAllExtensions(self->message_descriptor, &extensions);
373 
374  ScopedPyObjectPtr result(PyDict_New());
375  for (int i = 0; i < extensions.size(); i++) {
378  if (extension == NULL) {
379  return NULL;
380  }
381  ScopedPyObjectPtr number(PyLong_FromLong(extensions[i]->number()));
382  if (number == NULL) {
383  return NULL;
384  }
385  if (PyDict_SetItem(result.get(), number.get(), extension.get()) < 0) {
386  return NULL;
387  }
388  }
389  return result.release();
390 }
391 
392 static PyGetSetDef Getters[] = {
393  {"_extensions_by_name", (getter)GetExtensionsByName, NULL},
394  {"_extensions_by_number", (getter)GetExtensionsByNumber, NULL},
395  {NULL}
396 };
397 
398 // Compute some class attributes on the fly:
399 // - All the _FIELD_NUMBER attributes, for all fields and nested extensions.
400 // Returns a new reference, or NULL with an exception set.
401 static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) {
402  char* attr;
403  Py_ssize_t attr_size;
404  static const char kSuffix[] = "_FIELD_NUMBER";
405  if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 &&
406  HasSuffixString(StringPiece(attr, attr_size), kSuffix)) {
407  std::string field_name(attr, attr_size - sizeof(kSuffix) + 1);
408  LowerString(&field_name);
409 
410  // Try to find a field with the given name, without the suffix.
411  const FieldDescriptor* field =
412  self->message_descriptor->FindFieldByLowercaseName(field_name);
413  if (!field) {
414  // Search nested extensions as well.
415  field =
416  self->message_descriptor->FindExtensionByLowercaseName(field_name);
417  }
418  if (field) {
419  return PyLong_FromLong(field->number());
420  }
421  }
422  PyErr_SetObject(PyExc_AttributeError, name);
423  return NULL;
424 }
425 
426 static PyObject* GetAttr(CMessageClass* self, PyObject* name) {
427  PyObject* result = CMessageClass_Type->tp_base->tp_getattro(
428  reinterpret_cast<PyObject*>(self), name);
429  if (result != NULL) {
430  return result;
431  }
432  if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
433  return NULL;
434  }
435 
436  PyErr_Clear();
437  return GetClassAttribute(self, name);
438 }
439 
440 } // namespace message_meta
441 
442 // Protobuf has a 64MB limit built in, this variable will override this. Please
443 // do not enable this unless you fully understand the implications: protobufs
444 // must all be kept in memory at the same time, so if they grow too big you may
445 // get OOM errors. The protobuf APIs do not provide any tools for processing
446 // protobufs in chunks. If you have protos this big you should break them up if
447 // it is at all convenient to do so.
448 #ifdef PROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS
449 static bool allow_oversize_protos = true;
450 #else
451 static bool allow_oversize_protos = false;
452 #endif
453 
454 static PyTypeObject _CMessageClass_Type = {
455  PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
456  ".MessageMeta", // tp_name
457  sizeof(CMessageClass), // tp_basicsize
458  0, // tp_itemsize
459  message_meta::Dealloc, // tp_dealloc
460  0, // tp_print
461  0, // tp_getattr
462  0, // tp_setattr
463  0, // tp_compare
464  0, // tp_repr
465  0, // tp_as_number
466  0, // tp_as_sequence
467  0, // tp_as_mapping
468  0, // tp_hash
469  0, // tp_call
470  0, // tp_str
471  (getattrofunc)message_meta::GetAttr, // tp_getattro
472  0, // tp_setattro
473  0, // tp_as_buffer
474  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, // tp_flags
475  "The metaclass of ProtocolMessages", // tp_doc
476  message_meta::GcTraverse, // tp_traverse
477  message_meta::GcClear, // tp_clear
478  0, // tp_richcompare
479  0, // tp_weaklistoffset
480  0, // tp_iter
481  0, // tp_iternext
482  0, // tp_methods
483  0, // tp_members
484  message_meta::Getters, // tp_getset
485  0, // tp_base
486  0, // tp_dict
487  0, // tp_descr_get
488  0, // tp_descr_set
489  0, // tp_dictoffset
490  0, // tp_init
491  0, // tp_alloc
492  message_meta::New, // tp_new
493 };
494 PyTypeObject* CMessageClass_Type = &_CMessageClass_Type;
495 
496 static CMessageClass* CheckMessageClass(PyTypeObject* cls) {
497  if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
498  PyErr_Format(PyExc_TypeError, "Class %s is not a Message", cls->tp_name);
499  return NULL;
500  }
501  return reinterpret_cast<CMessageClass*>(cls);
502 }
503 
504 static const Descriptor* GetMessageDescriptor(PyTypeObject* cls) {
506  if (type == NULL) {
507  return NULL;
508  }
509  return type->message_descriptor;
510 }
511 
512 // Forward declarations
513 namespace cmessage {
515  CMessage* self,
516  const FieldDescriptor* field_descriptor);
517 } // namespace cmessage
518 
519 // ---------------------------------------------------------------------
520 
521 PyObject* EncodeError_class;
522 PyObject* DecodeError_class;
523 PyObject* PickleError_class;
524 
525 // Format an error message for unexpected types.
526 // Always return with an exception set.
527 void FormatTypeError(PyObject* arg, const char* expected_types) {
528  // This function is often called with an exception set.
529  // Clear it to call PyObject_Repr() in good conditions.
530  PyErr_Clear();
531  PyObject* repr = PyObject_Repr(arg);
532  if (repr) {
533  PyErr_Format(PyExc_TypeError,
534  "%.100s has type %.100s, but expected one of: %s",
535  PyString_AsString(repr),
536  Py_TYPE(arg)->tp_name,
537  expected_types);
538  Py_DECREF(repr);
539  }
540 }
541 
542 void OutOfRangeError(PyObject* arg) {
543  PyObject *s = PyObject_Str(arg);
544  if (s) {
545  PyErr_Format(PyExc_ValueError,
546  "Value out of range: %s",
547  PyString_AsString(s));
548  Py_DECREF(s);
549  }
550 }
551 
552 template<class RangeType, class ValueType>
553 bool VerifyIntegerCastAndRange(PyObject* arg, ValueType value) {
554  if (PROTOBUF_PREDICT_FALSE(value == -1 && PyErr_Occurred())) {
555  if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
556  // Replace it with the same ValueError as pure python protos instead of
557  // the default one.
558  PyErr_Clear();
560  } // Otherwise propagate existing error.
561  return false;
562  }
563  if (PROTOBUF_PREDICT_FALSE(!IsValidNumericCast<RangeType>(value))) {
565  return false;
566  }
567  return true;
568 }
569 
570 template <class T>
571 bool CheckAndGetInteger(PyObject* arg, T* value) {
572  // This effectively defines an integer as "an object that can be cast as
573  // an integer and can be used as an ordinal number".
574  // This definition includes everything that implements numbers.Integral
575  // and shouldn't cast the net too wide.
576  if (PROTOBUF_PREDICT_FALSE(!PyIndex_Check(arg))) {
577  FormatTypeError(arg, "int, long");
578  return false;
579  }
580 
581  // Now we have an integral number so we can safely use PyLong_ functions.
582  // We need to treat the signed and unsigned cases differently in case arg is
583  // holding a value above the maximum for signed longs.
584  if (std::numeric_limits<T>::min() == 0) {
585  // Unsigned case.
586  unsigned PY_LONG_LONG ulong_result;
587  if (PyLong_Check(arg)) {
588  ulong_result = PyLong_AsUnsignedLongLong(arg);
589  } else {
590  // Unlike PyLong_AsLongLong, PyLong_AsUnsignedLongLong is very
591  // picky about the exact type.
592  PyObject* casted = PyNumber_Long(arg);
593  if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
594  // Propagate existing error.
595  return false;
596  }
597  ulong_result = PyLong_AsUnsignedLongLong(casted);
598  Py_DECREF(casted);
599  }
600  if (VerifyIntegerCastAndRange<T, unsigned PY_LONG_LONG>(arg,
601  ulong_result)) {
602  *value = static_cast<T>(ulong_result);
603  } else {
604  return false;
605  }
606  } else {
607  // Signed case.
608  PY_LONG_LONG long_result;
609  PyNumberMethods *nb;
610  if ((nb = arg->ob_type->tp_as_number) != NULL && nb->nb_int != NULL) {
611  // PyLong_AsLongLong requires it to be a long or to have an __int__()
612  // method.
613  long_result = PyLong_AsLongLong(arg);
614  } else {
615  // Valid subclasses of numbers.Integral should have a __long__() method
616  // so fall back to that.
617  PyObject* casted = PyNumber_Long(arg);
618  if (PROTOBUF_PREDICT_FALSE(casted == nullptr)) {
619  // Propagate existing error.
620  return false;
621  }
622  long_result = PyLong_AsLongLong(casted);
623  Py_DECREF(casted);
624  }
625  if (VerifyIntegerCastAndRange<T, PY_LONG_LONG>(arg, long_result)) {
626  *value = static_cast<T>(long_result);
627  } else {
628  return false;
629  }
630  }
631 
632  return true;
633 }
634 
635 // These are referenced by repeated_scalar_container, and must
636 // be explicitly instantiated.
637 template bool CheckAndGetInteger<int32>(PyObject*, int32*);
638 template bool CheckAndGetInteger<int64>(PyObject*, int64*);
639 template bool CheckAndGetInteger<uint32>(PyObject*, uint32*);
640 template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
641 
642 bool CheckAndGetDouble(PyObject* arg, double* value) {
643  *value = PyFloat_AsDouble(arg);
644  if (PROTOBUF_PREDICT_FALSE(*value == -1 && PyErr_Occurred())) {
645  FormatTypeError(arg, "int, long, float");
646  return false;
647  }
648  return true;
649 }
650 
651 bool CheckAndGetFloat(PyObject* arg, float* value) {
652  double double_value;
653  if (!CheckAndGetDouble(arg, &double_value)) {
654  return false;
655  }
656  *value = io::SafeDoubleToFloat(double_value);
657  return true;
658 }
659 
660 bool CheckAndGetBool(PyObject* arg, bool* value) {
661  long long_value = PyLong_AsLong(arg); // NOLINT
662  if (long_value == -1 && PyErr_Occurred()) {
663  FormatTypeError(arg, "int, long, bool");
664  return false;
665  }
666  *value = static_cast<bool>(long_value);
667 
668  return true;
669 }
670 
671 // Checks whether the given object (which must be "bytes" or "unicode") contains
672 // valid UTF-8.
673 bool IsValidUTF8(PyObject* obj) {
674  if (PyBytes_Check(obj)) {
675  PyObject* unicode = PyUnicode_FromEncodedObject(obj, "utf-8", NULL);
676 
677  // Clear the error indicator; we report our own error when desired.
678  PyErr_Clear();
679 
680  if (unicode) {
681  Py_DECREF(unicode);
682  return true;
683  } else {
684  return false;
685  }
686  } else {
687  // Unicode object, known to be valid UTF-8.
688  return true;
689  }
690 }
691 
692 bool AllowInvalidUTF8(const FieldDescriptor* field) { return false; }
693 
694 PyObject* CheckString(PyObject* arg, const FieldDescriptor* descriptor) {
697  if (descriptor->type() == FieldDescriptor::TYPE_STRING) {
698  if (!PyBytes_Check(arg) && !PyUnicode_Check(arg)) {
699  FormatTypeError(arg, "bytes, unicode");
700  return NULL;
701  }
702 
704  PyObject* repr = PyObject_Repr(arg);
705  PyErr_Format(PyExc_ValueError,
706  "%s has type str, but isn't valid UTF-8 "
707  "encoding. Non-UTF-8 strings must be converted to "
708  "unicode objects before being added.",
709  PyString_AsString(repr));
710  Py_DECREF(repr);
711  return NULL;
712  }
713  } else if (!PyBytes_Check(arg)) {
714  FormatTypeError(arg, "bytes");
715  return NULL;
716  }
717 
718  PyObject* encoded_string = NULL;
719  if (descriptor->type() == FieldDescriptor::TYPE_STRING) {
720  if (PyBytes_Check(arg)) {
721  // The bytes were already validated as correctly encoded UTF-8 above.
722  encoded_string = arg; // Already encoded.
723  Py_INCREF(encoded_string);
724  } else {
725  encoded_string = PyUnicode_AsEncodedString(arg, "utf-8", NULL);
726  }
727  } else {
728  // In this case field type is "bytes".
729  encoded_string = arg;
730  Py_INCREF(encoded_string);
731  }
732 
733  return encoded_string;
734 }
735 
736 bool CheckAndSetString(
737  PyObject* arg, Message* message,
739  const Reflection* reflection,
740  bool append,
741  int index) {
742  ScopedPyObjectPtr encoded_string(CheckString(arg, descriptor));
743 
744  if (encoded_string.get() == NULL) {
745  return false;
746  }
747 
748  char* value;
749  Py_ssize_t value_len;
750  if (PyBytes_AsStringAndSize(encoded_string.get(), &value, &value_len) < 0) {
751  return false;
752  }
753 
754  std::string value_string(value, value_len);
755  if (append) {
756  reflection->AddString(message, descriptor, std::move(value_string));
757  } else if (index < 0) {
758  reflection->SetString(message, descriptor, std::move(value_string));
759  } else {
760  reflection->SetRepeatedString(message, descriptor, index,
761  std::move(value_string));
762  }
763  return true;
764 }
765 
767  const std::string& value) {
768  if (descriptor->type() != FieldDescriptor::TYPE_STRING) {
769  return PyBytes_FromStringAndSize(value.c_str(), value.length());
770  }
771 
772  PyObject* result = PyUnicode_DecodeUTF8(value.c_str(), value.length(), NULL);
773  // If the string can't be decoded in UTF-8, just return a string object that
774  // contains the raw bytes. This can't happen if the value was assigned using
775  // the members of the Python message object, but can happen if the values were
776  // parsed from the wire (binary).
777  if (result == NULL) {
778  PyErr_Clear();
779  result = PyBytes_FromStringAndSize(value.c_str(), value.length());
780  }
781  return result;
782 }
783 
784 bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
785  const Message* message) {
786  if (message->GetDescriptor() == field_descriptor->containing_type()) {
787  return true;
788  }
789  PyErr_Format(PyExc_KeyError, "Field '%s' does not belong to message '%s'",
790  field_descriptor->full_name().c_str(),
791  message->GetDescriptor()->full_name().c_str());
792  return false;
793 }
794 
795 namespace cmessage {
796 
797 PyMessageFactory* GetFactoryForMessage(CMessage* message) {
798  GOOGLE_DCHECK(PyObject_TypeCheck(message, CMessage_Type));
799  return reinterpret_cast<CMessageClass*>(Py_TYPE(message))->py_message_factory;
800 }
801 
803  CMessage* cmessage,
804  const FieldDescriptor* field) {
805 #ifdef GOOGLE_PROTOBUF_HAS_ONEOF
806  Message* message = cmessage->message;
807  const Reflection* reflection = message->GetReflection();
808  if (!field->containing_oneof() ||
809  !reflection->HasOneof(*message, field->containing_oneof()) ||
810  reflection->HasField(*message, field)) {
811  // No other field in this oneof, no need to release.
812  return 0;
813  }
814 
815  const OneofDescriptor* oneof = field->containing_oneof();
816  const FieldDescriptor* existing_field =
817  reflection->GetOneofFieldDescriptor(*message, oneof);
818  if (existing_field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
819  // Non-message fields don't need to be released.
820  return 0;
821  }
822  if (InternalReleaseFieldByDescriptor(cmessage, existing_field) < 0) {
823  return -1;
824  }
825 #endif
826  return 0;
827 }
828 
829 // After a Merge, visit every sub-message that was read-only, and
830 // eventually update their pointer if the Merge operation modified them.
831 int FixupMessageAfterMerge(CMessage* self) {
832  if (!self->composite_fields) {
833  return 0;
834  }
835  PyMessageFactory* factory = GetFactoryForMessage(self);
836  for (const auto& item : *self->composite_fields) {
837  const FieldDescriptor* descriptor = item.first;
838  if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
839  !descriptor->is_repeated()) {
840  CMessage* cmsg = reinterpret_cast<CMessage*>(item.second);
841  if (cmsg->read_only == false) {
842  return 0;
843  }
844  Message* message = self->message;
845  const Reflection* reflection = message->GetReflection();
846  if (reflection->HasField(*message, descriptor)) {
847  // Message used to be read_only, but is no longer. Get the new pointer
848  // and record it.
849  Message* mutable_message = reflection->MutableMessage(
850  message, descriptor, factory->message_factory);
851  cmsg->message = mutable_message;
852  cmsg->read_only = false;
853  if (FixupMessageAfterMerge(cmsg) < 0) {
854  return -1;
855  }
856  }
857  }
858  }
859 
860  return 0;
861 }
862 
863 // ---------------------------------------------------------------------
864 // Making a message writable
865 
866 int AssureWritable(CMessage* self) {
867  if (self == NULL || !self->read_only) {
868  return 0;
869  }
870 
871  // Toplevel messages are always mutable.
872  GOOGLE_DCHECK(self->parent);
873 
874  if (AssureWritable(self->parent) == -1) {
875  return -1;
876  }
877  // If this message is part of a oneof, there might be a field to release in
878  // the parent.
880  self->parent_field_descriptor) < 0) {
881  return -1;
882  }
883 
884  // Make self->message writable.
885  Message* parent_message = self->parent->message;
886  const Reflection* reflection = parent_message->GetReflection();
887  Message* mutable_message = reflection->MutableMessage(
888  parent_message, self->parent_field_descriptor,
890  if (mutable_message == NULL) {
891  return -1;
892  }
893  self->message = mutable_message;
894  self->read_only = false;
895 
896  return 0;
897 }
898 
899 // --- Globals:
900 
901 // Retrieve a C++ FieldDescriptor for an extension handle.
903  ScopedPyObjectPtr cdescriptor;
904  if (!PyObject_TypeCheck(extension, &PyFieldDescriptor_Type)) {
905  // Most callers consider extensions as a plain dictionary. We should
906  // allow input which is not a field descriptor, and simply pretend it does
907  // not exist.
908  PyErr_SetObject(PyExc_KeyError, extension);
909  return NULL;
910  }
912 }
913 
914 // If value is a string, convert it into an enum value based on the labels in
915 // descriptor, otherwise simply return value. Always returns a new reference.
917  PyObject* value) {
918  if (PyUnicode_Check(value)) {
919  const EnumDescriptor* enum_descriptor = descriptor.enum_type();
920  if (enum_descriptor == NULL) {
921  PyErr_SetString(PyExc_TypeError, "not an enum field");
922  return NULL;
923  }
924  char* enum_label;
925  Py_ssize_t size;
926  if (PyString_AsStringAndSize(value, &enum_label, &size) < 0) {
927  return NULL;
928  }
929  const EnumValueDescriptor* enum_value_descriptor =
930  enum_descriptor->FindValueByName(StringParam(enum_label, size));
931  if (enum_value_descriptor == NULL) {
932  PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label);
933  return NULL;
934  }
935  return PyLong_FromLong(enum_value_descriptor->number());
936  }
937  Py_INCREF(value);
938  return value;
939 }
940 
941 // Delete a slice from a repeated field.
942 // The only way to remove items in C++ protos is to delete the last one,
943 // so we swap items to move the deleted ones at the end, and then strip the
944 // sequence.
946  CMessage* self,
947  const FieldDescriptor* field_descriptor,
948  PyObject* slice) {
949  Py_ssize_t length, from, to, step, slice_length;
950  Message* message = self->message;
951  const Reflection* reflection = message->GetReflection();
952  int min, max;
953  length = reflection->FieldSize(*message, field_descriptor);
954 
955  if (PySlice_Check(slice)) {
956  from = to = step = slice_length = 0;
957  PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slice_length);
958  if (from < to) {
959  min = from;
960  max = to - 1;
961  } else {
962  min = to + 1;
963  max = from;
964  }
965  } else {
966  from = to = PyLong_AsLong(slice);
967  if (from == -1 && PyErr_Occurred()) {
968  PyErr_SetString(PyExc_TypeError, "list indices must be integers");
969  return -1;
970  }
971 
972  if (from < 0) {
973  from = to = length + from;
974  }
975  step = 1;
976  min = max = from;
977 
978  // Range check.
979  if (from < 0 || from >= length) {
980  PyErr_Format(PyExc_IndexError, "list assignment index out of range");
981  return -1;
982  }
983  }
984 
985  Py_ssize_t i = from;
986  std::vector<bool> to_delete(length, false);
987  while (i >= min && i <= max) {
988  to_delete[i] = true;
989  i += step;
990  }
991 
992  // Swap elements so that items to delete are at the end.
993  to = 0;
994  for (i = 0; i < length; ++i) {
995  if (!to_delete[i]) {
996  if (i != to) {
997  reflection->SwapElements(message, field_descriptor, i, to);
998  }
999  ++to;
1000  }
1001  }
1002 
1003  Arena* arena = Arena::InternalHelper<Message>::GetArenaForAllocation(message);
1004  GOOGLE_DCHECK_EQ(arena, nullptr)
1005  << "python protobuf is expected to be allocated from heap";
1006  // Remove items, starting from the end.
1007  for (; length > to; length--) {
1008  if (field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
1009  reflection->RemoveLast(message, field_descriptor);
1010  continue;
1011  }
1012  // It seems that RemoveLast() is less efficient for sub-messages, and
1013  // the memory is not completely released. Prefer ReleaseLast().
1014  //
1015  // To work around a debug hardening (PROTOBUF_FORCE_COPY_IN_RELEASE),
1016  // explicitly use UnsafeArenaReleaseLast. To not break rare use cases where
1017  // arena is used, we fallback to ReleaseLast (but GOOGLE_DCHECK to find/fix it).
1018  //
1019  // Note that arena is likely null and GOOGLE_DCHECK and ReleaesLast might be
1020  // redundant. The current approach takes extra cautious path not to disrupt
1021  // production.
1022  Message* sub_message =
1023  (arena == nullptr)
1024  ? reflection->UnsafeArenaReleaseLast(message, field_descriptor)
1025  : reflection->ReleaseLast(message, field_descriptor);
1026  // If there is a live weak reference to an item being removed, we "Release"
1027  // it, and it takes ownership of the message.
1028  if (CMessage* released = self->MaybeReleaseSubMessage(sub_message)) {
1029  released->message = sub_message;
1030  } else {
1031  // sub_message was not transferred, delete it.
1032  delete sub_message;
1033  }
1034  }
1035 
1036  return 0;
1037 }
1038 
1039 // Initializes fields of a message. Used in constructors.
1040 int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
1041  if (args != NULL && PyTuple_Size(args) != 0) {
1042  PyErr_SetString(PyExc_TypeError, "No positional arguments allowed");
1043  return -1;
1044  }
1045 
1046  if (kwargs == NULL) {
1047  return 0;
1048  }
1049 
1050  Py_ssize_t pos = 0;
1051  PyObject* name;
1052  PyObject* value;
1053  while (PyDict_Next(kwargs, &pos, &name, &value)) {
1054  if (!(PyUnicode_Check(name))) {
1055  PyErr_SetString(PyExc_ValueError, "Field name must be a string");
1056  return -1;
1057  }
1058  ScopedPyObjectPtr property(
1059  PyObject_GetAttr(reinterpret_cast<PyObject*>(Py_TYPE(self)), name));
1060  if (property == NULL ||
1061  !PyObject_TypeCheck(property.get(), CFieldProperty_Type)) {
1062  PyErr_Format(PyExc_ValueError, "Protocol message %s has no \"%s\" field.",
1063  self->message->GetDescriptor()->name().c_str(),
1065  return -1;
1066  }
1067  const FieldDescriptor* descriptor =
1068  reinterpret_cast<PyMessageFieldProperty*>(property.get())
1069  ->field_descriptor;
1070  if (value == Py_None) {
1071  // field=None is the same as no field at all.
1072  continue;
1073  }
1074  if (descriptor->is_map()) {
1076  const FieldDescriptor* value_descriptor =
1077  descriptor->message_type()->FindFieldByName("value");
1078  if (value_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
1079  ScopedPyObjectPtr iter(PyObject_GetIter(value));
1080  if (iter == NULL) {
1081  PyErr_Format(PyExc_TypeError, "Argument %s is not iterable", PyString_AsString(name));
1082  return -1;
1083  }
1085  while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
1086  ScopedPyObjectPtr source_value(PyObject_GetItem(value, next.get()));
1087  ScopedPyObjectPtr dest_value(PyObject_GetItem(map.get(), next.get()));
1088  if (source_value.get() == NULL || dest_value.get() == NULL) {
1089  return -1;
1090  }
1091  ScopedPyObjectPtr ok(PyObject_CallMethod(
1092  dest_value.get(), "MergeFrom", "O", source_value.get()));
1093  if (ok.get() == NULL) {
1094  return -1;
1095  }
1096  }
1097  } else {
1098  ScopedPyObjectPtr function_return;
1099  function_return.reset(
1100  PyObject_CallMethod(map.get(), "update", "O", value));
1101  if (function_return.get() == NULL) {
1102  return -1;
1103  }
1104  }
1105  } else if (descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
1107  if (container == NULL) {
1108  return -1;
1109  }
1110  if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
1111  RepeatedCompositeContainer* rc_container =
1112  reinterpret_cast<RepeatedCompositeContainer*>(container.get());
1113  ScopedPyObjectPtr iter(PyObject_GetIter(value));
1114  if (iter == NULL) {
1115  PyErr_SetString(PyExc_TypeError, "Value must be iterable");
1116  return -1;
1117  }
1119  while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
1120  PyObject* kwargs = (PyDict_Check(next.get()) ? next.get() : NULL);
1121  ScopedPyObjectPtr new_msg(
1122  repeated_composite_container::Add(rc_container, NULL, kwargs));
1123  if (new_msg == NULL) {
1124  return -1;
1125  }
1126  if (kwargs == NULL) {
1127  // next was not a dict, it's a message we need to merge
1129  reinterpret_cast<CMessage*>(new_msg.get()), next.get()));
1130  if (merged.get() == NULL) {
1131  return -1;
1132  }
1133  }
1134  }
1135  if (PyErr_Occurred()) {
1136  // Check to see how PyIter_Next() exited.
1137  return -1;
1138  }
1139  } else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
1140  RepeatedScalarContainer* rs_container =
1141  reinterpret_cast<RepeatedScalarContainer*>(container.get());
1142  ScopedPyObjectPtr iter(PyObject_GetIter(value));
1143  if (iter == NULL) {
1144  PyErr_SetString(PyExc_TypeError, "Value must be iterable");
1145  return -1;
1146  }
1148  while ((next.reset(PyIter_Next(iter.get()))) != NULL) {
1149  ScopedPyObjectPtr enum_value(
1151  if (enum_value == NULL) {
1152  return -1;
1153  }
1155  rs_container, enum_value.get()));
1156  if (new_msg == NULL) {
1157  return -1;
1158  }
1159  }
1160  if (PyErr_Occurred()) {
1161  // Check to see how PyIter_Next() exited.
1162  return -1;
1163  }
1164  } else {
1166  reinterpret_cast<RepeatedScalarContainer*>(container.get()),
1167  value)) ==
1168  NULL) {
1169  return -1;
1170  }
1171  }
1172  } else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
1174  if (message == NULL) {
1175  return -1;
1176  }
1177  CMessage* cmessage = reinterpret_cast<CMessage*>(message.get());
1178  if (PyDict_Check(value)) {
1179  // Make the message exist even if the dict is empty.
1180  AssureWritable(cmessage);
1181  if (InitAttributes(cmessage, NULL, value) < 0) {
1182  return -1;
1183  }
1184  } else {
1185  ScopedPyObjectPtr merged(MergeFrom(cmessage, value));
1186  if (merged == NULL) {
1187  return -1;
1188  }
1189  }
1190  } else {
1191  ScopedPyObjectPtr new_val;
1192  if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
1193  new_val.reset(GetIntegerEnumValue(*descriptor, value));
1194  if (new_val == NULL) {
1195  return -1;
1196  }
1197  value = new_val.get();
1198  }
1199  if (SetFieldValue(self, descriptor, value) < 0) {
1200  return -1;
1201  }
1202  }
1203  }
1204  return 0;
1205 }
1206 
1207 // Allocates an incomplete Python Message: the caller must fill self->message
1208 // and eventually self->parent.
1209 CMessage* NewEmptyMessage(CMessageClass* type) {
1210  CMessage* self = reinterpret_cast<CMessage*>(
1211  PyType_GenericAlloc(&type->super.ht_type, 0));
1212  if (self == NULL) {
1213  return NULL;
1214  }
1215 
1216  self->message = NULL;
1217  self->parent = NULL;
1218  self->parent_field_descriptor = NULL;
1219  self->read_only = false;
1220 
1221  self->composite_fields = NULL;
1222  self->child_submessages = NULL;
1223 
1224  self->unknown_field_set = NULL;
1225 
1226  return self;
1227 }
1228 
1229 // The __new__ method of Message classes.
1230 // Creates a new C++ message and takes ownership.
1232  // Retrieve the message descriptor and the default instance (=prototype).
1233  const Descriptor* message_descriptor = type->message_descriptor;
1234  if (message_descriptor == nullptr) {
1235  // This would be very unexpected since the CMessageClass has already
1236  // been checked.
1237  PyErr_Format(PyExc_TypeError,
1238  "CMessageClass object '%s' has no descriptor.",
1239  Py_TYPE(type)->tp_name);
1240  return nullptr;
1241  }
1242  const Message* prototype =
1243  type->py_message_factory->message_factory->GetPrototype(
1244  message_descriptor);
1245  if (prototype == nullptr) {
1246  PyErr_SetString(PyExc_TypeError, message_descriptor->full_name().c_str());
1247  return nullptr;
1248  }
1249 
1250  CMessage* self = NewEmptyMessage(type);
1251  if (self == nullptr) {
1252  return nullptr;
1253  }
1254  self->message = prototype->New(nullptr); // Ensures no arena is used.
1255  self->parent = nullptr; // This message owns its data.
1256  return self;
1257 }
1258 
1259 static PyObject* New(PyTypeObject* cls, PyObject* unused_args,
1260  PyObject* unused_kwargs) {
1262  if (type == nullptr) {
1263  return nullptr;
1264  }
1265  return reinterpret_cast<PyObject*>(NewCMessage(type));
1266 }
1267 
1268 // The __init__ method of Message classes.
1269 // It initializes fields from keywords passed to the constructor.
1270 static int Init(CMessage* self, PyObject* args, PyObject* kwargs) {
1271  return InitAttributes(self, args, kwargs);
1272 }
1273 
1274 // ---------------------------------------------------------------------
1275 // Deallocating a CMessage
1276 
1277 static void Dealloc(CMessage* self) {
1278  if (self->weakreflist) {
1279  PyObject_ClearWeakRefs(reinterpret_cast<PyObject*>(self));
1280  }
1281  // At this point all dependent objects have been removed.
1282  GOOGLE_DCHECK(!self->child_submessages || self->child_submessages->empty());
1283  GOOGLE_DCHECK(!self->composite_fields || self->composite_fields->empty());
1284  delete self->child_submessages;
1285  delete self->composite_fields;
1286  if (self->unknown_field_set) {
1288  reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
1289  }
1290 
1291  CMessage* parent = self->parent;
1292  if (!parent) {
1293  // No parent, we own the message.
1294  delete self->message;
1295  } else if (parent->AsPyObject() == Py_None) {
1296  // Message owned externally: Nothing to dealloc
1297  Py_CLEAR(self->parent);
1298  } else {
1299  // Clear this message from its parent's map.
1300  if (self->parent_field_descriptor->is_repeated()) {
1301  if (parent->child_submessages)
1302  parent->child_submessages->erase(self->message);
1303  } else {
1304  if (parent->composite_fields)
1305  parent->composite_fields->erase(self->parent_field_descriptor);
1306  }
1307  Py_CLEAR(self->parent);
1308  }
1309  Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
1310 }
1311 
1312 // ---------------------------------------------------------------------
1313 
1314 
1315 PyObject* IsInitialized(CMessage* self, PyObject* args) {
1316  PyObject* errors = NULL;
1317  if (!PyArg_ParseTuple(args, "|O", &errors)) {
1318  return NULL;
1319  }
1320  if (self->message->IsInitialized()) {
1321  Py_RETURN_TRUE;
1322  }
1323  if (errors != NULL) {
1324  ScopedPyObjectPtr initialization_errors(
1325  FindInitializationErrors(self));
1326  if (initialization_errors == NULL) {
1327  return NULL;
1328  }
1329  ScopedPyObjectPtr extend_name(PyUnicode_FromString("extend"));
1330  if (extend_name == NULL) {
1331  return NULL;
1332  }
1333  ScopedPyObjectPtr result(PyObject_CallMethodObjArgs(
1334  errors,
1335  extend_name.get(),
1336  initialization_errors.get(),
1337  NULL));
1338  if (result == NULL) {
1339  return NULL;
1340  }
1341  }
1342  Py_RETURN_FALSE;
1343 }
1344 
1345 int HasFieldByDescriptor(CMessage* self,
1346  const FieldDescriptor* field_descriptor) {
1347  Message* message = self->message;
1348  if (!CheckFieldBelongsToMessage(field_descriptor, message)) {
1349  return -1;
1350  }
1351  if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
1352  PyErr_SetString(PyExc_KeyError,
1353  "Field is repeated. A singular method is required.");
1354  return -1;
1355  }
1356  return message->GetReflection()->HasField(*message, field_descriptor);
1357 }
1358 
1360  ConstStringParam field_name,
1361  bool* in_oneof) {
1362  *in_oneof = false;
1363  const Descriptor* descriptor = message->GetDescriptor();
1364  const FieldDescriptor* field_descriptor =
1365  descriptor->FindFieldByName(field_name);
1366  if (field_descriptor != NULL) {
1367  return field_descriptor;
1368  }
1369  const OneofDescriptor* oneof_desc =
1370  descriptor->FindOneofByName(field_name);
1371  if (oneof_desc != NULL) {
1372  *in_oneof = true;
1373  return message->GetReflection()->GetOneofFieldDescriptor(*message,
1374  oneof_desc);
1375  }
1376  return NULL;
1377 }
1378 
1379 bool CheckHasPresence(const FieldDescriptor* field_descriptor, bool in_oneof) {
1380  auto message_name = field_descriptor->containing_type()->name();
1381  if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
1382  PyErr_Format(PyExc_ValueError,
1383  "Protocol message %s has no singular \"%s\" field.",
1384  message_name.c_str(), field_descriptor->name().c_str());
1385  return false;
1386  }
1387 
1388  if (!field_descriptor->has_presence()) {
1389  PyErr_Format(PyExc_ValueError,
1390  "Can't test non-optional, non-submessage field \"%s.%s\" for "
1391  "presence in proto3.",
1392  message_name.c_str(), field_descriptor->name().c_str());
1393  return false;
1394  }
1395 
1396  return true;
1397 }
1398 
1399 PyObject* HasField(CMessage* self, PyObject* arg) {
1400  char* field_name;
1401  Py_ssize_t size;
1402  field_name = const_cast<char*>(PyUnicode_AsUTF8AndSize(arg, &size));
1403  if (!field_name) {
1404  return NULL;
1405  }
1406 
1407  Message* message = self->message;
1408  bool is_in_oneof;
1409  const FieldDescriptor* field_descriptor =
1410  FindFieldWithOneofs(message, StringParam(field_name, size), &is_in_oneof);
1411  if (field_descriptor == NULL) {
1412  if (!is_in_oneof) {
1413  PyErr_Format(PyExc_ValueError, "Protocol message %s has no field %s.",
1414  message->GetDescriptor()->name().c_str(), field_name);
1415  return NULL;
1416  } else {
1417  Py_RETURN_FALSE;
1418  }
1419  }
1420 
1421  if (!CheckHasPresence(field_descriptor, is_in_oneof)) {
1422  return NULL;
1423  }
1424 
1425  if (message->GetReflection()->HasField(*message, field_descriptor)) {
1426  Py_RETURN_TRUE;
1427  }
1428 
1429  Py_RETURN_FALSE;
1430 }
1431 
1432 PyObject* ClearExtension(CMessage* self, PyObject* extension) {
1434  if (descriptor == NULL) {
1435  return NULL;
1436  }
1437  if (ClearFieldByDescriptor(self, descriptor) < 0) {
1438  return nullptr;
1439  }
1440  Py_RETURN_NONE;
1441 }
1442 
1443 PyObject* HasExtension(CMessage* self, PyObject* extension) {
1445  if (descriptor == NULL) {
1446  return NULL;
1447  }
1448  int has_field = HasFieldByDescriptor(self, descriptor);
1449  if (has_field < 0) {
1450  return nullptr;
1451  } else {
1452  return PyBool_FromLong(has_field);
1453  }
1454 }
1455 
1456 // ---------------------------------------------------------------------
1457 // Releasing messages
1458 //
1459 // The Python API's ClearField() and Clear() methods behave
1460 // differently than their C++ counterparts. While the C++ versions
1461 // clears the children, the Python versions detaches the children,
1462 // without touching their content. This impedance mismatch causes
1463 // some complexity in the implementation, which is captured in this
1464 // section.
1465 //
1466 // When one or multiple fields are cleared we need to:
1467 //
1468 // * Gather all child objects that need to be detached from the message.
1469 // In composite_fields and child_submessages.
1470 //
1471 // * Create a new Python message of the same kind. Use SwapFields() to move
1472 // data from the original message.
1473 //
1474 // * Change the parent of all child objects: update their strong reference
1475 // to their parent, and move their presence in composite_fields and
1476 // child_submessages.
1477 
1478 // ---------------------------------------------------------------------
1479 // Release a composite child of a CMessage
1480 
1482  CMessage* self, const std::vector<CMessage*>& messages_to_release,
1483  const std::vector<ContainerBase*>& containers_to_release) {
1484  if (messages_to_release.empty() && containers_to_release.empty()) {
1485  return 0;
1486  }
1487 
1488  // Move all the passed sub_messages to another message.
1489  CMessage* new_message = cmessage::NewEmptyMessage(self->GetMessageClass());
1490  if (new_message == nullptr) {
1491  return -1;
1492  }
1493  new_message->message = self->message->New(nullptr);
1494  ScopedPyObjectPtr holder(reinterpret_cast<PyObject*>(new_message));
1495  new_message->child_submessages = new CMessage::SubMessagesMap();
1496  new_message->composite_fields = new CMessage::CompositeFieldsMap();
1497  std::set<const FieldDescriptor*> fields_to_swap;
1498 
1499  // In case this the removed fields are the last reference to a message, keep
1500  // a reference.
1501  Py_INCREF(self);
1502 
1503  for (const auto& to_release : messages_to_release) {
1504  fields_to_swap.insert(to_release->parent_field_descriptor);
1505  // Reparent
1506  Py_INCREF(new_message);
1507  Py_DECREF(to_release->parent);
1508  to_release->parent = new_message;
1509  self->child_submessages->erase(to_release->message);
1510  new_message->child_submessages->emplace(to_release->message, to_release);
1511  }
1512 
1513  for (const auto& to_release : containers_to_release) {
1514  fields_to_swap.insert(to_release->parent_field_descriptor);
1515  Py_INCREF(new_message);
1516  Py_DECREF(to_release->parent);
1517  to_release->parent = new_message;
1518  self->composite_fields->erase(to_release->parent_field_descriptor);
1519  new_message->composite_fields->emplace(to_release->parent_field_descriptor,
1520  to_release);
1521  }
1522 
1523  if (self->message->GetArena() == new_message->message->GetArena()) {
1525  self->message, new_message->message,
1526  std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
1527  fields_to_swap.end()));
1528  } else {
1529  self->message->GetReflection()->SwapFields(
1530  self->message, new_message->message,
1531  std::vector<const FieldDescriptor*>(fields_to_swap.begin(),
1532  fields_to_swap.end()));
1533  }
1534 
1535  // This might delete the Python message completely if all children were moved.
1536  Py_DECREF(self);
1537 
1538  return 0;
1539 }
1540 
1542  CMessage* self,
1543  const FieldDescriptor* field_descriptor) {
1544  if (!field_descriptor->is_repeated() &&
1545  field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
1546  // Single scalars are not in any cache.
1547  return 0;
1548  }
1549  std::vector<CMessage*> messages_to_release;
1550  std::vector<ContainerBase*> containers_to_release;
1551  if (self->child_submessages && field_descriptor->is_repeated() &&
1552  field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
1553  for (const auto& child_item : *self->child_submessages) {
1554  if (child_item.second->parent_field_descriptor == field_descriptor) {
1555  messages_to_release.push_back(child_item.second);
1556  }
1557  }
1558  }
1559  if (self->composite_fields) {
1561  self->composite_fields->find(field_descriptor);
1562  if (it != self->composite_fields->end()) {
1563  containers_to_release.push_back(it->second);
1564  }
1565  }
1566 
1567  return InternalReparentFields(self, messages_to_release,
1568  containers_to_release);
1569 }
1570 
1572  const FieldDescriptor* field_descriptor) {
1573  if (!CheckFieldBelongsToMessage(field_descriptor, self->message)) {
1574  return -1;
1575  }
1576  if (InternalReleaseFieldByDescriptor(self, field_descriptor) < 0) {
1577  return -1;
1578  }
1579  AssureWritable(self);
1580  Message* message = self->message;
1581  message->GetReflection()->ClearField(message, field_descriptor);
1582  return 0;
1583 }
1584 
1585 PyObject* ClearField(CMessage* self, PyObject* arg) {
1586  char* field_name;
1587  Py_ssize_t field_size;
1588  if (PyString_AsStringAndSize(arg, &field_name, &field_size) < 0) {
1589  return NULL;
1590  }
1591  AssureWritable(self);
1592  bool is_in_oneof;
1593  const FieldDescriptor* field_descriptor = FindFieldWithOneofs(
1594  self->message, StringParam(field_name, field_size), &is_in_oneof);
1595  if (field_descriptor == NULL) {
1596  if (is_in_oneof) {
1597  // We gave the name of a oneof, and none of its fields are set.
1598  Py_RETURN_NONE;
1599  } else {
1600  PyErr_Format(PyExc_ValueError,
1601  "Protocol message has no \"%s\" field.", field_name);
1602  return NULL;
1603  }
1604  }
1605 
1606  if (ClearFieldByDescriptor(self, field_descriptor) < 0) {
1607  return nullptr;
1608  }
1609  Py_RETURN_NONE;
1610 }
1611 
1612 PyObject* Clear(CMessage* self) {
1613  AssureWritable(self);
1614  // Detach all current fields of this message
1615  std::vector<CMessage*> messages_to_release;
1616  std::vector<ContainerBase*> containers_to_release;
1617  if (self->child_submessages) {
1618  for (const auto& item : *self->child_submessages) {
1619  messages_to_release.push_back(item.second);
1620  }
1621  }
1622  if (self->composite_fields) {
1623  for (const auto& item : *self->composite_fields) {
1624  containers_to_release.push_back(item.second);
1625  }
1626  }
1627  if (InternalReparentFields(self, messages_to_release, containers_to_release) <
1628  0) {
1629  return NULL;
1630  }
1631  if (self->unknown_field_set) {
1633  reinterpret_cast<PyUnknownFields*>(self->unknown_field_set));
1634  self->unknown_field_set = nullptr;
1635  }
1636  self->message->Clear();
1637  Py_RETURN_NONE;
1638 }
1639 
1640 // ---------------------------------------------------------------------
1641 
1643  if (self->parent_field_descriptor != NULL) {
1644  return self->parent_field_descriptor->full_name();
1645  } else {
1646  return self->message->GetDescriptor()->full_name();
1647  }
1648 }
1649 
1650 static PyObject* InternalSerializeToString(
1651  CMessage* self, PyObject* args, PyObject* kwargs,
1652  bool require_initialized) {
1653  // Parse the "deterministic" kwarg; defaults to False.
1654  static const char* kwlist[] = {"deterministic", 0};
1655  PyObject* deterministic_obj = Py_None;
1656  if (!PyArg_ParseTupleAndKeywords(
1657  args, kwargs, "|O", const_cast<char**>(kwlist), &deterministic_obj)) {
1658  return NULL;
1659  }
1660  // Preemptively convert to a bool first, so we don't need to back out of
1661  // allocating memory if this raises an exception.
1662  // NOTE: This is unused later if deterministic == Py_None, but that's fine.
1663  int deterministic = PyObject_IsTrue(deterministic_obj);
1664  if (deterministic < 0) {
1665  return NULL;
1666  }
1667 
1668  if (require_initialized && !self->message->IsInitialized()) {
1670  if (errors == NULL) {
1671  return NULL;
1672  }
1673  ScopedPyObjectPtr comma(PyUnicode_FromString(","));
1674  if (comma == NULL) {
1675  return NULL;
1676  }
1677  ScopedPyObjectPtr joined(
1678  PyObject_CallMethod(comma.get(), "join", "O", errors.get()));
1679  if (joined == NULL) {
1680  return NULL;
1681  }
1682 
1683  // TODO(haberman): this is a (hopefully temporary) hack. The unit testing
1684  // infrastructure reloads all pure-Python modules for every test, but not
1685  // C++ modules (because that's generally impossible:
1686  // http://bugs.python.org/issue1144263). But if we cache EncodeError, we'll
1687  // return the EncodeError from a previous load of the module, which won't
1688  // match a user's attempt to catch EncodeError. So we have to look it up
1689  // again every time.
1690  ScopedPyObjectPtr message_module(PyImport_ImportModule(
1691  "google.protobuf.message"));
1692  if (message_module.get() == NULL) {
1693  return NULL;
1694  }
1695 
1696  ScopedPyObjectPtr encode_error(
1697  PyObject_GetAttrString(message_module.get(), "EncodeError"));
1698  if (encode_error.get() == NULL) {
1699  return NULL;
1700  }
1701  PyErr_Format(encode_error.get(),
1702  "Message %s is missing required fields: %s",
1703  GetMessageName(self).c_str(), PyString_AsString(joined.get()));
1704  return NULL;
1705  }
1706 
1707  // Ok, arguments parsed and errors checked, now encode to a string
1708  const size_t size = self->message->ByteSizeLong();
1709  if (size == 0) {
1710  return PyBytes_FromString("");
1711  }
1712 
1713  if (size > INT_MAX) {
1714  PyErr_Format(PyExc_ValueError,
1715  "Message %s exceeds maximum protobuf "
1716  "size of 2GB: %zu",
1717  GetMessageName(self).c_str(), size);
1718  return nullptr;
1719  }
1720 
1721  PyObject* result = PyBytes_FromStringAndSize(NULL, size);
1722  if (result == NULL) {
1723  return NULL;
1724  }
1725  io::ArrayOutputStream out(PyBytes_AS_STRING(result), size);
1726  io::CodedOutputStream coded_out(&out);
1727  if (deterministic_obj != Py_None) {
1728  coded_out.SetSerializationDeterministic(deterministic);
1729  }
1730  self->message->SerializeWithCachedSizes(&coded_out);
1731  GOOGLE_CHECK(!coded_out.HadError());
1732  return result;
1733 }
1734 
1735 static PyObject* SerializeToString(
1736  CMessage* self, PyObject* args, PyObject* kwargs) {
1737  return InternalSerializeToString(self, args, kwargs,
1738  /*require_initialized=*/true);
1739 }
1740 
1741 static PyObject* SerializePartialToString(
1742  CMessage* self, PyObject* args, PyObject* kwargs) {
1743  return InternalSerializeToString(self, args, kwargs,
1744  /*require_initialized=*/false);
1745 }
1746 
1747 // Formats proto fields for ascii dumps using python formatting functions where
1748 // appropriate.
1749 class PythonFieldValuePrinter : public TextFormat::FastFieldValuePrinter {
1750  public:
1751  // Python has some differences from C++ when printing floating point numbers.
1752  //
1753  // 1) Trailing .0 is always printed.
1754  // 2) (Python2) Output is rounded to 12 digits.
1755  // 3) (Python3) The full precision of the double is preserved (and Python uses
1756  // David M. Gay's dtoa(), when the C++ code uses SimpleDtoa. There are some
1757  // differences, but they rarely happen)
1758  //
1759  // We override floating point printing with the C-API function for printing
1760  // Python floats to ensure consistency.
1761  void PrintFloat(float val,
1762  TextFormat::BaseTextGenerator* generator) const override {
1763  PrintDouble(val, generator);
1764  }
1765  void PrintDouble(double val,
1766  TextFormat::BaseTextGenerator* generator) const override {
1767  // This implementation is not highly optimized (it allocates two temporary
1768  // Python objects) but it is simple and portable. If this is shown to be a
1769  // performance bottleneck, we can optimize it, but the results will likely
1770  // be more complicated to accommodate the differing behavior of double
1771  // formatting between Python 2 and Python 3.
1772  //
1773  // (Though a valid question is: do we really want to make out output
1774  // dependent on the Python version?)
1775  ScopedPyObjectPtr py_value(PyFloat_FromDouble(val));
1776  if (!py_value.get()) {
1777  return;
1778  }
1779 
1780  ScopedPyObjectPtr py_str(PyObject_Str(py_value.get()));
1781  if (!py_str.get()) {
1782  return;
1783  }
1784 
1785  generator->PrintString(PyString_AsString(py_str.get()));
1786  }
1787 };
1788 
1789 static PyObject* ToStr(CMessage* self) {
1790  TextFormat::Printer printer;
1791  // Passes ownership
1793  printer.SetHideUnknownFields(true);
1795  if (!printer.PrintToString(*self->message, &output)) {
1796  PyErr_SetString(PyExc_ValueError, "Unable to convert message to str");
1797  return NULL;
1798  }
1799  return PyUnicode_FromString(output.c_str());
1800 }
1801 
1802 PyObject* MergeFrom(CMessage* self, PyObject* arg) {
1803  CMessage* other_message;
1804  if (!PyObject_TypeCheck(arg, CMessage_Type)) {
1805  PyErr_Format(PyExc_TypeError,
1806  "Parameter to MergeFrom() must be instance of same class: "
1807  "expected %s got %s.",
1808  self->message->GetDescriptor()->full_name().c_str(),
1809  Py_TYPE(arg)->tp_name);
1810  return NULL;
1811  }
1812 
1813  other_message = reinterpret_cast<CMessage*>(arg);
1814  if (other_message->message->GetDescriptor() !=
1815  self->message->GetDescriptor()) {
1816  PyErr_Format(PyExc_TypeError,
1817  "Parameter to MergeFrom() must be instance of same class: "
1818  "expected %s got %s.",
1819  self->message->GetDescriptor()->full_name().c_str(),
1820  other_message->message->GetDescriptor()->full_name().c_str());
1821  return NULL;
1822  }
1823  AssureWritable(self);
1824 
1825  self->message->MergeFrom(*other_message->message);
1826  // Child message might be lazily created before MergeFrom. Make sure they
1827  // are mutable at this point if child messages are really created.
1828  if (FixupMessageAfterMerge(self) < 0) {
1829  return NULL;
1830  }
1831 
1832  Py_RETURN_NONE;
1833 }
1834 
1835 static PyObject* CopyFrom(CMessage* self, PyObject* arg) {
1836  CMessage* other_message;
1837  if (!PyObject_TypeCheck(arg, CMessage_Type)) {
1838  PyErr_Format(PyExc_TypeError,
1839  "Parameter to CopyFrom() must be instance of same class: "
1840  "expected %s got %s.",
1841  self->message->GetDescriptor()->full_name().c_str(),
1842  Py_TYPE(arg)->tp_name);
1843  return NULL;
1844  }
1845 
1846  other_message = reinterpret_cast<CMessage*>(arg);
1847 
1848  if (self == other_message) {
1849  Py_RETURN_NONE;
1850  }
1851 
1852  if (other_message->message->GetDescriptor() !=
1853  self->message->GetDescriptor()) {
1854  PyErr_Format(PyExc_TypeError,
1855  "Parameter to CopyFrom() must be instance of same class: "
1856  "expected %s got %s.",
1857  self->message->GetDescriptor()->full_name().c_str(),
1858  other_message->message->GetDescriptor()->full_name().c_str());
1859  return NULL;
1860  }
1861 
1862  AssureWritable(self);
1863 
1864  // CopyFrom on the message will not clean up self->composite_fields,
1865  // which can leave us in an inconsistent state, so clear it out here.
1866  (void)ScopedPyObjectPtr(Clear(self));
1867 
1868  self->message->CopyFrom(*other_message->message);
1869 
1870  Py_RETURN_NONE;
1871 }
1872 
1873 // Provide a method in the module to set allow_oversize_protos to a boolean
1874 // value. This method returns the newly value of allow_oversize_protos.
1875 PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg) {
1876  if (!arg || !PyBool_Check(arg)) {
1877  PyErr_SetString(PyExc_TypeError,
1878  "Argument to SetAllowOversizeProtos must be boolean");
1879  return NULL;
1880  }
1881  allow_oversize_protos = PyObject_IsTrue(arg);
1882  if (allow_oversize_protos) {
1883  Py_RETURN_TRUE;
1884  } else {
1885  Py_RETURN_FALSE;
1886  }
1887 }
1888 
1889 static PyObject* MergeFromString(CMessage* self, PyObject* arg) {
1890  Py_buffer data;
1891  if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) < 0) {
1892  return NULL;
1893  }
1894 
1895  AssureWritable(self);
1896 
1897  PyMessageFactory* factory = GetFactoryForMessage(self);
1899  ? INT_MAX
1901  const char* ptr;
1903  depth, false, &ptr,
1904  StringPiece(static_cast<const char*>(data.buf), data.len));
1905  PyBuffer_Release(&data);
1906  ctx.data().pool = factory->pool->pool;
1907  ctx.data().factory = factory->message_factory;
1908 
1909  ptr = self->message->_InternalParse(ptr, &ctx);
1910 
1911  // Child message might be lazily created before MergeFrom. Make sure they
1912  // are mutable at this point if child messages are really created.
1913  if (FixupMessageAfterMerge(self) < 0) {
1914  return NULL;
1915  }
1916 
1917  // Python makes distinction in error message, between a general parse failure
1918  // and in-correct ending on a terminating tag. Hence we need to be a bit more
1919  // explicit in our correctness checks.
1920  if (ptr == nullptr || ctx.BytesUntilLimit(ptr) < 0) {
1921  // Parse error or the parser overshoot the limit.
1922  PyErr_Format(
1923  DecodeError_class, "Error parsing message with type '%s'",
1924  self->GetMessageClass()->message_descriptor->full_name().c_str());
1925  return NULL;
1926  }
1927  // ctx has an explicit limit set (length of string_view), so we have to
1928  // check we ended at that limit.
1929  if (!ctx.EndedAtLimit()) {
1930  // TODO(jieluo): Raise error and return NULL instead.
1931  // b/27494216
1932  PyErr_Warn(nullptr, "Unexpected end-group tag: Not all data was converted");
1933  return PyLong_FromLong(data.len - ctx.BytesUntilLimit(ptr));
1934  }
1935  return PyLong_FromLong(data.len);
1936 }
1937 
1938 static PyObject* ParseFromString(CMessage* self, PyObject* arg) {
1939  if (ScopedPyObjectPtr(Clear(self)) == NULL) {
1940  return NULL;
1941  }
1942  return MergeFromString(self, arg);
1943 }
1944 
1945 static PyObject* ByteSize(CMessage* self, PyObject* args) {
1946  return PyLong_FromLong(self->message->ByteSizeLong());
1947 }
1948 
1949 PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) {
1950  const FieldDescriptor* descriptor =
1951  GetExtensionDescriptor(extension_handle);
1952  if (descriptor == NULL) {
1953  return NULL;
1954  }
1955  if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
1956  PyErr_Format(PyExc_TypeError, "Expected a message class, got %s",
1957  cls->ob_type->tp_name);
1958  return NULL;
1959  }
1960  CMessageClass *message_class = reinterpret_cast<CMessageClass*>(cls);
1961  if (message_class == NULL) {
1962  return NULL;
1963  }
1964  // If the extension was already registered, check that it is the same.
1965  const FieldDescriptor* existing_extension =
1966  message_class->py_message_factory->pool->pool->FindExtensionByNumber(
1967  descriptor->containing_type(), descriptor->number());
1968  if (existing_extension != NULL && existing_extension != descriptor) {
1969  PyErr_SetString(PyExc_ValueError, "Double registration of Extensions");
1970  return NULL;
1971  }
1972  Py_RETURN_NONE;
1973 }
1974 
1975 static PyObject* SetInParent(CMessage* self, PyObject* args) {
1976  AssureWritable(self);
1977  Py_RETURN_NONE;
1978 }
1979 
1980 static PyObject* WhichOneof(CMessage* self, PyObject* arg) {
1981  Py_ssize_t name_size;
1982  char *name_data;
1983  if (PyString_AsStringAndSize(arg, &name_data, &name_size) < 0)
1984  return NULL;
1985  const OneofDescriptor* oneof_desc =
1986  self->message->GetDescriptor()->FindOneofByName(
1987  StringParam(name_data, name_size));
1988  if (oneof_desc == NULL) {
1989  PyErr_Format(PyExc_ValueError,
1990  "Protocol message has no oneof \"%s\" field.", name_data);
1991  return NULL;
1992  }
1993  const FieldDescriptor* field_in_oneof =
1994  self->message->GetReflection()->GetOneofFieldDescriptor(
1995  *self->message, oneof_desc);
1996  if (field_in_oneof == NULL) {
1997  Py_RETURN_NONE;
1998  } else {
1999  const std::string& name = field_in_oneof->name();
2000  return PyUnicode_FromStringAndSize(name.c_str(), name.size());
2001  }
2002 }
2003 
2004 static PyObject* GetExtensionDict(CMessage* self, void *closure);
2005 
2006 static PyObject* ListFields(CMessage* self) {
2007  std::vector<const FieldDescriptor*> fields;
2008  self->message->GetReflection()->ListFields(*self->message, &fields);
2009 
2010  // Normally, the list will be exactly the size of the fields.
2011  ScopedPyObjectPtr all_fields(PyList_New(fields.size()));
2012  if (all_fields == NULL) {
2013  return NULL;
2014  }
2015 
2016  // When there are unknown extensions, the py list will *not* contain
2017  // the field information. Thus the actual size of the py list will be
2018  // smaller than the size of fields. Set the actual size at the end.
2019  Py_ssize_t actual_size = 0;
2020  for (size_t i = 0; i < fields.size(); ++i) {
2021  ScopedPyObjectPtr t(PyTuple_New(2));
2022  if (t == NULL) {
2023  return NULL;
2024  }
2025 
2026  if (fields[i]->is_extension()) {
2027  ScopedPyObjectPtr extension_field(
2029  if (extension_field == NULL) {
2030  return NULL;
2031  }
2032  // With C++ descriptors, the field can always be retrieved, but for
2033  // unknown extensions which have not been imported in Python code, there
2034  // is no message class and we cannot retrieve the value.
2035  // TODO(amauryfa): consider building the class on the fly!
2036  if (fields[i]->message_type() != NULL &&
2038  GetFactoryForMessage(self),
2039  fields[i]->message_type()) == NULL) {
2040  PyErr_Clear();
2041  continue;
2042  }
2044  if (extensions == NULL) {
2045  return NULL;
2046  }
2047  // 'extension' reference later stolen by PyTuple_SET_ITEM.
2048  PyObject* extension = PyObject_GetItem(
2049  extensions.get(), extension_field.get());
2050  if (extension == NULL) {
2051  return NULL;
2052  }
2053  PyTuple_SET_ITEM(t.get(), 0, extension_field.release());
2054  // Steals reference to 'extension'
2055  PyTuple_SET_ITEM(t.get(), 1, extension);
2056  } else {
2057  // Normal field
2058  ScopedPyObjectPtr field_descriptor(
2060  if (field_descriptor == NULL) {
2061  return NULL;
2062  }
2063 
2064  PyObject* field_value = GetFieldValue(self, fields[i]);
2065  if (field_value == NULL) {
2066  PyErr_SetString(PyExc_ValueError, fields[i]->name().c_str());
2067  return NULL;
2068  }
2069  PyTuple_SET_ITEM(t.get(), 0, field_descriptor.release());
2070  PyTuple_SET_ITEM(t.get(), 1, field_value);
2071  }
2072  PyList_SET_ITEM(all_fields.get(), actual_size, t.release());
2073  ++actual_size;
2074  }
2075  if (static_cast<size_t>(actual_size) != fields.size() &&
2076  (PyList_SetSlice(all_fields.get(), actual_size, fields.size(), NULL) <
2077  0)) {
2078  return NULL;
2079  }
2080  return all_fields.release();
2081 }
2082 
2083 static PyObject* DiscardUnknownFields(CMessage* self) {
2084  AssureWritable(self);
2085  self->message->DiscardUnknownFields();
2086  Py_RETURN_NONE;
2087 }
2088 
2089 PyObject* FindInitializationErrors(CMessage* self) {
2090  Message* message = self->message;
2091  std::vector<std::string> errors;
2092  message->FindInitializationErrors(&errors);
2093 
2094  PyObject* error_list = PyList_New(errors.size());
2095  if (error_list == NULL) {
2096  return NULL;
2097  }
2098  for (size_t i = 0; i < errors.size(); ++i) {
2099  const std::string& error = errors[i];
2100  PyObject* error_string =
2101  PyUnicode_FromStringAndSize(error.c_str(), error.length());
2102  if (error_string == NULL) {
2103  Py_DECREF(error_list);
2104  return NULL;
2105  }
2106  PyList_SET_ITEM(error_list, i, error_string);
2107  }
2108  return error_list;
2109 }
2110 
2111 static PyObject* RichCompare(CMessage* self, PyObject* other, int opid) {
2112  // Only equality comparisons are implemented.
2113  if (opid != Py_EQ && opid != Py_NE) {
2114  Py_INCREF(Py_NotImplemented);
2115  return Py_NotImplemented;
2116  }
2117  bool equals = true;
2118  // If other is not a message, it cannot be equal.
2119  if (!PyObject_TypeCheck(other, CMessage_Type)) {
2120  equals = false;
2121  } else {
2122  // Otherwise, we have a CMessage whose message we can inspect.
2123  const google::protobuf::Message* other_message =
2124  reinterpret_cast<CMessage*>(other)->message;
2125  // If messages don't have the same descriptors, they are not equal.
2126  if (equals &&
2127  self->message->GetDescriptor() != other_message->GetDescriptor()) {
2128  equals = false;
2129  }
2130  // Check the message contents.
2131  if (equals &&
2133  *self->message, *reinterpret_cast<CMessage*>(other)->message)) {
2134  equals = false;
2135  }
2136  }
2137 
2138  if (equals ^ (opid == Py_EQ)) {
2139  Py_RETURN_FALSE;
2140  } else {
2141  Py_RETURN_TRUE;
2142  }
2143 }
2144 
2145 PyObject* InternalGetScalar(const Message* message,
2146  const FieldDescriptor* field_descriptor) {
2147  const Reflection* reflection = message->GetReflection();
2148 
2149  if (!CheckFieldBelongsToMessage(field_descriptor, message)) {
2150  return NULL;
2151  }
2152 
2153  PyObject* result = NULL;
2154  switch (field_descriptor->cpp_type()) {
2156  int32_t value = reflection->GetInt32(*message, field_descriptor);
2157  result = PyLong_FromLong(value);
2158  break;
2159  }
2161  int64_t value = reflection->GetInt64(*message, field_descriptor);
2162  result = PyLong_FromLongLong(value);
2163  break;
2164  }
2166  uint32_t value = reflection->GetUInt32(*message, field_descriptor);
2167  result = PyLong_FromSsize_t(value);
2168  break;
2169  }
2171  uint64_t value = reflection->GetUInt64(*message, field_descriptor);
2172  result = PyLong_FromUnsignedLongLong(value);
2173  break;
2174  }
2176  float value = reflection->GetFloat(*message, field_descriptor);
2177  result = PyFloat_FromDouble(value);
2178  break;
2179  }
2181  double value = reflection->GetDouble(*message, field_descriptor);
2182  result = PyFloat_FromDouble(value);
2183  break;
2184  }
2186  bool value = reflection->GetBool(*message, field_descriptor);
2187  result = PyBool_FromLong(value);
2188  break;
2189  }
2192  const std::string& value =
2193  reflection->GetStringReference(*message, field_descriptor, &scratch);
2194  result = ToStringObject(field_descriptor, value);
2195  break;
2196  }
2198  const EnumValueDescriptor* enum_value =
2199  message->GetReflection()->GetEnum(*message, field_descriptor);
2200  result = PyLong_FromLong(enum_value->number());
2201  break;
2202  }
2203  default:
2204  PyErr_Format(
2205  PyExc_SystemError, "Getting a value from a field of unknown type %d",
2206  field_descriptor->cpp_type());
2207  }
2208 
2209  return result;
2210 }
2211 
2213  CMessage* self, const FieldDescriptor* field_descriptor) {
2214  const Reflection* reflection = self->message->GetReflection();
2215  PyMessageFactory* factory = GetFactoryForMessage(self);
2216 
2217  CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
2218  factory, field_descriptor->message_type());
2219  ScopedPyObjectPtr message_class_owner(
2220  reinterpret_cast<PyObject*>(message_class));
2221  if (message_class == NULL) {
2222  return NULL;
2223  }
2224 
2225  CMessage* cmsg = cmessage::NewEmptyMessage(message_class);
2226  if (cmsg == NULL) {
2227  return NULL;
2228  }
2229 
2230  Py_INCREF(self);
2231  cmsg->parent = self;
2232  cmsg->parent_field_descriptor = field_descriptor;
2233  if (reflection->HasField(*self->message, field_descriptor)) {
2234  // Force triggering MutableMessage to set the lazy message 'Dirty'
2235  if (MessageReflectionFriend::IsLazyField(reflection, *self->message,
2236  field_descriptor)) {
2237  Message* sub_message = reflection->MutableMessage(
2238  self->message, field_descriptor, factory->message_factory);
2239  cmsg->read_only = false;
2240  cmsg->message = sub_message;
2241  return cmsg;
2242  }
2243  } else {
2244  cmsg->read_only = true;
2245  }
2246  const Message& sub_message = reflection->GetMessage(
2247  *self->message, field_descriptor, factory->message_factory);
2248  cmsg->message = const_cast<Message*>(&sub_message);
2249  return cmsg;
2250 }
2251 
2253  Message* message,
2254  const FieldDescriptor* field_descriptor,
2255  PyObject* arg) {
2256  const Reflection* reflection = message->GetReflection();
2257 
2258  if (!CheckFieldBelongsToMessage(field_descriptor, message)) {
2259  return -1;
2260  }
2261 
2262  switch (field_descriptor->cpp_type()) {
2265  reflection->SetInt32(message, field_descriptor, value);
2266  break;
2267  }
2270  reflection->SetInt64(message, field_descriptor, value);
2271  break;
2272  }
2275  reflection->SetUInt32(message, field_descriptor, value);
2276  break;
2277  }
2280  reflection->SetUInt64(message, field_descriptor, value);
2281  break;
2282  }
2285  reflection->SetFloat(message, field_descriptor, value);
2286  break;
2287  }
2290  reflection->SetDouble(message, field_descriptor, value);
2291  break;
2292  }
2295  reflection->SetBool(message, field_descriptor, value);
2296  break;
2297  }
2299  if (!CheckAndSetString(
2300  arg, message, field_descriptor, reflection, false, -1)) {
2301  return -1;
2302  }
2303  break;
2304  }
2307  if (reflection->SupportsUnknownEnumValues()) {
2308  reflection->SetEnumValue(message, field_descriptor, value);
2309  } else {
2310  const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
2311  const EnumValueDescriptor* enum_value =
2312  enum_descriptor->FindValueByNumber(value);
2313  if (enum_value != NULL) {
2314  reflection->SetEnum(message, field_descriptor, enum_value);
2315  } else {
2316  PyErr_Format(PyExc_ValueError, "Unknown enum value: %d", value);
2317  return -1;
2318  }
2319  }
2320  break;
2321  }
2322  default:
2323  PyErr_Format(
2324  PyExc_SystemError, "Setting value to a field of unknown type %d",
2325  field_descriptor->cpp_type());
2326  return -1;
2327  }
2328 
2329  return 0;
2330 }
2331 
2332 int InternalSetScalar(
2333  CMessage* self,
2334  const FieldDescriptor* field_descriptor,
2335  PyObject* arg) {
2336  if (!CheckFieldBelongsToMessage(field_descriptor, self->message)) {
2337  return -1;
2338  }
2339 
2340  if (MaybeReleaseOverlappingOneofField(self, field_descriptor) < 0) {
2341  return -1;
2342  }
2343 
2344  return InternalSetNonOneofScalar(self->message, field_descriptor, arg);
2345 }
2346 
2347 PyObject* FromString(PyTypeObject* cls, PyObject* serialized) {
2348  PyObject* py_cmsg = PyObject_CallObject(
2349  reinterpret_cast<PyObject*>(cls), NULL);
2350  if (py_cmsg == NULL) {
2351  return NULL;
2352  }
2353  CMessage* cmsg = reinterpret_cast<CMessage*>(py_cmsg);
2354 
2355  ScopedPyObjectPtr py_length(MergeFromString(cmsg, serialized));
2356  if (py_length == NULL) {
2357  Py_DECREF(py_cmsg);
2358  return NULL;
2359  }
2360 
2361  return py_cmsg;
2362 }
2363 
2364 PyObject* DeepCopy(CMessage* self, PyObject* arg) {
2365  PyObject* clone = PyObject_CallObject(
2366  reinterpret_cast<PyObject*>(Py_TYPE(self)), NULL);
2367  if (clone == NULL) {
2368  return NULL;
2369  }
2370  if (!PyObject_TypeCheck(clone, CMessage_Type)) {
2371  Py_DECREF(clone);
2372  return NULL;
2373  }
2375  reinterpret_cast<CMessage*>(clone),
2376  reinterpret_cast<PyObject*>(self))) == NULL) {
2377  Py_DECREF(clone);
2378  return NULL;
2379  }
2380  return clone;
2381 }
2382 
2383 PyObject* ToUnicode(CMessage* self) {
2384  // Lazy import to prevent circular dependencies
2385  ScopedPyObjectPtr text_format(
2386  PyImport_ImportModule("google.protobuf.text_format"));
2387  if (text_format == NULL) {
2388  return NULL;
2389  }
2390  ScopedPyObjectPtr method_name(PyUnicode_FromString("MessageToString"));
2391  if (method_name == NULL) {
2392  return NULL;
2393  }
2394  Py_INCREF(Py_True);
2395  ScopedPyObjectPtr encoded(PyObject_CallMethodObjArgs(
2396  text_format.get(), method_name.get(), self, Py_True, NULL));
2397  Py_DECREF(Py_True);
2398  if (encoded == NULL) {
2399  return NULL;
2400  }
2401  PyObject* decoded = PyUnicode_FromEncodedObject(encoded.get(), "utf-8", NULL);
2402  if (decoded == NULL) {
2403  return NULL;
2404  }
2405  return decoded;
2406 }
2407 
2408 // CMessage static methods:
2409 PyObject* _CheckCalledFromGeneratedFile(PyObject* unused,
2410  PyObject* unused_arg) {
2411  if (!_CalledFromGeneratedFile(1)) {
2412  PyErr_SetString(PyExc_TypeError,
2413  "Descriptors should not be created directly, "
2414  "but only retrieved from their parent.");
2415  return NULL;
2416  }
2417  Py_RETURN_NONE;
2418 }
2419 
2420 static PyObject* GetExtensionDict(CMessage* self, void *closure) {
2421  // If there are extension_ranges, the message is "extendable". Allocate a
2422  // dictionary to store the extension fields.
2424  if (!descriptor->extension_range_count()) {
2425  PyErr_SetNone(PyExc_AttributeError);
2426  return NULL;
2427  }
2428  if (!self->composite_fields) {
2429  self->composite_fields = new CMessage::CompositeFieldsMap();
2430  }
2431  if (!self->composite_fields) {
2432  return NULL;
2433  }
2434  ExtensionDict* extension_dict = extension_dict::NewExtensionDict(self);
2435  return reinterpret_cast<PyObject*>(extension_dict);
2436 }
2437 
2438 static PyObject* UnknownFieldSet(CMessage* self) {
2439  if (self->unknown_field_set == NULL) {
2440  self->unknown_field_set = unknown_fields::NewPyUnknownFields(self);
2441  } else {
2442  Py_INCREF(self->unknown_field_set);
2443  }
2444  return self->unknown_field_set;
2445 }
2446 
2447 static PyObject* GetExtensionsByName(CMessage *self, void *closure) {
2449  reinterpret_cast<CMessageClass*>(Py_TYPE(self)), closure);
2450 }
2451 
2452 static PyObject* GetExtensionsByNumber(CMessage *self, void *closure) {
2454  reinterpret_cast<CMessageClass*>(Py_TYPE(self)), closure);
2455 }
2456 
2457 static PyGetSetDef Getters[] = {
2458  {"Extensions", (getter)GetExtensionDict, NULL, "Extension dict"},
2459  {"_extensions_by_name", (getter)GetExtensionsByName, NULL},
2460  {"_extensions_by_number", (getter)GetExtensionsByNumber, NULL},
2461  {NULL}
2462 };
2463 
2464 
2465 static PyMethodDef Methods[] = {
2466  { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
2467  "Makes a deep copy of the class." },
2468  { "__unicode__", (PyCFunction)ToUnicode, METH_NOARGS,
2469  "Outputs a unicode representation of the message." },
2470  { "ByteSize", (PyCFunction)ByteSize, METH_NOARGS,
2471  "Returns the size of the message in bytes." },
2472  { "Clear", (PyCFunction)Clear, METH_NOARGS,
2473  "Clears the message." },
2474  { "ClearExtension", (PyCFunction)ClearExtension, METH_O,
2475  "Clears a message field." },
2476  { "ClearField", (PyCFunction)ClearField, METH_O,
2477  "Clears a message field." },
2478  { "CopyFrom", (PyCFunction)CopyFrom, METH_O,
2479  "Copies a protocol message into the current message." },
2480  { "DiscardUnknownFields", (PyCFunction)DiscardUnknownFields, METH_NOARGS,
2481  "Discards the unknown fields." },
2482  { "FindInitializationErrors", (PyCFunction)FindInitializationErrors,
2483  METH_NOARGS,
2484  "Finds unset required fields." },
2485  { "FromString", (PyCFunction)FromString, METH_O | METH_CLASS,
2486  "Creates new method instance from given serialized data." },
2487  { "HasExtension", (PyCFunction)HasExtension, METH_O,
2488  "Checks if a message field is set." },
2489  { "HasField", (PyCFunction)HasField, METH_O,
2490  "Checks if a message field is set." },
2491  { "IsInitialized", (PyCFunction)IsInitialized, METH_VARARGS,
2492  "Checks if all required fields of a protocol message are set." },
2493  { "ListFields", (PyCFunction)ListFields, METH_NOARGS,
2494  "Lists all set fields of a message." },
2495  { "MergeFrom", (PyCFunction)MergeFrom, METH_O,
2496  "Merges a protocol message into the current message." },
2497  { "MergeFromString", (PyCFunction)MergeFromString, METH_O,
2498  "Merges a serialized message into the current message." },
2499  { "ParseFromString", (PyCFunction)ParseFromString, METH_O,
2500  "Parses a serialized message into the current message." },
2501  { "RegisterExtension", (PyCFunction)RegisterExtension, METH_O | METH_CLASS,
2502  "Registers an extension with the current message." },
2503  { "SerializePartialToString", (PyCFunction)SerializePartialToString,
2504  METH_VARARGS | METH_KEYWORDS,
2505  "Serializes the message to a string, even if it isn't initialized." },
2506  { "SerializeToString", (PyCFunction)SerializeToString,
2507  METH_VARARGS | METH_KEYWORDS,
2508  "Serializes the message to a string, only for initialized messages." },
2509  { "SetInParent", (PyCFunction)SetInParent, METH_NOARGS,
2510  "Sets the has bit of the given field in its parent message." },
2511  { "UnknownFields", (PyCFunction)UnknownFieldSet, METH_NOARGS,
2512  "Parse unknown field set"},
2513  { "WhichOneof", (PyCFunction)WhichOneof, METH_O,
2514  "Returns the name of the field set inside a oneof, "
2515  "or None if no field is set." },
2516 
2517  // Static Methods.
2518  { "_CheckCalledFromGeneratedFile", (PyCFunction)_CheckCalledFromGeneratedFile,
2519  METH_NOARGS | METH_STATIC,
2520  "Raises TypeError if the caller is not in a _pb2.py file."},
2521  { NULL, NULL}
2522 };
2523 
2524 bool SetCompositeField(CMessage* self, const FieldDescriptor* field,
2525  ContainerBase* value) {
2526  if (self->composite_fields == NULL) {
2527  self->composite_fields = new CMessage::CompositeFieldsMap();
2528  }
2529  (*self->composite_fields)[field] = value;
2530  return true;
2531 }
2532 
2533 bool SetSubmessage(CMessage* self, CMessage* submessage) {
2534  if (self->child_submessages == NULL) {
2535  self->child_submessages = new CMessage::SubMessagesMap();
2536  }
2537  (*self->child_submessages)[submessage->message] = submessage;
2538  return true;
2539 }
2540 
2541 PyObject* GetAttr(PyObject* pself, PyObject* name) {
2542  CMessage* self = reinterpret_cast<CMessage*>(pself);
2543  PyObject* result = PyObject_GenericGetAttr(
2544  reinterpret_cast<PyObject*>(self), name);
2545  if (result != NULL) {
2546  return result;
2547  }
2548  if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
2549  return NULL;
2550  }
2551 
2552  PyErr_Clear();
2554  CheckMessageClass(Py_TYPE(self)), name);
2555 }
2556 
2557 PyObject* GetFieldValue(CMessage* self,
2558  const FieldDescriptor* field_descriptor) {
2559  if (self->composite_fields) {
2561  self->composite_fields->find(field_descriptor);
2562  if (it != self->composite_fields->end()) {
2563  ContainerBase* value = it->second;
2564  Py_INCREF(value);
2565  return value->AsPyObject();
2566  }
2567  }
2568 
2569  if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
2570  PyErr_Format(PyExc_TypeError,
2571  "descriptor to field '%s' doesn't apply to '%s' object",
2572  field_descriptor->full_name().c_str(),
2573  Py_TYPE(self)->tp_name);
2574  return NULL;
2575  }
2576 
2577  if (!field_descriptor->is_repeated() &&
2578  field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
2579  return InternalGetScalar(self->message, field_descriptor);
2580  }
2581 
2582  ContainerBase* py_container = nullptr;
2583  if (field_descriptor->is_map()) {
2584  const Descriptor* entry_type = field_descriptor->message_type();
2585  const FieldDescriptor* value_type = entry_type->FindFieldByName("value");
2586  if (value_type->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
2587  CMessageClass* value_class = message_factory::GetMessageClass(
2588  GetFactoryForMessage(self), value_type->message_type());
2589  if (value_class == NULL) {
2590  return NULL;
2591  }
2592  py_container =
2593  NewMessageMapContainer(self, field_descriptor, value_class);
2594  } else {
2595  py_container = NewScalarMapContainer(self, field_descriptor);
2596  }
2597  } else if (field_descriptor->is_repeated()) {
2598  if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
2599  CMessageClass* message_class = message_factory::GetMessageClass(
2600  GetFactoryForMessage(self), field_descriptor->message_type());
2601  if (message_class == NULL) {
2602  return NULL;
2603  }
2605  self, field_descriptor, message_class);
2606  } else {
2607  py_container =
2608  repeated_scalar_container::NewContainer(self, field_descriptor);
2609  }
2610  } else if (field_descriptor->cpp_type() ==
2612  py_container = InternalGetSubMessage(self, field_descriptor);
2613  } else {
2614  PyErr_SetString(PyExc_SystemError, "Should never happen");
2615  }
2616 
2617  if (py_container == NULL) {
2618  return NULL;
2619  }
2620  if (!SetCompositeField(self, field_descriptor, py_container)) {
2621  Py_DECREF(py_container);
2622  return NULL;
2623  }
2624  return py_container->AsPyObject();
2625 }
2626 
2627 int SetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor,
2628  PyObject* value) {
2629  if (self->message->GetDescriptor() != field_descriptor->containing_type()) {
2630  PyErr_Format(PyExc_TypeError,
2631  "descriptor to field '%s' doesn't apply to '%s' object",
2632  field_descriptor->full_name().c_str(),
2633  Py_TYPE(self)->tp_name);
2634  return -1;
2635  } else if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) {
2636  PyErr_Format(PyExc_AttributeError,
2637  "Assignment not allowed to repeated "
2638  "field \"%s\" in protocol message object.",
2639  field_descriptor->name().c_str());
2640  return -1;
2641  } else if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
2642  PyErr_Format(PyExc_AttributeError,
2643  "Assignment not allowed to "
2644  "field \"%s\" in protocol message object.",
2645  field_descriptor->name().c_str());
2646  return -1;
2647  } else {
2648  AssureWritable(self);
2649  return InternalSetScalar(self, field_descriptor, value);
2650  }
2651 }
2652 
2653 } // namespace cmessage
2654 
2655 // All containers which are not messages:
2656 // - Make a new parent message
2657 // - Copy the field
2658 // - return the field.
2659 PyObject* ContainerBase::DeepCopy() {
2660  CMessage* new_parent =
2662  new_parent->message = this->parent->message->New(nullptr);
2663 
2664  // Copy the map field into the new message.
2666  this->parent->message, new_parent->message,
2667  {this->parent_field_descriptor});
2668  this->parent->message->MergeFrom(*new_parent->message);
2669 
2670  PyObject* result =
2672  Py_DECREF(new_parent);
2673  return result;
2674 }
2675 
2677  CMessage* parent = this->parent;
2678  if (parent) {
2679  if (parent->composite_fields)
2681  Py_CLEAR(parent);
2682  }
2683 }
2684 
2686  const FieldDescriptor* field_descriptor, Message* sub_message,
2687  CMessageClass* message_class) {
2688  if (!this->child_submessages) {
2690  }
2691  CMessage* cmsg = FindPtrOrNull(
2692  *this->child_submessages, sub_message);
2693  if (cmsg) {
2694  Py_INCREF(cmsg);
2695  } else {
2696  cmsg = cmessage::NewEmptyMessage(message_class);
2697 
2698  if (cmsg == NULL) {
2699  return NULL;
2700  }
2701  cmsg->message = sub_message;
2702  Py_INCREF(this);
2703  cmsg->parent = this;
2704  cmsg->parent_field_descriptor = field_descriptor;
2705  cmessage::SetSubmessage(this, cmsg);
2706  }
2707  return cmsg;
2708 }
2709 
2711  if (!this->child_submessages) {
2712  return nullptr;
2713  }
2714  CMessage* released = FindPtrOrNull(
2715  *this->child_submessages, sub_message);
2716  if (!released) {
2717  return nullptr;
2718  }
2719  // The target message will now own its content.
2720  Py_CLEAR(released->parent);
2721  released->parent_field_descriptor = nullptr;
2722  released->read_only = false;
2723  // Delete it from the cache.
2724  this->child_submessages->erase(sub_message);
2725  return released;
2726 }
2727 
2730  FULL_MODULE_NAME ".CMessage", // tp_name
2731  sizeof(CMessage), // tp_basicsize
2732  0, // tp_itemsize
2733  (destructor)cmessage::Dealloc, // tp_dealloc
2734  0, // tp_print
2735  0, // tp_getattr
2736  0, // tp_setattr
2737  0, // tp_compare
2738  (reprfunc)cmessage::ToStr, // tp_repr
2739  0, // tp_as_number
2740  0, // tp_as_sequence
2741  0, // tp_as_mapping
2742  PyObject_HashNotImplemented, // tp_hash
2743  0, // tp_call
2744  (reprfunc)cmessage::ToStr, // tp_str
2745  cmessage::GetAttr, // tp_getattro
2746  0, // tp_setattro
2747  0, // tp_as_buffer
2748  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
2749  | Py_TPFLAGS_HAVE_VERSION_TAG, // tp_flags
2750  "A ProtocolMessage", // tp_doc
2751  0, // tp_traverse
2752  0, // tp_clear
2753  (richcmpfunc)cmessage::RichCompare, // tp_richcompare
2754  offsetof(CMessage, weakreflist), // tp_weaklistoffset
2755  0, // tp_iter
2756  0, // tp_iternext
2757  cmessage::Methods, // tp_methods
2758  0, // tp_members
2759  cmessage::Getters, // tp_getset
2760  0, // tp_base
2761  0, // tp_dict
2762  0, // tp_descr_get
2763  0, // tp_descr_set
2764  0, // tp_dictoffset
2765  (initproc)cmessage::Init, // tp_init
2766  0, // tp_alloc
2767  cmessage::New, // tp_new
2768 } } };
2769 PyTypeObject* CMessage_Type = &_CMessage_Type.super.ht_type;
2770 
2771 // --- Exposing the C proto living inside Python proto to C code:
2772 
2773 const Message* (*GetCProtoInsidePyProtoPtr)(PyObject* msg);
2774 Message* (*MutableCProtoInsidePyProtoPtr)(PyObject* msg);
2775 
2776 static const Message* GetCProtoInsidePyProtoImpl(PyObject* msg) {
2778  if (message == NULL) {
2779  PyErr_Clear();
2780  return NULL;
2781  }
2782  return message;
2783 }
2784 
2787  if (message == NULL) {
2788  PyErr_Clear();
2789  return NULL;
2790  }
2791  return message;
2792 }
2793 
2794 const Message* PyMessage_GetMessagePointer(PyObject* msg) {
2795  if (!PyObject_TypeCheck(msg, CMessage_Type)) {
2796  PyErr_SetString(PyExc_TypeError, "Not a Message instance");
2797  return NULL;
2798  }
2799  CMessage* cmsg = reinterpret_cast<CMessage*>(msg);
2800  return cmsg->message;
2801 }
2802 
2804  if (!PyObject_TypeCheck(msg, CMessage_Type)) {
2805  PyErr_SetString(PyExc_TypeError, "Not a Message instance");
2806  return NULL;
2807  }
2808  CMessage* cmsg = reinterpret_cast<CMessage*>(msg);
2809 
2810 
2811  if ((cmsg->composite_fields && !cmsg->composite_fields->empty()) ||
2812  (cmsg->child_submessages && !cmsg->child_submessages->empty())) {
2813  // There is currently no way of accurately syncing arbitrary changes to
2814  // the underlying C++ message back to the CMessage (e.g. removed repeated
2815  // composite containers). We only allow direct mutation of the underlying
2816  // C++ message if there is no child data in the CMessage.
2817  PyErr_SetString(PyExc_ValueError,
2818  "Cannot reliably get a mutable pointer "
2819  "to a message with extra references");
2820  return NULL;
2821  }
2823  return cmsg->message;
2824 }
2825 
2826 // Returns a new reference to the MessageClass to use for message creation.
2827 // - if a PyMessageFactory is passed, use it.
2828 // - Otherwise, if a PyDescriptorPool was created, use its factory.
2830  const Descriptor* descriptor, PyObject* py_message_factory) {
2831  PyMessageFactory* factory = nullptr;
2832  if (py_message_factory == nullptr) {
2834  GetDescriptorPool_FromPool(descriptor->file()->pool());
2835  if (pool == nullptr) {
2836  PyErr_SetString(PyExc_TypeError,
2837  "Unknown descriptor pool; C++ users should call "
2838  "DescriptorPool_FromPool and keep it alive");
2839  return nullptr;
2840  }
2841  factory = pool->py_message_factory;
2842  } else if (PyObject_TypeCheck(py_message_factory, &PyMessageFactory_Type)) {
2843  factory = reinterpret_cast<PyMessageFactory*>(py_message_factory);
2844  } else {
2845  PyErr_SetString(PyExc_TypeError, "Expected a MessageFactory");
2846  return nullptr;
2847  }
2848 
2850 }
2851 
2853  PyObject* py_message_factory) {
2854  CMessageClass* message_class =
2855  GetMessageClassFromDescriptor(descriptor, py_message_factory);
2856  if (message_class == nullptr) {
2857  return nullptr;
2858  }
2859 
2860  CMessage* self = cmessage::NewCMessage(message_class);
2861  Py_DECREF(message_class);
2862  if (self == nullptr) {
2863  return nullptr;
2864  }
2865  return self->AsPyObject();
2866 }
2867 
2869  PyObject* py_message_factory) {
2870  CMessageClass* message_class = GetMessageClassFromDescriptor(
2871  message->GetDescriptor(), py_message_factory);
2872  if (message_class == nullptr) {
2873  return nullptr;
2874  }
2875 
2876  CMessage* self = cmessage::NewEmptyMessage(message_class);
2877  Py_DECREF(message_class);
2878  if (self == nullptr) {
2879  return nullptr;
2880  }
2881  self->message = message;
2882  Py_INCREF(Py_None);
2883  self->parent = reinterpret_cast<CMessage*>(Py_None);
2884  return self->AsPyObject();
2885 }
2886 
2887 void InitGlobals() {
2888  // TODO(gps): Check all return values in this function for NULL and propagate
2889  // the error (MemoryError) on up to result in an import failure. These should
2890  // also be freed and reset to NULL during finalization.
2891  kDESCRIPTOR = PyUnicode_FromString("DESCRIPTOR");
2892 
2893  PyObject *dummy_obj = PySet_New(NULL);
2894  kEmptyWeakref = PyWeakref_NewRef(dummy_obj, NULL);
2895  Py_DECREF(dummy_obj);
2896 }
2897 
2898 bool InitProto2MessageModule(PyObject *m) {
2899  // Initialize types and globals in descriptor.cc
2900  if (!InitDescriptor()) {
2901  return false;
2902  }
2903 
2904  // Initialize types and globals in descriptor_pool.cc
2905  if (!InitDescriptorPool()) {
2906  return false;
2907  }
2908 
2909  // Initialize types and globals in message_factory.cc
2910  if (!InitMessageFactory()) {
2911  return false;
2912  }
2913 
2914  // Initialize constants defined in this file.
2915  InitGlobals();
2916 
2917  CMessageClass_Type->tp_base = &PyType_Type;
2918  if (PyType_Ready(CMessageClass_Type) < 0) {
2919  return false;
2920  }
2921  PyModule_AddObject(m, "MessageMeta",
2922  reinterpret_cast<PyObject*>(CMessageClass_Type));
2923 
2924  if (PyType_Ready(CMessage_Type) < 0) {
2925  return false;
2926  }
2927  if (PyType_Ready(CFieldProperty_Type) < 0) {
2928  return false;
2929  }
2930 
2931  // DESCRIPTOR is set on each protocol buffer message class elsewhere, but set
2932  // it here as well to document that subclasses need to set it.
2933  PyDict_SetItem(CMessage_Type->tp_dict, kDESCRIPTOR, Py_None);
2934  // Invalidate any cached data for the CMessage type.
2935  // This call is necessary to correctly support Py_TPFLAGS_HAVE_VERSION_TAG,
2936  // after we have modified CMessage_Type.tp_dict.
2937  PyType_Modified(CMessage_Type);
2938 
2939  PyModule_AddObject(m, "Message", reinterpret_cast<PyObject*>(CMessage_Type));
2940 
2941  // Initialize Repeated container types.
2942  {
2943  if (PyType_Ready(&RepeatedScalarContainer_Type) < 0) {
2944  return false;
2945  }
2946 
2947  PyModule_AddObject(
2948  m, "RepeatedScalarContainer",
2949  reinterpret_cast<PyObject*>(&RepeatedScalarContainer_Type));
2950 
2951  if (PyType_Ready(&RepeatedCompositeContainer_Type) < 0) {
2952  return false;
2953  }
2954 
2955  PyModule_AddObject(
2956  m, "RepeatedCompositeContainer",
2957  reinterpret_cast<PyObject*>(&RepeatedCompositeContainer_Type));
2958 
2959  // Register them as MutableSequence.
2960  ScopedPyObjectPtr collections(PyImport_ImportModule("collections.abc"));
2961  if (collections == NULL) {
2962  return false;
2963  }
2964  ScopedPyObjectPtr mutable_sequence(
2965  PyObject_GetAttrString(collections.get(), "MutableSequence"));
2966  if (mutable_sequence == NULL) {
2967  return false;
2968  }
2969  if (ScopedPyObjectPtr(
2970  PyObject_CallMethod(mutable_sequence.get(), "register", "O",
2971  &RepeatedScalarContainer_Type)) == NULL) {
2972  return false;
2973  }
2974  if (ScopedPyObjectPtr(
2975  PyObject_CallMethod(mutable_sequence.get(), "register", "O",
2976  &RepeatedCompositeContainer_Type)) == NULL) {
2977  return false;
2978  }
2979  }
2980 
2981  if (PyType_Ready(&PyUnknownFields_Type) < 0) {
2982  return false;
2983  }
2984 
2985  PyModule_AddObject(m, "UnknownFieldSet",
2986  reinterpret_cast<PyObject*>(&PyUnknownFields_Type));
2987 
2988  if (PyType_Ready(&PyUnknownFieldRef_Type) < 0) {
2989  return false;
2990  }
2991 
2992  PyModule_AddObject(m, "UnknownField",
2993  reinterpret_cast<PyObject*>(&PyUnknownFieldRef_Type));
2994 
2995  // Initialize Map container types.
2996  if (!InitMapContainers()) {
2997  return false;
2998  }
2999  PyModule_AddObject(m, "ScalarMapContainer",
3000  reinterpret_cast<PyObject*>(ScalarMapContainer_Type));
3001  PyModule_AddObject(m, "MessageMapContainer",
3002  reinterpret_cast<PyObject*>(MessageMapContainer_Type));
3003  PyModule_AddObject(m, "MapIterator",
3004  reinterpret_cast<PyObject*>(&MapIterator_Type));
3005 
3006  if (PyType_Ready(&ExtensionDict_Type) < 0) {
3007  return false;
3008  }
3009  PyModule_AddObject(m, "ExtensionDict",
3010  reinterpret_cast<PyObject*>(&ExtensionDict_Type));
3011  if (PyType_Ready(&ExtensionIterator_Type) < 0) {
3012  return false;
3013  }
3014  PyModule_AddObject(m, "ExtensionIterator",
3015  reinterpret_cast<PyObject*>(&ExtensionIterator_Type));
3016 
3017  // Expose the DescriptorPool used to hold all descriptors added from generated
3018  // pb2.py files.
3019  // PyModule_AddObject steals a reference.
3020  Py_INCREF(GetDefaultDescriptorPool());
3021  PyModule_AddObject(m, "default_pool",
3022  reinterpret_cast<PyObject*>(GetDefaultDescriptorPool()));
3023 
3024  PyModule_AddObject(m, "DescriptorPool",
3025  reinterpret_cast<PyObject*>(&PyDescriptorPool_Type));
3026  PyModule_AddObject(m, "Descriptor",
3027  reinterpret_cast<PyObject*>(&PyMessageDescriptor_Type));
3028  PyModule_AddObject(m, "FieldDescriptor",
3029  reinterpret_cast<PyObject*>(&PyFieldDescriptor_Type));
3030  PyModule_AddObject(m, "EnumDescriptor",
3031  reinterpret_cast<PyObject*>(&PyEnumDescriptor_Type));
3032  PyModule_AddObject(m, "EnumValueDescriptor",
3033  reinterpret_cast<PyObject*>(&PyEnumValueDescriptor_Type));
3034  PyModule_AddObject(m, "FileDescriptor",
3035  reinterpret_cast<PyObject*>(&PyFileDescriptor_Type));
3036  PyModule_AddObject(m, "OneofDescriptor",
3037  reinterpret_cast<PyObject*>(&PyOneofDescriptor_Type));
3038  PyModule_AddObject(m, "ServiceDescriptor",
3039  reinterpret_cast<PyObject*>(&PyServiceDescriptor_Type));
3040  PyModule_AddObject(m, "MethodDescriptor",
3041  reinterpret_cast<PyObject*>(&PyMethodDescriptor_Type));
3042 
3043  PyObject* enum_type_wrapper = PyImport_ImportModule(
3044  "google.protobuf.internal.enum_type_wrapper");
3045  if (enum_type_wrapper == NULL) {
3046  return false;
3047  }
3049  PyObject_GetAttrString(enum_type_wrapper, "EnumTypeWrapper");
3050  Py_DECREF(enum_type_wrapper);
3051 
3052  PyObject* message_module = PyImport_ImportModule(
3053  "google.protobuf.message");
3054  if (message_module == NULL) {
3055  return false;
3056  }
3057  EncodeError_class = PyObject_GetAttrString(message_module, "EncodeError");
3058  DecodeError_class = PyObject_GetAttrString(message_module, "DecodeError");
3059  PythonMessage_class = PyObject_GetAttrString(message_module, "Message");
3060  Py_DECREF(message_module);
3061 
3062  PyObject* pickle_module = PyImport_ImportModule("pickle");
3063  if (pickle_module == NULL) {
3064  return false;
3065  }
3066  PickleError_class = PyObject_GetAttrString(pickle_module, "PickleError");
3067  Py_DECREF(pickle_module);
3068 
3069  // Override {Get,Mutable}CProtoInsidePyProto.
3072 
3073  return true;
3074 }
3075 
3076 } // namespace python
3077 } // namespace protobuf
3078 } // namespace google
google::protobuf::Descriptor::full_name
const std::string & full_name() const
google::protobuf::python::cmessage::GetExtensionsByNumber
static PyObject * GetExtensionsByNumber(CMessage *self, void *closure)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2452
google::protobuf::python::message_meta::GetExtensionsByNumber
static PyObject * GetExtensionsByNumber(CMessageClass *self, void *closure)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:393
google::protobuf::python::repeated_scalar_container::Extend
PyObject * Extend(RepeatedScalarContainer *self, PyObject *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:491
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
google::protobuf::python::cmessage::GetExtensionDescriptor
const FieldDescriptor * GetExtensionDescriptor(PyObject *extension)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:934
unicode
Definition: bloaty/third_party/re2/re2/unicode.py:1
google::protobuf::python::InitMapContainers
bool InitMapContainers()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:1019
google::protobuf::Reflection::GetStringReference
const std::string & GetStringReference(const Message &message, const FieldDescriptor *field, std::string *scratch) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1171
google::protobuf::python::EnumTypeWrapper_class
PyObject * EnumTypeWrapper_class
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:103
GOOGLE_CHECK_GET_FLOAT
#define GOOGLE_CHECK_GET_FLOAT(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:312
google::protobuf::python::GetMessageClassFromDescriptor
static CMessageClass * GetMessageClassFromDescriptor(const Descriptor *descriptor, PyObject *py_message_factory)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2829
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
google::protobuf::python::PyServiceDescriptor_Type
PyTypeObject PyServiceDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1731
google::protobuf::python::unknown_fields::NewPyUnknownFields
PyObject * NewPyUnknownFields(CMessage *c_message)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/unknown_fields.cc:101
regen-readme.it
it
Definition: regen-readme.py:15
google::protobuf::value
const Descriptor::ReservedRange value
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1954
google::protobuf::FieldDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:515
google::protobuf::python::PickleError_class
PyObject * PickleError_class
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:543
google::protobuf::python::cmessage::MergeFromString
static PyObject * MergeFromString(CMessage *self, PyObject *arg)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1889
google::protobuf::python::ScopedPythonPtr::reset
PyObjectStruct * reset(PyObjectStruct *p=NULL)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:62
google::protobuf::python::GetCProtoInsidePyProtoImpl
static const Message * GetCProtoInsidePyProtoImpl(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2854
pos
int pos
Definition: libuv/docs/code/tty-gravity/main.c:11
google::protobuf::python::message_meta::Getters
static PyGetSetDef Getters[]
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:424
ctx
Definition: benchmark-async.c:30
google::protobuf::python::cmessage::NewEmptyMessage
CMessage * NewEmptyMessage(CMessageClass *type)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1235
google::protobuf::python::PyMessageFactory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.h:49
google::protobuf::python::cmessage::SerializePartialToString
static PyObject * SerializePartialToString(CMessage *self, PyObject *args, PyObject *kwargs)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1741
google::protobuf::python::message_meta::Dealloc
static void Dealloc(PyObject *pself)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:315
google::protobuf::FieldDescriptor::CPPTYPE_STRING
@ CPPTYPE_STRING
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:562
google::protobuf::extension
const Descriptor::ReservedRange const EnumValueDescriptor const MethodDescriptor extension
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:2001
google::protobuf::int64
int64_t int64
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:151
google::protobuf::python::PyEnumValueDescriptor_Type
PyTypeObject PyEnumValueDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1278
google::protobuf::python::cmessage::InitAttributes
int InitAttributes(CMessage *self, PyObject *args, PyObject *kwargs)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1066
google::protobuf::python::cmessage::MaybeReleaseOverlappingOneofField
static int MaybeReleaseOverlappingOneofField(CMessage *cmessage, const FieldDescriptor *field)
Definition: protobuf/python/google/protobuf/pyext/message.cc:802
google::protobuf::FieldDescriptor::label
Label label() const
google::protobuf::FieldDescriptor::full_name
const std::string & full_name() const
google::protobuf.internal.python_message.MergeFrom
MergeFrom
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1339
google::protobuf::python::MutableCProtoInsidePyProtoPtr
Message *(* MutableCProtoInsidePyProtoPtr)(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_protobuf.cc:47
google::protobuf::MessageLite::GetArena
virtual Arena * GetArena() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/message_lite.h:207
google::protobuf::Reflection::GetFloat
float GetFloat(const Message &message, const FieldDescriptor *field) const
google::protobuf::python::GetDefaultDescriptorPool
PyDescriptorPool * GetDefaultDescriptorPool()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:751
google::protobuf::Reflection::GetUInt32
uint32 GetUInt32(const Message &message, const FieldDescriptor *field) const
google::protobuf::python::CMessage
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:100
google::protobuf::python::kEmptyWeakref
static PyObject * kEmptyWeakref
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:105
google::protobuf::python::ToStringObject
PyObject * ToStringObject(const FieldDescriptor *descriptor, const string &value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:799
GOOGLE_DCHECK
#define GOOGLE_DCHECK
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:194
phone_pb2.message_type
message_type
Definition: phone_pb2.py:200
google::protobuf::FindPtrOrNull
Collection::value_type::second_type FindPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/map_util.h:166
google::protobuf::Message::GetReflection
const Reflection * GetReflection() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:332
google::protobuf::python::NewScalarMapContainer
MapContainer * NewScalarMapContainer(CMessage *parent, const google::protobuf::FieldDescriptor *parent_field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:374
google::protobuf::python::cmessage::CopyFrom
static PyObject * CopyFrom(CMessage *self, PyObject *arg)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1835
google::protobuf::TextFormat::Printer::PrintToString
bool PrintToString(const Message &message, std::string *output) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.cc:1860
google::protobuf::python::ScopedPythonPtr::get
PyObjectStruct * get() const
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:76
google::protobuf::python::ScopedPyObjectPtr
ScopedPythonPtr< PyObject > ScopedPyObjectPtr
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:95
google::protobuf::python::CheckAndGetInteger< uint32 >
template bool CheckAndGetInteger< uint32 >(PyObject *, uint32 *)
google::protobuf::io::SafeDoubleToFloat
float SafeDoubleToFloat(double value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/strtod.cc:116
Arena
Definition: arena.c:39
google::protobuf::python::PyFieldDescriptor_AsDescriptor
const FieldDescriptor * PyFieldDescriptor_AsDescriptor(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1043
google::protobuf::io::CodedOutputStream::HadError
bool HadError()
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream.h:1058
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
google::protobuf::io::CodedInputStream::GetDefaultRecursionLimit
static int GetDefaultRecursionLimit()
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream.h:414
google::protobuf::FieldDescriptor::TYPE_BYTES
@ TYPE_BYTES
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:538
GOOGLE_CHECK_GET_INT64
#define GOOGLE_CHECK_GET_INT64(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:294
google::protobuf::python::cmessage::HasFieldByDescriptor
int HasFieldByDescriptor(CMessage *self, const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1362
google::protobuf::uint32
uint32_t uint32
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:155
google::protobuf::python::CheckAndGetInteger< int64 >
template bool CheckAndGetInteger< int64 >(PyObject *, int64 *)
google::protobuf::python::RepeatedScalarContainer_Type
PyTypeObject RepeatedScalarContainer_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:737
google::protobuf.internal::ParseContext
Definition: bloaty/third_party/protobuf/src/google/protobuf/parse_context.h:336
New
T * New(Args &&... args)
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:195
google::protobuf::FieldDescriptor::containing_type
const Descriptor * containing_type() const
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf::python::CheckAndGetInteger< uint64 >
template bool CheckAndGetInteger< uint64 >(PyObject *, uint64 *)
google::protobuf::python::PyMessage_New
PyObject * PyMessage_New(const Descriptor *descriptor, PyObject *py_message_factory)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2852
PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size)
Definition: protobuf/python/google/protobuf/pyext/message.cc:47
google::protobuf::python::cmessage::ToStr
static PyObject * ToStr(CMessage *self)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1789
google::protobuf::python::MessageReflectionFriend::IsLazyField
static bool IsLazyField(const Reflection *reflection, const Message &message, const FieldDescriptor *field)
Definition: protobuf/python/google/protobuf/pyext/message.cc:100
google::protobuf::Reflection::UnsafeShallowSwapFields
void UnsafeShallowSwapFields(Message *message1, Message *message2, const std::vector< const FieldDescriptor * > &fields) const
Definition: protobuf/src/google/protobuf/generated_message_reflection.cc:1045
google::protobuf::python::cmessage::Init
static int Init(CMessage *self, PyObject *args, PyObject *kwargs)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1270
google::protobuf::python::cmessage::Dealloc
static void Dealloc(CMessage *self)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1277
GOOGLE_CHECK_GET_INT32
#define GOOGLE_CHECK_GET_INT32(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:288
ctx
static struct test_ctx ctx
Definition: test-ipc-send-recv.c:65
google::protobuf::OneofDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:843
google::protobuf::python::cmessage::FindFieldWithOneofs
const FieldDescriptor * FindFieldWithOneofs(const Message *message, ConstStringParam field_name, bool *in_oneof)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1359
setup.name
name
Definition: setup.py:542
FULL_MODULE_NAME
#define FULL_MODULE_NAME
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:331
google::protobuf::python::cmessage::InternalGetScalar
PyObject * InternalGetScalar(const Message *message, const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2181
google::protobuf::io::CodedOutputStream::SetSerializationDeterministic
void SetSerializationDeterministic(bool value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream.h:1223
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
google::protobuf::python::cmessage::ByteSize
static PyObject * ByteSize(CMessage *self, PyObject *args)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1945
google::protobuf::TextFormat::Printer::SetHideUnknownFields
void SetHideUnknownFields(bool hide)
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.h:301
google::protobuf::Reflection::IsLazyField
bool IsLazyField(const FieldDescriptor *field) const
Definition: protobuf/src/google/protobuf/message.h:1011
google::protobuf::python::ScopedPythonPtr
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:46
google::protobuf::python::cmessage::GetAttr
PyObject * GetAttr(PyObject *pself, PyObject *name)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2619
google::protobuf::python::PyDescriptorPool
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:56
google::protobuf::Reflection
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:397
google::protobuf::python::DecodeError_class
PyObject * DecodeError_class
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:542
iterator
const typedef MCPhysReg * iterator
Definition: MCRegisterInfo.h:27
google::protobuf::python::cmessage::GetMessageName
static std::string GetMessageName(CMessage *self)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1642
google::protobuf::python::CMessageClass
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:148
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
google::protobuf::Reflection::HasField
bool HasField(const Message &message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:728
google::protobuf::Reflection::GetBool
bool GetBool(const Message &message, const FieldDescriptor *field) const
google::protobuf::python::cmessage::UnknownFieldSet
static PyObject * UnknownFieldSet(CMessage *self)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2438
google::protobuf::python::CMessage::CompositeFieldsMap
std::unordered_map< const FieldDescriptor *, ContainerBase * > CompositeFieldsMap
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:116
google::protobuf::python::_CMessageClass_Type
static PyTypeObject _CMessageClass_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:474
google::protobuf::python::ScopedPythonPtr::release
PyObjectStruct * release()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:70
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
T
#define T(upbtypeconst, upbtype, ctype, default_value)
google::protobuf::python::PyEnumDescriptor_FromDescriptor
PyObject * PyEnumDescriptor_FromDescriptor(const EnumDescriptor *enum_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1192
Descriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:121
google::protobuf::python::GetMessageDescriptor
static const Descriptor * GetMessageDescriptor(PyTypeObject *cls)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:524
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
GOOGLE_CHECK_GET_UINT32
#define GOOGLE_CHECK_GET_UINT32(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:300
google::protobuf::python::PyFieldDescriptor_FromDescriptor
PyObject * PyFieldDescriptor_FromDescriptor(const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1037
google::protobuf::Reflection::GetOneofFieldDescriptor
const FieldDescriptor * GetOneofFieldDescriptor(const Message &message, const OneofDescriptor *oneof_descriptor) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1753
google::protobuf::python::cmessage::ListFields
static PyObject * ListFields(CMessage *self)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2006
google::protobuf::python::cmessage::DiscardUnknownFields
static PyObject * DiscardUnknownFields(CMessage *self)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2083
google::protobuf::python::PyFileDescriptor_Type
PyTypeObject PyFileDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1454
google::protobuf::python::PyUnknownFields
struct google::protobuf::python::PyUnknownFields PyUnknownFields
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
google::protobuf::python::cmessage::DeepCopy
PyObject * DeepCopy(CMessage *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2388
google::protobuf::EnumValueDescriptor::name
const std::string & name() const
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
FieldDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:133
google::protobuf::FieldDescriptor::has_presence
bool has_presence() const
google::protobuf::python::repeated_composite_container::Add
PyObject * Add(RepeatedCompositeContainer *self, PyObject *args, PyObject *kwargs)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc:78
google::protobuf::python::InitMessageFactory
bool InitMessageFactory()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc:293
google::protobuf::int32
int32_t int32
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:150
google::protobuf::python::GetDescriptorPool_FromPool
PyDescriptorPool * GetDescriptorPool_FromPool(const DescriptorPool *pool)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:755
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
google::protobuf::Reflection::SwapFields
void SwapFields(Message *message1, Message *message2, const std::vector< const FieldDescriptor * > &fields) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:673
google::protobuf.internal.python_message.ClearExtension
ClearExtension
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:914
google::protobuf::ConstStringParam
const std::string & ConstStringParam
Definition: third_party/protobuf/src/google/protobuf/stubs/port.h:129
google::protobuf::python::PyMessageDescriptor_AsDescriptor
const Descriptor * PyMessageDescriptor_AsDescriptor(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:728
errors
const char * errors
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc:841
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
google::protobuf::python::message_meta::GetClassAttribute
static PyObject * GetClassAttribute(CMessageClass *self, PyObject *name)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:433
GOOGLE_CHECK_GET_BOOL
#define GOOGLE_CHECK_GET_BOOL(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:324
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
google::protobuf::python::message_meta::GcClear
static int GcClear(PyObject *pself)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:329
PyString_AsString
#define PyString_AsString(ob)
Definition: protobuf/python/google/protobuf/pyext/message.cc:80
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
google::protobuf::python::CheckString
PyObject * CheckString(PyObject *arg, const FieldDescriptor *descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:728
google::protobuf::python::allow_oversize_protos
static bool allow_oversize_protos
Definition: protobuf/python/google/protobuf/pyext/message.cc:451
google::protobuf::TextFormat::BaseTextGenerator
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.h:100
google::protobuf::python::AllowInvalidUTF8
bool AllowInvalidUTF8(const FieldDescriptor *field)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:726
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
google::protobuf::python::CMessageClass_Type
PyTypeObject * CMessageClass_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:514
google::protobuf::python::cmessage::PythonFieldValuePrinter::PrintFloat
void PrintFloat(float val, TextFormat::BaseTextGenerator *generator) const override
Definition: protobuf/python/google/protobuf/pyext/message.cc:1761
google::protobuf::python::MapIterator_Type
PyTypeObject MapIterator_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:980
google::protobuf::python::ContainerBase
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:71
google::protobuf::python::VerifyIntegerCastAndRange
bool VerifyIntegerCastAndRange(PyObject *arg, ValueType value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:573
google::protobuf::Reflection::HasOneof
bool HasOneof(const Message &message, const OneofDescriptor *oneof_descriptor) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:2022
google::protobuf::python::PyUnknownFieldRef_Type
PyTypeObject PyUnknownFieldRef_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/unknown_fields.cc:315
google::protobuf::StringPiece
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/stringpiece.h:180
google::protobuf::python::CMessage_Type
PyTypeObject * CMessage_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2847
google::protobuf::python::MessageMapContainer_Type
PyTypeObject * MessageMapContainer_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:838
google::protobuf::python::PyDescriptorPool::py_message_factory
PyMessageFactory * py_message_factory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:77
google::protobuf::TextFormat::Printer::SetDefaultFieldValuePrinter
void SetDefaultFieldValuePrinter(const FastFieldValuePrinter *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.cc:1809
google::protobuf::python::message_meta::GetExtensionsByName
static PyObject * GetExtensionsByName(CMessageClass *self, void *closure)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:363
google::protobuf::python::GetCProtoInsidePyProtoPtr
const Message *(* GetCProtoInsidePyProtoPtr)(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_protobuf.cc:45
google::protobuf::python::cmessage::InternalSerializeToString
static PyObject * InternalSerializeToString(CMessage *self, PyObject *args, PyObject *kwargs, bool require_initialized)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1650
google::protobuf::python::ContainerBase::parent_field_descriptor
const FieldDescriptor * parent_field_descriptor
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:88
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
google::protobuf::TextFormat::Printer
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.h:236
google::protobuf::EnumValueDescriptor::number
int number() const
google::protobuf::python::CMessageClass::py_message_descriptor
PyObject * py_message_descriptor
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:158
google::protobuf::util::MessageDifferencer::Equals
static bool Equals(const Message &message1, const Message &message2)
Definition: bloaty/third_party/protobuf/src/google/protobuf/util/message_differencer.cc:230
google::protobuf::python::ExtensionIterator_Type
PyTypeObject ExtensionIterator_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/extension_dict.cc:438
google::protobuf::python::PyEnumDescriptor_Type
PyTypeObject PyEnumDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1158
google::protobuf::python::ExtensionDict
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/extension_dict.h:51
arg
Definition: cmdline.cc:40
google::protobuf::io::ArrayOutputStream
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h:100
absl::compare_internal::value_type
int8_t value_type
Definition: abseil-cpp/absl/types/compare.h:45
number
int32_t number
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:850
google::protobuf::python::NewMessageMapContainer
MessageMapContainer * NewMessageMapContainer(CMessage *parent, const google::protobuf::FieldDescriptor *parent_field_descriptor, CMessageClass *message_class)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:638
EnumValueDescriptor
Definition: protobuf/php/ext/google/protobuf/def.c:63
google::protobuf::python::cmessage::ToUnicode
PyObject * ToUnicode(CMessage *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2407
google::protobuf::python::kDESCRIPTOR
static PyObject * kDESCRIPTOR
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:102
google::protobuf::uint64
uint64_t uint64
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:156
google::protobuf::FieldDescriptor::LABEL_REPEATED
@ LABEL_REPEATED
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:574
Py_TYPE
#define Py_TYPE(ob)
Definition: protobuf/python/google/protobuf/pyext/message.cc:50
google::protobuf::python::cmessage::New
static PyObject * New(PyTypeObject *cls, PyObject *unused_args, PyObject *unused_kwargs)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1257
PyString_AsStringAndSize
#define PyString_AsStringAndSize(ob, charpp, sizep)
Definition: protobuf/python/google/protobuf/pyext/message.cc:82
google::protobuf::python::cmessage::InternalReparentFields
static int InternalReparentFields(CMessage *self, const std::vector< CMessage * > &messages_to_release, const std::vector< ContainerBase * > &containers_to_release)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1481
google::protobuf::python::extension_dict::NewExtensionDict
ExtensionDict * NewExtensionDict(CMessage *parent)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/extension_dict.cc:310
google::protobuf::python::cmessage::SetCompositeField
bool SetCompositeField(CMessage *self, const FieldDescriptor *field, ContainerBase *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2602
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
google::protobuf::python::cmessage::SetAllowOversizeProtos
PyObject * SetAllowOversizeProtos(PyObject *m, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1914
conf.extensions
list extensions
Definition: doc/python/sphinx/conf.py:54
google::protobuf::Reflection::IsLazyExtension
bool IsLazyExtension(const Message &message, const FieldDescriptor *field) const
Definition: protobuf/src/google/protobuf/generated_message_reflection.cc:254
google::protobuf::python::repeated_scalar_container::Append
PyObject * Append(RepeatedScalarContainer *self, PyObject *item)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:343
google::protobuf::Reflection::SwapElements
void SwapElements(Message *message, const FieldDescriptor *field, int index1, int index2) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:969
google::protobuf::Reflection::RemoveLast
void RemoveLast(Message *message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:902
google::protobuf::python::MessageReflectionFriend::UnsafeShallowSwapFields
static void UnsafeShallowSwapFields(Message *lhs, Message *rhs, const std::vector< const FieldDescriptor * > &fields)
Definition: protobuf/python/google/protobuf/pyext/message.cc:95
google::protobuf::python::ContainerBase::AsPyObject
PyObject * AsPyObject()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:90
google::protobuf::FieldDescriptor::CPPTYPE_UINT64
@ CPPTYPE_UINT64
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:557
min
#define min(a, b)
Definition: qsort.h:83
google::protobuf::python::cmessage::ClearFieldByDescriptor
int ClearFieldByDescriptor(CMessage *self, const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1602
google::protobuf::python::message_factory::GetOrCreateMessageClass
CMessageClass * GetOrCreateMessageClass(PyMessageFactory *self, const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc:155
google::protobuf::python::cmessage::Methods
static PyMethodDef Methods[]
Definition: protobuf/python/google/protobuf/pyext/message.cc:2465
google::protobuf::Reflection::UnsafeArenaReleaseLast
Message * UnsafeArenaReleaseLast(Message *message, const FieldDescriptor *field) const
Definition: protobuf/src/google/protobuf/generated_message_reflection.cc:1357
GOOGLE_CHECK_GET_UINT64
#define GOOGLE_CHECK_GET_UINT64(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:306
EnumDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:143
google::protobuf::python::PythonMessage_class
static PyObject * PythonMessage_class
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:104
google::protobuf::python::message_factory::RegisterMessageClass
int RegisterMessageClass(PyMessageFactory *self, const Descriptor *message_descriptor, CMessageClass *message_class)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc:140
google::protobuf::python::CFieldProperty_Type
PyTypeObject * CFieldProperty_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/field.cc:127
google::protobuf::python::message_meta::AddDescriptors
static int AddDescriptors(PyObject *cls, const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:124
google::protobuf::python::PyMessageFactory_Type
PyTypeObject PyMessageFactory_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc:251
google::protobuf::Reflection::FieldSize
int FieldSize(const Message &message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:744
Json::ValueType
ValueType
Type of the value held by a Value object.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:463
google::protobuf::Reflection::GetInt32
int32 GetInt32(const Message &message, const FieldDescriptor *field) const
google::protobuf::python::PyMessageDescriptor_Type
PyTypeObject PyMessageDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:688
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
google::protobuf::LowerString
void LowerString(string *s)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil.h:177
google::protobuf::python::ContainerBase::RemoveFromParentCache
void RemoveFromParentCache()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2754
google::protobuf::python::cmessage::FixupMessageAfterMerge
int FixupMessageAfterMerge(CMessage *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:864
google::protobuf::python::message_meta::GcTraverse
static int GcTraverse(PyObject *pself, visitproc visit, void *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:322
google::protobuf::python::CheckAndGetInteger< int32 >
template bool CheckAndGetInteger< int32 >(PyObject *, int32 *)
google::protobuf::python::cmessage::AssureWritable
int AssureWritable(CMessage *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:898
google::protobuf::python::cmessage::PythonFieldValuePrinter::PrintDouble
void PrintDouble(double val, TextFormat::BaseTextGenerator *generator) const override
Definition: protobuf/python/google/protobuf/pyext/message.cc:1765
google::protobuf::python::OutOfRangeError
void OutOfRangeError(PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:562
google::protobuf.internal.python_message.ClearField
ClearField
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:902
google::protobuf::python::PyDescriptorPool_Type
PyTypeObject PyDescriptorPool_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:677
google::protobuf::python::PyUnknownFields_Type
PyTypeObject PyUnknownFields_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/unknown_fields.cc:158
google::protobuf::TextFormat::FastFieldValuePrinter
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.h:124
google::protobuf::python::PyFieldDescriptor_Type
PyTypeObject PyFieldDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1003
google::protobuf::io::CodedOutputStream
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream.h:1044
google::protobuf::python::cmessage::SetFieldValue
int SetFieldValue(CMessage *self, const FieldDescriptor *field_descriptor, PyObject *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2705
google::protobuf::FieldDescriptor::CPPTYPE_INT64
@ CPPTYPE_INT64
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:555
google::protobuf::python::CMessageClass::message_descriptor
const Descriptor * message_descriptor
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:154
google::protobuf::python::cmessage::CheckHasPresence
bool CheckHasPresence(const FieldDescriptor *field_descriptor, bool in_oneof)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1395
google::protobuf::python::_CMessage_Type
static CMessageClass _CMessage_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2806
google::protobuf::python::cmessage::SetSubmessage
bool SetSubmessage(CMessage *self, CMessage *submessage)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2611
google::protobuf::python::cmessage::PythonFieldValuePrinter
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1780
google::protobuf::python::CheckAndGetFloat
bool CheckAndGetFloat(PyObject *arg, float *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:685
google::protobuf::python::cmessage::InternalReleaseFieldByDescriptor
int InternalReleaseFieldByDescriptor(CMessage *self, const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1572
attr
OPENSSL_EXPORT X509_ATTRIBUTE * attr
Definition: x509.h:1666
google::protobuf::Reflection::ReleaseLast
Message * ReleaseLast(Message *message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:950
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
google::protobuf::python::CMessage
google::protobuf::python::CMessage CMessage
google::protobuf::Message::GetDescriptor
const Descriptor * GetDescriptor() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:323
scratch
static char scratch[256]
Definition: test-random.c:27
google::protobuf::python::InitDescriptor
bool InitDescriptor()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1909
google::protobuf::FieldDescriptor::CPPTYPE_UINT32
@ CPPTYPE_UINT32
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:556
google::protobuf::FieldDescriptor::CPPTYPE_FLOAT
@ CPPTYPE_FLOAT
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:559
google::protobuf::python::NewFieldProperty
PyObject * NewFieldProperty(const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/field.cc:129
google::protobuf.internal.python_message.FromString
FromString
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:796
wrapped
grpc_call * wrapped
Definition: src/php/ext/grpc/call.h:32
google::protobuf::python::CMessage::MaybeReleaseSubMessage
CMessage * MaybeReleaseSubMessage(Message *sub_message)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2788
google::protobuf::FieldDescriptor::name
const std::string & name() const
google::protobuf::python::cmessage::SerializeToString
static PyObject * SerializeToString(CMessage *self, PyObject *args, PyObject *kwargs)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1735
google::protobuf::python::EncodeError_class
PyObject * EncodeError_class
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:541
google::protobuf::python::cmessage::GetFactoryForMessage
PyMessageFactory * GetFactoryForMessage(CMessage *message)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:830
google::protobuf.internal.python_message.HasExtension
HasExtension
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:929
google::protobuf::python::cmessage::ParseFromString
static PyObject * ParseFromString(CMessage *self, PyObject *arg)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1938
google::protobuf::python::ContainerBase::DeepCopy
PyObject * DeepCopy()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2737
google::protobuf::python::message_meta::New
static PyObject * New(PyTypeObject *type, PyObject *args, PyObject *kwargs)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:195
google::protobuf::TextFormat::BaseTextGenerator::PrintString
void PrintString(const std::string &str)
Definition: bloaty/third_party/protobuf/src/google/protobuf/text_format.h:112
google::protobuf::python::CMessageClass::py_message_factory
PyMessageFactory * py_message_factory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:164
google::protobuf::python::cmessage::WhichOneof
static PyObject * WhichOneof(CMessage *self, PyObject *arg)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1980
google::protobuf::python::cmessage::GetExtensionsByName
static PyObject * GetExtensionsByName(CMessage *self, void *closure)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2447
google::protobuf::python::unknown_fields::Clear
void Clear(PyUnknownFields *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/unknown_fields.cc:65
google::protobuf::python::CheckFieldBelongsToMessage
bool CheckFieldBelongsToMessage(const FieldDescriptor *field_descriptor, const Message *message)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:817
google::protobuf::FieldDescriptor::CPPTYPE_BOOL
@ CPPTYPE_BOOL
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:560
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE
@ CPPTYPE_DOUBLE
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:558
google::protobuf::python::InitDescriptorPool
bool InitDescriptorPool()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:723
google::protobuf::python::cmessage::Getters
static PyGetSetDef Getters[]
Definition: protobuf/python/google/protobuf/pyext/message.cc:2457
google::protobuf::python::cmessage::DeleteRepeatedField
int DeleteRepeatedField(CMessage *self, const FieldDescriptor *field_descriptor, PyObject *slice)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:977
google::protobuf::python::cmessage::InternalSetScalar
int InternalSetScalar(CMessage *self, const FieldDescriptor *field_descriptor, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2356
google::protobuf.internal.python_message.RegisterExtension
RegisterExtension
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:790
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
profile_analyzer.fields
list fields
Definition: profile_analyzer.py:266
google::protobuf::python::PyMessageFactory::pool
PyDescriptorPool * pool
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.h:62
step
static int step
Definition: test-mutexes.c:31
google::protobuf::python::cmessage::SetInParent
static PyObject * SetInParent(CMessage *self, PyObject *args)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1975
google::protobuf::python::PyOneofDescriptor_Type
PyTypeObject PyOneofDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1613
google::protobuf::python::PyDescriptorPool::pool
PyObject_HEAD DescriptorPool * pool
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:60
google::protobuf::python::_CalledFromGeneratedFile
bool _CalledFromGeneratedFile(int stacklevel)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:99
google::protobuf::FieldDescriptor::CPPTYPE_ENUM
@ CPPTYPE_ENUM
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:561
google::protobuf::UnknownFieldSet
Definition: bloaty/third_party/protobuf/src/google/protobuf/unknown_field_set.h:81
google::protobuf::python::StringParam
std::string StringParam
Definition: protobuf/python/google/protobuf/pyext/descriptor.h:46
google::protobuf::Descriptor::name
const std::string & name() const
google::protobuf::python::Clear
PyObject * Clear(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:318
GOOGLE_CHECK_GET_DOUBLE
#define GOOGLE_CHECK_GET_DOUBLE(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:318
google::protobuf::python::CMessage::composite_fields
CompositeFieldsMap * composite_fields
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:117
ok
bool ok
Definition: async_end2end_test.cc:197
google::protobuf::EnumValueDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1075
arg
struct arg arg
GOOGLE_CHECK
#define GOOGLE_CHECK(EXPRESSION)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:153
google::protobuf::Descriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:231
google::protobuf::python::IsValidUTF8
bool IsValidUTF8(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:707
google::protobuf::python::CMessage::SubMessagesMap
std::unordered_map< const Message *, CMessage * > SubMessagesMap
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:122
closure
Definition: proxy.cc:59
google::protobuf::python::CMessage::BuildSubMessageFromPointer
CMessage * BuildSubMessageFromPointer(const FieldDescriptor *field_descriptor, Message *sub_message, CMessageClass *message_class)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2763
google::protobuf::python::CheckAndGetBool
bool CheckAndGetBool(PyObject *arg, bool *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:694
GOOGLE_DCHECK_EQ
#define GOOGLE_DCHECK_EQ
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:196
google::protobuf::Reflection::GetInt64
int64 GetInt64(const Message &message, const FieldDescriptor *field) const
google::protobuf::Message::New
Message * New() const override=0
google::protobuf::python::CheckMessageClass
static CMessageClass * CheckMessageClass(PyTypeObject *cls)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:516
google::protobuf::python::ContainerBase::parent
struct CMessage * parent
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:82
google::protobuf.internal.python_message.IsInitialized
IsInitialized
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1245
google::protobuf::python::RepeatedScalarContainer
google::protobuf::python::RepeatedScalarContainer RepeatedScalarContainer
pool
InternalDescriptorPool * pool
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:807
google::protobuf::python::InitProto2MessageModule
bool InitProto2MessageModule(PyObject *m)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2943
google::protobuf::python::CheckAndSetString
bool CheckAndSetString(PyObject *arg, Message *message, const FieldDescriptor *descriptor, const Reflection *reflection, bool append, int index)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:770
google::protobuf::python::FormatTypeError
void FormatTypeError(PyObject *arg, char *expected_types)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:547
google::protobuf::python::cmessage::InternalSetNonOneofScalar
int InternalSetNonOneofScalar(Message *message, const FieldDescriptor *field_descriptor, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2276
google::protobuf::python::ExtensionDict_Type
PyTypeObject ExtensionDict_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/extension_dict.cc:371
google::protobuf::python::RepeatedCompositeContainer_Type
PyTypeObject RepeatedCompositeContainer_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc:539
iter
Definition: test_winkernel.cpp:47
google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE
@ CPPTYPE_MESSAGE
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:563
google::protobuf::python::MessageReflectionFriend
Definition: protobuf/python/google/protobuf/pyext/message.cc:93
google::protobuf::HasSuffixString
bool HasSuffixString(const string &str, const string &suffix)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil.h:137
in_oneof
static bool in_oneof(const upb_msglayout_field *field)
Definition: php-upb.c:7050
google::protobuf::python::CheckAndGetDouble
bool CheckAndGetDouble(PyObject *arg, double *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:676
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
google::protobuf::python::PyMessage_NewMessageOwnedExternally
PyObject * PyMessage_NewMessageOwnedExternally(Message *message, PyObject *message_factory)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2904
google::protobuf.internal.python_message.HasField
HasField
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:864
google::protobuf::python::cmessage::NewCMessage
static CMessage * NewCMessage(CMessageClass *type)
Definition: protobuf/python/google/protobuf/pyext/message.cc:1231
absl::visit
variant_internal::VisitResult< Visitor, Variants... > visit(Visitor &&vis, Variants &&... vars)
Definition: abseil-cpp/absl/types/variant.h:430
EnumValueDescriptor::number
int32_t number
Definition: protobuf/php/ext/google/protobuf/def.c:66
google::protobuf::python::cmessage::_CheckCalledFromGeneratedFile
PyObject * _CheckCalledFromGeneratedFile(PyObject *unused, PyObject *unused_arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2483
google::protobuf::python::PyMethodDescriptor_Type
PyTypeObject PyMethodDescriptor_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1843
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
google::protobuf::python::RepeatedCompositeContainer
google::protobuf::python::RepeatedCompositeContainer RepeatedCompositeContainer
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
google::protobuf::python::InitGlobals
void InitGlobals()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2932
self
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:543
google::protobuf::python::CMessage::GetMessageClass
CMessageClass * GetMessageClass()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:132
mkowners.depth
depth
Definition: mkowners.py:114
regress.m
m
Definition: regress/regress.py:25
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
google::protobuf::EnumDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:918
enum_descriptor
VALUE enum_descriptor(VALUE self)
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/message.c:794
google::protobuf::python::PyMessageFactory::message_factory
PyObject_HEAD MessageFactory * message_factory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.h:58
google::protobuf::python::cmessage::GetExtensionDict
static PyObject * GetExtensionDict(CMessage *self, void *closure)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2420
phone_pb2.enum_type
enum_type
Definition: phone_pb2.py:198
google::protobuf::python::cmessage::GetFieldValue
PyObject * GetFieldValue(CMessage *self, const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2635
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16
method_name
absl::string_view method_name
Definition: call_creds_util.cc:40
google::protobuf::python::PyMessage_GetMessagePointer
const Message * PyMessage_GetMessagePointer(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2872
google::protobuf::FieldDescriptor::is_repeated
bool is_repeated() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:2067
google::protobuf::FieldDescriptor::TYPE_STRING
@ TYPE_STRING
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:534
google::protobuf::FieldDescriptor::cpp_type
CppType cpp_type() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:2139
google::protobuf::python::cmessage::GetIntegerEnumValue
static PyObject * GetIntegerEnumValue(const FieldDescriptor &descriptor, PyObject *value)
Definition: protobuf/python/google/protobuf/pyext/message.cc:916
google::protobuf::python::CMessage::child_submessages
SubMessagesMap * child_submessages
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:123
google::protobuf::python::message_factory::GetMessageClass
CMessageClass * GetMessageClass(PyMessageFactory *self, const Descriptor *message_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc:223
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::python::cmessage::RichCompare
static PyObject * RichCompare(CMessage *self, PyObject *other, int opid)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2111
google::protobuf::python::ScalarMapContainer_Type
PyTypeObject * ScalarMapContainer_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:556
google::protobuf::python::cmessage::InternalGetSubMessage
CMessage * InternalGetSubMessage(CMessage *self, const FieldDescriptor *field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2248
Message
Definition: protobuf/php/ext/google/protobuf/message.c:53
google::protobuf::Reflection::GetUInt64
uint64 GetUInt64(const Message &message, const FieldDescriptor *field) const
container
static struct async_container * container
Definition: benchmark-million-async.c:33
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
google::protobuf::python::MutableCProtoInsidePyProtoImpl
static Message * MutableCProtoInsidePyProtoImpl(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2863
google::protobuf::python::PyMessage_GetMutableMessagePointer
Message * PyMessage_GetMutableMessagePointer(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2881
google::protobuf::Message::MergeFrom
virtual void MergeFrom(const Message &from)
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.cc:81
google::protobuf::python::PyUnknownFields
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/unknown_fields.h:50
google::protobuf::python::repeated_composite_container::NewContainer
RepeatedCompositeContainer * NewContainer(CMessage *parent, const FieldDescriptor *parent_field_descriptor, CMessageClass *child_message_class)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc:471
google::protobuf::python::repeated_scalar_container::NewContainer
RepeatedScalarContainer * NewContainer(CMessage *parent, const FieldDescriptor *parent_field_descriptor)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:670
google::protobuf::python::CMessage::message
Message * message
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:104
google::protobuf::python::CheckAndGetInteger
bool CheckAndGetInteger(PyObject *arg, T *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:591
google::protobuf::FieldDescriptor::CPPTYPE_INT32
@ CPPTYPE_INT32
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:554
google::protobuf::python::message_meta::GetAttr
static PyObject * GetAttr(CMessageClass *self, PyObject *name)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:458
google::protobuf.internal.python_message.FindInitializationErrors
FindInitializationErrors
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1291
google::protobuf::python::WKT_classes
static PyObject * WKT_classes
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:106
google::protobuf::python::CMessageClass::super
PyHeapTypeObject super
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:151
google::protobuf::Reflection::GetDouble
double GetDouble(const Message &message, const FieldDescriptor *field) const


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:25