Skip to content

Commit 7e9af23

Browse files
committed
Squashed commit of the following:
commit 1461e51 Author: Stefan Behnel <[email protected]> Date: Mon Oct 25 14:29:02 2021 +0200 Clean up the NumPy integration test by moving the doctests into the functions that they test. commit 68bb716 Author: Stefan Behnel <[email protected]> Date: Mon Oct 25 14:14:24 2021 +0200 Remove dead test code. commit 4a74678 Author: Stefan Behnel <[email protected]> Date: Sun Oct 24 21:27:44 2021 +0200 Use newer test dependencies in Py3.6+. (Excluding 3.10 for now to give the projects a bit more time.) commit 9d1ffd5 Author: da-woods <[email protected]> Date: Sun Oct 24 23:13:50 2021 +0100 Initial support for Python 3.11 (cythonGH-4414) * Add a basic replacement for PyCode_New(). An optimized versions would be nice, but this is intended to work sufficiently to start testing. Also, CPython 3.11 might actually add a new C-API function to simplify setting the current code position. That might be used instead. * Disable introspection of frame object with vectorcall This feature looked to only be used for early Python versions that don't have the full vectorcall protocol (and the contents of the frame object are changed in Python 3.11). commit 346c81f Author: Stefan Behnel <[email protected]> Date: Sun Oct 24 21:18:10 2021 +0200 Make sure that version dependent special methods are correctly and completely excluded via preprocessor guards. Previously, implementing "__div__" could fail in Py3 (if the code for adapting the Python wrapper was generated) or would at least generate C compiler warnings about unused "__div__" C functions. commit 3748c3c Author: Stefan Behnel <[email protected]> Date: Sun Oct 24 13:22:34 2021 +0200 Add Py3.10 as CI test target. commit 0f84a57 Author: Max Bachmann <[email protected]> Date: Sat Oct 23 22:06:37 2021 +0200 Update incorrect version support comment for pycapsule.pxd (cythonGH-4426) commit c25c87d Author: Dobatymo <[email protected]> Date: Sat Oct 23 03:33:02 2021 +0800 Fix libcpp map/set/multiset/unordered type issues (cythonGH-4410) Fix insert return types, constness and input iterator templates. Fix typing in iterators and add constructor to allow explicit conversion from iterator to const_iterator. commit f776da0 Author: Dobatymo <[email protected]> Date: Sat Oct 23 03:28:53 2021 +0800 Add C++ multimap/unordered_multimap (cythonGH-4419) commit c83fd44 Author: 0dminnimda <[email protected]> Date: Fri Oct 22 21:44:11 2021 +0300 Introduce new shell syntax for ci-run.sh to improve Windows support (cythonGH-4400) commit c8c9a12 Merge: 174ca03 f53ac52 Author: Stefan Behnel <[email protected]> Date: Thu Oct 21 19:02:11 2021 +0200 Merge branch '0.29.x' commit f53ac52 Author: Stefan Behnel <[email protected]> Date: Tue May 25 11:20:54 2021 +0200 docs: Use the Cython + IPython lexers that come with Pygments to avoid having to maintain our own ones. commit 174ca03 Author: account-login <[email protected]> Date: Wed Oct 20 17:03:20 2021 +0800 Add some missing functions to libcpp maps and string (cythonGH-4395) * add swap() to libcpp.string * add load_factor() to libcpp.unordered_map and libcpp.unordered_set commit 42a4af2 Merge: 53b0eb2 fb5d29e Author: Stefan Behnel <[email protected]> Date: Mon Oct 18 20:38:22 2021 +0200 Merge branch '0.29.x' commit fb5d29e Author: da-woods <[email protected]> Date: Mon Oct 18 19:36:54 2021 +0100 Fix tracing after adapting it to Py3.11 (cythonGH-4420) commit 53b0eb2 Author: da-woods <[email protected]> Date: Mon Oct 18 19:36:54 2021 +0100 Fix tracing after adapting it to Py3.11 (cythonGH-4420) commit 5f820ed Author: da-woods <[email protected]> Date: Mon Oct 18 11:10:05 2021 +0100 Fix fused.__self__ tests on PyPy (cythonGH-4417) PyPy v7.3.6 looks to have added a helpful "did you mean..." to the AttributeError exception. It's currently tripping up these tests. commit 4df1103 Merge: f6eeeda cbddad2 Author: Stefan Behnel <[email protected]> Date: Mon Oct 18 12:05:10 2021 +0200 Merge branch '0.29.x' commit cbddad2 Author: Victor Stinner <[email protected]> Date: Mon Oct 18 12:03:17 2021 +0200 Make Profile.c use PyThreadState_EnterTracing() (cythonGH-4411) Instead of __Pyx_SetTracing(), Profile.c now uses PyThreadState_EnterTracing() and PyThreadState_LeaveTracing(), which were added to Python 3.11.0a2: python/cpython#28542 When these functions are used, Cython no longer sets directly PyThreadState.cframe.use_tracing. commit f6eeeda Author: da-woods <[email protected]> Date: Sun Oct 17 19:01:52 2021 +0100 Fix fused cpdef default arguments (cythonGH-4413) A couple of things were going wrong: * they're creating CloneNodes (but not requiring the contents of the clone of the clone node to be temp) * assignment from a clone node generates cleanup code (which is against the general rules of a clone node), and also loses a reference via giveref * cpdef functions cause a small memory leak (cython#4412) by assigning to their constants twice. This is unfortunately difficult to test for. With this patch we no longer leak, but still duplicate a little bit of work. commit a0571a6 Author: da-woods <[email protected]> Date: Sun Oct 17 18:51:08 2021 +0100 Import TextTestResult in test runner instead of _TextTestResult (cythonGH-4415) All the versions we currently test are new enough that the alias is no longer necessary. commit c129b15 Author: Dobatymo <[email protected]> Date: Fri Oct 15 16:31:32 2021 +0800 Fix wrong type in unordered_multiset::swap() (cythonGH-4408) commit 72c18e7 Author: 0dminnimda <[email protected]> Date: Thu Oct 7 10:56:43 2021 +0300 Improve ci-run.sh (cythonGH-4398) commit 454a498 Author: da-woods <[email protected]> Date: Wed Oct 6 07:16:08 2021 +0100 Improve "import_array" guard (cythonGH-4397) Stop using NPY_NDARRAYOBJECT_H since: a) in principle it's private b) Numpy has renamed it and use a public symbol instead. I think the existing tests are adequate - we just aren't yet testing against a new enough version of Numpy to have caught it yet. Closes cython#4396 Closes cython#4394 commit 97c05e7 Author: Stefan Behnel <[email protected]> Date: Sat Oct 2 11:08:43 2021 +0200 Make a compile test runnable. commit 8c7b0f3 Author: da-woods <[email protected]> Date: Fri Oct 1 10:29:34 2021 +0100 Handle function "outer_attrs" more consistently (cythonGH-4375) A few children of function nodes need to be consistently evaluated outside the function scope. This PR attempts to do so and thus fixes cython#4367. commit 494f517 Author: da-woods <[email protected]> Date: Fri Oct 1 10:22:36 2021 +0100 Change gcc version check in test runner to a numeric comparison (cythonGH-4359) The string comparison was reporting '11' < '4' (so OpenMP tests were being skipped on GCC 11) commit cce3693 Author: Christian Clauss <[email protected]> Date: Wed Sep 29 09:49:45 2021 +0200 Fix typo discovered by codespell (cython#4387) commit daa0a44 Author: da-woods <[email protected]> Date: Tue Sep 28 08:48:12 2021 +0100 Fix the name of attributes in the common ABI module (cythonGH-4376) Attribute names used to be fully qualified like "_cython_3_0_0a9.cython_function_or_method" instead of the plain name. Closes cython#4373 commit fa8db66 Author: da-woods <[email protected]> Date: Mon Sep 27 10:11:12 2021 +0100 Avoid AddTraceback() if stringtab isn't set up (cythonGH-4378) This can happen (rarely) with exceptions that occur very early in the module init process. Fixes cython#4377 Uses a fake Numpy module for testing to make a version of "import_array" that always fails. commit f94f26a Author: da-woods <[email protected]> Date: Mon Sep 27 09:58:20 2021 +0100 Make __Pyx_CoroutineAwaitType non-pickleable (cythonGH-4381) This is explicitly tested for: https://github.com/cython/cython/blob/aea4e6b84b38223c540266f8c57093ee2039f284/tests/run/test_coroutines_pep492.pyx#L2400 It turns out some earlier versions of Python assume that C-API classes without a dict or slot are pickleable by the class name. Currently it isn't pickleable because the class name lookup is failing but this change makes it more robust. See cython#4376 commit 7403055 Author: da-woods <[email protected]> Date: Fri Sep 24 11:05:52 2021 +0100 Avoid unnecessary binding of fused functions on class lookup (cythonGH-4370) Among other things this makes it pickleable by ensuring that it's the same object each time. commit e2a23fe Author: da-woods <[email protected]> Date: Mon Sep 20 08:34:34 2021 +0100 Remove usused "FetchCommonPointer" utility code (cythonGH-4380)
1 parent d97f33a commit 7e9af23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1562
-542
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ jobs:
2525
# in all python versions and test failures (builtin_float) in 3.5<
2626
os: [windows-2019, ubuntu-18.04]
2727
backend: [c, cpp]
28-
python-version: [2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10-dev]
28+
python-version: ["2.7", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11-dev"]
2929
env: [{}]
3030

3131
include:
32-
# Temporary - Allow failure on all Python -dev jobs until they are considered stable
33-
#- python-version: 3.10-dev
34-
# allowed_failure: true
32+
# Temporary - Allow failure on Python 3.11-dev jobs until they are considered stable
33+
- python-version: 3.11-dev
34+
allowed_failure: true
3535

3636
# Ubuntu sub-jobs:
3737
# ================
@@ -195,6 +195,14 @@ jobs:
195195
python-version: 3.9
196196
backend: cpp
197197
env: { MACOSX_DEPLOYMENT_TARGET: 10.14 }
198+
- os: macos-10.15
199+
python-version: "3.10"
200+
backend: c
201+
env: { MACOSX_DEPLOYMENT_TARGET: 10.14 }
202+
- os: macos-10.15
203+
python-version: "3.10"
204+
backend: cpp
205+
env: { MACOSX_DEPLOYMENT_TARGET: 10.14 }
198206

199207
# exclude:
200208
# # fails due to lack of a compatible compiler

Cython/Compiler/Code.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,8 @@ class GlobalState(object):
11381138
'pystring_table',
11391139
'cached_builtins',
11401140
'cached_constants',
1141-
'init_globals',
1141+
'init_constants',
1142+
'init_globals', # (utility code called at init-time)
11421143
'init_module',
11431144
'cleanup_globals',
11441145
'cleanup_module',
@@ -1209,6 +1210,11 @@ def initialize_main_c_code(self):
12091210
w.putln("")
12101211
w.putln("static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {")
12111212

1213+
w = self.parts['init_constants']
1214+
w.enter_cfunc_scope()
1215+
w.putln("")
1216+
w.putln("static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) {")
1217+
12121218
if not Options.generate_cleanup_code:
12131219
del self.parts['cleanup_globals']
12141220
else:
@@ -1284,13 +1290,14 @@ def close_global_decls(self):
12841290
w.putln("}")
12851291
w.exit_cfunc_scope()
12861292

1287-
w = self.parts['init_globals']
1288-
w.putln("return 0;")
1289-
if w.label_used(w.error_label):
1290-
w.put_label(w.error_label)
1291-
w.putln("return -1;")
1292-
w.putln("}")
1293-
w.exit_cfunc_scope()
1293+
for part in ['init_globals', 'init_constants']:
1294+
w = self.parts[part]
1295+
w.putln("return 0;")
1296+
if w.label_used(w.error_label):
1297+
w.put_label(w.error_label)
1298+
w.putln("return -1;")
1299+
w.putln("}")
1300+
w.exit_cfunc_scope()
12941301

12951302
if Options.generate_cleanup_code:
12961303
w = self.parts['cleanup_globals']
@@ -1510,7 +1517,7 @@ def generate_cached_methods_decls(self):
15101517
return
15111518

15121519
decl = self.parts['decls']
1513-
init = self.parts['init_globals']
1520+
init = self.parts['init_constants']
15141521
cnames = []
15151522
for (type_cname, method_name), cname in sorted(self.cached_cmethods.items()):
15161523
cnames.append(cname)
@@ -1560,7 +1567,7 @@ def generate_string_constants(self):
15601567
decls_writer.putln("static Py_UNICODE %s[] = { %s };" % (cname, utf16_array))
15611568
decls_writer.putln("#endif")
15621569

1563-
init_globals = self.parts['init_globals']
1570+
init_constants = self.parts['init_constants']
15641571
if py_strings:
15651572
self.use_utility_code(UtilityCode.load_cached("InitStrings", "StringTools.c"))
15661573
py_strings.sort()
@@ -1575,9 +1582,9 @@ def generate_string_constants(self):
15751582
decls_writer.putln("#if !CYTHON_USE_MODULE_STATE")
15761583
not_limited_api_decls_writer = decls_writer.insertion_point()
15771584
decls_writer.putln("#endif")
1578-
init_globals.putln("#if CYTHON_USE_MODULE_STATE")
1579-
init_globals_in_module_state = init_globals.insertion_point()
1580-
init_globals.putln("#endif")
1585+
init_constants.putln("#if CYTHON_USE_MODULE_STATE")
1586+
init_constants_in_module_state = init_constants.insertion_point()
1587+
init_constants.putln("#endif")
15811588
for idx, py_string_args in enumerate(py_strings):
15821589
c_cname, _, py_string = py_string_args
15831590
if not py_string.is_str or not py_string.encoding or \
@@ -1627,28 +1634,28 @@ def generate_string_constants(self):
16271634
py_string.is_str,
16281635
py_string.intern
16291636
))
1630-
init_globals_in_module_state.putln("if (__Pyx_InitString(%s[%d], &%s) < 0) %s;" % (
1637+
init_constants_in_module_state.putln("if (__Pyx_InitString(%s[%d], &%s) < 0) %s;" % (
16311638
Naming.stringtab_cname,
16321639
idx,
16331640
py_string.cname,
1634-
init_globals.error_goto(self.module_pos)))
1641+
init_constants.error_goto(self.module_pos)))
16351642
w.putln("{0, 0, 0, 0, 0, 0, 0}")
16361643
w.putln("};")
16371644

