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
Cython/Utility/Overflow.c CHANGED
@@ -45,20 +45,14 @@ static int __Pyx_check_twos_complement(void) {
45
45
  #define __Pyx_div_no_overflow(a, b, overflow) ((a) / (b))
46
46
  #define __Pyx_div_const_no_overflow(a, b, overflow) ((a) / (b))
47
47
 
48
- #if defined(__has_builtin)
49
- # if __has_builtin(__builtin_add_overflow) && !defined(__ibmxl__)
50
- # define __PYX_HAVE_BUILTIN_OVERFLOW
51
- # endif
48
+ #if __Pyx_has_cbuiltin(__builtin_add_overflow) && !defined(__ibmxl__)
49
+ # define __PYX_HAVE_BUILTIN_OVERFLOW
52
50
  #elif defined(__GNUC__) && (__GNUC__ >= 5) && (!defined(__INTEL_COMPILER) || (__INTEL_COMPILER >= 1800))
53
51
  # define __PYX_HAVE_BUILTIN_OVERFLOW
54
52
  #endif
55
53
 
56
- #if defined(__GNUC__)
54
+ #if defined(__GNUC__) || __Pyx_has_cbuiltin(__builtin_constant_p)
57
55
  # define __Pyx_is_constant(x) (__builtin_constant_p(x))
58
- #elif defined(__has_builtin)
59
- # if __has_builtin(__builtin_constant_p)
60
- # define __Pyx_is_constant(x) (__builtin_constant_p(x))
61
- # endif
62
56
  #else
63
57
  # define __Pyx_is_constant(x) (0)
64
58
  #endif
Cython/Utility/Profile.c CHANGED
@@ -253,6 +253,7 @@
253
253
  PyGILState_STATE state = PyGILState_Ensure(); \
254
254
  PyObject *pyvalue = convert_function(cresult); \
255
255
  if (unlikely(!pyvalue)) { \
256
+ if (!PyErr_ExceptionMatches(PyExc_Exception)) goto_error; \
256
257
  PyErr_Clear(); \
257
258
  pyvalue = Py_None; Py_INCREF(Py_None); \
258
259
  } \
@@ -263,6 +264,7 @@
263
264
  } else { \
264
265
  PyObject *pyvalue = convert_function(cresult); \
265
266
  if (unlikely(!pyvalue)) { \
267
+ if (!PyErr_ExceptionMatches(PyExc_Exception)) goto_error; \
266
268
  PyErr_Clear(); \
267
269
  pyvalue = Py_None; Py_INCREF(Py_None); \
268
270
  } \
@@ -486,6 +488,7 @@
486
488
  if (__Pyx_IsTracing(tstate, 0, 0)) { \
487
489
  PyObject *pyvalue = convert_function(cresult); \
488
490
  if (unlikely(!pyvalue)) { \
491
+ if (!PyErr_ExceptionMatches(PyExc_Exception)) goto_error \
489
492
  PyErr_Clear(); \
490
493
  pyvalue = Py_None; Py_INCREF(Py_None); \
491
494
  } \
@@ -499,6 +502,7 @@
499
502
  if (__Pyx_IsTracing(tstate, 0, 0)) { \
500
503
  PyObject *pyvalue = convert_function(cresult); \
501
504
  if (unlikely(!pyvalue)) { \
505
+ if (!PyErr_ExceptionMatches(PyExc_Exception)) goto_error \
502
506
  PyErr_Clear(); \
503
507
  pyvalue = Py_None; Py_INCREF(Py_None); \
504
508
  } \
@@ -52,13 +52,21 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
52
52
 
53
53
 
54
54
  //////////////////// DecompressString.proto ////////////////////
55
+ // TODO: Move to the shared module if we can import that before initialising the strings.
55
56
 
56
57
  static PyObject *__Pyx_DecompressString(const char *s, Py_ssize_t length, int algo); /*proto*/
57
58
 
58
59
  //////////////////// DecompressString ////////////////////
59
60
  //@requires: TypeConversion.c::GCCDiagnostics
60
61
 
61
- static PyObject *__Pyx_DecompressString(const char *s, Py_ssize_t length, int algo) {
62
+ CYTHON_UNUSED
63
+ static CYTHON_SMALL_CODE PyObject *__Pyx_DecompressString(const char *s, Py_ssize_t length, int algo) {
64
+ #ifdef __Pyx_DecompressString_UNUSED
65
+ CYTHON_UNUSED_VAR(s);
66
+ CYTHON_UNUSED_VAR(length);
67
+ CYTHON_UNUSED_VAR(algo);
68
+ return NULL;
69
+ #else
62
70
  PyObject *module = NULL, *decompress, *compressed_bytes, *decompressed;
63
71
 
64
72
  const char* module_name = algo == 3 ? "compression.zstd" : algo == 2 ? "bz2" : "zlib";
@@ -135,8 +143,93 @@ bad:
135
143
  Py_XDECREF(module);
136
144
  Py_DECREF(methodname);
137
145
  return NULL;
146
+ #endif
147
+ }
148
+
149
+
150
+ //////////////////// DecompressString_LZSS.proto ////////////////////
151
+ // TODO: Move to the shared module if we can import that before initialising the strings.
152
+
153
+ static PyObject *__Pyx_DecompressString_LZSS(const char *s, size_t compressed_length, size_t uncompressed_length); /*proto*/
154
+
155
+ //////////////////// DecompressString_LZSS ////////////////////
156
+ //@requires: IncludeStringH
157
+
158
+ #ifndef __Pyx_DecompressString_LZSS_UNUSED
159
+ // Depends on <stdint.h>, which is globally included in the module preamble.
160
+ CYTHON_UNUSED
161
+ static CYTHON_SMALL_CODE size_t __pyx_lzss_decompress(const uint8_t* src, uint8_t* dst, size_t dst_len) {
162
+ size_t pos = 0, out_pos = 0;
163
+
164
+ while (1) {
165
+ // Process 8 bytes/backreferences at a time.
166
+ uint32_t flags = src[pos++] | 0xFF00;
167
+ while (flags & 0x100) {
168
+ if (flags & 1) {
169
+ // plain byte
170
+ dst[out_pos++] = src[pos++];
171
+ } else {
172
+ // back reference, 2 or 3 bytes
173
+ uint32_t lo = src[pos++], hi = src[pos++];
174
+ uint32_t end_offset_of_last_occurrence, match_length;
175
+ if (!(lo & 0x80)) {
176
+ // 7 bit offset + 8 bit length
177
+ end_offset_of_last_occurrence = lo;
178
+ match_length = hi;
179
+ } else if (!(hi & 0x80)) {
180
+ // 2+7 bit offset + 5 bit length
181
+ end_offset_of_last_occurrence = ((hi << 2) & 0x180) | (lo & 0x7F);
182
+ match_length = hi & 0x1F;
183
+ } else {
184
+ // 7+7 bit offset + 8 bit length
185
+ end_offset_of_last_occurrence = (hi & 0x7F) << 7 | (lo & 0x7F);
186
+ match_length = src[pos++];
187
+ }
188
+
189
+ match_length += 3;
190
+ size_t ref_pos = out_pos - end_offset_of_last_occurrence - match_length;
191
+
192
+ memcpy(dst + out_pos, dst + ref_pos, match_length);
193
+ out_pos += match_length;
194
+ }
195
+
196
+ if (out_pos >= dst_len) return pos;
197
+ flags >>= 1;
198
+ }
199
+ }
138
200
  }
201
+ #endif
139
202
 
203
+ static CYTHON_SMALL_CODE PyObject *__Pyx_DecompressString_LZSS(const char *s, size_t compressed_length, size_t uncompressed_length) {
204
+ #ifdef __Pyx_DecompressString_LZSS_UNUSED
205
+ CYTHON_UNUSED_VAR(s);
206
+ CYTHON_UNUSED_VAR(compressed_length);
207
+ CYTHON_UNUSED_VAR(uncompressed_length);
208
+ return NULL;
209
+ #else
210
+ PyObject *result;
211
+ unsigned char *result_data;
212
+ size_t src_length;
213
+
214
+ result = PyBytes_FromStringAndSize(NULL, (Py_ssize_t) uncompressed_length);
215
+ if (unlikely(!result)) return NULL;
216
+
217
+ result_data = __Pyx_PyBytes_AsWritableUString(result);
218
+ if (unlikely(!result_data)) goto bad;
219
+
220
+ src_length = __pyx_lzss_decompress((const uint8_t*) s, result_data, uncompressed_length);
221
+ if (unlikely(src_length != compressed_length)) goto decompression_failed;
222
+
223
+ return result;
224
+
225
+ decompression_failed:
226
+ PyErr_SetString(PyExc_RuntimeError, "LZSS string data decompression failed");
227
+
228
+ bad:
229
+ Py_DECREF(result);
230
+ return NULL;
231
+ #endif
232
+ }
140
233
 
141
234
  //////////////////// BytesContains.proto ////////////////////
142
235
 
@@ -182,156 +275,92 @@ static CYTHON_INLINE int __Pyx_PyUnicode_ContainsTF(PyObject* substring, PyObjec
182
275
  }
183
276
 
184
277
 
185
- //////////////////// CStringEquals.proto ////////////////////
278
+ //////////////////// UnicodeEquals_uchar.proto ////////////////////
279
+ //@requires: UnicodeEqualsUCS4
186
280
 
187
- static CYTHON_INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/
281
+ {{if REVERSE}}
282
+ #define __Pyx_PyObject_Equals_ch{{CHAR}}_{{'str' if IS_STR else 'obj'}}(s1, s2, equals) __Pyx_PyObject_Equals_uchar(s2, s1, {{CHAR}}, equals, {{1 if IS_STR else 0}})
283
+ {{else}}
284
+ #define __Pyx_PyObject_Equals_{{'str' if IS_STR else 'obj'}}_ch{{CHAR}}(s1, s2, equals) __Pyx_PyObject_Equals_uchar(s1, s2, {{CHAR}}, equals, {{1 if IS_STR else 0}})
285
+ {{endif}}
188
286
 
189
- //////////////////// CStringEquals ////////////////////
190
287
 
191
- static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
192
- while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
193
- return *s1 == *s2;
194
- }
288
+ //////////////////// UnicodeEqualsUCS4.proto ////////////////////
195
289
 
290
+ #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL
291
+ #define __Pyx_PyObject_Equals_uchar(s1, s2, ch2, equals, s1_is_str) (\
292
+ ((s1) == (s2)) ? ((equals) == Py_EQ) : \
293
+ ((s1) == Py_None) ? ((equals) == Py_NE) : \
294
+ __Pyx_PyObject_RichCompareBool(s1, s2, equals) \
295
+ )
196
296
 
197
- //////////////////// UnicodeEquals.proto ////////////////////
297
+ #else
298
+ #define __Pyx_PyObject_Equals_uchar(s1, s2, ch2, equals, s1_is_str) (\
299
+ ((s1) == (s2)) ? ((equals) == Py_EQ) : \
300
+ ((s1) == Py_None) ? ((equals) == Py_NE) : \
301
+ (likely((s1_is_str) || PyUnicode_CheckExact(s1)) ? \
302
+ __Pyx__PyUnicode_EqualsUCS4(s1, ch2, equals) : \
303
+ __Pyx_PyObject_RichCompareBool(s1, s2, equals) \
304
+ ))
305
+
306
+ static CYTHON_INLINE int __Pyx__PyUnicode_EqualsUCS4(PyObject* s1, Py_UCS4 ch2, int equals); /*proto*/
307
+ #endif
198
308
 
199
- static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
309
+ //////////////////// UnicodeEqualsUCS4 ////////////////////
200
310
 
201
- //////////////////// UnicodeEquals ////////////////////
202
- //@requires: BytesEquals
311
+ #if !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL)
312
+ static CYTHON_INLINE int __Pyx__PyUnicode_EqualsUCS4(PyObject* s1, Py_UCS4 ch2, int equals) {
313
+ Py_ssize_t length;
314
+ Py_UCS4 ch1;
315
+ int kind;
203
316
 
204
- static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
205
- #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL
206
- return PyObject_RichCompareBool(s1, s2, equals);
207
- #else
208
- int s1_is_unicode, s2_is_unicode;
209
- if (s1 == s2) {
210
- /* as done by PyObject_RichCompareBool(); also catches the (interned) empty string */
211
- goto return_eq;
212
- }
213
- s1_is_unicode = PyUnicode_CheckExact(s1);
214
- s2_is_unicode = PyUnicode_CheckExact(s2);
215
- if (s1_is_unicode & s2_is_unicode) {
216
- Py_ssize_t length, length2;
217
- int kind;
218
- void *data1, *data2;
219
- #if !CYTHON_COMPILING_IN_LIMITED_API
220
- if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
221
- return -1;
222
- #endif
223
- length = __Pyx_PyUnicode_GET_LENGTH(s1);
224
- #if !CYTHON_ASSUME_SAFE_SIZE
225
- if (unlikely(length < 0)) return -1;
226
- #endif
227
- length2 = __Pyx_PyUnicode_GET_LENGTH(s2);
228
- #if !CYTHON_ASSUME_SAFE_SIZE
229
- if (unlikely(length2 < 0)) return -1;
230
- #endif
231
- if (length != length2) {
232
- goto return_ne;
233
- }
234
- #if CYTHON_USE_UNICODE_INTERNALS
235
- {
236
- Py_hash_t hash1, hash2;
237
- hash1 = ((PyASCIIObject*)s1)->hash;
238
- hash2 = ((PyASCIIObject*)s2)->hash;
239
- if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
240
- goto return_ne;
241
- }
317
+ if (unlikely(__Pyx_PyUnicode_READY(s1) < 0)) goto bad;
318
+ length = __Pyx_PyUnicode_GET_LENGTH(s1);
319
+ #if !CYTHON_ASSUME_SAFE_SIZE
320
+ if (unlikely(length < 0)) goto bad;
321
+ #endif
322
+ if (length != 1) goto return_ne;
323
+
324
+ kind = PyUnicode_KIND(s1);
325
+ // The following conditions are written to allow optimising on the inlined constant ch2.
326
+ if (ch2 < 256) {
327
+ if (likely(kind == PyUnicode_1BYTE_KIND)) {
328
+ ch1 = PyUnicode_1BYTE_DATA(s1)[0];
329
+ } else if (kind == PyUnicode_2BYTE_KIND) {
330
+ ch1 = PyUnicode_2BYTE_DATA(s1)[0];
331
+ } else {
332
+ ch1 = PyUnicode_4BYTE_DATA(s1)[0];
242
333
  }
243
- #endif
244
- // len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
245
- kind = __Pyx_PyUnicode_KIND(s1);
246
- if (kind != __Pyx_PyUnicode_KIND(s2)) {
334
+ } else if (ch2 < 65536) {
335
+ if (kind == PyUnicode_2BYTE_KIND) {
336
+ ch1 = PyUnicode_2BYTE_DATA(s1)[0];
337
+ } else if (kind == PyUnicode_4BYTE_KIND) {
338
+ ch1 = PyUnicode_4BYTE_DATA(s1)[0];
339
+ } else {
247
340
  goto return_ne;
248
341
  }
249
- data1 = __Pyx_PyUnicode_DATA(s1);
250
- data2 = __Pyx_PyUnicode_DATA(s2);
251
- if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
252
- goto return_ne;
253
- } else if (length == 1) {
254
- goto return_eq;
342
+ } else {
343
+ if (kind == PyUnicode_4BYTE_KIND){
344
+ ch1 = PyUnicode_4BYTE_DATA(s1)[0];
255
345
  } else {
256
- int result = memcmp(data1, data2, (size_t)(length * kind));
257
- return (equals == Py_EQ) ? (result == 0) : (result != 0);
346
+ goto return_ne;
258
347
  }
259
- } else if ((s1 == Py_None) & s2_is_unicode) {
260
- goto return_ne;
261
- } else if ((s2 == Py_None) & s1_is_unicode) {
262
- goto return_ne;
348
+ }
349
+
350
+ if (ch1 == ch2) {
351
+ goto return_eq;
263
352
  } else {
264
- int result;
265
- PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
266
- if (!py_result)
267
- return -1;
268
- result = __Pyx_PyObject_IsTrue(py_result);
269
- Py_DECREF(py_result);
270
- return result;
353
+ goto return_ne;
271
354
  }
272
355
  return_eq:
273
356
  return (equals == Py_EQ);
274
357
  return_ne:
275
358
  return (equals == Py_NE);
276
- #endif
359
+ bad:
360
+ return -1;
277
361
  }
278
-
279
-
280
- //////////////////// BytesEquals.proto ////////////////////
281
-
282
- static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
283
-
284
- //////////////////// BytesEquals ////////////////////
285
- //@requires: IncludeStringH
286
-
287
- static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
288
- #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL || \
289
- !(CYTHON_ASSUME_SAFE_SIZE && CYTHON_ASSUME_SAFE_MACROS)
290
- return PyObject_RichCompareBool(s1, s2, equals);
291
- #else
292
- if (s1 == s2) {
293
- /* as done by PyObject_RichCompareBool(); also catches the (interned) empty string */
294
- return (equals == Py_EQ);
295
- } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
296
- const char *ps1, *ps2;
297
- Py_ssize_t length = PyBytes_GET_SIZE(s1);
298
- if (length != PyBytes_GET_SIZE(s2))
299
- return (equals == Py_NE);
300
- // len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
301
- ps1 = PyBytes_AS_STRING(s1);
302
- ps2 = PyBytes_AS_STRING(s2);
303
- if (ps1[0] != ps2[0]) {
304
- return (equals == Py_NE);
305
- } else if (length == 1) {
306
- return (equals == Py_EQ);
307
- } else {
308
- int result;
309
- #if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000)
310
- Py_hash_t hash1, hash2;
311
- hash1 = ((PyBytesObject*)s1)->ob_shash;
312
- hash2 = ((PyBytesObject*)s2)->ob_shash;
313
- if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
314
- return (equals == Py_NE);
315
- }
316
- #endif
317
- result = memcmp(ps1, ps2, (size_t)length);
318
- return (equals == Py_EQ) ? (result == 0) : (result != 0);
319
- }
320
- } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
321
- return (equals == Py_NE);
322
- } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
323
- return (equals == Py_NE);
324
- } else {
325
- int result;
326
- PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
327
- if (!py_result)
328
- return -1;
329
- result = __Pyx_PyObject_IsTrue(py_result);
330
- Py_DECREF(py_result);
331
- return result;
332
- }
333
362
  #endif
