Cython 3.2.6__py3-none-any.whl → 3.3.0a2.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of Cython might be problematic. Click here for more details.

Files changed (112) hide show
  1. Cython/Build/BuildExecutable.py +1 -14
  2. Cython/Build/Dependencies.py +6 -44
  3. Cython/Build/Inline.py +7 -3
  4. Cython/Build/IpythonMagic.py +0 -1
  5. Cython/Build/SharedModule.py +1 -2
  6. Cython/Build/Tests/TestCythonizeArgsParser.py +6 -6
  7. Cython/Build/Tests/TestDependencies.py +3 -3
  8. Cython/Build/Tests/TestInline.py +3 -3
  9. Cython/Build/Tests/TestIpythonMagic.py +35 -19
  10. Cython/Build/Tests/TestStripLiterals.py +2 -2
  11. Cython/Compiler/Buffer.py +5 -5
  12. Cython/Compiler/Builtin.py +57 -46
  13. Cython/Compiler/Code.pxd +12 -9
  14. Cython/Compiler/Code.py +220 -94
  15. Cython/Compiler/Dataclass.py +78 -52
  16. Cython/Compiler/Errors.py +21 -8
  17. Cython/Compiler/ExprNodes.py +871 -459
  18. Cython/Compiler/FlowControl.pxd +8 -6
  19. Cython/Compiler/FlowControl.py +111 -8
  20. Cython/Compiler/FusedNode.py +17 -12
  21. Cython/Compiler/Lexicon.py +123 -122
  22. Cython/Compiler/Main.py +3 -4
  23. Cython/Compiler/MatchCaseNodes.py +1948 -10
  24. Cython/Compiler/MemoryView.py +62 -33
  25. Cython/Compiler/ModuleNode.py +559 -283
  26. Cython/Compiler/Naming.py +4 -0
  27. Cython/Compiler/Nodes.py +333 -197
  28. Cython/Compiler/Optimize.py +268 -112
  29. Cython/Compiler/Options.py +0 -5
  30. Cython/Compiler/ParseTreeTransforms.pxd +2 -1
  31. Cython/Compiler/ParseTreeTransforms.py +180 -76
  32. Cython/Compiler/Parsing.py +55 -38
  33. Cython/Compiler/PyrexTypes.py +364 -128
  34. Cython/Compiler/Scanning.pxd +27 -5
  35. Cython/Compiler/Scanning.py +24 -14
  36. Cython/Compiler/StringEncoding.py +1 -2
  37. Cython/Compiler/Symtab.py +27 -19
  38. Cython/Compiler/Tests/TestBuiltin.py +41 -6
  39. Cython/Compiler/Tests/TestCmdLine.py +3 -2
  40. Cython/Compiler/Tests/TestCode.py +4 -3
  41. Cython/Compiler/Tests/TestFlowControl.py +2 -2
  42. Cython/Compiler/Tests/TestParseTreeTransforms.py +2 -2
  43. Cython/Compiler/Tests/TestScanning.py +2 -4
  44. Cython/Compiler/Tests/TestSignatureMatching.py +3 -3
  45. Cython/Compiler/Tests/TestStringEncoding.py +2 -3
  46. Cython/Compiler/Tests/TestTypes.py +46 -3
  47. Cython/Compiler/Tests/TestUtilityLoad.py +4 -4
  48. Cython/Compiler/TypeInference.py +20 -0
  49. Cython/Compiler/TypeSlots.py +171 -16
  50. Cython/Compiler/UtilNodes.py +24 -0
  51. Cython/Compiler/UtilityCode.py +1 -0
  52. Cython/Compiler/Visitor.pxd +1 -1
  53. Cython/Compiler/Visitor.py +3 -2
  54. Cython/Debugger/Tests/TestLibCython.py +7 -2
  55. Cython/Debugger/Tests/test_libcython_in_gdb.py +4 -2
  56. Cython/Debugger/Tests/test_libpython_in_gdb.py +1 -1
  57. Cython/Includes/cpython/array.pxd +5 -5
  58. Cython/Includes/cpython/dict.pxd +1 -6
  59. Cython/Includes/cpython/float.pxd +19 -10
  60. Cython/Includes/cpython/frozendict.pxd +37 -0
  61. Cython/Includes/cpython/long.pxd +31 -0
  62. Cython/Includes/cpython/object.pxd +9 -12
  63. Cython/Includes/cpython/sentinel.pxd +17 -0
  64. Cython/Includes/cpython/type.pxd +93 -0
  65. Cython/Includes/libcpp/exception.pxd +90 -0
  66. Cython/LZSS.py +170 -0
  67. Cython/Shadow.py +550 -73
  68. Cython/StringIOTree.py +1 -2
  69. Cython/Tempita/_tempita.py +45 -46
  70. Cython/TestUtils.py +50 -8
  71. Cython/Tests/TestCythonUtils.py +2 -2
  72. Cython/Tests/TestJediTyper.py +1 -1
  73. Cython/Tests/TestShadow.py +7 -5
  74. Cython/Tests/TestStringIOTree.py +4 -3
  75. Cython/Tests/TestTestUtils.py +2 -3
  76. Cython/Utility/AsyncGen.c +59 -19
  77. Cython/Utility/Buffer.c +4 -3
  78. Cython/Utility/Builtins.c +139 -17
  79. Cython/Utility/CConvert.pyx +27 -12
  80. Cython/Utility/CommonStructures.c +55 -37
  81. Cython/Utility/Coroutine.c +112 -68
  82. Cython/Utility/CythonFunction.c +607 -330
  83. Cython/Utility/Embed.c +8 -0
  84. Cython/Utility/Exceptions.c +20 -3
  85. Cython/Utility/ExtensionTypes.c +414 -224
  86. Cython/Utility/FunctionArguments.c +83 -81
  87. Cython/Utility/ImportExport.c +72 -61
  88. Cython/Utility/MatchCase.c +979 -0
  89. Cython/Utility/MatchCase_Cy.pyx +12 -0
  90. Cython/Utility/MemoryView.pxd +9 -88
  91. Cython/Utility/MemoryView.pyx +173 -61
  92. Cython/Utility/MemoryView_C.c +3 -3
  93. Cython/Utility/ModuleSetupCode.c +306 -157
  94. Cython/Utility/ObjectHandling.c +483 -404
  95. Cython/Utility/Optimize.c +1117 -164
  96. Cython/Utility/Overflow.c +3 -9
  97. Cython/Utility/Profile.c +4 -0
  98. Cython/Utility/StringTools.c +187 -149
  99. Cython/Utility/Synchronization.c +39 -0
  100. Cython/Utility/TString.c +24 -13
  101. Cython/Utility/TypeConversion.c +405 -250
  102. Cython/Utility/arrayarray.h +24 -22
  103. Cython/Utils.py +11 -23
  104. Cython/__init__.py +3 -1
  105. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/METADATA +14 -33
  106. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/RECORD +109 -107
  107. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/WHEEL +1 -1
  108. Cython/Shadow.pyi +0 -521
  109. Cython/Utility/Printing.c +0 -86
  110. Cython/__init__.pyi +0 -7
  111. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/entry_points.txt +0 -0
  112. {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/top_level.txt +0 -0
@@ -1,134 +1,16 @@
1
- /////////////// FixUpExtensionType.proto ///////////////
2
-
3
- static CYTHON_INLINE int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); /*proto*/
4
-
5
- /////////////// FixUpExtensionType ///////////////
6
- //@requires:ModuleSetupCode.c::IncludeStructmemberH
7
- //@requires:StringTools.c::IncludeStringH
8
- //@requires:SetItemOnTypeDict
9
-
10
- static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) {
11
- #if __PYX_LIMITED_VERSION_HEX > 0x030900B1
12
- CYTHON_UNUSED_VAR(spec);
13
- CYTHON_UNUSED_VAR(type);
14
- CYTHON_UNUSED_VAR(__Pyx__SetItemOnTypeDict);
15
- #else
16
- // Set tp_weakreflist, tp_dictoffset, tp_vectorcalloffset
17
- // Copied and adapted from https://bugs.python.org/issue38140
18
- const PyType_Slot *slot = spec->slots;
19
- int changed = 0;
20
- #if !CYTHON_COMPILING_IN_LIMITED_API
21
- while (slot && slot->slot && slot->slot != Py_tp_members)
22
- slot++;
23
- if (slot && slot->slot == Py_tp_members) {
24
- #if !CYTHON_COMPILING_IN_CPYTHON
25
- const
26
- #endif // !CYTHON_COMPILING_IN_CPYTHON)
27
- PyMemberDef *memb = (PyMemberDef*) slot->pfunc;
28
- while (memb && memb->name) {
29
- if (memb->name[0] == '_' && memb->name[1] == '_') {
30
- if (strcmp(memb->name, "__weaklistoffset__") == 0) {
31
- // The PyMemberDef must be a Py_ssize_t and readonly.
32
- assert(memb->type == T_PYSSIZET);
33
- assert(memb->flags == READONLY);
34
- type->tp_weaklistoffset = memb->offset;
35
- // FIXME: is it even worth calling PyType_Modified() here?
36
- changed = 1;
37
- }
38
- else if (strcmp(memb->name, "__dictoffset__") == 0) {
39
- // The PyMemberDef must be a Py_ssize_t and readonly.
40
- assert(memb->type == T_PYSSIZET);
41
- assert(memb->flags == READONLY);
42
- type->tp_dictoffset = memb->offset;
43
- // FIXME: is it even worth calling PyType_Modified() here?
44
- changed = 1;
45
- }
46
- #if CYTHON_METH_FASTCALL
47
- else if (strcmp(memb->name, "__vectorcalloffset__") == 0) {
48
- // The PyMemberDef must be a Py_ssize_t and readonly.
49
- assert(memb->type == T_PYSSIZET);
50
- assert(memb->flags == READONLY);
51
- type->tp_vectorcall_offset = memb->offset;
52
- // FIXME: is it even worth calling PyType_Modified() here?
53
- changed = 1;
54
- }
55
- #endif // CYTHON_METH_FASTCALL
56
- #if !CYTHON_COMPILING_IN_PYPY
57
- else if (strcmp(memb->name, "__module__") == 0) {
58
- // PyType_FromSpec() in CPython <= 3.9b1 overwrites this field with a constant string.
59
- // See https://bugs.python.org/issue40703
60
- PyObject *descr;
61
- // The PyMemberDef must be an object and normally readable, possibly writable.
62
- assert(memb->type == T_OBJECT);
63
- assert(memb->flags == 0 || memb->flags == READONLY);
64
- descr = PyDescr_NewMember(type, memb);
65
- if (unlikely(!descr))
66
- return -1;
67
- int set_item_result = PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr);
68
- Py_DECREF(descr);
69
- if (unlikely(set_item_result < 0)) {
70
- return -1;
71
- }
72
- changed = 1;
73
- }
74
- #endif // !CYTHON_COMPILING_IN_PYPY
75
- }
76
- memb++;
77
- }
78
- }
79
- #endif // !CYTHON_COMPILING_IN_LIMITED_API
80
- #if !CYTHON_COMPILING_IN_PYPY
81
- slot = spec->slots;
82
- while (slot && slot->slot && slot->slot != Py_tp_getset)
83
- slot++;
84
- if (slot && slot->slot == Py_tp_getset) {
85
- PyGetSetDef *getset = (PyGetSetDef*) slot->pfunc;
86
- while (getset && getset->name) {
87
- if (getset->name[0] == '_' && getset->name[1] == '_' && strcmp(getset->name, "__module__") == 0) {
88
- PyObject *descr = PyDescr_NewGetSet(type, getset);
89
- if (unlikely(!descr))
90
- return -1;
91
- #if CYTHON_COMPILING_IN_LIMITED_API
92
- PyObject *pyname = PyUnicode_FromString(getset->name);
93
- if (unlikely(!pyname)) {
94
- Py_DECREF(descr);
95
- return -1;
96
- }
97
- int set_item_result = __Pyx_SetItemOnTypeDict(type, pyname, descr);
98
- Py_DECREF(pyname);
99
- #else
100
- CYTHON_UNUSED_VAR(__Pyx__SetItemOnTypeDict);
101
- int set_item_result = PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr);
102
- #endif
103
- Py_DECREF(descr);
104
- if (unlikely(set_item_result < 0)) {
105
- return -1;
106
- }
107
- changed = 1;
108
- }
109
- ++getset;
110
- }
111
- }
112
- #else
113
- CYTHON_UNUSED_VAR(__Pyx__SetItemOnTypeDict);
114
- #endif // !CYTHON_COMPILING_IN_PYPY
115
- if (changed)
116
- PyType_Modified(type);
117
- #endif // PY_VERSION_HEX > 0x030900B1
118
- return 0;
119
- }
120
-
121
-
122
1
  /////////////// ValidateBasesTuple.proto ///////////////
