repeated_composite_container.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. // Author: anuraag@google.com (Anuraag Agrawal)
  31. // Author: tibell@google.com (Johan Tibell)
  32. #include <google/protobuf/pyext/repeated_composite_container.h>
  33. #include <memory>
  34. #include <google/protobuf/stubs/logging.h>
  35. #include <google/protobuf/stubs/common.h>
  36. #include <google/protobuf/descriptor.h>
  37. #include <google/protobuf/dynamic_message.h>
  38. #include <google/protobuf/message.h>
  39. #include <google/protobuf/pyext/descriptor.h>
  40. #include <google/protobuf/pyext/descriptor_pool.h>
  41. #include <google/protobuf/pyext/message.h>
  42. #include <google/protobuf/pyext/message_factory.h>
  43. #include <google/protobuf/pyext/scoped_pyobject_ptr.h>
  44. #include <google/protobuf/reflection.h>
  45. #include <google/protobuf/stubs/map_util.h>
  46. #if PY_MAJOR_VERSION >= 3
  47. #define PyInt_Check PyLong_Check
  48. #define PyInt_AsLong PyLong_AsLong
  49. #define PyInt_FromLong PyLong_FromLong
  50. #endif
  51. namespace google {
  52. namespace protobuf {
  53. namespace python {
  54. namespace repeated_composite_container {
  55. // ---------------------------------------------------------------------
  56. // len()
  57. static Py_ssize_t Length(PyObject* pself) {
  58. RepeatedCompositeContainer* self =
  59. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  60. Message* message = self->parent->message;
  61. return message->GetReflection()->FieldSize(*message,
  62. self->parent_field_descriptor);
  63. }
  64. // ---------------------------------------------------------------------
  65. // add()
  66. PyObject* Add(RepeatedCompositeContainer* self, PyObject* args,
  67. PyObject* kwargs) {
  68. if (cmessage::AssureWritable(self->parent) == -1) return nullptr;
  69. Message* message = self->parent->message;
  70. Message* sub_message =
  71. message->GetReflection()->AddMessage(
  72. message,
  73. self->parent_field_descriptor,
  74. self->child_message_class->py_message_factory->message_factory);
  75. CMessage* cmsg = self->parent->BuildSubMessageFromPointer(
  76. self->parent_field_descriptor, sub_message, self->child_message_class);
  77. if (cmessage::InitAttributes(cmsg, args, kwargs) < 0) {
  78. message->GetReflection()->RemoveLast(
  79. message, self->parent_field_descriptor);
  80. Py_DECREF(cmsg);
  81. return nullptr;
  82. }
  83. return cmsg->AsPyObject();
  84. }
  85. static PyObject* AddMethod(PyObject* self, PyObject* args, PyObject* kwargs) {
  86. return Add(reinterpret_cast<RepeatedCompositeContainer*>(self), args, kwargs);
  87. }
  88. // ---------------------------------------------------------------------
  89. // append()
  90. static PyObject* AddMessage(RepeatedCompositeContainer* self, PyObject* value) {
  91. cmessage::AssureWritable(self->parent);
  92. PyObject* py_cmsg;
  93. Message* message = self->parent->message;
  94. const Reflection* reflection = message->GetReflection();
  95. py_cmsg = Add(self, nullptr, nullptr);
  96. if (py_cmsg == nullptr) return nullptr;
  97. CMessage* cmsg = reinterpret_cast<CMessage*>(py_cmsg);
  98. if (ScopedPyObjectPtr(cmessage::MergeFrom(cmsg, value)) == nullptr) {
  99. reflection->RemoveLast(
  100. message, self->parent_field_descriptor);
  101. Py_DECREF(cmsg);
  102. return nullptr;
  103. }
  104. return py_cmsg;
  105. }
  106. static PyObject* AppendMethod(PyObject* pself, PyObject* value) {
  107. RepeatedCompositeContainer* self =
  108. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  109. ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
  110. if (py_cmsg == nullptr) {
  111. return nullptr;
  112. }
  113. Py_RETURN_NONE;
  114. }
  115. // ---------------------------------------------------------------------
  116. // insert()
  117. static PyObject* Insert(PyObject* pself, PyObject* args) {
  118. RepeatedCompositeContainer* self =
  119. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  120. Py_ssize_t index;
  121. PyObject* value;
  122. if (!PyArg_ParseTuple(args, "nO", &index, &value)) {
  123. return nullptr;
  124. }
  125. ScopedPyObjectPtr py_cmsg(AddMessage(self, value));
  126. if (py_cmsg == nullptr) {
  127. return nullptr;
  128. }
  129. // Swap the element to right position.
  130. Message* message = self->parent->message;
  131. const Reflection* reflection = message->GetReflection();
  132. const FieldDescriptor* field_descriptor = self->parent_field_descriptor;
  133. Py_ssize_t length = reflection->FieldSize(*message, field_descriptor) - 1;
  134. Py_ssize_t end_index = index;
  135. if (end_index < 0) end_index += length;
  136. if (end_index < 0) end_index = 0;
  137. for (Py_ssize_t i = length; i > end_index; i --) {
  138. reflection->SwapElements(message, field_descriptor, i, i - 1);
  139. }
  140. Py_RETURN_NONE;
  141. }
  142. // ---------------------------------------------------------------------
  143. // extend()
  144. PyObject* Extend(RepeatedCompositeContainer* self, PyObject* value) {
  145. cmessage::AssureWritable(self->parent);
  146. ScopedPyObjectPtr iter(PyObject_GetIter(value));
  147. if (iter == nullptr) {
  148. PyErr_SetString(PyExc_TypeError, "Value must be iterable");
  149. return nullptr;
  150. }
  151. ScopedPyObjectPtr next;
  152. while ((next.reset(PyIter_Next(iter.get()))) != nullptr) {
  153. if (!PyObject_TypeCheck(next.get(), CMessage_Type)) {
  154. PyErr_SetString(PyExc_TypeError, "Not a cmessage");
  155. return nullptr;
  156. }
  157. ScopedPyObjectPtr new_message(Add(self, nullptr, nullptr));
  158. if (new_message == nullptr) {
  159. return nullptr;
  160. }
  161. CMessage* new_cmessage = reinterpret_cast<CMessage*>(new_message.get());
  162. if (ScopedPyObjectPtr(cmessage::MergeFrom(new_cmessage, next.get())) ==
  163. nullptr) {
  164. return nullptr;
  165. }
  166. }
  167. if (PyErr_Occurred()) {
  168. return nullptr;
  169. }
  170. Py_RETURN_NONE;
  171. }
  172. static PyObject* ExtendMethod(PyObject* self, PyObject* value) {
  173. return Extend(reinterpret_cast<RepeatedCompositeContainer*>(self), value);
  174. }
  175. PyObject* MergeFrom(RepeatedCompositeContainer* self, PyObject* other) {
  176. return Extend(self, other);
  177. }
  178. static PyObject* MergeFromMethod(PyObject* self, PyObject* other) {
  179. return MergeFrom(reinterpret_cast<RepeatedCompositeContainer*>(self), other);
  180. }
  181. // This function does not check the bounds.
  182. static PyObject* GetItem(RepeatedCompositeContainer* self, Py_ssize_t index,
  183. Py_ssize_t length = -1) {
  184. if (length == -1) {
  185. Message* message = self->parent->message;
  186. const Reflection* reflection = message->GetReflection();
  187. length = reflection->FieldSize(*message, self->parent_field_descriptor);
  188. }
  189. if (index < 0 || index >= length) {
  190. PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
  191. return nullptr;
  192. }
  193. Message* message = self->parent->message;
  194. Message* sub_message = message->GetReflection()->MutableRepeatedMessage(
  195. message, self->parent_field_descriptor, index);
  196. return self->parent
  197. ->BuildSubMessageFromPointer(self->parent_field_descriptor, sub_message,
  198. self->child_message_class)
  199. ->AsPyObject();
  200. }
  201. PyObject* Subscript(RepeatedCompositeContainer* self, PyObject* item) {
  202. Message* message = self->parent->message;
  203. const Reflection* reflection = message->GetReflection();
  204. Py_ssize_t length =
  205. reflection->FieldSize(*message, self->parent_field_descriptor);
  206. if (PyIndex_Check(item)) {
  207. Py_ssize_t index;
  208. index = PyNumber_AsSsize_t(item, PyExc_IndexError);
  209. if (index == -1 && PyErr_Occurred()) return nullptr;
  210. if (index < 0) index += length;
  211. return GetItem(self, index, length);
  212. } else if (PySlice_Check(item)) {
  213. Py_ssize_t from, to, step, slicelength, cur, i;
  214. PyObject* result;
  215. #if PY_MAJOR_VERSION >= 3
  216. if (PySlice_GetIndicesEx(item,
  217. length, &from, &to, &step, &slicelength) == -1) {
  218. #else
  219. if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(item),
  220. length, &from, &to, &step, &slicelength) == -1) {
  221. #endif
  222. return nullptr;
  223. }
  224. if (slicelength <= 0) {
  225. return PyList_New(0);
  226. } else {
  227. result = PyList_New(slicelength);
  228. if (!result) return nullptr;
  229. for (cur = from, i = 0; i < slicelength; cur += step, i++) {
  230. PyList_SET_ITEM(result, i, GetItem(self, cur, length));
  231. }
  232. return result;
  233. }
  234. } else {
  235. PyErr_Format(PyExc_TypeError, "indices must be integers, not %.200s",
  236. item->ob_type->tp_name);
  237. return nullptr;
  238. }
  239. }
  240. static PyObject* SubscriptMethod(PyObject* self, PyObject* slice) {
  241. return Subscript(reinterpret_cast<RepeatedCompositeContainer*>(self), slice);
  242. }
  243. int AssignSubscript(RepeatedCompositeContainer* self,
  244. PyObject* slice,
  245. PyObject* value) {
  246. if (value != nullptr) {
  247. PyErr_SetString(PyExc_TypeError, "does not support assignment");
  248. return -1;
  249. }
  250. return cmessage::DeleteRepeatedField(self->parent,
  251. self->parent_field_descriptor, slice);
  252. }
  253. static int AssignSubscriptMethod(PyObject* self, PyObject* slice,
  254. PyObject* value) {
  255. return AssignSubscript(reinterpret_cast<RepeatedCompositeContainer*>(self),
  256. slice, value);
  257. }
  258. static PyObject* Remove(PyObject* pself, PyObject* value) {
  259. RepeatedCompositeContainer* self =
  260. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  261. Py_ssize_t len = Length(reinterpret_cast<PyObject*>(self));
  262. for (Py_ssize_t i = 0; i < len; i++) {
  263. ScopedPyObjectPtr item(GetItem(self, i, len));
  264. if (item == nullptr) {
  265. return nullptr;
  266. }
  267. int result = PyObject_RichCompareBool(item.get(), value, Py_EQ);
  268. if (result < 0) {
  269. return nullptr;
  270. }
  271. if (result) {
  272. ScopedPyObjectPtr py_index(PyLong_FromSsize_t(i));
  273. if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
  274. return nullptr;
  275. }
  276. Py_RETURN_NONE;
  277. }
  278. }
  279. PyErr_SetString(PyExc_ValueError, "Item to delete not in list");
  280. return nullptr;
  281. }
  282. static PyObject* RichCompare(PyObject* pself, PyObject* other, int opid) {
  283. RepeatedCompositeContainer* self =
  284. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  285. if (!PyObject_TypeCheck(other, &RepeatedCompositeContainer_Type)) {
  286. PyErr_SetString(PyExc_TypeError,
  287. "Can only compare repeated composite fields "
  288. "against other repeated composite fields.");
  289. return nullptr;
  290. }
  291. if (opid == Py_EQ || opid == Py_NE) {
  292. // TODO(anuraag): Don't make new lists just for this...
  293. ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
  294. if (full_slice == nullptr) {
  295. return nullptr;
  296. }
  297. ScopedPyObjectPtr list(Subscript(self, full_slice.get()));
  298. if (list == nullptr) {
  299. return nullptr;
  300. }
  301. ScopedPyObjectPtr other_list(
  302. Subscript(reinterpret_cast<RepeatedCompositeContainer*>(other),
  303. full_slice.get()));
  304. if (other_list == nullptr) {
  305. return nullptr;
  306. }
  307. return PyObject_RichCompare(list.get(), other_list.get(), opid);
  308. } else {
  309. Py_INCREF(Py_NotImplemented);
  310. return Py_NotImplemented;
  311. }
  312. }
  313. static PyObject* ToStr(PyObject* pself) {
  314. ScopedPyObjectPtr full_slice(PySlice_New(nullptr, nullptr, nullptr));
  315. if (full_slice == nullptr) {
  316. return nullptr;
  317. }
  318. ScopedPyObjectPtr list(Subscript(
  319. reinterpret_cast<RepeatedCompositeContainer*>(pself), full_slice.get()));
  320. if (list == nullptr) {
  321. return nullptr;
  322. }
  323. return PyObject_Repr(list.get());
  324. }
  325. // ---------------------------------------------------------------------
  326. // sort()
  327. static void ReorderAttached(RepeatedCompositeContainer* self,
  328. PyObject* child_list) {
  329. Message* message = self->parent->message;
  330. const Reflection* reflection = message->GetReflection();
  331. const FieldDescriptor* descriptor = self->parent_field_descriptor;
  332. const Py_ssize_t length = Length(reinterpret_cast<PyObject*>(self));
  333. // Since Python protobuf objects are never arena-allocated, adding and
  334. // removing message pointers to the underlying array is just updating
  335. // pointers.
  336. for (Py_ssize_t i = 0; i < length; ++i)
  337. reflection->ReleaseLast(message, descriptor);
  338. for (Py_ssize_t i = 0; i < length; ++i) {
  339. CMessage* py_cmsg = reinterpret_cast<CMessage*>(
  340. PyList_GET_ITEM(child_list, i));
  341. reflection->AddAllocatedMessage(message, descriptor, py_cmsg->message);
  342. }
  343. }
  344. // Returns 0 if successful; returns -1 and sets an exception if
  345. // unsuccessful.
  346. static int SortPythonMessages(RepeatedCompositeContainer* self,
  347. PyObject* args,
  348. PyObject* kwds) {
  349. ScopedPyObjectPtr child_list(
  350. PySequence_List(reinterpret_cast<PyObject*>(self)));
  351. if (child_list == nullptr) {
  352. return -1;
  353. }
  354. ScopedPyObjectPtr m(PyObject_GetAttrString(child_list.get(), "sort"));
  355. if (m == nullptr) return -1;
  356. if (ScopedPyObjectPtr(PyObject_Call(m.get(), args, kwds)) == nullptr)
  357. return -1;
  358. ReorderAttached(self, child_list.get());
  359. return 0;
  360. }
  361. static PyObject* Sort(PyObject* pself, PyObject* args, PyObject* kwds) {
  362. RepeatedCompositeContainer* self =
  363. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  364. // Support the old sort_function argument for backwards
  365. // compatibility.
  366. if (kwds != nullptr) {
  367. PyObject* sort_func = PyDict_GetItemString(kwds, "sort_function");
  368. if (sort_func != nullptr) {
  369. // Must set before deleting as sort_func is a borrowed reference
  370. // and kwds might be the only thing keeping it alive.
  371. PyDict_SetItemString(kwds, "cmp", sort_func);
  372. PyDict_DelItemString(kwds, "sort_function");
  373. }
  374. }
  375. if (SortPythonMessages(self, args, kwds) < 0) {
  376. return nullptr;
  377. }
  378. Py_RETURN_NONE;
  379. }
  380. // ---------------------------------------------------------------------
  381. // reverse()
  382. // Returns 0 if successful; returns -1 and sets an exception if
  383. // unsuccessful.
  384. static int ReversePythonMessages(RepeatedCompositeContainer* self) {
  385. ScopedPyObjectPtr child_list(
  386. PySequence_List(reinterpret_cast<PyObject*>(self)));
  387. if (child_list == nullptr) {
  388. return -1;
  389. }
  390. if (ScopedPyObjectPtr(
  391. PyObject_CallMethod(child_list.get(), "reverse", nullptr)) == nullptr)
  392. return -1;
  393. ReorderAttached(self, child_list.get());
  394. return 0;
  395. }
  396. static PyObject* Reverse(PyObject* pself) {
  397. RepeatedCompositeContainer* self =
  398. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  399. if (ReversePythonMessages(self) < 0) {
  400. return nullptr;
  401. }
  402. Py_RETURN_NONE;
  403. }
  404. // ---------------------------------------------------------------------
  405. static PyObject* Item(PyObject* pself, Py_ssize_t index) {
  406. RepeatedCompositeContainer* self =
  407. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  408. return GetItem(self, index);
  409. }
  410. static PyObject* Pop(PyObject* pself, PyObject* args) {
  411. RepeatedCompositeContainer* self =
  412. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  413. Py_ssize_t index = -1;
  414. if (!PyArg_ParseTuple(args, "|n", &index)) {
  415. return nullptr;
  416. }
  417. Py_ssize_t length = Length(pself);
  418. if (index < 0) index += length;
  419. PyObject* item = GetItem(self, index, length);
  420. if (item == nullptr) {
  421. return nullptr;
  422. }
  423. ScopedPyObjectPtr py_index(PyLong_FromSsize_t(index));
  424. if (AssignSubscript(self, py_index.get(), nullptr) < 0) {
  425. return nullptr;
  426. }
  427. return item;
  428. }
  429. PyObject* DeepCopy(PyObject* pself, PyObject* arg) {
  430. return reinterpret_cast<RepeatedCompositeContainer*>(pself)->DeepCopy();
  431. }
  432. // The private constructor of RepeatedCompositeContainer objects.
  433. RepeatedCompositeContainer *NewContainer(
  434. CMessage* parent,
  435. const FieldDescriptor* parent_field_descriptor,
  436. CMessageClass* child_message_class) {
  437. if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
  438. return nullptr;
  439. }
  440. RepeatedCompositeContainer* self =
  441. reinterpret_cast<RepeatedCompositeContainer*>(
  442. PyType_GenericAlloc(&RepeatedCompositeContainer_Type, 0));
  443. if (self == nullptr) {
  444. return nullptr;
  445. }
  446. Py_INCREF(parent);
  447. self->parent = parent;
  448. self->parent_field_descriptor = parent_field_descriptor;
  449. Py_INCREF(child_message_class);
  450. self->child_message_class = child_message_class;
  451. return self;
  452. }
  453. static void Dealloc(PyObject* pself) {
  454. RepeatedCompositeContainer* self =
  455. reinterpret_cast<RepeatedCompositeContainer*>(pself);
  456. self->RemoveFromParentCache();
  457. Py_CLEAR(self->child_message_class);
  458. Py_TYPE(self)->tp_free(pself);
  459. }
  460. static PySequenceMethods SqMethods = {
  461. Length, /* sq_length */
  462. nullptr, /* sq_concat */
  463. nullptr, /* sq_repeat */
  464. Item /* sq_item */
  465. };
  466. static PyMappingMethods MpMethods = {
  467. Length, /* mp_length */
  468. SubscriptMethod, /* mp_subscript */
  469. AssignSubscriptMethod, /* mp_ass_subscript */
  470. };
  471. static PyMethodDef Methods[] = {
  472. {"__deepcopy__", DeepCopy, METH_VARARGS, "Makes a deep copy of the class."},
  473. {"add", reinterpret_cast<PyCFunction>(AddMethod),
  474. METH_VARARGS | METH_KEYWORDS, "Adds an object to the repeated container."},
  475. {"append", AppendMethod, METH_O,
  476. "Appends a message to the end of the repeated container."},
  477. {"insert", Insert, METH_VARARGS,
  478. "Inserts a message before the specified index."},
  479. {"extend", ExtendMethod, METH_O, "Adds objects to the repeated container."},
  480. {"pop", Pop, METH_VARARGS,
  481. "Removes an object from the repeated container and returns it."},
  482. {"remove", Remove, METH_O,
  483. "Removes an object from the repeated container."},
  484. {"sort", reinterpret_cast<PyCFunction>(Sort), METH_VARARGS | METH_KEYWORDS,
  485. "Sorts the repeated container."},
  486. {"reverse", reinterpret_cast<PyCFunction>(Reverse), METH_NOARGS,
  487. "Reverses elements order of the repeated container."},
  488. {"MergeFrom", MergeFromMethod, METH_O,
  489. "Adds objects to the repeated container."},
  490. {nullptr, nullptr}};
  491. } // namespace repeated_composite_container
  492. PyTypeObject RepeatedCompositeContainer_Type = {
  493. PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME
  494. ".RepeatedCompositeContainer", // tp_name
  495. sizeof(RepeatedCompositeContainer), // tp_basicsize
  496. 0, // tp_itemsize
  497. repeated_composite_container::Dealloc, // tp_dealloc
  498. #if PY_VERSION_HEX >= 0x03080000
  499. 0, // tp_vectorcall_offset
  500. #else
  501. nullptr, // tp_print
  502. #endif
  503. nullptr, // tp_getattr
  504. nullptr, // tp_setattr
  505. nullptr, // tp_compare
  506. repeated_composite_container::ToStr, // tp_repr
  507. nullptr, // tp_as_number
  508. &repeated_composite_container::SqMethods, // tp_as_sequence
  509. &repeated_composite_container::MpMethods, // tp_as_mapping
  510. PyObject_HashNotImplemented, // tp_hash
  511. nullptr, // tp_call
  512. nullptr, // tp_str
  513. nullptr, // tp_getattro
  514. nullptr, // tp_setattro
  515. nullptr, // tp_as_buffer
  516. Py_TPFLAGS_DEFAULT, // tp_flags
  517. "A Repeated scalar container", // tp_doc
  518. nullptr, // tp_traverse
  519. nullptr, // tp_clear
  520. repeated_composite_container::RichCompare, // tp_richcompare
  521. 0, // tp_weaklistoffset
  522. nullptr, // tp_iter
  523. nullptr, // tp_iternext
  524. repeated_composite_container::Methods, // tp_methods
  525. nullptr, // tp_members
  526. nullptr, // tp_getset
  527. nullptr, // tp_base
  528. nullptr, // tp_dict
  529. nullptr, // tp_descr_get
  530. nullptr, // tp_descr_set
  531. 0, // tp_dictoffset
  532. nullptr, // tp_init
  533. };
  534. } // namespace python
  535. } // namespace protobuf
  536. } // namespace google