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
@@ -34,6 +34,12 @@
34
34
  #endif
35
35
  #endif
36
36
 
37
+ #ifdef __has_builtin
38
+ #define __Pyx_has_cbuiltin(name) __has_builtin(name)
39
+ #else
40
+ #define __Pyx_has_cbuiltin(name) (0)
41
+ #endif
42
+
37
43
  #ifndef DL_IMPORT
38
44
  #define DL_IMPORT(t) t
39
45
  #endif
@@ -67,8 +73,9 @@
67
73
 
68
74
  #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 0
69
75
 
70
- #undef CYTHON_USE_TYPE_SLOTS
71
- #define CYTHON_USE_TYPE_SLOTS 0
76
+ #ifndef CYTHON_USE_TYPE_SLOTS
77
+ #define CYTHON_USE_TYPE_SLOTS 0
78
+ #endif
72
79
  #undef CYTHON_USE_TYPE_SPECS
73
80
  #define CYTHON_USE_TYPE_SPECS 0
74
81
  #undef CYTHON_USE_PYTYPE_LOOKUP
@@ -95,10 +102,16 @@
95
102
  #define CYTHON_FAST_THREAD_STATE 0
96
103
  #undef CYTHON_FAST_GIL
97
104
  #define CYTHON_FAST_GIL 0
98
- #undef CYTHON_METH_FASTCALL
99
- #define CYTHON_METH_FASTCALL 0
100
- #undef CYTHON_FAST_PYCALL
101
- #define CYTHON_FAST_PYCALL 0
105
+ #ifndef CYTHON_VECTORCALL
106
+ #define CYTHON_VECTORCALL 1
107
+ #endif
108
+ #if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX < 0x030E0000
109
+ // Py_tp_vectorcall slot unavailable
110
+ #undef CYTHON_VECTORCALL_TPNEW
111
+ #define CYTHON_VECTORCALL_TPNEW 0
112
+ #elif !defined(CYTHON_VECTORCALL_TPNEW)
113
+ #define CYTHON_VECTORCALL_TPNEW CYTHON_VECTORCALL
114
+ #endif
102
115
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
103
116
  #define CYTHON_PEP487_INIT_SUBCLASS 1
104
117
  #endif
@@ -123,6 +136,8 @@
123
136
  #define CYTHON_USE_FREELISTS 0
124
137
  #undef CYTHON_IMMORTAL_CONSTANTS
125
138
  #define CYTHON_IMMORTAL_CONSTANTS 0
139
+ #undef CYTHON_OPAQUE_OBJECTS
140
+ #define CYTHON_OPAQUE_OBJECTS 0
126
141
 
127
142
  #elif defined(PYPY_VERSION)
128
143
  #define CYTHON_COMPILING_IN_PYPY 1
@@ -162,17 +177,21 @@
162
177
  #define CYTHON_FAST_THREAD_STATE 0
163
178
  #undef CYTHON_FAST_GIL
164
179
  #define CYTHON_FAST_GIL 0
165
- #undef CYTHON_METH_FASTCALL
166
- #define CYTHON_METH_FASTCALL 0
167
- #undef CYTHON_FAST_PYCALL
168
- #define CYTHON_FAST_PYCALL 0
180
+ #ifndef CYTHON_VECTORCALL
181
+ #define CYTHON_VECTORCALL 1
182
+ #endif
183
+ #if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX < 0x030E0000
184
+ // Py_tp_vectorcall slot unavailable
185
+ #undef CYTHON_VECTORCALL_TPNEW
186
+ #define CYTHON_VECTORCALL_TPNEW 0
187
+ #elif !defined(CYTHON_VECTORCALL_TPNEW)
188
+ // PyPy doesn't define the slot below 7.3.8.
189
+ #define CYTHON_VECTORCALL_TPNEW (PYPY_VERSION_NUM >= 0x07030800 && CYTHON_VECTORCALL)
190
+ #endif
169
191
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
170
192
  #define CYTHON_PEP487_INIT_SUBCLASS 1
171
193
  #endif
172
- #if PY_VERSION_HEX < 0x03090000
173
- #undef CYTHON_PEP489_MULTI_PHASE_INIT
174
- #define CYTHON_PEP489_MULTI_PHASE_INIT 0
175
- #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT)
194
+ #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
176
195
  #define CYTHON_PEP489_MULTI_PHASE_INIT 1
177
196
  #endif
178
197
  #undef CYTHON_USE_MODULE_STATE
@@ -195,12 +214,16 @@
195
214
  #define CYTHON_USE_FREELISTS 0
196
215
  #undef CYTHON_IMMORTAL_CONSTANTS
197
216
  #define CYTHON_IMMORTAL_CONSTANTS 0
217
+ #undef CYTHON_OPAQUE_OBJECTS
218
+ #define CYTHON_OPAQUE_OBJECTS 0
198
219
 
199
220
  #elif defined(CYTHON_LIMITED_API)
200
- // EXPERIMENTAL !!
201
221
  #ifdef Py_LIMITED_API
202
222
  #undef __PYX_LIMITED_VERSION_HEX
203
223
  #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API
224
+ #if Py_LIMITED_API < 0x03090000
225
+ #error "Cython 3.3 requires the Python Limited API version to be 3.9 or greater."
226
+ #endif
204
227
  #endif
205
228
  #define CYTHON_COMPILING_IN_PYPY 0
206
229
  #define CYTHON_COMPILING_IN_CPYTHON 0
@@ -240,10 +263,11 @@
240
263
  #define CYTHON_FAST_THREAD_STATE 0
241
264
  #undef CYTHON_FAST_GIL
242
265
  #define CYTHON_FAST_GIL 0
243
- #undef CYTHON_METH_FASTCALL
244
- #define CYTHON_METH_FASTCALL (__PYX_LIMITED_VERSION_HEX >= 0x030C0000)
245
- #undef CYTHON_FAST_PYCALL
246
- #define CYTHON_FAST_PYCALL 0
266
+ #undef CYTHON_VECTORCALL
267
+ #define CYTHON_VECTORCALL (__PYX_LIMITED_VERSION_HEX >= 0x030C0000)
268
+ #ifndef CYTHON_VECTORCALL_TPNEW
269
+ #define CYTHON_VECTORCALL_TPNEW (CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030E0000)
270
+ #endif
247
271
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
248
272
  #define CYTHON_PEP487_INIT_SUBCLASS 1