123
2
 
124
3
  #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS
125
- static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); /*proto*/
4
+ static int __Pyx_validate_bases_tuple(const char *type_name, int has_dictoffset, PyObject *bases); /*proto*/
126
5
  #endif
127
6
 
128
7
  /////////////// ValidateBasesTuple ///////////////
8
+ //@requires: GetTypeDictOffset
9
+ //@requires: ObjectHandling.c::RaiseErrorWithObjectType
10
+ //@requires: ObjectHandling.c::RaiseErrorWithObjectType1
129
11
 
130
12
  #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS
131
- static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) {
13
+ static int __Pyx_validate_bases_tuple(const char *type_name, int has_dictoffset, PyObject *bases) {
132
14
  // Loop over all bases (except the first) and check that those
133
15
  // really are heap types. Otherwise, it would not be safe to
134
16
  // subclass them.
@@ -146,6 +28,32 @@ static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffs
146
28
  n = PyTuple_Size(bases);
147
29
  if (unlikely(n < 0)) return -1;
148
30
  #endif
31
+ if (!has_dictoffset) {
32
+ // maybe one of the direct first bases does
33
+ PyObject *b;
34
+ #if CYTHON_AVOID_BORROWED_REFS
35
+ b = PySequence_GetItem(bases, 0);
36
+ if (!b) return -1;
37
+ #elif CYTHON_ASSUME_SAFE_MACROS
38
+ b = PyTuple_GET_ITEM(bases, 0);
39
+ #else
40
+ b = PyTuple_GetItem(bases, 0);
41
+ if (!b) return -1;
42
+ #endif
43
+ #if CYTHON_USE_TYPE_SLOTS
44
+ has_dictoffset = ((PyTypeObject*)b)->tp_dictoffset != 0;
45
+ #else
46
+ Py_ssize_t dictoffset = __Pyx_GetTypeDictOffset(b, 0);
47
+ has_dictoffset = dictoffset != 0;
48
+ #endif
49
+ #if CYTHON_AVOID_BORROWED_REFS
50
+ Py_DECREF(b);
51
+ #endif
52
+ #if !CYTHON_USE_TYPE_SLOTS
53
+ if (dictoffset == -1 && PyErr_Occurred()) return -1;
54
+ #endif
55
+ }
56
+
149
57
  for (i = 1; i < n; i++) /* Skip first base */
150
58
  {
151
59
  PyTypeObject *b;
@@ -161,38 +69,30 @@ static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffs
161
69
  b = (PyTypeObject*) b0;
162
70
  if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE))
163
71
  {
164
- __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b);
165
- PyErr_Format(PyExc_TypeError,
166
- "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name);
167
- __Pyx_DECREF_TypeName(b_name);
72
+ __Pyx_RaiseErrorWithType(
73
+ PyExc_TypeError, "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b);
168
74
  #if CYTHON_AVOID_BORROWED_REFS
169
75
  Py_DECREF(b0);
170
76
  #endif
171
77
  return -1;
172
78
  }
173
- if (dictoffset == 0)
79
+ if (!has_dictoffset)
174
80
  {
175
81
  Py_ssize_t b_dictoffset = 0;
176
82
  #if CYTHON_USE_TYPE_SLOTS
177
83
  b_dictoffset = b->tp_dictoffset;
178
84
  #else
179
- PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__");
180
- if (!py_b_dictoffset) goto dictoffset_return;
181
- b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset);
182
- Py_DECREF(py_b_dictoffset);
85
+ b_dictoffset = __Pyx_GetTypeDictOffset((PyObject*)b, 0);
183
86
  if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return;
184
87
  #endif
185
88
  if (b_dictoffset) {
186
- {
187
- __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b);
188
- PyErr_Format(PyExc_TypeError,
189
- "extension type '%.200s' has no __dict__ slot, "
190
- "but base type '" __Pyx_FMT_TYPENAME "' has: "
191
- "either add 'cdef dict __dict__' to the extension type "
192
- "or add '__slots__ = [...]' to the base type",
193
- type_name, b_name);
194
- __Pyx_DECREF_TypeName(b_name);
195
- }
89
+ __Pyx_RaiseErrorWithType1(
90
+ PyExc_TypeError,
91
+ "extension type '%.200s' has no __dict__ slot, "
92
+ "but base type '" __Pyx_FMT_TYPENAME "' has: "
93
+ "either add 'cdef dict __dict__' to the extension type "
94
+ "or add '__slots__ = [...]' to the base type",
95
+ type_name, b);
196
96
  #if !CYTHON_USE_TYPE_SLOTS
197
97
  dictoffset_return:
198
98
  #endif
@@ -211,7 +111,7 @@ static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffs
211
111
  #endif
212
112
 
213
113
 
214
- /////////////// PyType_Ready.proto ///////////////
114
+ /////////////// PyType_Ready.export ///////////////
215
115
 
216
116
  // unused when using type specs
217
117
  CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t);/*proto*/
@@ -235,7 +135,7 @@ CYTHON_UNUSED static int __Pyx_PyType_HasMultipleInheritance(PyTypeObject *t) {
235
135
  // to deal with multiple inheritance.
236
136
  static int __Pyx_PyType_Ready(PyTypeObject *t) {
237
137
 
238
- #if CYTHON_USE_TYPE_SPECS || !CYTHON_COMPILING_IN_CPYTHON || defined(PYSTON_MAJOR_VERSION)
138
+ #if CYTHON_USE_TYPE_SPECS || !CYTHON_COMPILING_IN_CPYTHON
239
139
  // avoid C warning about unused helper function
240
140
  (void)__Pyx_PyObject_CallMethod0;
241
141
  #if CYTHON_USE_TYPE_SPECS
@@ -253,10 +153,9 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
253
153
  return PyType_Ready(t);
254
154
  }
255
155
  PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*);
256
- if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1))
156
+ if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset != 0, bases) == -1))
257
157
  return -1;