334
- }
363
+
335
364
 
336
365
  //////////////////// SetStringIndexingError.proto /////////////////
337
366
 
@@ -351,7 +380,7 @@ static void __Pyx_SetStringIndexingError(const char* message, int has_gil) {
351
380
  /////////////// GetItemIntBytes.proto ///////////////
352
381
  //@requires: SetStringIndexingError
353
382
 
354
- #define __Pyx_GetItemInt_Bytes(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck, has_gil, unsafe_shared) \
383
+ #define __Pyx_GetItemInt_Bytes(o, i, type, is_signed, to_py_func, wraparound, boundscheck, has_gil, unsafe_shared) \
355
384
  (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
356
385
  __Pyx_GetItemInt_Bytes_Fast(o, (Py_ssize_t)i, wraparound, boundscheck, has_gil) : \
357
386
  (__Pyx_SetStringIndexingError("string index out of range", has_gil), -1))
@@ -392,7 +421,7 @@ static CYTHON_INLINE int __Pyx_GetItemInt_Bytes_Fast(PyObject* bytes, Py_ssize_t
392
421
  //////////////////// GetItemIntByteArray.proto ////////////////////
393
422
  //@requires: SetStringIndexingError
394
423
 
395
- #define __Pyx_GetItemInt_ByteArray(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck, has_gil, unsafe_shared) \
424
+ #define __Pyx_GetItemInt_ByteArray(o, i, type, is_signed, to_py_func, wraparound, boundscheck, has_gil, unsafe_shared) \
396
425
  (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
397
426
  __Pyx_GetItemInt_ByteArray_Fast(o, (Py_ssize_t)i, wraparound, boundscheck, has_gil, unsafe_shared) : \
398
427
  (__Pyx_SetStringIndexingError("bytearray index out of range", has_gil), -1))
@@ -456,7 +485,7 @@ static CYTHON_INLINE int __Pyx_GetItemInt_ByteArray_Fast(PyObject* string, Py_ss
456
485
  //////////////////// SetItemIntByteArray.proto ////////////////////
457
486
  //@requires: SetStringIndexingError
458
487
 
459
- #define __Pyx_SetItemInt_ByteArray(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck, has_gil, unsafe_shared) \
488
+ #define __Pyx_SetItemInt_ByteArray(o, i, v, type, is_signed, to_py_func, wraparound, boundscheck, has_gil, unsafe_shared) \
460
489
  (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
461
490
  __Pyx_SetItemInt_ByteArray_Fast(o, (Py_ssize_t)i, v, wraparound, boundscheck, has_gil, unsafe_shared) : \
462
491
  (__Pyx_SetStringIndexingError("bytearray index out of range", has_gil), -1))
@@ -524,7 +553,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_ByteArray_Fast(PyObject* string, Py_ss
524
553
  //////////////////// GetItemIntUnicode.proto ////////////////////
525
554
  //@requires: SetStringIndexingError
526
555
 
527
- #define __Pyx_GetItemInt_Unicode(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck, has_gil, unsafe_shared) \
556
+ #define __Pyx_GetItemInt_Unicode(o, i, type, is_signed, to_py_func, wraparound, boundscheck, has_gil, unsafe_shared) \
528
557
  (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
529
558
  __Pyx_GetItemInt_Unicode_Fast(o, (Py_ssize_t)i, wraparound, boundscheck, has_gil) : \
530
559
  (__Pyx_SetStringIndexingError("string index out of range", has_gil), (Py_UCS4)-1))
@@ -728,9 +757,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring(
728
757
  static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring(
729
758
  PyObject* text, Py_ssize_t start, Py_ssize_t stop) {
730
759
  Py_ssize_t length;
731
- #if !CYTHON_COMPILING_IN_LIMITED_API
732
760
  if (unlikely(__Pyx_PyUnicode_READY(text) == -1)) return NULL;
733
- #endif
734
761
  length = __Pyx_PyUnicode_GET_LENGTH(text);
735
762
  #if !CYTHON_ASSUME_SAFE_SIZE
736
763
  if (unlikely(length < 0)) return NULL;
@@ -1036,28 +1063,39 @@ static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* value
1036
1063
 
1037
1064
  /////////////// JoinPyUnicode.export ///////////////
1038
1065
 
1039
- static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength,
1040
- Py_UCS4 max_char);
1066
+ static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength, int kind); /*proto*/
1067
+
1068
+ /////////////// JoinPyUnicode.proto ///////////////
1069
+
1070
+ // This macro guard excludes the kind and length calculation on platforms where we definitely don't need it.
1071
+ // If the function lives in the shared module, user modules must provide kind and length on all other
1072
+ // platforms to prevent incorrect argument values if the shared module implementation requires it.
1073
+ #define __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH \
1074
+ (!CYTHON_COMPILING_IN_GRAAL && !CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API)
1041
1075
 
1042
1076
  /////////////// JoinPyUnicode ///////////////
1043
1077
  //@requires: IncludeStringH
1044
1078
 
1045
- static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength,
1046
- Py_UCS4 max_char) {
1047
- #if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
1079
+ static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count, Py_ssize_t result_ulength, int kind) {
1080
+ #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH && CYTHON_USE_UNICODE_INTERNALS
1048
1081
  PyObject *result_uval;
1049
1082
  int result_ukind, kind_shift;
1050
1083
  Py_ssize_t i, char_pos;
1051
1084
  void *result_udata;
1052
1085
 
1053
- if (max_char > 1114111) max_char = 1114111;
1054
- result_uval = PyUnicode_New(result_ulength, max_char);
1086
+ // We use '|' to combine the substring kinds, so index 3 actually means 1|2 => 2.
1087
+ static const Py_UCS4 max_char[5] = {0x7fU, 0xffU, 0xffffU, 0xffffU, 0x10ffffU};
1088
+ assert (kind >= 0); /* ASCII */
1089
+ if (kind > PyUnicode_4BYTE_KIND) kind = PyUnicode_4BYTE_KIND;
1090
+
1091
+ result_uval = PyUnicode_New(result_ulength, max_char[kind]);
1055
1092
  if (unlikely(!result_uval)) return NULL;
1056
- result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
1057
- kind_shift = (result_ukind == PyUnicode_4BYTE_KIND) ? 2 : result_ukind - 1;
1093
+
1094
+ kind_shift = kind >> 1; // 0, 1, 2
1095
+ result_ukind = 1 << kind_shift; // 1, 2, 4
1058
1096
  result_udata = PyUnicode_DATA(result_uval);
1059
- assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0);
1060
1097
 
1098
+ assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0);
1061
1099
  if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - result_ulength < 0))