249
273
  #endif
@@ -257,7 +281,7 @@
257
281
  #define CYTHON_USE_SYS_MONITORING 0
258
282
  #ifndef CYTHON_USE_TP_FINALIZE
259
283
  // PyObject_CallFinalizerFromDealloc is missing and not easily replaced
260
- #define CYTHON_USE_TP_FINALIZE 0
284
+ #define CYTHON_USE_TP_FINALIZE (__PYX_LIMITED_VERSION_HEX >= 0x030F0000 && PY_VERSION_HEX > 0x030F00A8)
261
285
  #endif
262
286
  #ifndef CYTHON_USE_AM_SEND
263
287
  #define CYTHON_USE_AM_SEND (__PYX_LIMITED_VERSION_HEX >= 0x030A0000)
@@ -274,6 +298,16 @@
274
298
  #endif
275
299
  #undef CYTHON_IMMORTAL_CONSTANTS
276
300
  #define CYTHON_IMMORTAL_CONSTANTS 0
301
+ // Opaque objects: generally we prefer not to use them for performance reasons.
302
+ #if __PYX_LIMITED_VERSION_HEX < 0x030E0000
303
+ // If users manually request them then they aren't usable before 3.14 because
304
+ // it isn't possible to specify relative offsets like vectorcall.
305
+ #undef CYTHON_OPAQUE_OBJECTS
306
+ #define CYTHON_OPAQUE_OBJECTS 0
307
+ #elif !defined(CYTHON_OPAQUE_OBJECTS)
308
+ // From 3.15 it starts being needed for freethreading compatibility
309
+ #define CYTHON_OPAQUE_OBJECTS (__PYX_LIMITED_VERSION_HEX >= 0x030F0000)
310
+ #endif
277
311
 
278
312
  #else
279
313
  #define CYTHON_COMPILING_IN_PYPY 0
@@ -354,13 +388,15 @@
354
388
  // The gain is unclear, however, since the GIL handling itself became faster in recent CPython versions.
355
389
  #define CYTHON_FAST_GIL (PY_VERSION_HEX < 0x030C00A6)
356
390
  #endif
357
- #ifndef CYTHON_METH_FASTCALL
358
- // CPython 3.6 introduced METH_FASTCALL but with slightly different
359
- // semantics. It became stable starting from CPython 3.7.
360
- #define CYTHON_METH_FASTCALL 1
391
+ #ifndef CYTHON_VECTORCALL
392
+ #define CYTHON_VECTORCALL 1
361
393
  #endif
362
- #ifndef CYTHON_FAST_PYCALL
363
- #define CYTHON_FAST_PYCALL 1
394
+ #if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX < 0x030E0000
395
+ // Py_tp_vectorcall slot unavailable
396
+ #undef CYTHON_VECTORCALL_TPNEW
397
+ #define CYTHON_VECTORCALL_TPNEW 0
398
+ #elif !defined(CYTHON_VECTORCALL_TPNEW)
399
+ #define CYTHON_VECTORCALL_TPNEW CYTHON_VECTORCALL
364
400
  #endif
365
401
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
366
402
  #define CYTHON_PEP487_INIT_SUBCLASS 1
@@ -408,27 +444,9 @@
408
444
  // could be a memory leak). However the user can always override these assumptions.
409
445
  #define CYTHON_IMMORTAL_CONSTANTS (PY_VERSION_HEX >= 0x030C0000 && !CYTHON_USE_MODULE_STATE && CYTHON_COMPILING_IN_CPYTHON_FREETHREADING)
410
446
  #endif
411
- #endif
412
-
413
- #ifndef CYTHON_COMPRESS_STRINGS
414
- #define CYTHON_COMPRESS_STRINGS 1
415
- #endif
416
-
417
- #ifndef CYTHON_FAST_PYCCALL
418
- #define CYTHON_FAST_PYCCALL CYTHON_FAST_PYCALL
419
- #endif
420
-
421
- #ifndef CYTHON_VECTORCALL
422
- #if CYTHON_COMPILING_IN_LIMITED_API
423
- // Possibly needs a bit of clearing up, however:
424
- // the limited API doesn't define CYTHON_FAST_PYCCALL (because that involves
425
- // a lot of access to internals) but does define CYTHON_VECTORCALL because
426
- // that's available cleanly from Python 3.12. Note that only VectorcallDict isn't
427
- // available though.
428
- #define CYTHON_VECTORCALL (__PYX_LIMITED_VERSION_HEX >= 0x030C0000)
429
- #else
430
- #define CYTHON_VECTORCALL (CYTHON_FAST_PYCCALL)
431
- #endif
447
+ #ifndef CYTHON_OPAQUE_OBJECTS
448
+ #define CYTHON_OPAQUE_OBJECTS 0
449
+ #endif
432
450
  #endif
433
451
 
434
452
  #if CYTHON_USE_PYLONG_INTERNALS
@@ -473,6 +491,8 @@
473
491
  #define CYTHON_UNUSED [[maybe_unused]]
474
492
  #endif
475
493
  #endif
494
+ #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
495
+ #define CYTHON_UNUSED [[maybe_unused]]
476
496
  #endif
477
497
  #endif
478
498
  #ifndef CYTHON_UNUSED
@@ -559,8 +579,20 @@ typedef uintptr_t __pyx_uintptr_t;
559
579
  #endif
560
580
  #endif
561
581
 
582
+ #ifdef Py_UNREACHABLE
583
+ #define __Pyx_UNREACHABLE() Py_UNREACHABLE()
584
+ #elif __Pyx_has_cbuiltin(__builtin_unreachable)
585
+ #define __Pyx_UNREACHABLE() __builtin_unreachable()
586
+ #elif defined(__clang__) || defined(__INTEL_COMPILER) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)))
587
+ #define __Pyx_UNREACHABLE() __builtin_unreachable()
588
+ #elif defined(_MSC_VER)
589
+ #define __Pyx_UNREACHABLE() __assume(0)
590
+ #else
591
+ #define __Pyx_UNREACHABLE() Py_FatalError("Unreachable C code path reached")
592
+ #endif
593
+
562
594
  #ifndef Py_UNREACHABLE
563
- #define Py_UNREACHABLE() assert(0); abort()
595
+ #define Py_UNREACHABLE() __Pyx_UNREACHABLE()
564
596
  #endif