258
158
 
259
- #if !defined(PYSTON_MAJOR_VERSION)
260
159
  {
261
160
  // Make sure GC does not pick up our non-heap type as heap type with this hack!
262
161
  // For details, see https://github.com/cython/cython/issues/3603
@@ -314,14 +213,9 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
314
213
  // is immutable
315
214
  t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE;
316
215
  #endif
317
- #else
318
- // avoid C warning about unused helper function
319
- (void)__Pyx_PyObject_CallMethod0;
320
- #endif
321
216
 
322
- r = PyType_Ready(t);
217
+ r = PyType_Ready(t);
323
218
 
324
- #if !defined(PYSTON_MAJOR_VERSION)
325
219
  t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
326
220
 
327
221
  #if PY_VERSION_HEX >= 0x030A00b1
@@ -347,7 +241,6 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
347
241
  Py_DECREF(gc);
348
242
  #endif
349
243
  }
350
- #endif
351
244
 
352
245
  return r;
353
246
  #endif
@@ -402,6 +295,34 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
402
295
  #define __Pyx_TRASHCAN_END
403
296
  #endif
404
297
 
298
+ /////////////// DeallocKeepAlive.proto ///////////////
299
+
300
+ // Keep `o` alive across a call into user __dealloc__ code, to prevent the user
301
+ // code from triggering recursive deallocation, then drop the temporary reference.
302
+ //
303
+ // On the GIL build this is a plain refcount bump. On free-threading we must NOT
304
+ // use Py_SET_REFCNT(o, 1): the object reaching tp_dealloc is unowned and merged
305
+ // (ob_ref_shared == _Py_REF_MERGED), so Py_SET_REFCNT takes the unowned branch and
306
+ // writes ob_ref_shared = _Py_REF_SHARED(1, _Py_REF_MERGED), i.e. "merged, shared
307
+ // count 1" -- indistinguishable from a live object. A concurrent
308
+ // PyUnstable_TryIncRef() would then succeed and resurrect the dying object
309
+ // (use-after-free). Instead we mirror CPython's _PyObject_ResurrectStart/End:
310
+ // re-take ownership and keep the *shared* refcount at the refuse sentinel (0), so
311
+ // the bump is invisible to other threads and TryIncRef keeps refusing.
312
+
313
+ #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
314
+ #define __Pyx_DeallocKeepAliveBegin(o) do { \
315
+ _Py_atomic_store_uintptr_relaxed(&(o)->ob_tid, _Py_ThreadId()); \
316
+ _Py_atomic_store_uint32_relaxed(&(o)->ob_ref_local, 1); \
317
+ _Py_atomic_store_ssize_relaxed(&(o)->ob_ref_shared, 0); \
318
+ } while (0)
319
+ #define __Pyx_DeallocKeepAliveEnd(o) \
320
+ _Py_atomic_store_uint32_relaxed(&(o)->ob_ref_local, 0)
321
+ #else
322
+ #define __Pyx_DeallocKeepAliveBegin(o) Py_SET_REFCNT(o, Py_REFCNT(o) + 1)
323
+ #define __Pyx_DeallocKeepAliveEnd(o) Py_SET_REFCNT(o, Py_REFCNT(o) - 1)
324
+ #endif
325
+
405
326
  /////////////// CallNextTpDealloc.proto ///////////////