1062
1100
  goto overflow;
1063
1101
 
@@ -1067,10 +1105,8 @@ static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count,
1067
1105
  Py_ssize_t ulength;
1068
1106
  void *udata;
1069
1107
  PyObject *uval = values[i];
1070
- #if !CYTHON_COMPILING_IN_LIMITED_API
1071
1108
  if (__Pyx_PyUnicode_READY(uval) == (-1))
1072
1109
  goto bad;
1073
- #endif
1074
1110
  ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
1075
1111
  #if !CYTHON_ASSUME_SAFE_SIZE
1076
1112
  if (unlikely(ulength < 0)) goto bad;
@@ -1099,18 +1135,20 @@ static PyObject* __Pyx_PyUnicode_Join(PyObject** values, Py_ssize_t value_count,
1099
1135
  char_pos += ulength;
1100
1136
  }
1101
1137
  return result_uval;
1138
+
1102
1139
  overflow:
1103
1140
  PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
1104
1141
  bad:
1105
1142
  Py_DECREF(result_uval);
1106
1143
  return NULL;
1144
+
1107
1145
  #else
1108
1146
  // non-CPython fallback
1109
1147
  Py_ssize_t i;
1110
1148
  PyObject *result = NULL;
1111
1149
  PyObject *value_tuple = PyTuple_New(value_count);
