protobuf/python/google/protobuf/pyext/map_container.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: haberman@google.com (Josh Haberman)
32 
33 #include <google/protobuf/pyext/map_container.h>
34 
35 #include <cstdint>
36 #include <memory>
37 
38 #include <google/protobuf/stubs/logging.h>
39 #include <google/protobuf/stubs/common.h>
40 #include <google/protobuf/map.h>
41 #include <google/protobuf/map_field.h>
42 #include <google/protobuf/message.h>
43 #include <google/protobuf/pyext/message.h>
44 #include <google/protobuf/pyext/message_factory.h>
45 #include <google/protobuf/pyext/repeated_composite_container.h>
46 #include <google/protobuf/pyext/scoped_pyobject_ptr.h>
47 #include <google/protobuf/stubs/map_util.h>
48 
49 namespace google {
50 namespace protobuf {
51 namespace python {
52 
53 // Functions that need access to map reflection functionality.
54 // They need to be contained in this class because it is friended.
55 class MapReflectionFriend {
56  public:
57  // Methods that are in common between the map types.
58  static PyObject* Contains(PyObject* _self, PyObject* key);
59  static Py_ssize_t Length(PyObject* _self);
60  static PyObject* GetIterator(PyObject *_self);
61  static PyObject* IterNext(PyObject* _self);
62  static PyObject* MergeFrom(PyObject* _self, PyObject* arg);
63 
64  // Methods that differ between the map types.
65  static PyObject* ScalarMapGetItem(PyObject* _self, PyObject* key);
66  static PyObject* MessageMapGetItem(PyObject* _self, PyObject* key);
67  static int ScalarMapSetItem(PyObject* _self, PyObject* key, PyObject* v);
68  static int MessageMapSetItem(PyObject* _self, PyObject* key, PyObject* v);
69  static PyObject* ScalarMapToStr(PyObject* _self);
70  static PyObject* MessageMapToStr(PyObject* _self);
71 };
72 
73 struct MapIterator {
75 
76  std::unique_ptr<::google::protobuf::MapIterator> iter;
77 
78  // A pointer back to the container, so we can notice changes to the version.
79  // We own a ref on this.
80  MapContainer* container;
81 
82  // We need to keep a ref on the parent Message too, because
83  // MapIterator::~MapIterator() accesses it. Normally this would be ok because
84  // the ref on container (above) would guarantee outlive semantics. However in
85  // the case of ClearField(), the MapContainer points to a different message,
86  // a copy of the original. But our iterator still points to the original,
87  // which could now get deleted before us.
88  //
89  // To prevent this, we ensure that the Message will always stay alive as long
90  // as this iterator does. This is solely for the benefit of the MapIterator
91  // destructor -- we should never actually access the iterator in this state
92  // except to delete it.
94  // The version of the map when we took the iterator to it.
95  //
96  // We store this so that if the map is modified during iteration we can throw
97  // an error.
99 };
100 
103  return parent->message;
104 }
105 
106 // Consumes a reference on the Python string object.
107 static bool PyStringToSTL(PyObject* py_string, std::string* stl_string) {
108  char *value;
109  Py_ssize_t value_len;
110 
111  if (!py_string) {
112  return false;
113  }
114  if (PyBytes_AsStringAndSize(py_string, &value, &value_len) < 0) {
115  Py_DECREF(py_string);
116  return false;
117  } else {
118  stl_string->assign(value, value_len);
119  Py_DECREF(py_string);
120  return true;
121  }
122 }
123 
124 static bool PythonToMapKey(MapContainer* self, PyObject* obj, MapKey* key) {
125  const FieldDescriptor* field_descriptor =
126  self->parent_field_descriptor->message_type()->map_key();
127  switch (field_descriptor->cpp_type()) {
130  key->SetInt32Value(value);
131  break;
132  }
135  key->SetInt64Value(value);
136  break;
137  }
140  key->SetUInt32Value(value);
141  break;
142  }
145  key->SetUInt64Value(value);
146  break;
147  }
150  key->SetBoolValue(value);
151  break;
152  }
155  if (!PyStringToSTL(CheckString(obj, field_descriptor), &str)) {
156  return false;
157  }
158  key->SetStringValue(str);
159  break;
160  }
161  default:
162  PyErr_Format(
163  PyExc_SystemError, "Type %d cannot be a map key",
164  field_descriptor->cpp_type());
165  return false;
166  }
167  return true;
168 }
169 
170 static PyObject* MapKeyToPython(MapContainer* self, const MapKey& key) {
171  const FieldDescriptor* field_descriptor =
172  self->parent_field_descriptor->message_type()->map_key();
173  switch (field_descriptor->cpp_type()) {
175  return PyLong_FromLong(key.GetInt32Value());
177  return PyLong_FromLongLong(key.GetInt64Value());
179  return PyLong_FromSize_t(key.GetUInt32Value());
181  return PyLong_FromUnsignedLongLong(key.GetUInt64Value());
183  return PyBool_FromLong(key.GetBoolValue());
185  return ToStringObject(field_descriptor, key.GetStringValue());
186  default:
187  PyErr_Format(
188  PyExc_SystemError, "Couldn't convert type %d to value",
189  field_descriptor->cpp_type());
190  return NULL;
191  }
192 }
193 
194 // This is only used for ScalarMap, so we don't need to handle the
195 // CPPTYPE_MESSAGE case.
197  const FieldDescriptor* field_descriptor =
198  self->parent_field_descriptor->message_type()->map_value();
199  switch (field_descriptor->cpp_type()) {
201  return PyLong_FromLong(value.GetInt32Value());
203  return PyLong_FromLongLong(value.GetInt64Value());
205  return PyLong_FromSize_t(value.GetUInt32Value());
207  return PyLong_FromUnsignedLongLong(value.GetUInt64Value());
209  return PyFloat_FromDouble(value.GetFloatValue());
211  return PyFloat_FromDouble(value.GetDoubleValue());
213  return PyBool_FromLong(value.GetBoolValue());
215  return ToStringObject(field_descriptor, value.GetStringValue());
217  return PyLong_FromLong(value.GetEnumValue());
218  default:
219  PyErr_Format(
220  PyExc_SystemError, "Couldn't convert type %d to value",
221  field_descriptor->cpp_type());
222  return NULL;
223  }
224 }
225 
226 // This is only used for ScalarMap, so we don't need to handle the
227 // CPPTYPE_MESSAGE case.
228 static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
229  bool allow_unknown_enum_values,
230  MapValueRef* value_ref) {
231  const FieldDescriptor* field_descriptor =
232  self->parent_field_descriptor->message_type()->map_value();
233  switch (field_descriptor->cpp_type()) {
236  value_ref->SetInt32Value(value);
237  return true;
238  }
241  value_ref->SetInt64Value(value);
242  return true;
243  }
246  value_ref->SetUInt32Value(value);
247  return true;
248  }
251  value_ref->SetUInt64Value(value);
252  return true;
253  }
256  value_ref->SetFloatValue(value);
257  return true;
258  }
261  value_ref->SetDoubleValue(value);
262  return true;
263  }
266  value_ref->SetBoolValue(value);
267  return true;;
268  }
271  if (!PyStringToSTL(CheckString(obj, field_descriptor), &str)) {
272  return false;
273  }
274  value_ref->SetStringValue(str);
275  return true;
276  }
279  if (allow_unknown_enum_values) {
280  value_ref->SetEnumValue(value);
281  return true;
282  } else {
283  const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
284  const EnumValueDescriptor* enum_value =
285  enum_descriptor->FindValueByNumber(value);
286  if (enum_value != NULL) {
287  value_ref->SetEnumValue(value);
288  return true;
289  } else {
290  PyErr_Format(PyExc_ValueError, "Unknown enum value: %d", value);
291  return false;
292  }
293  }
294  break;
295  }
296  default:
297  PyErr_Format(
298  PyExc_SystemError, "Setting value to a field of unknown type %d",
299  field_descriptor->cpp_type());
300  return false;
301  }
302 }
303 
304 // Map methods common to ScalarMap and MessageMap //////////////////////////////
305 
306 static MapContainer* GetMap(PyObject* obj) {
307  return reinterpret_cast<MapContainer*>(obj);
308 }
309 
310 Py_ssize_t MapReflectionFriend::Length(PyObject* _self) {
311  MapContainer* self = GetMap(_self);
312  const google::protobuf::Message* message = self->parent->message;
313  return message->GetReflection()->MapSize(*message,
314  self->parent_field_descriptor);
315 }
316 
317 PyObject* Clear(PyObject* _self) {
318  MapContainer* self = GetMap(_self);
319  Message* message = self->GetMutableMessage();
320  const Reflection* reflection = message->GetReflection();
321 
322  reflection->ClearField(message, self->parent_field_descriptor);
323 
324  Py_RETURN_NONE;
325 }
326 
327 PyObject* GetEntryClass(PyObject* _self) {
328  MapContainer* self = GetMap(_self);
329  CMessageClass* message_class = message_factory::GetMessageClass(
331  self->parent_field_descriptor->message_type());
332  Py_XINCREF(message_class);
333  return reinterpret_cast<PyObject*>(message_class);
334 }
335 
336 PyObject* MapReflectionFriend::MergeFrom(PyObject* _self, PyObject* arg) {
337  MapContainer* self = GetMap(_self);
338  if (!PyObject_TypeCheck(arg, ScalarMapContainer_Type) &&
339  !PyObject_TypeCheck(arg, MessageMapContainer_Type)) {
340  PyErr_SetString(PyExc_AttributeError, "Not a map field");
341  return nullptr;
342  }
343  MapContainer* other_map = GetMap(arg);
344  Message* message = self->GetMutableMessage();
345  const Message* other_message = other_map->parent->message;
346  const Reflection* reflection = message->GetReflection();
347  const Reflection* other_reflection = other_message->GetReflection();
348  internal::MapFieldBase* field = reflection->MutableMapData(
349  message, self->parent_field_descriptor);
350  const internal::MapFieldBase* other_field = other_reflection->GetMapData(
351  *other_message, other_map->parent_field_descriptor);
352  field->MergeFrom(*other_field);
353  self->version++;
354  Py_RETURN_NONE;
355 }
356 
357 PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) {
358  MapContainer* self = GetMap(_self);
359 
360  const Message* message = self->parent->message;
361  const Reflection* reflection = message->GetReflection();
362  MapKey map_key;
363 
364  if (!PythonToMapKey(self, key, &map_key)) {
365  return NULL;
366  }
367 
368  if (reflection->ContainsMapKey(*message, self->parent_field_descriptor,
369  map_key)) {
370  Py_RETURN_TRUE;
371  } else {
372  Py_RETURN_FALSE;
373  }
374 }
375 
376 // ScalarMap ///////////////////////////////////////////////////////////////////
377 
378 MapContainer* NewScalarMapContainer(
379  CMessage* parent, const google::protobuf::FieldDescriptor* parent_field_descriptor) {
380  if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
381  return NULL;
382  }
383 
384  PyObject* obj(PyType_GenericAlloc(ScalarMapContainer_Type, 0));
385  if (obj == NULL) {
386  PyErr_Format(PyExc_RuntimeError,
387  "Could not allocate new container.");
388  return NULL;
389  }
390 
391  MapContainer* self = GetMap(obj);
392 
393  Py_INCREF(parent);
394  self->parent = parent;
395  self->parent_field_descriptor = parent_field_descriptor;
396  self->version = 0;
397 
398  return self;
399 }
400 
401 PyObject* MapReflectionFriend::ScalarMapGetItem(PyObject* _self,
402  PyObject* key) {
403  MapContainer* self = GetMap(_self);
404 
405  Message* message = self->GetMutableMessage();
406  const Reflection* reflection = message->GetReflection();
407  MapKey map_key;
408  MapValueRef value;
409 
410  if (!PythonToMapKey(self, key, &map_key)) {
411  return NULL;
412  }
413 
414  if (reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
415  map_key, &value)) {
416  self->version++;
417  }
418 
419  return MapValueRefToPython(self, value);
420 }
421 
422 int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
423  PyObject* v) {
424  MapContainer* self = GetMap(_self);
425 
426  Message* message = self->GetMutableMessage();
427  const Reflection* reflection = message->GetReflection();
428  MapKey map_key;
429  MapValueRef value;
430 
431  if (!PythonToMapKey(self, key, &map_key)) {
432  return -1;
433  }
434 
435  self->version++;
436 
437  if (v) {
438  // Set item to v.
439  reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
440  map_key, &value);
441 
442  if (!PythonToMapValueRef(self, v, reflection->SupportsUnknownEnumValues(),
443  &value)) {
444  return -1;
445  }
446  return 0;
447  } else {
448  // Delete key from map.
449  if (reflection->DeleteMapValue(message, self->parent_field_descriptor,
450  map_key)) {
451  return 0;
452  } else {
453  PyErr_Format(PyExc_KeyError, "Key not present in map");
454  return -1;
455  }
456  }
457 }
458 
459 static PyObject* ScalarMapGet(PyObject* self, PyObject* args,
460  PyObject* kwargs) {
461  static const char* kwlist[] = {"key", "default", nullptr};
462  PyObject* key;
463  PyObject* default_value = NULL;
464  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
465  const_cast<char**>(kwlist), &key,
466  &default_value)) {
467  return NULL;
468  }
469 
471  if (is_present.get() == NULL) {
472  return NULL;
473  }
474 
475  if (PyObject_IsTrue(is_present.get())) {
477  } else {
478  if (default_value != NULL) {
479  Py_INCREF(default_value);
480  return default_value;
481  } else {
482  Py_RETURN_NONE;
483  }
484  }
485 }
486 
487 PyObject* MapReflectionFriend::ScalarMapToStr(PyObject* _self) {
488  ScopedPyObjectPtr dict(PyDict_New());
489  if (dict == NULL) {
490  return NULL;
491  }
494 
495  MapContainer* self = GetMap(_self);
496  Message* message = self->GetMutableMessage();
497  const Reflection* reflection = message->GetReflection();
498  for (google::protobuf::MapIterator it = reflection->MapBegin(
499  message, self->parent_field_descriptor);
500  it != reflection->MapEnd(message, self->parent_field_descriptor);
501  ++it) {
502  key.reset(MapKeyToPython(self, it.GetKey()));
503  if (key == NULL) {
504  return NULL;
505  }
506  value.reset(MapValueRefToPython(self, it.GetValueRef()));
507  if (value == NULL) {
508  return NULL;
509  }
510  if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
511  return NULL;
512  }
513  }
514  return PyObject_Repr(dict.get());
515 }
516 
517 static void ScalarMapDealloc(PyObject* _self) {
518  MapContainer* self = GetMap(_self);
519  self->RemoveFromParentCache();
520  PyTypeObject *type = Py_TYPE(_self);
521  type->tp_free(_self);
522  if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
523  // With Python3, the Map class is not static, and must be managed.
524  Py_DECREF(type);
525  }
526 }
527 
528 static PyMethodDef ScalarMapMethods[] = {
529  {"__contains__", MapReflectionFriend::Contains, METH_O,
530  "Tests whether a key is a member of the map."},
531  {"clear", (PyCFunction)Clear, METH_NOARGS,
532  "Removes all elements from the map."},
533  {"get", (PyCFunction)ScalarMapGet, METH_VARARGS | METH_KEYWORDS,
534  "Gets the value for the given key if present, or otherwise a default"},
535  {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
536  "Return the class used to build Entries of (key, value) pairs."},
537  {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
538  "Merges a map into the current map."},
539  /*
540  { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
541  "Makes a deep copy of the class." },
542  { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
543  "Outputs picklable representation of the repeated field." },
544  */
545  {NULL, NULL},
546 };
547 
548 PyTypeObject* ScalarMapContainer_Type;
549 static PyType_Slot ScalarMapContainer_Type_slots[] = {
550  {Py_tp_dealloc, (void*)ScalarMapDealloc},
551  {Py_mp_length, (void*)MapReflectionFriend::Length},
552  {Py_mp_subscript, (void*)MapReflectionFriend::ScalarMapGetItem},
553  {Py_mp_ass_subscript, (void*)MapReflectionFriend::ScalarMapSetItem},
554  {Py_tp_methods, (void*)ScalarMapMethods},
555  {Py_tp_iter, (void*)MapReflectionFriend::GetIterator},
556  {Py_tp_repr, (void*)MapReflectionFriend::ScalarMapToStr},
557  {0, 0},
558 };
559 
561  FULL_MODULE_NAME ".ScalarMapContainer", sizeof(MapContainer), 0,
562  Py_TPFLAGS_DEFAULT, ScalarMapContainer_Type_slots};
563 
564 // MessageMap //////////////////////////////////////////////////////////////////
565 
567  return reinterpret_cast<MessageMapContainer*>(obj);
568 }
569 
570 static PyObject* GetCMessage(MessageMapContainer* self, Message* message) {
571  // Get or create the CMessage object corresponding to this message.
572  return self->parent
573  ->BuildSubMessageFromPointer(self->parent_field_descriptor, message,
574  self->message_class)
575  ->AsPyObject();
576 }
577 
578 MessageMapContainer* NewMessageMapContainer(
579  CMessage* parent, const google::protobuf::FieldDescriptor* parent_field_descriptor,
580  CMessageClass* message_class) {
581  if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
582  return NULL;
583  }
584 
585  PyObject* obj = PyType_GenericAlloc(MessageMapContainer_Type, 0);
586  if (obj == NULL) {
587  PyErr_SetString(PyExc_RuntimeError, "Could not allocate new container.");
588  return NULL;
589  }
590 
591  MessageMapContainer* self = GetMessageMap(obj);
592 
593  Py_INCREF(parent);
594  self->parent = parent;
595  self->parent_field_descriptor = parent_field_descriptor;
596  self->version = 0;
597 
598  Py_INCREF(message_class);
599  self->message_class = message_class;
600 
601  return self;
602 }
603 
604 int MapReflectionFriend::MessageMapSetItem(PyObject* _self, PyObject* key,
605  PyObject* v) {
606  if (v) {
607  PyErr_Format(PyExc_ValueError,
608  "Direct assignment of submessage not allowed");
609  return -1;
610  }
611 
612  // Now we know that this is a delete, not a set.
613 
614  MessageMapContainer* self = GetMessageMap(_self);
615  Message* message = self->GetMutableMessage();
616  const Reflection* reflection = message->GetReflection();
617  MapKey map_key;
618  MapValueRef value;
619 
620  self->version++;
621 
622  if (!PythonToMapKey(self, key, &map_key)) {
623  return -1;
624  }
625 
626  // Delete key from map.
627  if (reflection->ContainsMapKey(*message, self->parent_field_descriptor,
628  map_key)) {
629  // Delete key from CMessage dict.
630  MapValueRef value;
631  reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
632  map_key, &value);
633  Message* sub_message = value.MutableMessageValue();
634  // If there is a living weak reference to an item, we "Release" it,
635  // otherwise we just discard the C++ value.
636  if (CMessage* released =
637  self->parent->MaybeReleaseSubMessage(sub_message)) {
638  Message* msg = released->message;
639  released->message = msg->New();
640  msg->GetReflection()->Swap(msg, released->message);
641  }
642 
643  // Delete key from map.
644  reflection->DeleteMapValue(message, self->parent_field_descriptor,
645  map_key);
646  return 0;
647  } else {
648  PyErr_Format(PyExc_KeyError, "Key not present in map");
649  return -1;
650  }
651 }
652 
653 PyObject* MapReflectionFriend::MessageMapGetItem(PyObject* _self,
654  PyObject* key) {
655  MessageMapContainer* self = GetMessageMap(_self);
656 
657  Message* message = self->GetMutableMessage();
658  const Reflection* reflection = message->GetReflection();
659  MapKey map_key;
660  MapValueRef value;
661 
662  if (!PythonToMapKey(self, key, &map_key)) {
663  return NULL;
664  }
665 
666  if (reflection->InsertOrLookupMapValue(message, self->parent_field_descriptor,
667  map_key, &value)) {
668  self->version++;
669  }
670 
671  return GetCMessage(self, value.MutableMessageValue());
672 }
673 
674 PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) {
675  ScopedPyObjectPtr dict(PyDict_New());
676  if (dict == NULL) {
677  return NULL;
678  }
681 
682  MessageMapContainer* self = GetMessageMap(_self);
683  Message* message = self->GetMutableMessage();
684  const Reflection* reflection = message->GetReflection();
685  for (google::protobuf::MapIterator it = reflection->MapBegin(
686  message, self->parent_field_descriptor);
687  it != reflection->MapEnd(message, self->parent_field_descriptor);
688  ++it) {
689  key.reset(MapKeyToPython(self, it.GetKey()));
690  if (key == NULL) {
691  return NULL;
692  }
693  value.reset(GetCMessage(self, it.MutableValueRef()->MutableMessageValue()));
694  if (value == NULL) {
695  return NULL;
696  }
697  if (PyDict_SetItem(dict.get(), key.get(), value.get()) < 0) {
698  return NULL;
699  }
700  }
701  return PyObject_Repr(dict.get());
702 }
703 
704 PyObject* MessageMapGet(PyObject* self, PyObject* args, PyObject* kwargs) {
705  static const char* kwlist[] = {"key", "default", nullptr};
706  PyObject* key;
707  PyObject* default_value = NULL;
708  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
709  const_cast<char**>(kwlist), &key,
710  &default_value)) {
711  return NULL;
712  }
713 
715  if (is_present.get() == NULL) {
716  return NULL;
717  }
718 
719  if (PyObject_IsTrue(is_present.get())) {
721  } else {
722  if (default_value != NULL) {
723  Py_INCREF(default_value);
724  return default_value;
725  } else {
726  Py_RETURN_NONE;
727  }
728  }
729 }
730 
731 static void MessageMapDealloc(PyObject* _self) {
732  MessageMapContainer* self = GetMessageMap(_self);
733  self->RemoveFromParentCache();
734  Py_DECREF(self->message_class);
735  PyTypeObject *type = Py_TYPE(_self);
736  type->tp_free(_self);
737  if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
738  // With Python3, the Map class is not static, and must be managed.
739  Py_DECREF(type);
740  }
741 }
742 
743 static PyMethodDef MessageMapMethods[] = {
744  {"__contains__", (PyCFunction)MapReflectionFriend::Contains, METH_O,
745  "Tests whether the map contains this element."},
746  {"clear", (PyCFunction)Clear, METH_NOARGS,
747  "Removes all elements from the map."},
748  {"get", (PyCFunction)MessageMapGet, METH_VARARGS | METH_KEYWORDS,
749  "Gets the value for the given key if present, or otherwise a default"},
750  {"get_or_create", MapReflectionFriend::MessageMapGetItem, METH_O,
751  "Alias for getitem, useful to make explicit that the map is mutated."},
752  {"GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS,
753  "Return the class used to build Entries of (key, value) pairs."},
754  {"MergeFrom", (PyCFunction)MapReflectionFriend::MergeFrom, METH_O,
755  "Merges a map into the current map."},
756  /*
757  { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
758  "Makes a deep copy of the class." },
759  { "__reduce__", (PyCFunction)Reduce, METH_NOARGS,
760  "Outputs picklable representation of the repeated field." },
761  */
762  {NULL, NULL},
763 };
764 
765 PyTypeObject* MessageMapContainer_Type;
766 static PyType_Slot MessageMapContainer_Type_slots[] = {
767  {Py_tp_dealloc, (void*)MessageMapDealloc},
768  {Py_mp_length, (void*)MapReflectionFriend::Length},
769  {Py_mp_subscript, (void*)MapReflectionFriend::MessageMapGetItem},
770  {Py_mp_ass_subscript, (void*)MapReflectionFriend::MessageMapSetItem},
771  {Py_tp_methods, (void*)MessageMapMethods},
772  {Py_tp_iter, (void*)MapReflectionFriend::GetIterator},
773  {Py_tp_repr, (void*)MapReflectionFriend::MessageMapToStr},
774  {0, 0}};
775 
777  FULL_MODULE_NAME ".MessageMapContainer", sizeof(MessageMapContainer), 0,
778  Py_TPFLAGS_DEFAULT, MessageMapContainer_Type_slots};
779 
780 // MapIterator /////////////////////////////////////////////////////////////////
781 
782 static MapIterator* GetIter(PyObject* obj) {
783  return reinterpret_cast<MapIterator*>(obj);
784 }
785 
786 PyObject* MapReflectionFriend::GetIterator(PyObject *_self) {
787  MapContainer* self = GetMap(_self);
788 
789  ScopedPyObjectPtr obj(PyType_GenericAlloc(&MapIterator_Type, 0));
790  if (obj == NULL) {
791  return PyErr_Format(PyExc_KeyError, "Could not allocate iterator");
792  }
793 
794  MapIterator* iter = GetIter(obj.get());
795 
796  Py_INCREF(self);
797  iter->container = self;
798  iter->version = self->version;
799  Py_INCREF(self->parent);
800  iter->parent = self->parent;
801 
802  if (MapReflectionFriend::Length(_self) > 0) {
803  Message* message = self->GetMutableMessage();
804  const Reflection* reflection = message->GetReflection();
805 
806  iter->iter.reset(new ::google::protobuf::MapIterator(
807  reflection->MapBegin(message, self->parent_field_descriptor)));
808  }
809 
810  return obj.release();
811 }
812 
813 PyObject* MapReflectionFriend::IterNext(PyObject* _self) {
814  MapIterator* self = GetIter(_self);
815 
816  // This won't catch mutations to the map performed by MergeFrom(); no easy way
817  // to address that.
818  if (self->version != self->container->version) {
819  return PyErr_Format(PyExc_RuntimeError,
820  "Map modified during iteration.");
821  }
822  if (self->parent != self->container->parent) {
823  return PyErr_Format(PyExc_RuntimeError,
824  "Map cleared during iteration.");
825  }
826 
827  if (self->iter.get() == NULL) {
828  return NULL;
829  }
830 
831  Message* message = self->container->GetMutableMessage();
832  const Reflection* reflection = message->GetReflection();
833 
834  if (*self->iter ==
835  reflection->MapEnd(message, self->container->parent_field_descriptor)) {
836  return NULL;
837  }
838 
839  PyObject* ret = MapKeyToPython(self->container, self->iter->GetKey());
840 
841  ++(*self->iter);
842 
843  return ret;
844 }
845 
846 static void DeallocMapIterator(PyObject* _self) {
847  MapIterator* self = GetIter(_self);
848  self->iter.reset();
849  Py_CLEAR(self->container);
850  Py_CLEAR(self->parent);
851  Py_TYPE(_self)->tp_free(_self);
852 }
853 
854 PyTypeObject MapIterator_Type = {
855  PyVarObject_HEAD_INIT(&PyType_Type, 0)
856  FULL_MODULE_NAME ".MapIterator", // tp_name
857  sizeof(MapIterator), // tp_basicsize
858  0, // tp_itemsize
859  DeallocMapIterator, // tp_dealloc
860  0, // tp_print
861  0, // tp_getattr
862  0, // tp_setattr
863  0, // tp_compare
864  0, // tp_repr
865  0, // tp_as_number
866  0, // tp_as_sequence
867  0, // tp_as_mapping
868  0, // tp_hash
869  0, // tp_call
870  0, // tp_str
871  0, // tp_getattro
872  0, // tp_setattro
873  0, // tp_as_buffer
874  Py_TPFLAGS_DEFAULT, // tp_flags
875  "A scalar map iterator", // tp_doc
876  0, // tp_traverse
877  0, // tp_clear
878  0, // tp_richcompare
879  0, // tp_weaklistoffset
880  PyObject_SelfIter, // tp_iter
881  MapReflectionFriend::IterNext, // tp_iternext
882  0, // tp_methods
883  0, // tp_members
884  0, // tp_getset
885  0, // tp_base
886  0, // tp_dict
887  0, // tp_descr_get
888  0, // tp_descr_set
889  0, // tp_dictoffset
890  0, // tp_init
891 };
892 
893 bool InitMapContainers() {
894  // ScalarMapContainer_Type derives from our MutableMapping type.
895  ScopedPyObjectPtr abc(PyImport_ImportModule("collections.abc"));
896  if (abc == NULL) {
897  return false;
898  }
899 
900  ScopedPyObjectPtr mutable_mapping(
901  PyObject_GetAttrString(abc.get(), "MutableMapping"));
902  if (mutable_mapping == NULL) {
903  return false;
904  }
905 
906  Py_INCREF(mutable_mapping.get());
907  ScopedPyObjectPtr bases(PyTuple_Pack(1, mutable_mapping.get()));
908  if (bases == NULL) {
909  return false;
910  }
911 
912  ScalarMapContainer_Type = reinterpret_cast<PyTypeObject*>(
913  PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases.get()));
914 
915  if (PyType_Ready(&MapIterator_Type) < 0) {
916  return false;
917  }
918 
919  MessageMapContainer_Type = reinterpret_cast<PyTypeObject*>(
920  PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases.get()));
921  return true;
922 }
923 
924 } // namespace python
925 } // namespace protobuf
926 } // namespace google
google::protobuf::python::MapIterator::version
uint64_t version
Definition: protobuf/python/google/protobuf/pyext/map_container.cc:98
xds_interop_client.str
str
Definition: xds_interop_client.py:487
google::protobuf::Descriptor::map_key
const FieldDescriptor * map_key() const
Definition: protobuf/src/google/protobuf/descriptor.cc:2320
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
google::protobuf::python::InitMapContainers
bool InitMapContainers()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:1019
google::protobuf::python::GetCMessage
static PyObject * GetCMessage(MessageMapContainer *self, Message *message)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:630
google::protobuf::MapValueRef::SetBoolValue
void SetBoolValue(bool value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:585
google::protobuf::python::MapReflectionFriend::ScalarMapToStr
static PyObject * ScalarMapToStr(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:493
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::MapValueRefToPython
PyObject * MapValueRefToPython(const FieldDescriptor *field_descriptor, const MapValueRef &value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:199
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::MapContainer::GetMutableMessage
Message * GetMutableMessage()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:105
google::protobuf::FieldDescriptor::CPPTYPE_STRING
@ CPPTYPE_STRING
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:562
google::protobuf::python::MapContainer
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.h:53
google::protobuf::python::ToStringObject
PyObject * ToStringObject(const FieldDescriptor *descriptor, const string &value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:799
scalar
Definition: spake25519.c:317
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::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::FieldDescriptor::message_type
const Descriptor * message_type
Definition: protobuf/src/google/protobuf/descriptor.h:936
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
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::MapReflectionFriend::MessageMapGetItem
static PyObject * MessageMapGetItem(PyObject *_self, PyObject *key)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:726
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
GOOGLE_CHECK_GET_INT32
#define GOOGLE_CHECK_GET_INT32(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:288
FULL_MODULE_NAME
#define FULL_MODULE_NAME
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:331
google::protobuf::python::ScopedPythonPtr
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:46
google::protobuf::python::MessageMapGet
PyObject * MessageMapGet(PyObject *self, PyObject *args, PyObject *kwargs)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:778
google::protobuf::python::MessageMapMethods
static PyMethodDef MessageMapMethods[]
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:816
iterator
const typedef MCPhysReg * iterator
Definition: MCRegisterInfo.h:27
google::protobuf::python::MapIterator::PyObject_HEAD
PyObject_HEAD
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:78
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
google::protobuf::MapValueRef::SetUInt32Value
void SetUInt32Value(uint32 value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:581
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::ScalarMapDealloc
static void ScalarMapDealloc(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:525
google::protobuf::python::IterNext
PyObject * IterNext(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/extension_dict.cc:410
google::protobuf::python::GetIter
static MapIterator * GetIter(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:907
google::protobuf::python::ScalarMapContainer_Type_spec
PyType_Spec ScalarMapContainer_Type_spec
Definition: protobuf/python/google/protobuf/pyext/map_container.cc:560
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
GOOGLE_CHECK_GET_BOOL
#define GOOGLE_CHECK_GET_BOOL(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:324
google::protobuf::python::MapReflectionFriend::MessageMapToStr
static PyObject * MessageMapToStr(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:747
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::GetMap
static MapContainer * GetMap(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:307
google::protobuf::python::MessageMapDealloc
static void MessageMapDealloc(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:804
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
google::protobuf::python::DeallocMapIterator
static void DeallocMapIterator(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:972
google::protobuf::python::MapIterator_Type
PyTypeObject MapIterator_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:980
google::protobuf::MapValueRef::SetFloatValue
void SetFloatValue(float value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:598
google::protobuf::python::MapReflectionFriend::Length
static Py_ssize_t Length(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:311
google::protobuf::python::MessageMapContainer_Type
PyTypeObject * MessageMapContainer_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:838
google::protobuf::python::GetEntryClass
PyObject * GetEntryClass(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:328
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
google::protobuf::MapValueRef::SetEnumValue
void SetEnumValue(int value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:590
google::protobuf::python::MapReflectionFriend::Contains
static PyObject * Contains(PyObject *_self, PyObject *key)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:353
arg
Definition: cmdline.cc:40
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
google::protobuf::MapValueRef::SetUInt64Value
void SetUInt64Value(uint64 value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:573
google::protobuf::python::PythonToMapKey
static bool PythonToMapKey(PyObject *obj, const FieldDescriptor *field_descriptor, MapKey *key)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:128
google::protobuf::MapValueRef::SetInt32Value
void SetInt32Value(int32 value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:577
google::protobuf::FieldDescriptor::CPPTYPE_UINT64
@ CPPTYPE_UINT64
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:557
GOOGLE_CHECK_GET_UINT64
#define GOOGLE_CHECK_GET_UINT64(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:306
google::protobuf::python::MessageMapContainer_Type_slots
static PyType_Slot MessageMapContainer_Type_slots[]
Definition: protobuf/python/google/protobuf/pyext/map_container.cc:766
google::protobuf::FieldDescriptor::enum_type
const EnumDescriptor * enum_type
Definition: protobuf/src/google/protobuf/descriptor.h:937
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
google::protobuf::python::cmessage::AssureWritable
int AssureWritable(CMessage *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:898
google::protobuf::python::ScalarMapContainer_Type_slots
static PyType_Slot ScalarMapContainer_Type_slots[]
Definition: protobuf/python/google/protobuf/pyext/map_container.cc:549
google::protobuf::MapValueRef::SetInt64Value
void SetInt64Value(int64 value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:569
google::protobuf::FieldDescriptor::CPPTYPE_INT64
@ CPPTYPE_INT64
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:555
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
google::protobuf::python::MapIterator::iter
std::unique_ptr<::google::protobuf::MapIterator > iter
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:80
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
key
const char * key
Definition: hpack_parser_table.cc:164
google::protobuf::python::CMessage
google::protobuf::python::CMessage CMessage
google::protobuf::python::GetMessageMap
static MessageMapContainer * GetMessageMap(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:626
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::ScalarMapMethods
static PyMethodDef ScalarMapMethods[]
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:536
google::protobuf::python::cmessage::GetFactoryForMessage
PyMessageFactory * GetFactoryForMessage(CMessage *message)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:830
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
google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE
@ CPPTYPE_DOUBLE
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:558
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
google::protobuf::MapKey
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:371
google::protobuf::python::MapReflectionFriend::GetIterator
static PyObject * GetIterator(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:911
google::protobuf::python::MapIterator::parent
CMessage * parent
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:97
google::protobuf::python::PythonToMapValueRef
static bool PythonToMapValueRef(PyObject *obj, const FieldDescriptor *field_descriptor, bool allow_unknown_enum_values, MapValueRef *value_ref)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:230
google::protobuf::FieldDescriptor::CPPTYPE_ENUM
@ CPPTYPE_ENUM
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:561
A
Definition: miscompile_with_no_unique_address_test.cc:23
google::protobuf::python::MapIterator
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:77
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::MapValueRef::SetDoubleValue
void SetDoubleValue(double value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:602
google::protobuf::EnumValueDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1075
google::protobuf::MapValueRef::SetStringValue
void SetStringValue(const std::string &value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:594
google::protobuf::python::ContainerBase::parent
struct CMessage * parent
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:82
google::protobuf::python::MessageMapContainer_Type_spec
PyType_Spec MessageMapContainer_Type_spec
Definition: protobuf/python/google/protobuf/pyext/map_container.cc:776
google::protobuf::python::MapReflectionFriend::ScalarMapGetItem
static PyObject * ScalarMapGetItem(PyObject *_self, PyObject *key)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:409
google::protobuf::python::MapKeyToPython
static PyObject * MapKeyToPython(const FieldDescriptor *field_descriptor, const MapKey &key)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:174
google::protobuf::python::MapReflectionFriend::ScalarMapSetItem
static int ScalarMapSetItem(PyObject *_self, PyObject *key, PyObject *v)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:430
PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:161
iter
Definition: test_winkernel.cpp:47
google::protobuf::Descriptor::map_value
const FieldDescriptor * map_value() const
Definition: protobuf/src/google/protobuf/descriptor.cc:2326
google::protobuf::python::MapReflectionFriend::IterNext
static PyObject * IterNext(PyObject *_self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:938
google::protobuf::python::ScalarMapGet
static PyObject * ScalarMapGet(PyObject *self, PyObject *args, PyObject *kwargs)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:466
Py_TYPE
#define Py_TYPE(ob)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:164
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
google::protobuf::python::PyStringToSTL
static bool PyStringToSTL(PyObject *py_string, string *stl_string)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:111
google::protobuf::MapIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:712
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::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::MapReflectionFriend::MergeFrom
static PyObject * MergeFrom(PyObject *_self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:337
google::protobuf::python::MapIterator::container
MapContainer * container
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:84
google::protobuf::python::MessageMapContainer
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.h:65
google::protobuf::FieldDescriptor::cpp_type
CppType cpp_type() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:2139
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::MapReflectionFriend::MessageMapSetItem
static int MessageMapSetItem(PyObject *_self, PyObject *key, PyObject *v)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:677
google::protobuf::python::ScalarMapContainer_Type
PyTypeObject * ScalarMapContainer_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/map_container.cc:556
Message
Definition: protobuf/php/ext/google/protobuf/message.c:53
google::protobuf::python::CMessage::message
Message * message
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:104
google::protobuf::MapValueRef
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:565
google::protobuf::FieldDescriptor::CPPTYPE_INT32
@ CPPTYPE_INT32
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:554


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