565
597
 
566
598
  #ifdef __cplusplus
@@ -574,7 +606,7 @@ typedef uintptr_t __pyx_uintptr_t;
574
606
  #if CYTHON_COMPILING_IN_PYPY == 1
575
607
  #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX < 0x030A0000)
576
608
  #else
577
- #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX < 0x03090000)
609
+ #define __PYX_NEED_TP_PRINT_SLOT 0
578
610
  #endif
579
611
  // reinterpret
580
612
 
@@ -583,6 +615,14 @@ typedef uintptr_t __pyx_uintptr_t;
583
615
  // #define __PYX_REINTERPRET_POINTER(pointer_type, pointer) ((pointer_type)(void *)(pointer))
584
616
  // #define __PYX_RUNTIME_REINTERPRET(type, var) (*(type *)(&var))
585
617
 
618
+ #if __PYX_LIMITED_VERSION_HEX < 0x030C0000
619
+ #define __Pyx_PyErr_FetchException(petype, peval, petb) PyErr_Fetch(petype, peval, petb)
620
+ #define __Pyx_PyErr_RestoreException(etype, eval, etb) PyErr_Restore(etype, eval, etb)
621
+ #else
622
+ #define __Pyx_PyErr_FetchException(petype, peval, petb) *(petype)=NULL; *(peval)=PyErr_GetRaisedException(); *(petb)=NULL
623
+ #define __Pyx_PyErr_RestoreException(etype, eval, etb) PyErr_SetRaisedException(eval)
624
+ #endif
625
+
586
626
 
587
627
  /////////////// CInitCode ///////////////
588
628
 
@@ -689,12 +729,6 @@ class __Pyx_FakeReference {
689
729
  #endif
690
730
  static int __Pyx_init_co_variables(void); /* proto */
691
731
 
692
- #if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE)
693
- #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type)
694
- #else
695
- #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type))
696
- #endif
697
-
698
732
  #if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is)
699
733
  #define __Pyx_Py_Is(x, y) Py_Is(x, y)
700
734
  #else
@@ -717,29 +751,33 @@ static int __Pyx_init_co_variables(void); /* proto */
717
751
  #endif
718
752
  #define __Pyx_NoneAsNull(obj) (__Pyx_Py_IsNone(obj) ? NULL : (obj))
719
753
 
720
- #if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY
721
- #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o)
722
- #else
754
+ #if CYTHON_COMPILING_IN_PYPY
723
755
  #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o)
756
+ #else
757
+ #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o)
724
758
  #endif
725
759
 
726
- #ifndef Py_TPFLAGS_CHECKTYPES
727
- #define Py_TPFLAGS_CHECKTYPES 0
728
- #endif
729
- #ifndef Py_TPFLAGS_HAVE_INDEX
730
- #define Py_TPFLAGS_HAVE_INDEX 0
731
- #endif
732
- #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
733
- #define Py_TPFLAGS_HAVE_NEWBUFFER 0
760
+ #if CYTHON_COMPILING_IN_LIMITED_API
761
+ // These can be deduced at runtime and are enough of an optimization that
762
+ // it's worth doing (while still respecting the decision not to add them to
763
+ // the Limited API).
764
+ static unsigned long __Pyx_Runtime_TPFLAGS_SEQUENCE;
765
+ static unsigned long __Pyx_Runtime_TPFLAGS_MAPPING;
766
+ #else
767
+ #define __Pyx_Runtime_TPFLAGS_SEQUENCE Py_TPFLAGS_SEQUENCE
768
+ #define __Pyx_Runtime_TPFLAGS_MAPPING Py_TPFLAGS_MAPPING
734
769
  #endif
770
+
771
+ static int __Pyx_init_tpflags_variables(void); /* proto */
772
+
735
773
  #ifndef Py_TPFLAGS_HAVE_FINALIZE
736
774
  #define Py_TPFLAGS_HAVE_FINALIZE 0
737
775
  #endif
738
776
  #ifndef Py_TPFLAGS_SEQUENCE
739
- #define Py_TPFLAGS_SEQUENCE 0
777
+ #define Py_TPFLAGS_SEQUENCE (CYTHON_COMPILING_IN_LIMITED_API ? 0 : 1 << 5)
740
778
  #endif
741
779
  #ifndef Py_TPFLAGS_MAPPING
742
- #define Py_TPFLAGS_MAPPING 0
780
+ #define Py_TPFLAGS_MAPPING (CYTHON_COMPILING_IN_LIMITED_API ? 0 : 1 << 6)
743
781
  #endif
744
782
  #ifndef Py_TPFLAGS_IMMUTABLETYPE
745
783
  #define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)
@@ -749,16 +787,17 @@ static int __Pyx_init_co_variables(void); /* proto */
749
787
  #endif
750
788
 
751
789
  #ifndef METH_STACKLESS
752
- // already defined for Stackless Python (all versions) and C-Python >= 3.7
753
- // value if defined: Stackless Python < 3.6: 0x80 else 0x100
790
+ // Now unused. Already defined for Stackless Python (all versions) and C-Python >= 3.7.
791
+ // Value if defined: Stackless Python < 3.6: 0x80 else 0x100.
754
792
  #define METH_STACKLESS 0
755
793
  #endif
756
- #ifndef METH_FASTCALL
794
+ #if !defined(METH_FASTCALL) || CYTHON_COMPILING_IN_PYPY
757
795
  // new in CPython 3.6, but changed in 3.7 - see
758
796
  // positional-only parameters:
759
797
  // https://bugs.python.org/issue29464
760
798
  // const args:
761
799
  // https://bugs.python.org/issue32240
800
+ // PyPy doesn't have the const args.
762
801
  #ifndef METH_FASTCALL
763
802
  #define METH_FASTCALL 0x80
764
803
  #endif
@@ -776,7 +815,7 @@ static int __Pyx_init_co_variables(void); /* proto */
776
815
  #endif
777
816
  #endif
778
817
 
779
- #if CYTHON_METH_FASTCALL
818
+ #if CYTHON_VECTORCALL
780
819
  #define __Pyx_METH_FASTCALL METH_FASTCALL
781
820
  #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast
782
821
  #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords
@@ -798,11 +837,7 @@ static int __Pyx_init_co_variables(void); /* proto */
798
837
  // These PyCFunction related macros get redefined in CythonFunction.c.
799
838
  // We need our own copies because the inline functions in CPython have a type-check assert
800
839
  // that breaks with a CyFunction in debug mode.
801
- #if PY_VERSION_HEX >= 0x030900B1
802
- #define __Pyx_PyCFunction_CheckExact(func) PyCFunction_CheckExact(func)
803
- #else
804
- #define __Pyx_PyCFunction_CheckExact(func) PyCFunction_Check(func)
805
- #endif
840
+ #define __Pyx_PyCFunction_CheckExact(func) PyCFunction_CheckExact(func)
806
841
  #define __Pyx_CyOrPyCFunction_Check(func) PyCFunction_Check(func)
807
842
 
808
843
  #if CYTHON_COMPILING_IN_CPYTHON
@@ -829,11 +864,15 @@ static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void (*cfunc)(vo
829
864
  #define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCFunction(func, cfunc)
830
865
 
831
866
  // PEP-573: PyCFunction holds reference to defining class (PyCMethodObject)
832
- #if PY_VERSION_HEX < 0x03090000 || (CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000)
867
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
833
868
  #define __Pyx_PyType_FromModuleAndSpec(m, s, b) ((void)m, PyType_FromSpecWithBases(s, b))
834
- typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *);
835
869
  #else
836
870
  #define __Pyx_PyType_FromModuleAndSpec(m, s, b) PyType_FromModuleAndSpec(m, s, b)
871
+ #endif
872
+ #if CYTHON_COMPILING_IN_PYPY
873
+ // PyPy's internal definition misses the const
874
+ typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *);
875
+ #else
837
876
  #define __Pyx_PyCMethod PyCMethod