1112
1150
  if (unlikely(!value_tuple)) return NULL;
1113
- CYTHON_UNUSED_VAR(max_char);
1151
+ CYTHON_UNUSED_VAR(kind);
1114
1152
  CYTHON_UNUSED_VAR(result_ulength);
1115
1153
 
1116
1154
  for (i=0; i<value_count; i++) {
@@ -237,6 +237,8 @@
237
237
  #define __Pyx_Locks_PyThreadTypeLock_Delete(l) PyThread_free_lock(l)
238
238
  #define __Pyx_Locks_PyThreadTypeLock_LockNogil(l) (void)PyThread_acquire_lock(l, WAIT_LOCK)
239
239
  #define __Pyx_Locks_PyThreadTypeLock_Unlock(l) PyThread_release_lock(l)
240
+ static CYTHON_INLINE int __Pyx_Locks_PyThreadTypeLock_CanCheckLocked(__Pyx_Locks_PyThreadTypeLock lock); /* proto */
241
+ static int __Pyx__Locks_PyThreadTypeLock_Locked(__Pyx_Locks_PyThreadTypeLock lock); /* proto */
240
242
  static void __Pyx__Locks_PyThreadTypeLock_Lock(__Pyx_Locks_PyThreadTypeLock lock); /* proto */
241
243
  static void __Pyx__Locks_PyThreadTypeLock_LockGil(__Pyx_Locks_PyThreadTypeLock lock); /* proto */
242
244
  // CYTHON_INLINE because these may be unused
@@ -246,6 +248,9 @@ static CYTHON_INLINE void __Pyx_Locks_PyThreadTypeLock_Lock(__Pyx_Locks_PyThread
246
248
  static CYTHON_INLINE void __Pyx_Locks_PyThreadTypeLock_LockGil(__Pyx_Locks_PyThreadTypeLock lock) {
247
249
  __Pyx__Locks_PyThreadTypeLock_LockGil(lock);
248
250
  }
251
+ static CYTHON_INLINE int __Pyx_Locks_PyThreadTypeLock_Locked(__Pyx_Locks_PyThreadTypeLock lock) {
252
+ return __Pyx__Locks_PyThreadTypeLock_Locked(lock);
253
+ }
249
254
 
250
255
 
251
256
  ////////////////////// PyThreadTypeLock ////////////////
@@ -314,6 +319,24 @@ static void __Pyx__Locks_PyThreadTypeLock_Lock(__Pyx_Locks_PyThreadTypeLock lock
314
319
  }
315
320
  }
316
321
 
322
+ static CYTHON_INLINE int __Pyx_Locks_PyThreadTypeLock_CanCheckLocked(__Pyx_Locks_PyThreadTypeLock lock) {
323
+ CYTHON_UNUSED_VAR(lock);
324
+ // PyThread_type_lock supports checking lock status via try-acquire
325
+ return 1;
326
+ }
327
+
328
+ static int __Pyx__Locks_PyThreadTypeLock_Locked(__Pyx_Locks_PyThreadTypeLock lock) {
329
+ // Check if lock is held by attempting a non-blocking acquire.
330
+ // If acquire succeeds, the lock was not held, so release it and return 0.
331
+ // If acquire fails, the lock is held (by this or another thread), return 1.
332
+ // This works for both "other thread locked" and "this thread locked" cases.
333
+ if (PyThread_acquire_lock(lock, NOWAIT_LOCK)) {
334
+ PyThread_release_lock(lock);
335
+ return 0; // Lock was not held
336
+ }
337
+ return 1; // Lock is held
338
+ }
339
+
317
340
 
318
341
  ////////////////////// PyMutexDecl.proto ////////////////////
319
342
  //@proto_block: utility_code_proto_before_types
@@ -359,6 +382,20 @@ static void __Pyx__Locks_PyThreadTypeLock_Lock(__Pyx_Locks_PyThreadTypeLock lock
359
382
  #define __Pyx_Locks_PyMutex_LockGil(l) PyMutex_Lock(&l)
360
383
  #define __Pyx_Locks_PyMutex_LockNogil(l) PyMutex_Lock(&l)
361
384
 
385
+ // For Python 3.13+, check if PyMutex_IsLocked is available
386
+ #if PY_VERSION_HEX >= 0x030e00C1
387
+ // Python 3.14+ has PyMutex_IsLocked API
388
+ #define __Pyx_Locks_PyMutex_Locked(l) PyMutex_IsLocked(&(l))
389
+ #else
390
+ // Python 3.13: Use atomic read of lock bits as per CPython's cpython/lock.h
391
+ // _Py_LOCKED is defined in Include/cpython/lock.h
392
+ #define __Pyx_Locks_PyMutex_Locked(l) \
393
+ ((int)(_Py_atomic_load_uint8_relaxed(&(l)._bits) & _Py_LOCKED))
394
+ #endif
395
+
396
+ // locked() is available on Python 3.13+ (atomic read) and older versions (try-acquire fallback)
397
+ #define __Pyx_Locks_PyMutex_CanCheckLocked(l) (CYTHON_UNUSED_VAR(l), 1)
398
+
362
399
  #else
363
400
 
364
401
  #define __Pyx_Locks_PyMutex_Init(l) __Pyx_Locks_PyThreadTypeLock_Init(l)
@@ -367,6 +404,8 @@ static void __Pyx__Locks_PyThreadTypeLock_Lock(__Pyx_Locks_PyThreadTypeLock lock
367
404
  #define __Pyx_Locks_PyMutex_Unlock(l) __Pyx_Locks_PyThreadTypeLock_Unlock(l)
368
405
  #define __Pyx_Locks_PyMutex_LockGil(l) __Pyx_Locks_PyThreadTypeLock_LockGil(l)
369
406
  #define __Pyx_Locks_PyMutex_LockNogil(l) __Pyx_Locks_PyThreadTypeLock_LockNogil(l)
407
+ #define __Pyx_Locks_PyMutex_Locked(l) __Pyx_Locks_PyThreadTypeLock_Locked(l)
408
+ #define __Pyx_Locks_PyMutex_CanCheckLocked(l) __Pyx_Locks_PyThreadTypeLock_CanCheckLocked(l)
370
409
 
371
410
  #endif
372
411