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


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:58