838
877
  #endif
839
878
  #ifndef METH_METHOD
@@ -871,6 +910,19 @@ static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void (*cfunc)(vo
871
910
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
872
911
  #endif
873
912
 
913
+ // For our shared types, they are only ever opaque in the Limited API.
914
+ // While there may be a reason to let users override their own types,
915
+ // there's no benefit to changing our internal types except in the Limited API.
916
+ #if CYTHON_OPAQUE_OBJECTS && CYTHON_COMPILING_IN_LIMITED_API
917
+ #define __PYX_SHARED_SIZEOF(T) -((int)sizeof(T))
918
+ #define __PYX_SHARED_RELATIVE_OFFSET Py_RELATIVE_OFFSET
919
+ #define CYTHON_OPAQUE_SHARED_TYPES 1
920
+ #else
921
+ #define __PYX_SHARED_SIZEOF(T) sizeof(T)
922
+ #define __PYX_SHARED_RELATIVE_OFFSET 0
923
+ #define CYTHON_OPAQUE_SHARED_TYPES 0
924
+ #endif
925
+
874
926
  #if CYTHON_USE_MODULE_STATE
875
927
  static CYTHON_INLINE void *__Pyx__PyModule_GetState(PyObject *op)
876
928
  {
@@ -924,7 +976,11 @@ static CYTHON_INLINE void *__Pyx__PyModule_GetState(PyObject *op)
924
976
  #define __Pyx_PyDict_GetItemStrWithError(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
925
977
  static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) {
926
978
  PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name);
927
- if (res == NULL) PyErr_Clear();
979
+ if (res == NULL && PyErr_Occurred()) {
980
+ // Like PyDict_GetItem, this is a bit indiscriminate about catching *all* errors.
981
+ // Recent versions of Python format any unraised exception so do that too here.
982
+ PyErr_WriteUnraisable(NULL);
983
+ }
928
984
  return res;
929
985
  }
930
986
  #elif !CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000
@@ -990,6 +1046,7 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
990
1046
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i)
991
1047
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((void)u, 1114111U)
992
1048
  #define __Pyx_PyUnicode_KIND(u) ((void)u, (0))
1049
+ #define __Pyx_PyUnicode_KIND_04(u) __Pyx_PyUnicode_KIND(u)
993
1050
  // __Pyx_PyUnicode_DATA() and __Pyx_PyUnicode_READ() must go together, e.g. for iteration.
994
1051
  #define __Pyx_PyUnicode_DATA(u) ((void*)u)
995
1052
  #define __Pyx_PyUnicode_READ(k, d, i) ((void)k, PyUnicode_ReadChar((PyObject*)(d), i))
@@ -1013,7 +1070,7 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
1013
1070
  #if PY_VERSION_HEX >= 0x030C0000
1014
1071
  #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u))
1015
1072
  #else
1016
- #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
1073
+ #if CYTHON_COMPILING_IN_CPYTHON
1017
1074
  // Avoid calling deprecated C-API functions in Py3.9+ that PEP-623 schedules for removal in Py3.12.
1018
1075
  // https://www.python.org/dev/peps/pep-0623/
1019
1076
  #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
@@ -1021,6 +1078,11 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
1021
1078
  #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
1022
1079
  #endif
1023
1080
  #endif
1081
+
1082
+ static CYTHON_INLINE int __Pyx_PyUnicode_KIND_04(PyObject *o) {
1083
+ // Returns 0 for ASCII strings and KIND (1, 2, 4) otherwise.
1084
+ return __Pyx_PyUnicode_KIND(o) - (int) !!PyUnicode_IS_ASCII(o);
1085
+ }
1024
1086
  #endif
1025
1087
 
1026
1088
  #if CYTHON_COMPILING_IN_PYPY
@@ -1061,15 +1123,7 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
1061
1123
  #endif
1062
1124
 
1063
1125
  #ifndef PySet_CheckExact
1064
- #define PySet_CheckExact(obj) __Pyx_IS_TYPE(obj, &PySet_Type)
1065
- #endif
1066
-
1067
- #if PY_VERSION_HEX >= 0x030900A4
1068
- #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
1069
- #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
1070
- #else
1071
- #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
1072
- #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
1126
+ #define PySet_CheckExact(obj) Py_IS_TYPE(obj, &PySet_Type)
1073
1127
  #endif
1074
1128
 