1638-
init_globals.putln("#if !CYTHON_USE_MODULE_STATE")
1639-
init_globals.putln(
1645+
init_constants.putln("#if !CYTHON_USE_MODULE_STATE")
1646+
init_constants.putln(
16401647
"if (__Pyx_InitStrings(%s) < 0) %s;" % (
16411648
Naming.stringtab_cname,
1642-
init_globals.error_goto(self.module_pos)))
1643-
init_globals.putln("#endif")
1649+
init_constants.error_goto(self.module_pos)))
1650+
init_constants.putln("#endif")
16441651

16451652
def generate_num_constants(self):
16461653
consts = [(c.py_type, c.value[0] == '-', len(c.value), c.value, c.value_code, c)
16471654
for c in self.num_const_index.values()]
16481655
consts.sort()
16491656
decls_writer = self.parts['decls']
16501657
decls_writer.putln("#if !CYTHON_USE_MODULE_STATE")
1651-
init_globals = self.parts['init_globals']
1658+
init_constants = self.parts['init_constants']
16521659
for py_type, _, _, value, value_code, c in consts:
16531660
cname = c.cname
16541661
self.parts['module_state'].putln("PyObject *%s;" % cname)
@@ -1669,9 +1676,9 @@ def generate_num_constants(self):
16691676
function = "PyInt_FromLong(%sL)"
16701677
else:
16711678
function = "PyInt_FromLong(%s)"
1672-
init_globals.putln('%s = %s; %s' % (
1679+
init_constants.putln('%s = %s; %s' % (
16731680
cname, function % value_code,
1674-
init_globals.error_goto_if_null(cname, self.module_pos)))
1681+
init_constants.error_goto_if_null(cname, self.module_pos)))
16751682
decls_writer.putln("#endif")
16761683