406
327
 
407
328
  static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);
@@ -459,13 +380,15 @@ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
459
380
  }
460
381
 
461
382
 
462
- /////////////// SetupReduce.proto ///////////////
383
+ /////////////// SetupReduce.export ///////////////
463
384
 
464
385
  static int __Pyx_setup_reduce(PyObject* type_obj);
465
386
 
466
387
  /////////////// SetupReduce ///////////////
467
388
  //@requires: ObjectHandling.c::PyObjectGetAttrStrNoError
468
389
  //@requires: ObjectHandling.c::PyObjectGetAttrStr
390
+ //@requires: ObjectHandling.c::RaiseErrorWithObjectType
391
+ //@requires: Exceptions.c::IgnoreException
469
392
  //@requires: SetItemOnTypeDict
470
393
  //@requires: DelItemOnTypeDict
471
394
 
@@ -480,15 +403,28 @@ static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
480
403
  ret = -1;
481
404
  }
482
405
 
483
- if (unlikely(ret < 0)) {
484
- PyErr_Clear();
485
- ret = 0;
406
+ if (unlikely(ret < 0) && __Pyx_IgnoreException(PyExc_Exception)) {
407
+ ret = 0; // But BaseException is still propagated.
486
408
  }
487
409
 
488
410
  Py_XDECREF(name_attr);
489
411
  return ret;
490
412
  }
491
413
 
414
+ // Returns a borrowed reference with CYTHON_USE_PYTYPE_LOOKUP
415
+ static PyObject *__Pyx_setup_reduce_get_reduce_attribute(PyObject *type_obj, PyObject *name, int allow_not_present) {
416
+ #if CYTHON_USE_PYTYPE_LOOKUP
417
+ CYTHON_UNUSED_VAR(allow_not_present);
418
+ return _PyType_Lookup((PyTypeObject*)type_obj, name);
419
+ #else
420
+ if (allow_not_present) {
421
+ return __Pyx_PyObject_GetAttrStrNoError(type_obj, name);
422
+ } else {
423
+ return __Pyx_PyObject_GetAttrStr(type_obj, name);
424
+ }
425
+ #endif
426
+ }
427
+
492
428
  static int __Pyx_setup_reduce(PyObject* type_obj) {
493
429
  int ret = 0;
494
430
  PyObject *object_reduce = NULL;
@@ -501,46 +437,38 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
501
437
  PyObject *setstate_cython = NULL;
502
438
  PyObject *getstate = NULL;
503
439
 
504
- #if CYTHON_USE_PYTYPE_LOOKUP
505
- getstate = _PyType_Lookup((PyTypeObject*)type_obj, PYIDENT("__getstate__"));
506
- #else
507
- getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__getstate__"));
440
+ getstate = __Pyx_setup_reduce_get_reduce_attribute(type_obj, PYIDENT("__getstate__"), 1);
508
441
  if (!getstate && PyErr_Occurred()) {
509
442
  goto __PYX_BAD;
510
443
  }
511
- #endif
512
444
  if (getstate) {
513
445
  // Python 3.11 introduces object.__getstate__. Because it's version-specific failure to find it should not be an error
514
- #if CYTHON_USE_PYTYPE_LOOKUP
515
- object_getstate = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__getstate__"));
516
- #else
517
- object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, PYIDENT("__getstate__"));
446
+ object_getstate = __Pyx_setup_reduce_get_reduce_attribute((PyObject*)&PyBaseObject_Type, PYIDENT("__getstate__"), 1);
518
447
  if (!object_getstate && PyErr_Occurred()) {
519
448
  goto __PYX_BAD;
520
449
  }
521
- #endif
522
450
  if (object_getstate != getstate) {
523
451
  goto __PYX_GOOD;
524
452
  }
525
453
  }
526
454
 