1075
1129
  enum __Pyx_ReferenceSharing {
@@ -1173,6 +1227,7 @@ static CYTHON_INLINE int __Pyx_PyDict_GetItemRef(PyObject *dict, PyObject *key,
1173
1227
  #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o)
1174
1228
  #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o)
1175
1229
  #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o)
1230
+ #define __Pyx_PyDict_GET_SIZE(o) PyDict_GET_SIZE(o)
1176
1231
  #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o)
1177
1232
  #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o)
1178
1233
  #define __Pyx_PyUnicode_GET_LENGTH(o) PyUnicode_GET_LENGTH(o)
@@ -1181,6 +1236,7 @@ static CYTHON_INLINE int __Pyx_PyDict_GetItemRef(PyObject *dict, PyObject *key,
1181
1236
  #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o)
1182
1237
  #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o)
1183
1238
  #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o)
1239
+ #define __Pyx_PyDict_GET_SIZE(o) PyDict_Size(o)
1184
1240
  #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o)
1185
1241
  #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o)
1186
1242
  #define __Pyx_PyUnicode_GET_LENGTH(o) PyUnicode_GetLength(o)
@@ -1241,12 +1297,6 @@ static CYTHON_INLINE int __Pyx_PyDict_GetItemRef(PyObject *dict, PyObject *key,
1241
1297
  #define __Pyx_TPFLAGS_HAVE_AM_SEND (0)
1242
1298
  #endif
1243
1299
 
1244
- #if PY_VERSION_HEX >= 0x03090000
1245
- #define __Pyx_PyInterpreterState_Get() PyInterpreterState_Get()
1246
- #else
1247
- #define __Pyx_PyInterpreterState_Get() PyThreadState_Get()->interp
1248
- #endif
1249
-
1250
1300
  #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030A0000
1251
1301
  // PyMem_Calloc *is* in the Stable ABI in all the Limited API versions we care about.
1252
1302
  // However, it is omitted from the Python headers which means that C incorrectly
@@ -1304,10 +1354,84 @@ static int __Pyx_init_co_variables(void) {
1304
1354
  Py_DECREF(inspect);
1305
1355
  return result ? 0 : -1;
1306
1356
  }
1357
+
1358
+ static int __Pyx_init_tpflags_bitcount(unsigned long flag) {
1359
+ int count = 0;
1360
+ while (flag) {
1361
+ count += (int) (flag & 1);
1362
+ flag >>= 1;
1363
+ }
1364
+ return count;
1365
+ }
1366
+
1367
+ // It's quite possible that the flags aren't reliably available at runtime.
1368
+ // Therefore most errors are ignored and we just leave the values as 0.
1369
+ static int __Pyx_init_tpflags_variables(void) {
1370
+ if (__Pyx_Runtime_TPFLAGS_SEQUENCE != 0 && __Pyx_Runtime_TPFLAGS_MAPPING != 0) {
1371
+ // Already set (possibly in another subinterpreter). Note that there's a
1372
+ // harmless race here because the variables aren't atomic.
1373
+ return 0;
1374
+ }
1375
+
1376
+ PyObject *collections_abc = PyImport_ImportModule("collections.abc");
1377
+ if (!collections_abc) return -1;
1378
+
1379
+ int result = 0;
1380
+ PyObject *sequence = NULL, *mapping = NULL;
1381
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030D0000
1382
+ if (PyObject_GetOptionalAttrString(collections_abc, "Sequence", &sequence) != 1) goto fail;
1383
+ if (PyObject_GetOptionalAttrString(collections_abc, "Mapping", &mapping) != 1) goto fail;
1384
+ #else
1385
+ sequence = PyObject_GetAttrString(collections_abc, "Sequence");
1386
+ if (!sequence) goto fail_attr_lookup;
1387
+ mapping = PyObject_GetAttrString(collections_abc, "Mapping");
1388
+ if (!mapping) goto fail_attr_lookup;
1389
+ #endif
1390
+
1391
+ // The assumption is that the the type flags for sequence and mapping
1392
+ // should be identical except for a single bit on each class.
1393
+ // If that isn't true then fail silently.
1394
+
1395
+ if (!PyType_Check(sequence) || !PyType_Check(mapping)) goto fail;
1396
+ {
1397
+ unsigned long sequence_flags = PyType_GetFlags((PyTypeObject*)sequence);
1398
+ unsigned long mapping_flags = PyType_GetFlags((PyTypeObject*)mapping);
1399
+ unsigned long mutual_flags = sequence_flags & mapping_flags;
1400
+ sequence_flags = sequence_flags ^ mutual_flags;
1401
+ mapping_flags = mapping_flags ^ mutual_flags;
1402
+
1403
+ if (__Pyx_Runtime_TPFLAGS_SEQUENCE == 0 && __Pyx_init_tpflags_bitcount(sequence_flags) == 1) {
1404
+ __Pyx_Runtime_TPFLAGS_SEQUENCE = sequence_flags;
1405
+ }
1406
+ if (__Pyx_Runtime_TPFLAGS_MAPPING == 0 && __Pyx_init_tpflags_bitcount(mapping_flags) == 1) {
1407
+ __Pyx_Runtime_TPFLAGS_MAPPING = mapping_flags;
1408
+ }
1409
+ }
1410
+
1411
+ cleanup:
1412
+ Py_XDECREF(mapping);
1413
+ Py_XDECREF(sequence);
1414
+ Py_DECREF(collections_abc);
1415
+
1416
+ return result;
1417
+ #if __PYX_LIMITED_VERSION_HEX < 0x030D0000
1418
+ fail_attr_lookup:
1419
+ if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
1420
+ PyErr_Clear();
1421
+ }
1422
+ #endif
1423
+ fail:
1424
+ result = PyErr_Occurred() ? -1 : 0;
1425
+ goto cleanup;
1426
+ }
1307
1427
  #else
1308
1428
  static int __Pyx_init_co_variables(void) {
1309
1429
  return 0; // It's a limited API-only feature
1310
1430
  }
1431
+
1432
+ static int __Pyx_init_tpflags_variables(void) {
1433
+ return 0; // It's a limited API-only feature
1434
+ }
1311
1435
  #endif
1312
1436
 
1313
1437
  /////////////// CythonABIVersion.proto ///////////////
@@ -1317,13 +1441,13 @@ static int __Pyx_init_co_variables(void) {
1317
1441
  #if CYTHON_COMPILING_IN_LIMITED_API
1318
1442
  // The limited API makes some significant changes to data structures, so we don't
1319
1443
  // want to share the implementations compiled with and without the limited API.
1320
- #if CYTHON_METH_FASTCALL
1321
- #define __PYX_FASTCALL_ABI_SUFFIX "_fastcall"
1444
+ #if CYTHON_VECTORCALL
1445
+ #define __PYX_VECTORCALL_ABI_SUFFIX "_vectorcall"
1322
1446
  #else
1323
- #define __PYX_FASTCALL_ABI_SUFFIX
1447
+ #define __PYX_VECTORCALL_ABI_SUFFIX
1324
1448
  #endif
1325
1449
 
1326
- #define __PYX_LIMITED_ABI_SUFFIX "limited" __PYX_FASTCALL_ABI_SUFFIX __PYX_AM_SEND_ABI_SUFFIX
1450
+ #define __PYX_LIMITED_ABI_SUFFIX "limited" __PYX_VECTORCALL_ABI_SUFFIX __PYX_AM_SEND_ABI_SUFFIX
1327
1451
  #else
1328
1452
  #define __PYX_LIMITED_ABI_SUFFIX
1329
1453
  #endif
@@ -1354,14 +1478,21 @@ static int __Pyx_init_co_variables(void) {
1354
1478
  #define __PYX_FREELISTS_ABI_SUFFIX "nofreelists"
1355
1479
  #endif
1356
1480
 
1357
- #define CYTHON_ABI __PYX_ABI_VERSION __PYX_LIMITED_ABI_SUFFIX __PYX_MONITORING_ABI_SUFFIX __PYX_TP_FINALIZE_ABI_SUFFIX __PYX_FREELISTS_ABI_SUFFIX __PYX_AM_SEND_ABI_SUFFIX
1481
+ // Outside the Limited API we don't use opaque objects for shared types (even if we may use them elsewhere)
1482
+ #if CYTHON_OPAQUE_OBJECTS && CYTHON_COMPILING_IN_LIMITED_API
1483
+ #define __PYX_OPAQUE_OBJECTS_ABI_SUFFIX "opaque"
1484
+ #else
1485
+ #define __PYX_OPAQUE_OBJECTS_ABI_SUFFIX
1486
+ #endif
1487
+
1488
+ #define CYTHON_ABI __PYX_ABI_VERSION __PYX_LIMITED_ABI_SUFFIX __PYX_MONITORING_ABI_SUFFIX __PYX_TP_FINALIZE_ABI_SUFFIX __PYX_FREELISTS_ABI_SUFFIX __PYX_AM_SEND_ABI_SUFFIX __PYX_OPAQUE_OBJECTS_ABI_SUFFIX
1358
1489
 
1359
1490
  #define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
1360
1491
  #define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
1361
1492
 
1362
1493
  /////////////// PythonCompatibility.init ///////////////
1363
1494
 
1364
- if (likely(__Pyx_init_co_variables() == 0)); else
1495
+ if (likely(__Pyx_init_co_variables() == 0 && __Pyx_init_tpflags_variables() == 0)); else
1365
1496
 
1366
1497
 
1367
1498
  /////////////// IncludeStructmemberH.proto ///////////////
@@ -1558,13 +1689,15 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj
1558
1689
  /////////////// ModuleCreationPEP489 ///////////////
1559
1690
  //@substitute: naming
1560
1691
 
1561
- #if CYTHON_COMPILING_IN_LIMITED_API && (__PYX_LIMITED_VERSION_HEX < 0x03090000 \
1562
- || ((defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)) && __PYX_LIMITED_VERSION_HEX < 0x030A0000))
1563
- // Probably won't work before 3.8, but we don't use restricted API to find that out.
1692
+ #if CYTHON_COMPILING_IN_LIMITED_API && (__PYX_LIMITED_VERSION_HEX < 0x030A0000 && \
1693
+ (defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)))
1564
1694
  static PY_INT64_T __Pyx_GetCurrentInterpreterId(void) {
1565
1695
  {
1566
1696
  PyObject *module = PyImport_ImportModule("_interpreters"); // 3.13+ I think
1567
1697
  if (!module) {
1698
+ if (!PyErr_ExceptionMatches(PyExc_Exception)) {
1699
+ goto bad; // BaseException
1700
+ }
1568
1701
  PyErr_Clear(); // just try the 3.8-3.12 version
1569
1702
  module = PyImport_ImportModule("_xxsubinterpreters");
1570
1703
  if (!module) goto bad;
@@ -1598,8 +1731,8 @@ static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
1598
1731
  PY_INT64_T current_id = GraalPyInterpreterState_GetIDFromThreadState(PyThreadState_Get());
1599
1732
  #elif CYTHON_COMPILING_IN_GRAAL
1600
1733
  PY_INT64_T current_id = PyInterpreterState_GetIDFromThreadState(PyThreadState_Get());
1601
- #elif CYTHON_COMPILING_IN_LIMITED_API && (__PYX_LIMITED_VERSION_HEX < 0x03090000 \
1602
- || ((defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)) && __PYX_LIMITED_VERSION_HEX < 0x030A0000))
1734
+ #elif CYTHON_COMPILING_IN_LIMITED_API && (__PYX_LIMITED_VERSION_HEX < 0x030A0000 && \
1735
+ (defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)))
1603
1736
  // Although PyInterpreterState_Get is part of the Stable ABI from Python 3.9,