16771684
# The functions below are there in a transition phase only

Cython/Compiler/ExprNodes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13814,6 +13814,12 @@ def generate_result_code(self, code):
1381413814
def generate_disposal_code(self, code):
1381513815
pass
1381613816

13817+
def generate_post_assignment_code(self, code):
13818+
# if we're assigning from a CloneNode then it's "giveref"ed away, so it does
13819+
# need a matching incref (ideally this should happen before the assignment though)
13820+
if self.is_temp: # should usually be true
13821+
code.put_incref(self.result(), self.ctype())
13822+
1381713823
def free_temps(self, code):
1381813824
pass
1381913825

Cython/Compiler/FusedNode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ def analyse_expressions(self, env):
841841
for arg in self.node.args:
842842
if arg.default:
843843
arg.default = arg.default.analyse_expressions(env)
844-
defaults.append(ProxyNode(arg.default))
844+
# coerce the argument to temp since CloneNode really requires a temp
845+
defaults.append(ProxyNode(arg.default.coerce_to_temp(env)))
845846
else:
846847
defaults.append(None)
847848

@@ -851,7 +852,7 @@ def analyse_expressions(self, env):
851852
# the dispatcher specifically doesn't want its defaults overriding
852853
for arg, default in zip(stat.args, defaults):
853854
if default is not None:
854-
arg.default = CloneNode(default).coerce_to(arg.type, env)
855+
arg.default = CloneNode(default).analyse_expressions(env).coerce_to(arg.type, env)
855856