527
- #if CYTHON_USE_PYTYPE_LOOKUP
528
- object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__reduce_ex__")); if (!object_reduce_ex) goto __PYX_BAD;
529
- #else
530
- object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce_ex__")); if (!object_reduce_ex) goto __PYX_BAD;
531
- #endif
532
-
455
+ object_reduce_ex = __Pyx_setup_reduce_get_reduce_attribute((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce_ex__"), 0);
456
+ if (unlikely(!object_reduce_ex)) goto __PYX_BAD;
533
457
  reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce_ex__")); if (unlikely(!reduce_ex)) goto __PYX_BAD;
534
458
  if (reduce_ex == object_reduce_ex) {
535
-
536
- #if CYTHON_USE_PYTYPE_LOOKUP
537
- object_reduce = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__reduce__")); if (!object_reduce) goto __PYX_BAD;
538
- #else
539
- object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce__")); if (!object_reduce) goto __PYX_BAD;
540
- #endif
459
+ object_reduce = __Pyx_setup_reduce_get_reduce_attribute((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce__"), 0);
460
+ if (!object_reduce) goto __PYX_BAD;
541
461
  reduce = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce__")); if (unlikely(!reduce)) goto __PYX_BAD;
542
462
 
543
- if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, PYIDENT("__reduce_cython__"))) {
463
+ int try_to_replace_reduce = (reduce == object_reduce);
464
+ if (!try_to_replace_reduce) {
465
+ try_to_replace_reduce = __Pyx_setup_reduce_is_named(reduce, PYIDENT("__reduce_cython__"));
466
+ if (unlikely(try_to_replace_reduce < 0)) {
467
+ goto __PYX_BAD;
468
+ }
469
+ }
470
+
471
+ if (try_to_replace_reduce) {
544
472
  reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__reduce_cython__"));
545
473
  if (likely(reduce_cython)) {
546
474
  ret = __Pyx_SetItemOnTypeDict((PyTypeObject*)type_obj, PYIDENT("__reduce__"), reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
@@ -552,8 +480,21 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
552
480
  }
553
481
 
554
482
  setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__setstate__"));
555
- if (!setstate) PyErr_Clear();
556
- if (!setstate || __Pyx_setup_reduce_is_named(setstate, PYIDENT("__setstate_cython__"))) {
483
+ int try_to_replace_setstate;
484
+ if (!setstate) {
485
+ PyObject *exc = PyErr_Occurred();
486
+ if (exc && !__Pyx_IgnoreGivenException(exc, PyExc_Exception)) {
487
+ goto __PYX_BAD;
488
+ }
489
+ try_to_replace_setstate = 1;
490
+ } else {
491
+ try_to_replace_setstate = __Pyx_setup_reduce_is_named(setstate, PYIDENT("__setstate_cython__"));
492
+ if (unlikely(try_to_replace_setstate < 0)) {
493
+ goto __PYX_BAD;
494
+ }
495
+ }
496
+
497
+ if (try_to_replace_setstate) {
557
498
  setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__setstate_cython__"));
558
499
  if (likely(setstate_cython)) {
559
500
  ret = __Pyx_SetItemOnTypeDict((PyTypeObject*)type_obj, PYIDENT("__setstate__"), setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
@@ -571,11 +512,10 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
571
512
 
572
513
  __PYX_BAD:
573
514
  if (!PyErr_Occurred()) {
574
- __Pyx_TypeName type_obj_name =
575
- __Pyx_PyType_GetFullyQualifiedName((PyTypeObject*)type_obj);
576
- PyErr_Format(PyExc_RuntimeError,
577
- "Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name);
578
- __Pyx_DECREF_TypeName(type_obj_name);
515
+ __Pyx_RaiseErrorWithType(
516
+ PyExc_RuntimeError,
517
+ "Unable to initialize pickling for " __Pyx_FMT_TYPENAME,
518
+ (PyTypeObject*)type_obj);
579
519
  }
580
520
  ret = -1;
581
521
  __PYX_GOOD:
@@ -635,7 +575,7 @@ static int __Pyx_CheckUnpickleChecksum(long checksum, long checksum1, long check
635
575
  }
636
576
 
637
577
 
638
- /////////////// UpdateUnpickledDict.proto ///////////////
578
+ /////////////// UpdateUnpickledDict.export ///////////////
639
579
 
640
580
  static int __Pyx_UpdateUnpickledDict(PyObject *obj, PyObject *state, Py_ssize_t index); /*proto*/
641
581
 
@@ -770,6 +710,7 @@ static int __Pyx_validate_extern_base(PyTypeObject *base); /* proto */
770
710
 
771
711
  /////////////// ValidateExternBase ///////////////
772
712
  //@requires: ObjectHandling.c::FormatTypeName
713
+ //@requires: ObjectHandling.c::RaiseErrorWithObjectType
773
714
 
774
715
  static int __Pyx_validate_extern_base(PyTypeObject *base) {
775
716
  Py_ssize_t itemsize;
@@ -789,10 +730,9 @@ static int __Pyx_validate_extern_base(PyTypeObject *base) {
789
730
  return -1;
790
731
  #endif
791
732
  if (itemsize) {
792
- __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(base);
793
- PyErr_Format(PyExc_TypeError,
794
- "inheritance from PyVarObject types like '" __Pyx_FMT_TYPENAME "' not currently supported", b_name);
795
- __Pyx_DECREF_TypeName(b_name);
733
+ __Pyx_RaiseErrorWithType(
734
+ PyExc_TypeError,
735
+ "inheritance from PyVarObject types like '" __Pyx_FMT_TYPENAME "' not currently supported", base);
796
736
  return -1;
797
737
  }
798
738
  return 0;
@@ -800,9 +740,8 @@ static int __Pyx_validate_extern_base(PyTypeObject *base) {
800
740
 
801
741
  /////////////// CallTypeTraverse.proto /////////////////////
802
742
 
803
- #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000)
743
+ #if !CYTHON_USE_TYPE_SPECS
804
744
  // Without type specs, we're never responsible for this.
805
- // If we *know* the Python version is less that 3.9 we're also not responsible
806
745
  #define __Pyx_call_type_traverse(o, always_call, visit, arg) 0
807
746
  #else
808
747
  static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg); /* proto */
@@ -810,15 +749,10 @@ static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visi
810
749
 
811
750
  /////////////// CallTypeTraverse ////////////////////////////
812
751
 
813
- #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000)
752
+ #if !CYTHON_USE_TYPE_SPECS
814
753
  // nothing to do
815
754
  #else
816
755
  static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg) {
817
- #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x03090000
818
- // We have to work out whether to call traverse based on the runtime version.
819
- // __Pyx_get_runtime_version is always available so no need to require it.
820
- if (__Pyx_get_runtime_version() < 0x03090000) return 0;
821
- #endif
822
756
  if (!always_call) {
823
757
  // Written with reference to https://docs.python.org/3/howto/isolating-extensions.html
824
758
  PyTypeObject *base = __Pyx_PyObject_GetSlot(o, tp_base, PyTypeObject*);
@@ -833,35 +767,29 @@ static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visi
833
767
  }
834
768
  #endif
835
769
 
770
+ ////////////////// GetTypeDictOffset.proto ////////////////
836
771
 
837
- ////////////////// LimitedApiGetTypeDict.proto //////////////////////
838
-
839
- #if CYTHON_COMPILING_IN_LIMITED_API
840
- // This is a little hacky - the Limited API works quite hard to stop us getting
841
- // the dict of a type object. But apparently not hard enough...
842
- //
843
- // In future we should prefer to work with mutable types, and then make them immutable
844
- // once we're done (pending C API support for this).
845
- static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp); /* proto */
772
+ #if !CYTHON_USE_TYPE_SLOTS
773
+ CYTHON_UNUSED static Py_ssize_t __Pyx_GetTypeDictOffset(PyObject *tp, int require_cython_valid_result);
846
774
  #endif
847
775
 
848
- ////////////////// LimitedApiGetTypeDict //////////////////////
776
+ ////////////////// GetTypeDictOffset //////////////////////
849
777
 
850
- #if CYTHON_COMPILING_IN_LIMITED_API
851
- static Py_ssize_t __Pyx_GetTypeDictOffset(void) {
778
+ #if !CYTHON_USE_TYPE_SLOTS
779
+ CYTHON_UNUSED static Py_ssize_t __Pyx_GetTypeDictOffset(PyObject *tp, int require_cython_valid_result) {
852
780
  PyObject *tp_dictoffset_o;
853
781
  Py_ssize_t tp_dictoffset;
854
- tp_dictoffset_o = PyObject_GetAttrString((PyObject*)(&PyType_Type), "__dictoffset__");
782
+ tp_dictoffset_o = PyObject_GetAttrString(tp, "__dictoffset__");
855
783
  if (unlikely(!tp_dictoffset_o)) return -1;
856
784
  tp_dictoffset = PyLong_AsSsize_t(tp_dictoffset_o);
857
785
  Py_DECREF(tp_dictoffset_o);
858
786
 
859
- if (unlikely(tp_dictoffset == 0)) {
787
+ if (unlikely(require_cython_valid_result && tp_dictoffset == 0)) {
860
788
  PyErr_SetString(
861
789
  PyExc_TypeError,
862
790
  "'type' doesn't have a dictoffset");
863
791
  return -1;
864
- } else if (unlikely(tp_dictoffset < 0)) {
792
+ } else if (unlikely(require_cython_valid_result && tp_dictoffset < 0)) {
865
793
  // This isn't completely future proof. dictoffset can be
866
794
  // negative, but isn't in Python <=3.13 (current at time
867
795
  // of writing). It's awkward to calculate in the limited
@@ -876,13 +804,29 @@ static Py_ssize_t __Pyx_GetTypeDictOffset(void) {
876
804
 
877
805
  return tp_dictoffset;
878
806
  }
807
+ #endif
808
+
809
+ ////////////////// LimitedApiGetTypeTypeDict.proto //////////////////////
810
+
811
+ #if CYTHON_COMPILING_IN_LIMITED_API
812
+ // This is a little hacky - the Limited API works quite hard to stop us getting
813
+ // the dict of a type object. But apparently not hard enough...
814
+ //
815
+ // In future we should prefer to work with mutable types, and then make them immutable
816
+ // once we're done (pending C API support for this).
817
+ static PyObject *__Pyx_GetTypeTypeDict(PyTypeObject *tp); /* proto */
818
+ #endif
819
+
820
+ ////////////////// LimitedApiGetTypeTypeDict //////////////////////
821
+ //@requires: GetTypeDictOffset
879
822
 
880
- static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp) {
823
+ #if CYTHON_COMPILING_IN_LIMITED_API
824
+ static PyObject *__Pyx_GetTypeTypeDict(PyTypeObject *tp) {
881
825
  // TODO - if we ever support custom metatypes for extension types then
882
826
  // we have to modify this caching.
883
827
  static Py_ssize_t tp_dictoffset = 0;
884
828
  if (unlikely(tp_dictoffset == 0)) {
885
- tp_dictoffset = __Pyx_GetTypeDictOffset();
829
+ tp_dictoffset = __Pyx_GetTypeDictOffset((PyObject*)(&PyType_Type), 1);
886
830
  // Note that negative dictoffsets are definitely allowed.
887
831
  // A dictoffset of -1 seems unlikely but isn't obviously forbidden.
888
832
  if (unlikely(tp_dictoffset == -1 && PyErr_Occurred())) {
@@ -895,11 +839,13 @@ static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp) {
895
839
  #endif
896
840
 
897
841
 
898
- ////////////////// SetItemOnTypeDict.proto //////////////////////////
899
- //@requires: LimitedApiGetTypeDict
842
+ ////////////////// SetItemOnTypeDict.export //////////////////////////
900
843
 
901
844
  static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v); /* proto */
902
845
 
846
+ ////////////////// SetItemOnTypeDict.proto //////////////////////////
847
+ //@requires: LimitedApiGetTypeTypeDict
848
+
903
849
  #define __Pyx_SetItemOnTypeDict(tp, k, v) __Pyx__SetItemOnTypeDict((PyTypeObject*)tp, k, v)
904
850
 
905
851
  ////////////////// SetItemOnTypeDict //////////////////////////
@@ -908,7 +854,7 @@ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v)
908
854
  int result;
909
855
  PyObject *tp_dict;
910
856
  #if CYTHON_COMPILING_IN_LIMITED_API
911
- tp_dict = __Pyx_GetTypeDict(tp);
857
+ tp_dict = __Pyx_GetTypeTypeDict(tp);
912
858
  if (unlikely(!tp_dict)) return -1;
913
859
  #else
914
860
  tp_dict = tp->tp_dict;
@@ -925,20 +871,22 @@ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v)
925
871
  return result;
926
872
  }
927
873
 
928
- ////////////////// DelItemOnTypeDict.proto //////////////////////////
874
+ ////////////////// DelItemOnTypeDict.export //////////////////////////
929
875
 
930
876
  static int __Pyx__DelItemOnTypeDict(PyTypeObject *tp, PyObject *k); /* proto */
931
877
 
878
+ ////////////////// DelItemOnTypeDict.proto //////////////////////////
879
+
932
880
  #define __Pyx_DelItemOnTypeDict(tp, k) __Pyx__DelItemOnTypeDict((PyTypeObject*)tp, k)
933
881
 
934
882
  ////////////////// DelItemOnTypeDict //////////////////////////
935
- //@requires: LimitedApiGetTypeDict
883
+ //@requires: LimitedApiGetTypeTypeDict
936
884
 
937
885
  static int __Pyx__DelItemOnTypeDict(PyTypeObject *tp, PyObject *k) {
938
886
  int result;
939
887
  PyObject *tp_dict;
940
888
  #if CYTHON_COMPILING_IN_LIMITED_API
941
- tp_dict = __Pyx_GetTypeDict(tp);
889
+ tp_dict = __Pyx_GetTypeTypeDict(tp);
942
890
  if (unlikely(!tp_dict)) return -1;
943
891
  #else
944
892
  tp_dict = tp->tp_dict;
@@ -993,4 +941,246 @@ static PyObject *__Pyx_AllocateExtensionType(PyTypeObject *t, int is_final) {
993
941
  #define __PYX_CHECK_TYPE_FOR_FREELISTS(t, expected_tp, expected_size) \
994
942
  (__PYX_CHECK_FINAL_TYPE_FOR_FREELISTS((t), (expected_tp), (expected_size)) & \
995
943
  (int) (!__Pyx_PyType_HasFeature((t), __PYX_CHECK_TYPE_FOR_FREELIST_FLAGS)))
996
- #endif
944
+ #endif
945
+
946
+
947
+ ////////////////// ClearFreelist.proto ///////////////////////
948
+
949
+ #if CYTHON_USE_FREELISTS
950
+ static void __Pyx_ClearFreelist(PyObject **freelist, int *count); /* proto */
951
+ #endif
952
+
953
+ ////////////////// ClearFreelist ////////////////////////////
954
+
955
+ #if CYTHON_USE_FREELISTS
956
+ static void __Pyx_ClearFreelist(PyObject **freelist, int *count) {
957
+ while (*count > 0) {
958
+ PyObject* o = freelist[--*count];
959
+ PyTypeObject *tp = Py_TYPE(o);
960
+ #if CYTHON_USE_TYPE_SLOTS
961
+ (*tp->tp_free)(o);
962
+ #else
963
+ // Asking for PyType_GetSlot(..., Py_tp_free) seems to cause an error in pypy.
964
+ freefunc tp_free = (freefunc) PyType_GetSlot(tp, Py_tp_free);
965
+ if (tp_free) tp_free(o);
966
+ #endif
967
+ #if CYTHON_USE_TYPE_SPECS
968
+ // Release the reference that "o" owned for its type.
969
+ Py_DECREF(tp);
970
+ #endif
971
+ }
972
+ }
973
+ #endif
974
+
975
+
976
+ /////////////////// ApplySequenceOrMappingFlag.proto //////////////////////
977
+
978
+ #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
979
+ int __Pyx_ApplySequenceOrMappingFlag(PyTypeObject *tp, int is_sequence);
980
+ #else
981
+ // No-op - the type flag is sufficient.
982
+ #define __Pyx_ApplySequenceOrMappingFlag(tp, is_sequence) (0)
983
+ #endif
984
+
985
+ /////////////////// ApplySequenceOrMappingFlag //////////////////////
986
+
987
+ #if CYTHON_COMPILING_IN_LIMITED_API || (CYTHON_COMPILING_IN_PYPY && CYTHON_USE_TYPE_SPECS)
988
+ int __Pyx_ApplySequenceOrMappingFlag(PyTypeObject *tp, int is_sequence) {
989
+ PyObject *abc;
990
+ PyObject *collections_abc = PyImport_ImportModule("collections.abc");
991
+ if (unlikely(!collections_abc)) return -1;
992
+ abc = PyObject_GetAttrString(collections_abc, is_sequence ? "Sequence": "Mapping");
993
+ Py_DECREF(collections_abc);
994
+ if (unlikely(!abc)) return -1;
995
+
996
+ PyObject *register_result = PyObject_CallMethod(abc, "register", "O", (PyObject*)tp);
997
+ Py_DECREF(abc);
998
+ if (unlikely(!register_result)) return -1;
999
+ Py_DECREF(register_result);
1000
+ return 0;
1001
+ }
1002
+ #elif CYTHON_COMPILING_IN_PYPY // && !CYTHON_USE_TYPE_SPECS
1003
+ int __Pyx_ApplySequenceOrMappingFlag(PyTypeObject *tp, int is_sequence) {
1004
+ CYTHON_UNUSED_VAR(tp);
1005
+ CYTHON_UNUSED_VAR(is_sequence);
1006
+ return PyErr_WarnEx(
1007
+ PyExc_RuntimeWarning,
1008
+ "cython.collection_type only works on PyPy with the C flag CYTHON_USE_TYPE_SPECS=1",
1009
+ 1
1010
+ );
1011
+ }
1012
+ #endif
1013
+
1014
+ ////////////////////////////// CallNewInitFromVectorcall.proto //////////////////////
1015
+
1016
+ #if CYTHON_VECTORCALL_TPNEW
1017
+ static PyObject *__Pyx_CallNewInitFromVectorcall(PyTypeObject *t, PyObject *const *args, size_t nargsf, PyObject *kwnames); /* proto */
1018
+ #endif
1019
+
1020
+ ////////////////////////////// CallNewInitFromVectorcall //////////////////////
1021
+ //@requires: ObjectHandling.c::TupleFromArray
1022
+ //@requires: ObjectHandling.c::RaiseErrorWithObjectType
1023
+
1024
+ #if CYTHON_VECTORCALL_TPNEW
1025
+ static PyObject *__Pyx_CallNewInitFromVectorcall(PyTypeObject *t, PyObject *const *args, size_t nargsf, PyObject *kwnames) {
1026
+ newfunc tp_new = __Pyx_PyType_GetSlot(t, tp_new, newfunc);
1027
+ if (unlikely(!tp_new)) {
1028
+ __Pyx_RaiseErrorWithType(PyExc_TypeError, "cannot create " __Pyx_FMT_TYPENAME " instances", t);
1029
+ return NULL;
1030
+ }
1031
+ Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(nargsf);
1032
+
1033
+ PyObject *result = NULL, *args_tuple = NULL, *kwds_dict = NULL;
1034
+ Py_ssize_t kw_size = kwnames ? __Pyx_PyTuple_GET_SIZE(kwnames) : 0;
1035
+ #if !CYTHON_ASSUME_SAFE_SIZE
1036
+ if (unlikely(kw_size == -1)) {
1037
+ return NULL;
1038
+ }
1039
+ #endif
1040
+ if (kw_size) {
1041
+ kwds_dict = __Pyx_PyDict_NewPresized(kw_size);
1042
+ if (unlikely(!kwds_dict)) {
1043
+ return NULL;
1044
+ }
1045
+ for (Py_ssize_t i=0; i<kw_size; ++i) {
1046
+ PyObject *v = args[nargs + i];
1047
+ PyObject *k = __Pyx_PyTuple_GET_ITEM(kwnames, i);
1048
+ #if !CYTHON_ASSUME_SAFE_MACROS
1049
+ if (unlikely(!k)) {
1050
+ goto end;
1051
+ }
1052
+ #endif
1053
+
1054
+ if (unlikely(PyDict_SetItem(kwds_dict, k, v) < 0)) {
1055
+ goto end;
1056
+ }
1057
+ }
1058
+ }
1059
+
1060
+ if (nargs) {
1061
+ args_tuple = __Pyx_PyTuple_FromArray(args, nargs);
1062
+ if (unlikely(!args_tuple)) {
1063
+ goto end;
1064
+ }
1065
+ } else {
1066
+ args_tuple = __Pyx_NewRef(EMPTY(tuple));
1067
+ }
1068
+
1069
+ result = tp_new(t, args_tuple, kwds_dict);
1070
+ if (unlikely(!result)) {
1071
+ goto end;
1072
+ }
1073
+ if (PyObject_TypeCheck(result, t)) {
1074
+ initproc tp_init = __Pyx_PyObject_GetSlot(result, tp_init, initproc);
1075
+ if (tp_init && unlikely(tp_init(result, args_tuple, kwds_dict) < 0)) {
1076
+ Py_CLEAR(result);
1077
+ }
1078
+ }
1079
+ end:
1080
+ Py_XDECREF(args_tuple);
1081
+ Py_XDECREF(kwds_dict);
1082
+ return result;
1083
+ }
1084
+ #endif
1085
+
1086
+ ///////////////////////// CallSlotAsVectorcall.proto ////////////////////////////////////
1087
+
1088
+ #if CYTHON_VECTORCALL_TPNEW
1089
+ typedef {{ret_type}} (*__Pyx_{{name}}vectorcallfunc)({{obj_type}} o, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames);
1090
+ static {{ret_type}} __Pyx_Call{{name.title()}}AsVectorcall(__Pyx_{{name}}vectorcallfunc f, {{obj_type}} o, PyObject *a, PyObject *k);
1091
+ #endif
1092
+
1093
+ ///////////////////////// CallSlotAsVectorcall ////////////////////////////////////
1094
+ //@requires: Synchronization.c::CriticalSections
1095
+ //@requires: CallSlotAsVectorcallUnpackDict
1096
+
1097
+ // Possible TODO - the !ASSUME_SAFE_MACROS case is inefficient due to a lot of
1098
+ // error checking, and the inability to optimize the common no-keywords case.
1099
+ // I think it might be possible to use a trampoline type and PyVectorcall_Call to
1100
+ // push this work into the Python interpreter (where they have access to the full C API).
1101
+ #if CYTHON_VECTORCALL_TPNEW
1102
+ static {{ret_type}} __Pyx_Call{{name.title()}}AsVectorcall(__Pyx_{{name}}vectorcallfunc f, {{obj_type}} o, PyObject *a, PyObject *k) {
1103
+ Py_ssize_t k_size = k ? __Pyx_PyDict_GET_SIZE(k) : 0;
1104
+ #if !CYTHON_ASSUME_SAFE_SIZE
1105
+ if (unlikely(k_size < 0)) return {{error_value}};
1106
+ #endif
1107
+ Py_ssize_t a_size = __Pyx_PyTuple_GET_SIZE(a);
1108
+ #if !CYTHON_ASSUME_SAFE_SIZE
1109
+ if (unlikely(a_size < 0)) return {{error_value}};
1110
+ #endif
1111
+ #if CYTHON_ASSUME_SAFE_MACROS
1112
+ if (k_size == 0) {
1113
+ return f(o, &PyTuple_GET_ITEM(a, 0), a_size, NULL);
1114
+ }
1115
+ #else
1116
+ if (k_size == 0 && a_size == 0) {
1117
+ return f(o, NULL, 0, NULL);
1118
+ }
1119
+ #endif
1120
+ PyObject *stack_args[5];
1121
+ PyObject **args = stack_args;
1122
+ Py_ssize_t maxnargs = PY_SSIZE_T_MAX / sizeof(PyObject*) - 1;
1123
+ if (a_size > maxnargs - k_size) {
1124
+ PyErr_NoMemory();
1125
+ return {{error_value}};
1126
+ }
1127
+ Py_ssize_t total_size = a_size + k_size;
1128
+ if (total_size > 5) {
1129
+ args = (PyObject**)PyMem_Malloc(((size_t)total_size)*sizeof(PyObject*));
1130
+ if (unlikely(!args)) {
1131
+ PyErr_NoMemory();
1132
+ return {{error_value}};
1133
+ }
1134
+ }
1135
+ {{ret_type}} result = {{error_value}};
1136
+ PyObject *kwnames = NULL;
1137
+ int unpack_dict_result;
1138
+ Py_ssize_t i = 0;
1139
+ for (; i < a_size; ++i) {
1140
+ args[i] = __Pyx_PyTuple_GET_ITEM(a, i);
1141
+ #if !CYTHON_ASSUME_SAFE_MACROS
1142
+ if (unlikely(!args[i])) goto cleanup;
1143
+ #endif
1144
+ }
1145
+ #if !CYTHON_ASSUME_SAFE_MACROS
1146
+ if (k) // There's a specific shortcut earlier for ASSUME_SAFE_MACROS with no keywords
1147
+ #endif
1148
+ {
1149
+ kwnames = PyTuple_New(k_size);
1150
+ if (unlikely(!kwnames)) goto cleanup;
1151
+ __Pyx_BEGIN_CRITICAL_SECTION(k);
1152
+ unpack_dict_result = __Pyx_CallSlotAsVectorcallUnpackDict(a_size, k, args, kwnames);
1153
+ __Pyx_END_CRITICAL_SECTION();
1154
+ if (unlikely(unpack_dict_result == -1)) goto cleanup;
1155
+ }
1156
+ result = f(o, args, a_size, kwnames);
1157
+ cleanup:
1158
+ Py_XDECREF(kwnames);
1159
+ for (i=a_size; i<total_size; ++i) {
1160
+ Py_XDECREF(args[i]);
1161
+ }
1162
+ if (args != stack_args) {
1163
+ PyMem_Free(args);
1164
+ }
1165
+ return result;
1166
+ }
1167
+ #endif
1168
+
1169
+ ///////////////////////// CallSlotAsVectorcallUnpackDict ////////////////////////////////////
1170
+
1171
+ static CYTHON_INLINE int __Pyx_CallSlotAsVectorcallUnpackDict(Py_ssize_t args_size, PyObject *keys_dict, PyObject **args, PyObject *kwnames) {
1172
+ Py_ssize_t pos = 0, i = 0;
1173
+ PyObject *key, *value;
1174
+ while (PyDict_Next(keys_dict, &pos, &key, &value)) {
1175
+ Py_INCREF(value);
1176
+ args[args_size+i] = value;
1177
+ Py_INCREF(key);
1178
+ if (unlikely(__Pyx_PyTuple_SET_ITEM(kwnames, i, key) == -1)) {
1179
+ return -1;
1180
+ }
1181
+ // CPython puts a check that the key is a string here. Cython skips this
1182
+ // because it's checked later in our function wrappers.
1183
+ ++i;
1184
+ }
1185
+ return 0;
1186
+ }