1604
1737
  // it was somehow omitted from the Windows dll in that version.
1605
1738
  PY_INT64_T current_id = __Pyx_GetCurrentInterpreterId();
@@ -2055,8 +2188,10 @@ end:
2055
2188
  #if CYTHON_REFNANNY
2056
2189
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
2057
2190
  if (!__Pyx_RefNanny) {
2058
- PyErr_Clear();
2059
- __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
2191
+ if (PyErr_ExceptionMatches(PyExc_Exception)) {
2192
+ PyErr_Clear();
2193
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
2194
+ }
2060
2195
  if (!__Pyx_RefNanny)
2061
2196
  Py_FatalError("failed to import 'refnanny' module");
2062
2197
  }
@@ -2076,6 +2211,7 @@ static int __Pyx_RegisterCleanup(void); /*proto*/
2076
2211
 
2077
2212
  /////////////// RegisterModuleCleanup ///////////////
2078
2213
  //@substitute: naming
2214
+ //@requires: Exceptions.c::IgnoreException
2079
2215
 
2080
2216
  #if CYTHON_COMPILING_IN_PYPY
2081
2217
  static PyObject* ${cleanup_cname}_atexit(PyObject *module, PyObject *unused) {
@@ -2113,10 +2249,11 @@ static int __Pyx_RegisterCleanup(void) {
2113
2249
  if (reg && PyList_Check(reg)) {
2114
2250
  PyObject *a, *kw;
2115
2251
  a = PyTuple_New(0);
2252
+ if (!a)
2253
+ goto bad;
2116
2254
  kw = PyDict_New();
2117
- if (!a || !kw) {
2118
- Py_XDECREF(a);
2119
- Py_XDECREF(kw);
2255
+ if (!kw) {
2256
+ Py_DECREF(a);
2120
2257
  goto bad;
2121
2258
  }
2122
2259
  args = PyTuple_Pack(3, cleanup_func, a, kw);
@@ -2126,9 +2263,13 @@ static int __Pyx_RegisterCleanup(void) {
2126
2263
  goto bad;
2127
2264
  ret = PyList_Insert(reg, 0, args);
2128
2265
  } else {
2129
- if (!reg)
2130
- PyErr_Clear();
2131
- Py_XDECREF(reg);
2266
+ if (!reg) {
2267
+ if (!__Pyx_IgnoreException(PyExc_AttributeError)) {
2268
+ goto bad;
2269
+ }
2270
+ } else {
2271
+ Py_DECREF(reg);
2272
+ }
2132
2273
  reg = PyObject_GetAttrString(atexit, "register");
2133
2274
  if (!reg)
2134
2275
  goto bad;
@@ -2211,6 +2352,7 @@ static void __Pyx_FastGilFuncInit(void);
2211
2352
 
2212
2353
  /////////////// FastGil ///////////////
2213
2354
  //@requires: AddModuleRef
2355
+ //@requires: Exceptions.c::IgnoreException
2214
2356
  // The implementations of PyGILState_Ensure/Release calls PyThread_get_key_value
2215
2357
  // several times which is turns out to be quite slow (slower in fact than
2216
2358
  // acquiring the GIL itself). Simply storing it in a thread local for the
@@ -2323,9 +2465,8 @@ static void __Pyx_FastGilFuncInit(void) {
2323
2465
  struct __Pyx_FastGilVtab* shared = (struct __Pyx_FastGilVtab*)PyCapsule_Import(__Pyx_FastGIL_PyCapsule, 1);
2324
2466
  if (shared) {
2325
2467
  __Pyx_FastGilFuncs = *shared;
2326
- } else {
2327
- PyErr_Clear();
2328
- __Pyx_FastGilFuncInit0();
2468
+ } else if (__Pyx_IgnoreException(PyExc_Exception)) {
2469
+ return __Pyx_FastGilFuncInit0();
2329
2470
  }
2330
2471
  }
2331
2472
 
@@ -2422,10 +2563,6 @@ static PyObject* __Pyx_PyCode_New(
2422
2563
  PyObject *py_minor_version = NULL;
2423
2564
  #endif
2424
2565
  long minor_version = 0;
2425
- PyObject *type, *value, *traceback;
2426
-
2427
- // we must be able to call this while an exception is happening - thus clear then restore the state
2428
- PyErr_Fetch(&type, &value, &traceback);
2429
2566
 
2430
2567
  #if __PYX_LIMITED_VERSION_HEX >= 0x030b0000
2431
2568
  minor_version = 11;
@@ -2442,16 +2579,8 @@ static PyObject* __Pyx_PyCode_New(
2442
2579
  if (!(types_module = PyImport_ImportModule("types"))) goto end;
2443
2580
  if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end;
2444
2581
 
2445
- if (minor_version <= 7) {
2446
- // 3.7:
2447
- // code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring,
2448
- // constants, names, varnames, filename, name, firstlineno,
2449
- // lnotab[, freevars[, cellvars]])
2450
- (void)p;
2451
- result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOOO", a, k, l, s, f, code,
2452
- c, n, v, fn, name, fline, lnos, fv, cell);
2453
- } else if (minor_version <= 10) {
2454
- // 3.8, 3.9, 3.10
2582
+ if (minor_version <= 10) {
2583
+ // [3.8], 3.9, 3.10
2455
2584
  // code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,
2456
2585
  // flags, codestring, constants, names, varnames, filename, name,
2457
2586
  // firstlineno, lnotab[, freevars[, cellvars]])
@@ -2473,9 +2602,25 @@ static PyObject* __Pyx_PyCode_New(
2473
2602
  Py_XDECREF(code_type);
2474
2603
  Py_XDECREF(exception_table);
2475
2604
  Py_XDECREF(types_module);
2476
- if (type) {
2477
- PyErr_Restore(type, value, traceback);
2605
+
2606
+ if (!result) {
2607
+ // We use private API to create code objects and so it could fail in future.
2608
+ // In this case it's probably best if they keep working with a warning:
2609
+ // they're mostly just introspection decoration.
2610
+ PyObject *exc_type, *exc_value, *exc_tb;
2611
+ PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
2612
+ if (PyErr_WarnFormat(
2613
+ PyExc_RuntimeWarning, 1,
2614
+ "Code object creation failed in Cython module: %S\nTry recompiling with a more recent version of Cython.",
2615
+ exc_value ? exc_value : exc_type) == 0) {
2616
+ result = Py_None;
2617
+ Py_INCREF(result);
2618
+ }
2619
+ Py_DECREF(exc_type);
2620
+ Py_XDECREF(exc_value);
2621
+ Py_XDECREF(exc_tb);
2478
2622
  }
2623
+
2479
2624
  return result;
2480
2625
  }
2481
2626
 
@@ -2776,7 +2921,7 @@ static __Pyx_InterpreterIdAndModule* __Pyx_State_FindModuleStateLookupTableLower
2776
2921
  }
2777
2922
 
2778
2923
  static PyObject *__Pyx_State_FindModule(CYTHON_UNUSED void* dummy) {
2779
- int64_t interpreter_id = PyInterpreterState_GetID(__Pyx_PyInterpreterState_Get());
2924
+ int64_t interpreter_id = PyInterpreterState_GetID(PyInterpreterState_Get());
2780
2925
  if (interpreter_id == -1) return NULL;
2781
2926
 
2782
2927
  #if CYTHON_MODULE_STATE_LOOKUP_THREAD_SAFE
@@ -2900,7 +3045,7 @@ static void __Pyx_State_ConvertFromInterpIdAsIndex(__Pyx_ModuleStateLookupData *
2900
3045
  }
2901
3046
 
2902
3047
  static int __Pyx_State_AddModule(PyObject* module, CYTHON_UNUSED void* dummy) {
2903
- int64_t interpreter_id = PyInterpreterState_GetID(__Pyx_PyInterpreterState_Get());
3048
+ int64_t interpreter_id = PyInterpreterState_GetID(PyInterpreterState_Get());
2904
3049
  if (interpreter_id == -1) return -1;
2905
3050
 
2906
3051
  int result = 0;
@@ -3002,7 +3147,7 @@ static int __Pyx_State_AddModule(PyObject* module, CYTHON_UNUSED void* dummy) {
3002
3147
  }
3003
3148
 
3004
3149
  static int __Pyx_State_RemoveModule(CYTHON_UNUSED void* dummy) {
3005
- int64_t interpreter_id = PyInterpreterState_GetID(__Pyx_PyInterpreterState_Get());
3150
+ int64_t interpreter_id = PyInterpreterState_GetID(PyInterpreterState_Get());
3006
3151
  if (interpreter_id == -1) return -1;
3007
3152
 
3008
3153
  __Pyx_ModuleStateLookup_Lock();
@@ -3143,8 +3288,8 @@ static CYTHON_INLINE int __Pyx_UnknownThreadStateMayHaveHadGil(__Pyx_UnknownThre
3143
3288
 
3144
3289
  ///////////////////// AddModuleRef.proto ///////////////////////
3145
3290
 
3146
- #if ((CYTHON_COMPILING_IN_CPYTHON_FREETHREADING /* && __PYX_LIMITED_VERSION_HEX < some future value */) || \
3147
- __PYX_LIMITED_VERSION_HEX < 0x030d0000)
3291
+ #if ((CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && PY_VERSION_HEX < 0x030F00a3) || \
3292
+ __PYX_LIMITED_VERSION_HEX < 0x030d0000)
3148
3293
  // https://github.com/python/cpython/issues/137422 - PyImport_AddModule(Ref) isn't thread safe!
3149
3294
  static PyObject *__Pyx_PyImport_AddModuleRef(const char *name); /* proto */
3150
3295
  #else
@@ -3153,24 +3298,26 @@ static CYTHON_INLINE int __Pyx_UnknownThreadStateMayHaveHadGil(__Pyx_UnknownThre
3153
3298
 
3154
3299
  ///////////////////// AddModuleRef ////////////////////////////
3155
3300
 
3156
- #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING /* && __PYX_LIMITED_VERSION_HEX < some future value */
3301
+ #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && PY_VERSION_HEX < 0x030F00a3
3157
3302
  // https://github.com/python/cpython/issues/137422 - PyImport_AddModule(Ref) isn't thread safe!
3303
+ // TODO - if this gets used for anything other than implementing AddModuleRef then add a
3304
+ // runtime version check for fixed versions.
3158
3305
  static PyObject *__Pyx_PyImport_AddModuleObjectRef(PyObject *name) {
3159
3306
  // We're going to assume nobody is swapping the module dict out from under us
3160
3307
  // (even though they're allowed to) because we really can't write code that's
3161
3308
  // safe against that.
3162
3309
  PyObject *module_dict = PyImport_GetModuleDict();
3163
3310
  PyObject *m;
3164
- if (PyMapping_GetOptionalItem(module_dict, name, &m) < 0) {
3165
- return NULL;
3166
- }
3167
- if (m != NULL && PyModule_Check(m)) {
3168
- return m;
3311
+ if (PyMapping_GetOptionalItem(module_dict, name, &m) < 0) {
3312
+ return NULL;
3313
+ }
3314
+ if (m != NULL && PyModule_Check(m)) {
3315
+ return m;
3169
3316
  }
3170
- Py_XDECREF(m);
3317
+ Py_XDECREF(m);
3171
3318
  m = PyModule_NewObject(name);
3172
- if (m == NULL)
3173
- return NULL;
3319
+ if (m == NULL)
3320
+ return NULL;
3174
3321
  if (PyDict_CheckExact(module_dict)) {
3175
3322
  PyObject *new_m;
3176
3323
  (void)PyDict_SetDefaultRef(module_dict, name, m, &new_m);
@@ -3178,23 +3325,25 @@ static CYTHON_INLINE int __Pyx_UnknownThreadStateMayHaveHadGil(__Pyx_UnknownThre
3178
3325
  return new_m;
3179
3326
  } else {
3180
3327
  // For non-dict sys-modules I don't think it's possible to reliably make thread-safe.
3181
- if (PyObject_SetItem(module_dict, name, m) != 0) {
3182
- Py_DECREF(m);
3183
- return NULL;
3184
- }
3185
- return m;
3328
+ if (PyObject_SetItem(module_dict, name, m) != 0) {
3329
+ Py_DECREF(m);
3330
+ return NULL;
3331
+ }
3332
+ return m;
3186
3333
  }
3187
3334
  }
3188
3335
  static PyObject *__Pyx_PyImport_AddModuleRef(const char *name) {
3336
+ if ((PY_VERSION_HEX >= 0x030E0000) && Py_Version >= 0x030E0100) {
3337
+ // Fixed here... their implementation is probably better
3338
+ return PyImport_AddModuleRef(name);
3339
+ }
3189
3340
  PyObject *py_name = PyUnicode_FromString(name);
3190
3341
  if (!py_name) return NULL;
3191
- PyObject *module = __Pyx_PyImport_AddModuleObjectRef(py_name);
3342
+ PyObject *module = __Pyx_PyImport_AddModuleObjectRef(py_name);
3192
3343
  Py_DECREF(py_name);
3193
3344
  return module;
3194
3345
  }
3195
- #elif __PYX_LIMITED_VERSION_HEX >= 0x030d0000
3196
- #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name)
3197
- #else
3346
+ #elif __PYX_LIMITED_VERSION_HEX < 0x030d0000
3198
3347
  static PyObject *__Pyx_PyImport_AddModuleRef(const char *name) {
3199
3348
  PyObject *module = PyImport_AddModule(name);
3200
3349
  Py_XINCREF(module);