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
@@ -69,6 +69,8 @@ def put_acquire_memoryviewslice(lhs_cname, lhs_type, lhs_pos, rhs, code,
69
69
  "We can avoid decreffing the lhs if we know it is the first assignment"
70
70
  assert rhs.type.is_memoryviewslice
71
71
 
72
+ rhs_is_borrowed_temp = rhs.is_memview_slice and rhs.use_borrowed_ref
73
+
72
74
  pretty_rhs = rhs.result_in_temp() or rhs.is_simple()
73
75
  if pretty_rhs:
74
76
  rhstmp = rhs.result()
@@ -79,23 +81,33 @@ def put_acquire_memoryviewslice(lhs_cname, lhs_type, lhs_pos, rhs, code,
79
81
  # Allow uninitialized assignment
80
82
  #code.putln(code.put_error_if_unbound(lhs_pos, rhs.entry))
81
83
  put_assign_to_memviewslice(lhs_cname, rhs, rhstmp, lhs_type, code,
82
- have_gil=have_gil, first_assignment=first_assignment)
84
+ have_gil=have_gil, first_assignment=first_assignment,
85
+ rhs_is_borrowed_temp=rhs_is_borrowed_temp)
83
86
 
84
87
  if not pretty_rhs:
85
88
  code.funcstate.release_temp(rhstmp)
86
89
 
87
90
 
88
91
  def put_assign_to_memviewslice(lhs_cname, rhs, rhs_cname, memviewslicetype, code,
89
- have_gil=False, first_assignment=False):
92
+ have_gil=False, first_assignment=False,
93
+ rhs_is_borrowed_temp=False):
90
94
  if lhs_cname == rhs_cname:
91
95
  # self assignment is tricky because memoryview xdecref clears the memoryview
92
96
  # thus invalidating both sides of the assignment. Therefore make it actually do nothing
93
97
  code.putln("/* memoryview self assignment no-op */")
94
98
  return
95
99
 
100
+ if rhs_is_borrowed_temp and not first_assignment:
101
+ # Here we can skip the reference counting in the fairly likely case
102
+ # that the lhs and rhs are equal (e.g. repeated slicing in a loop).
103
+ code.putln(f"if ({lhs_cname}.memview != {rhs_cname}.memview) ""{")
96
104
  if not first_assignment:
97
105
  code.put_xdecref(lhs_cname, memviewslicetype,
98
106
  have_gil=have_gil)
107
+ if rhs_is_borrowed_temp:
108
+ code.put_incref_memoryviewslice(rhs_cname, memviewslicetype, have_gil=have_gil)
109
+ if not first_assignment:
110
+ code.putln("}")
99
111
 
100
112
  if not rhs.result_in_temp():
101
113
  rhs.make_owned_memoryviewslice(code)
@@ -243,7 +255,7 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
243
255
  return bufp
244
256
 
245
257
  def generate_buffer_slice_code(self, code, indices, dst, dst_type, have_gil,
246
- have_slices, directives):
258
+ have_slices, directives, drop_temp_refcounting):
247
259
  """
248
260
  Slice a memoryviewslice.
249
261
 
@@ -257,9 +269,10 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
257
269
  """
258
270
  src = self.cname
259
271
 
260
- code.putln("%(dst)s.data = %(src)s.data;" % locals())
261
- code.putln("%(dst)s.memview = %(src)s.memview;" % locals())
262
- code.put_incref_memoryviewslice(dst, dst_type, have_gil=have_gil)
272
+ code.putln(f"{dst}.data = {src}.data;")
273
+ code.putln(f"{dst}.memview = {src}.memview;")
274
+ if not drop_temp_refcounting:
275
+ code.put_incref_memoryviewslice(dst, dst_type, have_gil=have_gil)
263
276
 
264
277
  all_dimensions_direct = all(access == 'direct' for access, packing in self.type.axes)
265
278
  suboffset_dim_temp = []
@@ -268,17 +281,28 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
268
281
  # create global temp variable at request
269
282
  if not suboffset_dim_temp:
270
283
  suboffset_dim = code.funcstate.allocate_temp(PyrexTypes.c_int_type, manage_ref=False)
