protobuf/python/google/protobuf/pyext/repeated_scalar_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: anuraag@google.com (Anuraag Agrawal)
32 // Author: tibell@google.com (Johan Tibell)
33 
34 #include <google/protobuf/pyext/repeated_scalar_container.h>
35 
36 #include <cstdint>
37 #include <memory>
38 
39 #include <google/protobuf/stubs/common.h>
40 #include <google/protobuf/stubs/logging.h>
41 #include <google/protobuf/descriptor.h>
42 #include <google/protobuf/dynamic_message.h>
43 #include <google/protobuf/message.h>
44 #include <google/protobuf/pyext/descriptor.h>
45 #include <google/protobuf/pyext/descriptor_pool.h>
46 #include <google/protobuf/pyext/message.h>
47 #include <google/protobuf/pyext/scoped_pyobject_ptr.h>
48 
49 #define PyString_AsString(ob) \
50  (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob))
51 
52 namespace google {
53 namespace protobuf {
54 namespace python {
55 
56 namespace repeated_scalar_container {
57 
59  PyObject* list) {
60  Message* message = self->parent->message;
61  message->GetReflection()->ClearField(message, self->parent_field_descriptor);
62  for (Py_ssize_t i = 0; i < PyList_GET_SIZE(list); ++i) {
63  PyObject* value = PyList_GET_ITEM(list, i);
64  if (ScopedPyObjectPtr(Append(self, value)) == nullptr) {
65  return -1;
66  }
67  }
68  return 0;
69 }
70 
71 static Py_ssize_t Len(PyObject* pself) {
73  reinterpret_cast<RepeatedScalarContainer*>(pself);
74  Message* message = self->parent->message;
75  return message->GetReflection()->FieldSize(*message,
76  self->parent_field_descriptor);
77 }
78 
79 static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
81  reinterpret_cast<RepeatedScalarContainer*>(pself);
82 
84  Message* message = self->parent->message;
85  const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
86 
87  const Reflection* reflection = message->GetReflection();
88  int field_size = reflection->FieldSize(*message, field_descriptor);
89  if (index < 0) {
90  index = field_size + index;
91  }
92  if (index < 0 || index >= field_size) {
93  PyErr_Format(PyExc_IndexError, "list assignment index (%d) out of range",
94  static_cast<int>(index));
95  return -1;
96  }
97 
98  if (arg == nullptr) {
99  ScopedPyObjectPtr py_index(PyLong_FromLong(index));
100  return cmessage::DeleteRepeatedField(self->parent, field_descriptor,
101  py_index.get());
102  }
103 
104  if (PySequence_Check(arg) && !(PyBytes_Check(arg) || PyUnicode_Check(arg))) {
105  PyErr_SetString(PyExc_TypeError, "Value must be scalar");
106  return -1;
107  }
108 
109  switch (field_descriptor->cpp_type()) {
112  reflection->SetRepeatedInt32(message, field_descriptor, index, value);
113  break;
114  }
117  reflection->SetRepeatedInt64(message, field_descriptor, index, value);
118  break;
119  }
122  reflection->SetRepeatedUInt32(message, field_descriptor, index, value);
123  break;
124  }
127  reflection->SetRepeatedUInt64(message, field_descriptor, index, value);
128  break;
129  }
132  reflection->SetRepeatedFloat(message, field_descriptor, index, value);
133  break;
134  }
137  reflection->SetRepeatedDouble(message, field_descriptor, index, value);
138  break;
139  }
142  reflection->SetRepeatedBool(message, field_descriptor, index, value);
143  break;
144  }
146  if (!CheckAndSetString(arg, message, field_descriptor, reflection, false,
147  index)) {
148  return -1;
149  }
150  break;
151  }
154  if (reflection->SupportsUnknownEnumValues()) {
155  reflection->SetRepeatedEnumValue(message, field_descriptor, index,
156  value);
157  } else {
158  const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
159  const EnumValueDescriptor* enum_value =
160  enum_descriptor->FindValueByNumber(value);
161  if (enum_value != nullptr) {
162  reflection->SetRepeatedEnum(message, field_descriptor, index,
163  enum_value);
164  } else {
165  ScopedPyObjectPtr s(PyObject_Str(arg));
166  if (s != nullptr) {
167  PyErr_Format(PyExc_ValueError, "Unknown enum value: %s",
168  PyString_AsString(s.get()));
169  }
170  return -1;
171  }
172  }
173  break;
174  }
175  default:
176  PyErr_Format(PyExc_SystemError,
177  "Adding value to a field of unknown type %d",
178  field_descriptor->cpp_type());
179  return -1;
180  }
181  return 0;
182 }
183 
184 static PyObject* Item(PyObject* pself, Py_ssize_t index) {
186  reinterpret_cast<RepeatedScalarContainer*>(pself);
187 
188  Message* message = self->parent->message;
189  const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
190  const Reflection* reflection = message->GetReflection();
191 
192  int field_size = reflection->FieldSize(*message, field_descriptor);
193  if (index < 0) {
194  index = field_size + index;
195  }
196  if (index < 0 || index >= field_size) {
197  PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
198  return nullptr;
199  }
200 
201  PyObject* result = nullptr;
202  switch (field_descriptor->cpp_type()) {
204  int32_t value =
205  reflection->GetRepeatedInt32(*message, field_descriptor, index);
206  result = PyLong_FromLong(value);
207  break;
208  }
210  int64_t value =
211  reflection->GetRepeatedInt64(*message, field_descriptor, index);
212  result = PyLong_FromLongLong(value);
213  break;
214  }
216  uint32_t value =
217  reflection->GetRepeatedUInt32(*message, field_descriptor, index);
218  result = PyLong_FromLongLong(value);
219  break;
220  }
222  uint64_t value =
223  reflection->GetRepeatedUInt64(*message, field_descriptor, index);
224  result = PyLong_FromUnsignedLongLong(value);
225  break;
226  }
228  float value =
229  reflection->GetRepeatedFloat(*message, field_descriptor, index);
230  result = PyFloat_FromDouble(value);
231  break;
232  }
234  double value =
235  reflection->GetRepeatedDouble(*message, field_descriptor, index);
236  result = PyFloat_FromDouble(value);
237  break;
238  }
240  bool value =
241  reflection->GetRepeatedBool(*message, field_descriptor, index);
242  result = PyBool_FromLong(value ? 1 : 0);
243  break;
244  }
246  const EnumValueDescriptor* enum_value =
247  message->GetReflection()->GetRepeatedEnum(*message, field_descriptor,
248  index);
249  result = PyLong_FromLong(enum_value->number());
250  break;
251  }
254  const std::string& value = reflection->GetRepeatedStringReference(
255  *message, field_descriptor, index, &scratch);
256  result = ToStringObject(field_descriptor, value);
257  break;
258  }
259  default:
260  PyErr_Format(PyExc_SystemError,
261  "Getting value from a repeated field of unknown type %d",
262  field_descriptor->cpp_type());
263  }
264 
265  return result;
266 }
267 
268 static PyObject* Subscript(PyObject* pself, PyObject* slice) {
269  Py_ssize_t from;
270  Py_ssize_t to;
271  Py_ssize_t step;
272  Py_ssize_t length;
273  Py_ssize_t slicelength;
274  bool return_list = false;
275  if (PyLong_Check(slice)) {
276  from = to = PyLong_AsLong(slice);
277  } else if (PySlice_Check(slice)) {
278  length = Len(pself);
279  if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
280  -1) {
281  return nullptr;
282  }
283  return_list = true;
284  } else {
285  PyErr_SetString(PyExc_TypeError, "list indices must be integers");
286  return nullptr;
287  }
288 
289  if (!return_list) {
290  return Item(pself, from);
291  }
292 
293  PyObject* list = PyList_New(0);
294  if (list == nullptr) {
295  return nullptr;
296  }
297  if (from <= to) {
298  if (step < 0) {
299  return list;
300  }
301  for (Py_ssize_t index = from; index < to; index += step) {
302  if (index < 0 || index >= length) {
303  break;
304  }
305  ScopedPyObjectPtr s(Item(pself, index));
306  PyList_Append(list, s.get());
307  }
308  } else {
309  if (step > 0) {
310  return list;
311  }
312  for (Py_ssize_t index = from; index > to; index += step) {
313  if (index < 0 || index >= length) {
314  break;
315  }
316  ScopedPyObjectPtr s(Item(pself, index));
317  PyList_Append(list, s.get());
318  }
319  }
320  return list;
321 }
322 
323 PyObject* Append(RepeatedScalarContainer* self, PyObject* item) {
325  Message* message = self->parent->message;
326  const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
327 
328  const Reflection* reflection = message->GetReflection();
329  switch (field_descriptor->cpp_type()) {
331  GOOGLE_CHECK_GET_INT32(item, value, nullptr);
332  reflection->AddInt32(message, field_descriptor, value);
333  break;
334  }
336  GOOGLE_CHECK_GET_INT64(item, value, nullptr);
337  reflection->AddInt64(message, field_descriptor, value);
338  break;
339  }
341  GOOGLE_CHECK_GET_UINT32(item, value, nullptr);
342  reflection->AddUInt32(message, field_descriptor, value);
343  break;
344  }
346  GOOGLE_CHECK_GET_UINT64(item, value, nullptr);
347  reflection->AddUInt64(message, field_descriptor, value);
348  break;
349  }
351  GOOGLE_CHECK_GET_FLOAT(item, value, nullptr);
352  reflection->AddFloat(message, field_descriptor, value);
353  break;
354  }
356  GOOGLE_CHECK_GET_DOUBLE(item, value, nullptr);
357  reflection->AddDouble(message, field_descriptor, value);
358  break;
359  }
361  GOOGLE_CHECK_GET_BOOL(item, value, nullptr);
362  reflection->AddBool(message, field_descriptor, value);
363  break;
364  }
366  if (!CheckAndSetString(item, message, field_descriptor, reflection, true,
367  -1)) {
368  return nullptr;
369  }
370  break;
371  }
373  GOOGLE_CHECK_GET_INT32(item, value, nullptr);
374  if (reflection->SupportsUnknownEnumValues()) {
375  reflection->AddEnumValue(message, field_descriptor, value);
376  } else {
377  const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();
378  const EnumValueDescriptor* enum_value =
379  enum_descriptor->FindValueByNumber(value);
380  if (enum_value != nullptr) {
381  reflection->AddEnum(message, field_descriptor, enum_value);
382  } else {
383  ScopedPyObjectPtr s(PyObject_Str(item));
384  if (s != nullptr) {
385  PyErr_Format(PyExc_ValueError, "Unknown enum value: %s",
386  PyString_AsString(s.get()));
387  }
388  return nullptr;
389  }
390  }
391  break;
392  }
393  default:
394  PyErr_Format(PyExc_SystemError,
395  "Adding value to a field of unknown type %d",
396  field_descriptor->cpp_type());
397  return nullptr;
398  }
399 
400  Py_RETURN_NONE;
401 }
402 
403 static PyObject* AppendMethod(PyObject* self, PyObject* item) {
404  return Append(reinterpret_cast<RepeatedScalarContainer*>(self), item);
405 }
406 
407 static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) {
409  reinterpret_cast<RepeatedScalarContainer*>(pself);
410 
411  Py_ssize_t from;
412  Py_ssize_t to;
413  Py_ssize_t step;
414  Py_ssize_t length;
415  Py_ssize_t slicelength;
416  bool create_list = false;
417 
419  Message* message = self->parent->message;
420  const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
421 
422  if (PyLong_Check(slice)) {
423  from = to = PyLong_AsLong(slice);
424  } else if (PySlice_Check(slice)) {
425  const Reflection* reflection = message->GetReflection();
426  length = reflection->FieldSize(*message, field_descriptor);
427  if (PySlice_GetIndicesEx(slice, length, &from, &to, &step, &slicelength) ==
428  -1) {
429  return -1;
430  }
431  create_list = true;
432  } else {
433  PyErr_SetString(PyExc_TypeError, "list indices must be integers");
434  return -1;
435  }
436 
437  if (value == nullptr) {
438  return cmessage::DeleteRepeatedField(self->parent, field_descriptor, slice);
439  }
440 
441  if (!create_list) {
442  return AssignItem(pself, from, value);
443  }
444 
445  ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
446  if (full_slice == nullptr) {
447  return -1;
448  }
449  ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
450  if (new_list == nullptr) {
451  return -1;
452  }
453  if (PySequence_SetSlice(new_list.get(), from, to, value) < 0) {
454  return -1;
455  }
456 
457  return InternalAssignRepeatedField(self, new_list.get());
458 }
459 
460 PyObject* Extend(RepeatedScalarContainer* self, PyObject* value) {
462 
463  // TODO(ptucker): Deprecate this behavior. b/18413862
464  if (value == Py_None) {
465  Py_RETURN_NONE;
466  }
467  if ((Py_TYPE(value)->tp_as_sequence == nullptr) && PyObject_Not(value)) {
468  Py_RETURN_NONE;
469  }
470 
471  ScopedPyObjectPtr iter(PyObject_GetIter(value));
472  if (iter == nullptr) {
473  PyErr_SetString(PyExc_TypeError, "Value must be iterable");
474  return nullptr;
475  }
477  while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
478  if (ScopedPyObjectPtr(Append(self, next.get())) == nullptr) {
479  return nullptr;
480  }
481  }
482  if (PyErr_Occurred()) {
483  return nullptr;
484  }
485  Py_RETURN_NONE;
486 }
487 
488 static PyObject* Insert(PyObject* pself, PyObject* args) {
490  reinterpret_cast<RepeatedScalarContainer*>(pself);
491 
492  Py_ssize_t index;
493  PyObject* value;
494  if (!PyArg_ParseTuple(args, "lO", &index, &value)) {
495  return nullptr;
496  }
497  ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
498  ScopedPyObjectPtr new_list(Subscript(pself, full_slice.get()));
499  if (PyList_Insert(new_list.get(), index, value) < 0) {
500  return nullptr;
501  }
502  int ret = InternalAssignRepeatedField(self, new_list.get());
503  if (ret < 0) {
504  return nullptr;
505  }
506  Py_RETURN_NONE;
507 }
508 
509 static PyObject* Remove(PyObject* pself, PyObject* value) {
510  Py_ssize_t match_index = -1;
511  for (Py_ssize_t i = 0; i < Len(pself); ++i) {
512  ScopedPyObjectPtr elem(Item(pself, i));
513  if (PyObject_RichCompareBool(elem.get(), value, Py_EQ)) {
514  match_index = i;
515  break;
516  }
517  }
518  if (match_index == -1) {
519  PyErr_SetString(PyExc_ValueError, "remove(x): x not in container");
520  return nullptr;
521  }
522  if (AssignItem(pself, match_index, nullptr) < 0) {
523  return nullptr;
524  }
525  Py_RETURN_NONE;
526 }
527 
528 static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
529  return Extend(reinterpret_cast<RepeatedScalarContainer*>(self), value);
530 }
531 
532 static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
533  if (opid != Py_EQ && opid != Py_NE) {
534  Py_INCREF(Py_NotImplemented);
535  return Py_NotImplemented;
536  }
537 
538  // Copy the contents of this repeated scalar container, and other if it is
539  // also a repeated scalar container, into Python lists so we can delegate
540  // to the list's compare method.
541 
542  ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
543  if (full_slice == nullptr) {
544  return nullptr;
545  }
546 
547  ScopedPyObjectPtr other_list_deleter;
548  if (PyObject_TypeCheck(other, &RepeatedScalarContainer_Type)) {
549  other_list_deleter.reset(Subscript(other, full_slice.get()));
550  other = other_list_deleter.get();
551  }
552 
553  ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
554  if (list == nullptr) {
555  return nullptr;
556  }
557  return PyObject_RichCompare(list.get(), other, opid);
558 }
559 
560 PyObject* Reduce(PyObject* unused_self, PyObject* unused_other) {
561  PyErr_Format(PickleError_class,
562  "can't pickle repeated message fields, convert to list first");
563  return nullptr;
564 }
565 
566 static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
567  // Support the old sort_function argument for backwards
568  // compatibility.
569  if (kwds != nullptr) {
570  PyObject* sort_func = PyDict_GetItemString(kwds, "sort_function");
571  if (sort_func != nullptr) {
572  // Must set before deleting as sort_func is a borrowed reference
573  // and kwds might be the only thing keeping it alive.
574  if (PyDict_SetItemString(kwds, "cmp", sort_func) == -1) return nullptr;
575  if (PyDict_DelItemString(kwds, "sort_function") == -1) return nullptr;
576  }
577  }
578 
579  ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
580  if (full_slice == nullptr) {
581  return nullptr;
582  }
583  ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
584  if (list == nullptr) {
585  return nullptr;
586  }
587  ScopedPyObjectPtr m(PyObject_GetAttrString(list.get(), "sort"));
588  if (m == nullptr) {
589  return nullptr;
590  }
591  ScopedPyObjectPtr res(PyObject_Call(m.get(), args, kwds));
592  if (res == nullptr) {
593  return nullptr;
594  }
596  reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
597  if (ret < 0) {
598  return nullptr;
599  }
600  Py_RETURN_NONE;
601 }
602 
603 static PyObject* Reverse(PyObject* pself) {
604  ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
605  if (full_slice == nullptr) {
606  return nullptr;
607  }
608  ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
609  if (list == nullptr) {
610  return nullptr;
611  }
612  ScopedPyObjectPtr res(PyObject_CallMethod(list.get(), "reverse", nullptr));
613  if (res == nullptr) {
614  return nullptr;
615  }
617  reinterpret_cast<RepeatedScalarContainer*>(pself), list.get());
618  if (ret < 0) {
619  return nullptr;
620  }
621  Py_RETURN_NONE;
622 }
623 
624 static PyObject* Pop(PyObject* pself, PyObject* args) {
625  Py_ssize_t index = -1;
626  if (!PyArg_ParseTuple(args, "|n", &index)) {
627  return nullptr;
628  }
629  PyObject* item = Item(pself, index);
630  if (item == nullptr) {
631  PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
632  return nullptr;
633  }
634  if (AssignItem(pself, index, nullptr) < 0) {
635  return nullptr;
636  }
637  return item;
638 }
639 
640 static PyObject* ToStr(PyObject* pself) {
641  ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
642  if (full_slice == nullptr) {
643  return nullptr;
644  }
645  ScopedPyObjectPtr list(Subscript(pself, full_slice.get()));
646  if (list == nullptr) {
647  return nullptr;
648  }
649  return PyObject_Repr(list.get());
650 }
651 
652 static PyObject* MergeFrom(PyObject* pself, PyObject* arg) {
653  return Extend(reinterpret_cast<RepeatedScalarContainer*>(pself), arg);
654 }
655 
656 // The private constructor of RepeatedScalarContainer objects.
658  CMessage* parent, const FieldDescriptor* parent_field_descriptor) {
659  if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
660  return nullptr;
661  }
662 
663  RepeatedScalarContainer* self = reinterpret_cast<RepeatedScalarContainer*>(
664  PyType_GenericAlloc(&RepeatedScalarContainer_Type, 0));
665  if (self == nullptr) {
666  return nullptr;
667  }
668 
669  Py_INCREF(parent);
670  self->parent = parent;
671  self->parent_field_descriptor = parent_field_descriptor;
672 
673  return self;
674 }
675 
676 PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
677  return reinterpret_cast<RepeatedScalarContainer*>(pself)->DeepCopy();
678 }
679 
680 static void Dealloc(PyObject* pself) {
681  reinterpret_cast<RepeatedScalarContainer*>(pself)->RemoveFromParentCache();
682  Py_TYPE(pself)->tp_free(pself);
683 }
684 
685 static PySequenceMethods SqMethods = {
686  Len, /* sq_length */
687  nullptr, /* sq_concat */
688  nullptr, /* sq_repeat */
689  Item, /* sq_item */
690  nullptr, /* sq_slice */
691  AssignItem /* sq_ass_item */
692 };
693 
694 static PyMappingMethods MpMethods = {
695  Len, /* mp_length */
696  Subscript, /* mp_subscript */
697  AssSubscript, /* mp_ass_subscript */
698 };
699 
700 static PyMethodDef Methods[] = {
701  {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
702  {"__reduce__", Reduce, METH_NOARGS,
703  "Outputs picklable representation of the repeated field."},
704  {"append", AppendMethod, METH_O,
705  "Appends an object to the repeated container."},
706  {"extend", ExtendMethod, METH_O,
707  "Appends objects to the repeated container."},
708  {"insert", Insert, METH_VARARGS,
709  "Inserts an object at the specified position in the container."},
710  {"pop", Pop, METH_VARARGS,
711  "Removes an object from the repeated container and returns it."},
712  {"remove", Remove, METH_O,
713  "Removes an object from the repeated container."},
714  {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
715  "Sorts the repeated container."},
716  {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
717  "Reverses elements order of the repeated container."},
718  {"MergeFrom", static_cast<PyCFunction>(MergeFrom), METH_O,
719  "Merges a repeated container into the current container."},
720  {nullptr, nullptr}};
721 
722 } // namespace repeated_scalar_container
723 
724 PyTypeObject RepeatedScalarContainer_Type = {
725  PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
726  ".RepeatedScalarContainer", // tp_name
727  sizeof(RepeatedScalarContainer), // tp_basicsize
728  0, // tp_itemsize
729  repeated_scalar_container::Dealloc, // tp_dealloc
730 #if PY_VERSION_HEX >= 0x03080000
731  0, // tp_vectorcall_offset
732 #else
733  nullptr, // tp_print
734 #endif
735  nullptr, // tp_getattr
736  nullptr, // tp_setattr
737  nullptr, // tp_compare
739  nullptr, // tp_as_number
740  &repeated_scalar_container::SqMethods, // tp_as_sequence
741  &repeated_scalar_container::MpMethods, // tp_as_mapping
742  PyObject_HashNotImplemented, // tp_hash
743  nullptr, // tp_call
744  nullptr, // tp_str
745  nullptr, // tp_getattro
746  nullptr, // tp_setattro
747  nullptr, // tp_as_buffer
748  Py_TPFLAGS_DEFAULT, // tp_flags
749  "A Repeated scalar container", // tp_doc
750  nullptr, // tp_traverse
751  nullptr, // tp_clear
752  repeated_scalar_container::RichCompare, // tp_richcompare
753  0, // tp_weaklistoffset
754  nullptr, // tp_iter
755  nullptr, // tp_iternext
757  nullptr, // tp_members
758  nullptr, // tp_getset
759  nullptr, // tp_base
760  nullptr, // tp_dict
761  nullptr, // tp_descr_get
762  nullptr, // tp_descr_set
763  0, // tp_dictoffset
764  nullptr, // tp_init
765 };
766 
767 } // namespace python
768 } // namespace protobuf
769 } // namespace google
google::protobuf::Reflection::AddUInt32
void AddUInt32(Message *message, const FieldDescriptor *field, uint32 value) const
google::protobuf::python::repeated_scalar_container::RichCompare
static PyObject * RichCompare(PyObject *pself, PyObject *other, int opid)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:563
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
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
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::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::ScopedPythonPtr::reset
PyObjectStruct * reset(PyObjectStruct *p=NULL)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:62
google::protobuf::FieldDescriptor::CPPTYPE_STRING
@ CPPTYPE_STRING
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:562
google::protobuf::Reflection::GetRepeatedFloat
float GetRepeatedFloat(const Message &message, const FieldDescriptor *field, int index) const
google::protobuf::python::repeated_scalar_container::MpMethods
static PyMappingMethods MpMethods
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:707
google::protobuf::python::repeated_scalar_container::Remove
static PyObject * Remove(PyObject *pself, PyObject *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:540
google::protobuf::python::CMessage
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:100
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::protobuf::python::repeated_scalar_container::Reduce
PyObject * Reduce(PyObject *unused_self, PyObject *unused_other)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:591
google::protobuf::Reflection::GetRepeatedStringReference
const std::string & GetRepeatedStringReference(const Message &message, const FieldDescriptor *field, int index, std::string *scratch) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1240
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
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::python::RepeatedScalarContainer
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h:48
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::repeated_scalar_container::Sort
static PyObject * Sort(PyObject *pself, PyObject *args, PyObject *kwds)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:598
google::protobuf::python::RepeatedScalarContainer_Type
PyTypeObject RepeatedScalarContainer_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:737
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
PyString_AsString
#define PyString_AsString(ob)
Definition: protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:49
GOOGLE_CHECK_GET_INT32
#define GOOGLE_CHECK_GET_INT32(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:288
google::protobuf::Reflection::SupportsUnknownEnumValues
bool SupportsUnknownEnumValues() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1824
FULL_MODULE_NAME
#define FULL_MODULE_NAME
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:331
absl::FormatConversionChar::s
@ s
google::protobuf::Reflection::AddInt32
void AddInt32(Message *message, const FieldDescriptor *field, int32 value) const
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
google::protobuf::python::ScopedPythonPtr
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h:46
google::protobuf::Reflection
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:397
google::protobuf::python::repeated_scalar_container::Insert
static PyObject * Insert(PyObject *pself, PyObject *args)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:519
google::protobuf::Reflection::AddDouble
void AddDouble(Message *message, const FieldDescriptor *field, double value) const
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
GOOGLE_CHECK_GET_UINT32
#define GOOGLE_CHECK_GET_UINT32(arg, value, err)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:300
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
google::protobuf::python::repeated_scalar_container::Len
static Py_ssize_t Len(PyObject *pself)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:77
google::protobuf::python::repeated_scalar_container::AssSubscript
static int AssSubscript(PyObject *pself, PyObject *slice, PyObject *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:427
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
google::protobuf::Reflection::GetRepeatedDouble
double GetRepeatedDouble(const Message &message, const FieldDescriptor *field, int index) const
google::protobuf::Reflection::AddEnum
void AddEnum(Message *message, const FieldDescriptor *field, const EnumValueDescriptor *value) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1405
google::protobuf::Reflection::GetRepeatedUInt32
uint32 GetRepeatedUInt32(const Message &message, const FieldDescriptor *field, int index) const
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
google::protobuf::Reflection::GetRepeatedInt32
int32 GetRepeatedInt32(const Message &message, const FieldDescriptor *field, int index) const
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::EnumValueDescriptor::number
int number() const
google::protobuf::python::repeated_scalar_container::ToStr
static PyObject * ToStr(PyObject *pself)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:653
arg
Definition: cmdline.cc:40
google::protobuf::Reflection::AddEnumValue
void AddEnumValue(Message *message, const FieldDescriptor *field, int value) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1412
EnumValueDescriptor
Definition: protobuf/php/ext/google/protobuf/def.c:63
google::protobuf::Reflection::SetRepeatedEnumValue
void SetRepeatedEnumValue(Message *message, const FieldDescriptor *field, int index, int value) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1377
google::protobuf::Reflection::SetRepeatedDouble
void SetRepeatedDouble(Message *message, const FieldDescriptor *field, int index, double value) const
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::FieldDescriptor::CPPTYPE_UINT64
@ CPPTYPE_UINT64
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:557
google::protobuf::python::repeated_scalar_container::Dealloc
static void Dealloc(PyObject *pself)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:693
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::Reflection::FieldSize
int FieldSize(const Message &message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:744
google::protobuf::Reflection::GetRepeatedInt64
int64 GetRepeatedInt64(const Message &message, const FieldDescriptor *field, int index) const
google::protobuf::Reflection::SetRepeatedUInt32
void SetRepeatedUInt32(Message *message, const FieldDescriptor *field, int index, uint32 value) const
google::protobuf::FieldDescriptor::enum_type
const EnumDescriptor * enum_type
Definition: protobuf/src/google/protobuf/descriptor.h:937
google::protobuf::python::cmessage::AssureWritable
int AssureWritable(CMessage *self)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:898
google::protobuf::Reflection::SetRepeatedInt64
void SetRepeatedInt64(Message *message, const FieldDescriptor *field, int index, int64 value) const
google::protobuf::python::repeated_scalar_container::MergeFrom
static PyObject * MergeFrom(PyObject *pself, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:665
google::protobuf::python::repeated_scalar_container::Pop
static PyObject * Pop(PyObject *pself, PyObject *args)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:637
google::protobuf::python::repeated_scalar_container::AppendMethod
static PyObject * AppendMethod(PyObject *self, PyObject *item)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:423
google::protobuf::Reflection::SetRepeatedInt32
void SetRepeatedInt32(Message *message, const FieldDescriptor *field, int index, int32 value) const
google::protobuf::FieldDescriptor::CPPTYPE_INT64
@ CPPTYPE_INT64
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:555
google::protobuf::python::repeated_scalar_container::Methods
static PyMethodDef Methods[]
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:713
google::protobuf::python::repeated_scalar_container::SqMethods
static PySequenceMethods SqMethods
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:698
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
scratch
static char scratch[256]
Definition: test-random.c:27
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::repeated_scalar_container::DeepCopy
PyObject * DeepCopy(PyObject *pself, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:689
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
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
google::protobuf::Reflection::AddFloat
void AddFloat(Message *message, const FieldDescriptor *field, float value) const
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
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
step
static int step
Definition: test-mutexes.c:31
google::protobuf::FieldDescriptor::CPPTYPE_ENUM
@ CPPTYPE_ENUM
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:561
google::protobuf::python::repeated_scalar_container::AssignItem
static int AssignItem(PyObject *pself, Py_ssize_t index, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:85
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::Reflection::SetRepeatedUInt64
void SetRepeatedUInt64(Message *message, const FieldDescriptor *field, int index, uint64 value) const
google::protobuf::EnumValueDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1075
google::protobuf::Reflection::GetRepeatedUInt64
uint64 GetRepeatedUInt64(const Message &message, const FieldDescriptor *field, int index) const
google::protobuf::Reflection::AddInt64
void AddInt64(Message *message, const FieldDescriptor *field, int64 value) const
google::protobuf::python::repeated_scalar_container::ExtendMethod
static PyObject * ExtendMethod(PyObject *self, PyObject *value)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:559
google::protobuf::python::repeated_scalar_container::Item
static PyObject * Item(PyObject *pself, Py_ssize_t index)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:191
google::protobuf::python::RepeatedScalarContainer
google::protobuf::python::RepeatedScalarContainer RepeatedScalarContainer
google::protobuf::python::repeated_scalar_container::Reverse
static PyObject * Reverse(PyObject *pself)
Definition: protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:603
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
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::python::repeated_scalar_container::Subscript
static PyObject * Subscript(PyObject *pself, PyObject *slice)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:278
Py_TYPE
#define Py_TYPE(ob)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:164
google::protobuf::Reflection::SetRepeatedBool
void SetRepeatedBool(Message *message, const FieldDescriptor *field, int index, bool value) const
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
google::protobuf::Reflection::SetRepeatedEnum
void SetRepeatedEnum(Message *message, const FieldDescriptor *field, int index, const EnumValueDescriptor *value) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1369
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
regress.m
m
Definition: regress/regress.py:25
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
google::protobuf::Reflection::GetRepeatedBool
bool GetRepeatedBool(const Message &message, const FieldDescriptor *field, int index) const
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::repeated_scalar_container::InternalAssignRepeatedField
static int InternalAssignRepeatedField(RepeatedScalarContainer *self, PyObject *list)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc:64
google::protobuf::FieldDescriptor::cpp_type
CppType cpp_type() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:2139
google::protobuf::Reflection::AddBool
void AddBool(Message *message, const FieldDescriptor *field, bool value) const
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
google::protobuf::Reflection::AddUInt64
void AddUInt64(Message *message, const FieldDescriptor *field, uint64 value) const
google::protobuf::python::CMessage::message
Message * message
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.h:104
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::Reflection::SetRepeatedFloat
void SetRepeatedFloat(Message *message, const FieldDescriptor *field, int index, float value) const
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 03:00:04