856857
if self.py_func:
857858
args = [CloneNode(default) for default in defaults if default]

Cython/Compiler/ModuleNode.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ def generate_module_init_func(self, imported_modules, env, code):
29392939

29402940
# start of module init/exec function (pre/post PEP 489)
29412941
code.putln("{")
2942-
2942+
code.putln('int stringtab_initialized = 0;')
29432943
tempdecl_code = code.insertion_point()
29442944

29452945
profile = code.globalstate.directives['profile']
@@ -3012,7 +3012,10 @@ def generate_module_init_func(self, imported_modules, env, code):
30123012
code.putln("#endif")
30133013

30143014
code.putln("/*--- Initialize various global constants etc. ---*/")
3015-
code.put_error_if_neg(self.pos, "__Pyx_InitGlobals()")
3015+
code.put_error_if_neg(self.pos, "__Pyx_InitConstants()")
3016+
code.putln("stringtab_initialized = 1;")
3017+
code.put_error_if_neg(self.pos, "__Pyx_InitGlobals()") # calls any utility code
3018+
30163019

30173020
code.putln("#if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || "
30183021
"__PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)")
@@ -3095,7 +3098,9 @@ def generate_module_init_func(self, imported_modules, env, code):
30953098
for cname, type in code.funcstate.all_managed_temps():
30963099
code.put_xdecref(cname, type)
30973100
code.putln('if (%s) {' % env.module_cname)
3098-
code.putln('if (%s) {' % env.module_dict_cname)
3101+
code.putln('if (%s && stringtab_initialized) {' % env.module_dict_cname)
3102+
# We can run into errors before the module or stringtab are initialized.
3103+
# In this case it is not safe to add a traceback (because it uses the stringtab)
30993104
code.put_add_traceback(EncodedString("init %s" % env.qualified_name))
31003105
code.globalstate.use_utility_code(Nodes.traceback_utility_code)
31013106
# Module reference and module dict are in global variables which might still be needed