271
- code.putln("%s = -1;" % suboffset_dim)
284
+ code.putln(f"{suboffset_dim} = -1;")
272
285
  suboffset_dim_temp.append(suboffset_dim)
273
286
  return suboffset_dim_temp[0]
274
287
 
288
+ boundscheck = directives['boundscheck']
289
+ template_vars = {
290
+ 'src': src,
291
+ 'dst': dst,
292
+ 'have_gil': have_gil,
293
+ 'get_suboffset_dim': get_suboffset_dim,
294
+ 'all_dimensions_direct': all_dimensions_direct,
295
+ 'wraparound': int(directives['wraparound']),
296
+ 'boundscheck': int(boundscheck),
297
+ }
298
+
275
299
  dim = -1
276
300
  new_ndim = 0
277
301
  for index in indices:
278
302
  if index.is_none:
279
303
  # newaxis
280
304
  for attrib, value in [('shape', 1), ('strides', 0), ('suboffsets', -1)]:
281
- code.putln("%s.%s[%d] = %d;" % (dst, attrib, new_ndim, value))
305
+ code.putln(f"{dst}.{attrib}[{new_ndim:d}] = {value:d};")
282
306
 
283
307
  new_ndim += 1
284
308
  continue
@@ -286,18 +310,29 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
286
310
  dim += 1
287
311
  access, packing = self.type.axes[dim]
288
312
 
313
+ d = dict(
314
+ template_vars,
315
+ dim=dim,
316
+ new_ndim=new_ndim,
317
+ access=access,
318
+ )
319
+
289
320
  if index.is_slice:
290
321
  # slice, unspecified dimension, or part of ellipsis
291
- d = dict(locals())
292
- for s in "start stop step".split():
322
+ is_full_slice = True
323
+ for s in ("start", "stop", "step"):
293
324
  idx = getattr(index, s)
294
- have_idx = d['have_' + s] = not idx.is_none
295
- d[s] = idx.result() if have_idx else "0"
296
-
297
- if not (d['have_start'] or d['have_stop'] or d['have_step']):
298
- # full slice (:), simply copy over the extent, stride
299
- # and suboffset. Also update suboffset_dim if needed
300
- d['access'] = access
325
+ if idx.is_none:
326
+ d['have_' + s] = False
327
+ d[s] = "0"
328
+ else:
329
+ is_full_slice = False
330
+ d['have_' + s] = True
331
+ d[s] = idx.result()
332
+
333
+ if is_full_slice:
334
+ # For a full slice (:), we just copy over the extent, stride and suboffset.
335
+ # Also update suboffset_dim if needed.
301
336
  util_name = "SimpleSlice"
302
337
  else:
303
338
  util_name = "ToughSlice"
@@ -307,24 +342,18 @@ class MemoryViewSliceBufferEntry(Buffer.BufferEntry):
307
342
  new_ndim += 1
308
343
  else:
309
344
  # normal index
310
- idx = index.result()
311
-
312
- indirect = access != 'direct'
313
- if indirect:
314
- generic = access == 'full'
315
- if new_ndim != 0:
316
- return error(index.pos,
317
- "All preceding dimensions must be "
318
- "indexed and not sliced")
319
-
320
- d = dict(
321
- locals(),
322
- wraparound=int(directives['wraparound']),
323
- boundscheck=int(directives['boundscheck']),
345
+ if access != 'direct' and new_ndim != 0:
346
+ error(index.pos, "All preceding dimensions must be indexed and not sliced")
347
+ return
348
+
349
+ util_name = "SliceIndex"
350
+ d.update(
351
+ idx=index.result(),
352
+ indirect=access != 'direct',
353
+ generic=access == 'full',
324
354
  )
325
- if d['boundscheck']:
355
+ if boundscheck:
326
356
  d['error_goto'] = code.error_goto(index.pos)
327
- util_name = "SliceIndex"
328
357
 
329
358
  _, impl = TempitaUtilityCode.load_as_string(util_name, "MemoryView_C.c", context=d)
330
359
  code.put(impl)