Cython/Compiler/Nodes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,8 @@ class FuncDefNode(StatNode, BlockNode):
17501750
code_object = None
17511751
return_type_annotation = None
17521752

1753+
outer_attrs = None # overridden by some derived classes - to be visited outside the node's scope
1754+
17531755
def analyse_default_values(self, env):
17541756
default_seen = 0
17551757
for arg in self.args:
@@ -2348,9 +2350,11 @@ def generate_wrapper_functions(self, code):
23482350
def generate_execution_code(self, code):
23492351
code.mark_pos(self.pos)
23502352
# Evaluate and store argument default values
2351-
for arg in self.args:
2352-
if not arg.is_dynamic:
2353-
arg.generate_assignment_code(code)
2353+
# skip this for wrappers since it's done by wrapped function
2354+
if not self.is_wrapper:
2355+
for arg in self.args:
2356+
if not arg.is_dynamic:
2357+
arg.generate_assignment_code(code)
23542358

23552359
#
23562360
# Special code for the __getbuffer__ function

Cython/Compiler/ParseTreeTransforms.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,8 +2054,6 @@ def visit_FuncDefNode(self, node):
20542054
def visit_DefNode(self, node):
20552055
node = self.visit_FuncDefNode(node)
20562056
env = self.current_env()
2057-
if isinstance(node, Nodes.DefNode) and node.is_wrapper:
2058-
env = env.parent_scope
20592057
if (not isinstance(node, Nodes.DefNode) or
20602058
node.fused_py_func or node.is_generator_body or
20612059
not node.needs_assignment_synthesis(env)):

Cython/Compiler/TypeSlots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ def __init__(self, signature, slot_name, left_method, **kargs):
515515
SyntheticSlot.__init__(
516516
self, slot_name, [left_method, right_method], "0", is_binop=True, **kargs)
517517
# MethodSlot causes special method registration.
518-
self.left_slot = MethodSlot(signature, "", left_method)
519-
self.right_slot = MethodSlot(signature, "", right_method)
518+
self.left_slot = MethodSlot(signature, "", left_method, **kargs)
519+
self.right_slot = MethodSlot(signature, "", right_method, **kargs)
520520

521521

522522
class RichcmpSlot(MethodSlot):

Cython/Compiler/Visitor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,10 @@ def exit_scope(self):
370370
self.env_stack.pop()
371371

372372
def visit_FuncDefNode(self, node):
373+
outer_attrs = node.outer_attrs
374+
self.visitchildren(node, attrs=outer_attrs)
373375
self.enter_scope(node, node.local_scope)
374-
self._process_children(node)
376+
self.visitchildren(node, attrs=None, exclude=outer_attrs)
375377
self.exit_scope()
376378
return node
377379

Cython/Includes/cpython/pycapsule.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# available since Python 3.1!
2+
# available since Python 2.7!
33

44

55
cdef extern from "Python.h":

0 commit comments

Comments
 (0)