From 326f36e8c21ce9bb07c119d00904c6cdc7103c76 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:47:47 +0800 Subject: [PATCH 01/15] fix PY_NEW signature --- src/sage/ext/stdsage.pxd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/ext/stdsage.pxd b/src/sage/ext/stdsage.pxd index 15abe13b7cd..e2bf7434f35 100644 --- a/src/sage/ext/stdsage.pxd +++ b/src/sage/ext/stdsage.pxd @@ -10,7 +10,7 @@ Standard C helper code for Cython modules # http://www.gnu.org/licenses/ #***************************************************************************** -from cpython.object cimport Py_TYPE, PyTypeObject +from cpython.object cimport Py_TYPE, PyTypeObject, PyObject cdef inline PY_NEW(type t): @@ -19,7 +19,7 @@ cdef inline PY_NEW(type t): :class:`Integer` where we change ``tp_new`` at runtime (Cython optimizations assume that ``tp_new`` doesn't change). """ - return (t).tp_new(t, NULL, NULL) + return (t).tp_new(t, NULL, NULL) cdef inline void PY_SET_TP_NEW(type dst, type src): From cba7b31edda2c2512001af01b0005a483bbab90e Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Sun, 20 Aug 2023 04:49:57 +0800 Subject: [PATCH 02/15] update doctests for cython 3 --- src/doc/en/thematic_tutorials/coercion_and_categories.rst | 2 +- src/sage/arith/srange.pyx | 2 +- src/sage/combinat/sloane_functions.py | 2 +- src/sage/misc/cachefunc.pyx | 7 ++++--- src/sage/misc/lazy_import.pyx | 2 +- src/sage/misc/lazy_list.pyx | 2 +- src/sage/misc/sageinspect.py | 4 ++-- src/sage/modules/free_module_element.pyx | 2 +- src/sage/rings/finite_rings/finite_field_base.pyx | 2 +- src/sage/rings/polynomial/skew_polynomial_finite_field.pyx | 6 +++--- src/sage/structure/coerce_dict.pyx | 4 ++-- src/sage/tests/cmdline.py | 3 +-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/doc/en/thematic_tutorials/coercion_and_categories.rst b/src/doc/en/thematic_tutorials/coercion_and_categories.rst index de2349a9a3f..bb23331c151 100644 --- a/src/doc/en/thematic_tutorials/coercion_and_categories.rst +++ b/src/doc/en/thematic_tutorials/coercion_and_categories.rst @@ -105,7 +105,7 @@ it makes sense to build on top of the base class This base class provides a lot more methods than a general parent:: sage: [p for p in dir(Field) if p not in dir(Parent)] - ['__fraction_field', + ['_CommutativeRing__fraction_field', '__iter__', '__len__', '__rxor__', diff --git a/src/sage/arith/srange.pyx b/src/sage/arith/srange.pyx index 156e548a11a..132cf93d085 100644 --- a/src/sage/arith/srange.pyx +++ b/src/sage/arith/srange.pyx @@ -84,7 +84,7 @@ def xsrange(start, end=None, step=1, universe=None, *, coerce=True, bint include EXAMPLES:: sage: xsrange(10) - + <...generator object at 0x...> sage: for i in xsrange(1,5): ....: print(i) 1 diff --git a/src/sage/combinat/sloane_functions.py b/src/sage/combinat/sloane_functions.py index c3cf9299093..e5c99b71fe7 100644 --- a/src/sage/combinat/sloane_functions.py +++ b/src/sage/combinat/sloane_functions.py @@ -9169,7 +9169,7 @@ def __getattribute__(self, name): :: sage: sloane.__repr__ - + sage: sloane.__name__ Traceback (most recent call last): ... diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index 8aa30a85272..2b1d38c12b9 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -50,7 +50,7 @@ be used:: sage: cython('''cpdef test_funct(x): return -x''') sage: wrapped_funct = cached_function(test_funct, name='wrapped_funct') sage: wrapped_funct - Cached version of + Cached version of sage: wrapped_funct.__name__ 'wrapped_funct' sage: wrapped_funct(5) @@ -82,9 +82,9 @@ approach is still needed for cpdef methods:: sage: cython(os.linesep.join(cython_code)) sage: O = MyClass() sage: O.direct_method - Cached version of + Cached version of sage: O.wrapped_method - Cached version of + Cached version of sage: O.wrapped_method.__name__ 'wrapped_method' sage: O.wrapped_method(5) @@ -270,6 +270,7 @@ Introspection works:: "some doc for a wrapped cython method" return -x sage: print(sage_getsource(O.direct_method)) + @cached_method def direct_method(self, x): "Some doc for direct method" return 2*x diff --git a/src/sage/misc/lazy_import.pyx b/src/sage/misc/lazy_import.pyx index c33a1e74efd..7fc73407ace 100644 --- a/src/sage/misc/lazy_import.pyx +++ b/src/sage/misc/lazy_import.pyx @@ -1095,7 +1095,7 @@ def lazy_import(module, names, as_=None, *, sage: lazy_import('ppl', 'equation', ....: feature=PythonModule('ppl', spkg='pplpy', type='standard')) sage: equation # needs pplpy - + sage: lazy_import('PyNormaliz', 'NmzListConeProperties', feature=PythonModule('PyNormaliz', spkg='pynormaliz')) # optional - pynormaliz sage: NmzListConeProperties # optional - pynormaliz diff --git a/src/sage/misc/lazy_list.pyx b/src/sage/misc/lazy_list.pyx index ba62c446b69..cd750933860 100644 --- a/src/sage/misc/lazy_list.pyx +++ b/src/sage/misc/lazy_list.pyx @@ -678,7 +678,7 @@ cdef class lazy_list_generic(): sage: from itertools import count sage: from sage.misc.lazy_list import lazy_list sage: iter(lazy_list(count())) - + <...generator object at 0x...> :: diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index ce5e9987027..df8e6bf89ac 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -76,8 +76,8 @@ sage: sage_getdoc(sage.rings.rational.make_rational).lstrip() 'Make a rational number ...' - sage: sage_getsource(sage.rings.rational.make_rational)[4:] - 'make_rational(s):...' + sage: sage_getsource(sage.rings.rational.make_rational) + '@cython.binding(True)\ndef make_rational(s):...' Python functions:: diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx index d5e8256b68c..c9af9bcbdf7 100644 --- a/src/sage/modules/free_module_element.pyx +++ b/src/sage/modules/free_module_element.pyx @@ -1634,7 +1634,7 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: v = vector([1,2/3,pi]) # needs sage.symbolic sage: v.items() # needs sage.symbolic - + <...generator object at ...> sage: list(v.items()) # needs sage.symbolic [(0, 1), (1, 2/3), (2, pi)] diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index 7e2eed91153..3a6db8995c6 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -328,7 +328,7 @@ cdef class FiniteField(Field): sage: p = next_prime(2^64) sage: k. = FiniteField(p^2, impl="pari") sage: it = iter(k); it - + <...generator object at ...> sage: [next(it) for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] diff --git a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx index 41951687939..c6b67cba5fb 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx @@ -629,7 +629,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense): sage: S. = k['x',Frob] sage: a = x^4 + 2*t*x^3 + 3*t^2*x^2 + (t^2 + t + 1)*x + 4*t + 3 sage: iter = a.right_irreducible_divisors(); iter - + <...generator object at 0x...> sage: next(iter) # random x + 2*t^2 + 4*t + 4 sage: next(iter) # random @@ -664,7 +664,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense): sage: S. = k['x',Frob] sage: a = x^4 + 2*t*x^3 + 3*t^2*x^2 + (t^2 + t + 1)*x + 4*t + 3 sage: iter = a.left_irreducible_divisors(); iter - + <...generator object at 0x...> sage: next(iter) # random x + 3*t + 3 sage: next(iter) # random @@ -1052,7 +1052,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense): sage: S. = k['x',Frob] sage: a = x^3 + (t^2 + 1)*x^2 + (2*t + 3)*x + t^2 + t + 2 sage: iter = a.factorizations(); iter - + <...generator object at 0x...> sage: next(iter) # random (x + 3*t^2 + 4*t) * (x + 2*t^2) * (x + 4*t^2 + 4*t + 2) sage: next(iter) # random diff --git a/src/sage/structure/coerce_dict.pyx b/src/sage/structure/coerce_dict.pyx index a2e8443084c..ef86c6af35c 100644 --- a/src/sage/structure/coerce_dict.pyx +++ b/src/sage/structure/coerce_dict.pyx @@ -777,7 +777,7 @@ cdef class MonoDict: sage: L[1] = None sage: L[2] = True sage: L.items() - + <...generator object at ...> sage: sorted(L.items()) [(1, None), (2, True)] """ @@ -1452,7 +1452,7 @@ cdef class TripleDict: sage: L = TripleDict() sage: L[1,2,3] = None sage: L.items() - + <...generator object at ...> sage: list(L.items()) [((1, 2, 3), None)] """ diff --git a/src/sage/tests/cmdline.py b/src/sage/tests/cmdline.py index ad0c44aa274..f14cd2db768 100644 --- a/src/sage/tests/cmdline.py +++ b/src/sage/tests/cmdline.py @@ -491,9 +491,8 @@ def test_executable(args, input="", timeout=100.0, pydebug_ignore_warnings=False sage: (out, err, ret) = test_executable(["sage", "--cython"]) sage: print(err) - Cython (http://cython.org) is a compiler for code written in the - Cython language. Cython is based on Pyrex by Greg Ewing. ... + cython: error: cython: Need at least one source file sage: def has_tty(): ....: try: From 703ec1b0e24037dcceba2a5c044c6ea3b1b4596c Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 00:21:52 +0800 Subject: [PATCH 03/15] update cython to 3.0.2 --- build/pkgs/cython/checksums.ini | 6 +- build/pkgs/cython/install-requires.txt | 2 +- build/pkgs/cython/package-version.txt | 2 +- ...directive-to-enable-the-Python-trash.patch | 355 ------------------ .../cython/patches/0001-rebased-PR2946.patch | 193 ---------- 5 files changed, 5 insertions(+), 553 deletions(-) delete mode 100644 build/pkgs/cython/patches/0001-cython.trashcan-directive-to-enable-the-Python-trash.patch delete mode 100644 build/pkgs/cython/patches/0001-rebased-PR2946.patch diff --git a/build/pkgs/cython/checksums.ini b/build/pkgs/cython/checksums.ini index 175914867ed..5d0bc66c242 100644 --- a/build/pkgs/cython/checksums.ini +++ b/build/pkgs/cython/checksums.ini @@ -1,5 +1,5 @@ tarball=Cython-VERSION.tar.gz -sha1=762987c737acfe7532cb3da38b450fb6e0cf1d7b -md5=a4d0f9fbc9c137f1a88937cd40e8c5ee -cksum=2260471737 +sha1=08eb99f7c95b7ca667b1547575e7369d8064b4b3 +md5=00def3f2b96c393098e01eb2f1f169ad +cksum=2321746451 upstream_url=https://pypi.io/packages/source/C/Cython/Cython-VERSION.tar.gz diff --git a/build/pkgs/cython/install-requires.txt b/build/pkgs/cython/install-requires.txt index b8a968fa247..3693d637891 100644 --- a/build/pkgs/cython/install-requires.txt +++ b/build/pkgs/cython/install-requires.txt @@ -1 +1 @@ -cython >=0.29.21, <1.0 +cython >=3.0, <4.0 diff --git a/build/pkgs/cython/package-version.txt b/build/pkgs/cython/package-version.txt index 5232b0aaea8..b5021469305 100644 --- a/build/pkgs/cython/package-version.txt +++ b/build/pkgs/cython/package-version.txt @@ -1 +1 @@ -0.29.36 +3.0.2 diff --git a/build/pkgs/cython/patches/0001-cython.trashcan-directive-to-enable-the-Python-trash.patch b/build/pkgs/cython/patches/0001-cython.trashcan-directive-to-enable-the-Python-trash.patch deleted file mode 100644 index 0cd3f35df32..00000000000 --- a/build/pkgs/cython/patches/0001-cython.trashcan-directive-to-enable-the-Python-trash.patch +++ /dev/null @@ -1,355 +0,0 @@ -See https://github.com/cython/cython/pull/2842 - -and https://github.com/cython/cython/pull/4475 - -commit c47c4ef735c4b7f1863b21bbe6f112b06c4aad05 -Author: Jeroen Demeyer -Date: Thu Feb 14 10:02:41 2019 +0100 - - @cython.trashcan directive to enable the Python trashcan for deallocations - -diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py -index 56845330d..3a3e8a956 100644 ---- a/Cython/Compiler/ModuleNode.py -+++ b/Cython/Compiler/ModuleNode.py -@@ -1443,6 +1443,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): - - is_final_type = scope.parent_type.is_final_type - needs_gc = scope.needs_gc() -+ needs_trashcan = scope.needs_trashcan() - - weakref_slot = scope.lookup_here("__weakref__") if not scope.is_closure_class_scope else None - if weakref_slot not in scope.var_entries: -@@ -1481,6 +1482,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): - # running this destructor. - code.putln("PyObject_GC_UnTrack(o);") - -+ if needs_trashcan: -+ code.globalstate.use_utility_code( -+ UtilityCode.load_cached("PyTrashcan", "ExtensionTypes.c")) -+ code.putln("__Pyx_TRASHCAN_BEGIN(o, %s)" % slot_func_cname) -+ - # call the user's __dealloc__ - self.generate_usr_dealloc_call(scope, code) - -@@ -1554,6 +1560,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): - code.putln("(*Py_TYPE(o)->tp_free)(o);") - if freelist_size: - code.putln("}") -+ -+ if needs_trashcan: -+ code.putln("__Pyx_TRASHCAN_END") -+ - code.putln( - "}") - -diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py -index d03119fca..539629926 100644 ---- a/Cython/Compiler/Options.py -+++ b/Cython/Compiler/Options.py -@@ -319,7 +319,8 @@ directive_types = { - 'freelist': int, - 'c_string_type': one_of('bytes', 'bytearray', 'str', 'unicode'), - 'c_string_encoding': normalise_encoding_name, -- 'cpow': bool -+ 'cpow': bool, -+ 'trashcan': bool, - } - - for key, val in _directive_defaults.items(): -@@ -362,6 +363,7 @@ directive_scopes = { # defaults to available everywhere - 'np_pythran': ('module',), - 'fast_gil': ('module',), - 'iterable_coroutine': ('module', 'function'), -+ 'trashcan' : ('cclass',), - } - - -diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py -index c309bd04b..9231130b5 100644 ---- a/Cython/Compiler/PyrexTypes.py -+++ b/Cython/Compiler/PyrexTypes.py -@@ -1129,6 +1129,7 @@ class PyObjectType(PyrexType): - is_extern = False - is_subclassed = False - is_gc_simple = False -+ builtin_trashcan = False # builtin type using trashcan - - def __str__(self): - return "Python object" -@@ -1183,10 +1184,14 @@ class PyObjectType(PyrexType): - - - builtin_types_that_cannot_create_refcycles = set([ -- 'bool', 'int', 'long', 'float', 'complex', -+ 'object', 'bool', 'int', 'long', 'float', 'complex', - 'bytearray', 'bytes', 'unicode', 'str', 'basestring' - ]) - -+builtin_types_with_trashcan = set([ -+ 'dict', 'list', 'set', 'frozenset', 'tuple', 'type', -+]) -+ - - class BuiltinObjectType(PyObjectType): - # objstruct_cname string Name of PyObject struct -@@ -1211,6 +1216,7 @@ class BuiltinObjectType(PyObjectType): - self.typeptr_cname = "(&%s)" % cname - self.objstruct_cname = objstruct_cname - self.is_gc_simple = name in builtin_types_that_cannot_create_refcycles -+ self.builtin_trashcan = name in builtin_types_with_trashcan - if name == 'type': - # Special case the type type, as many C API calls (and other - # libraries) actually expect a PyTypeObject* for type arguments. -diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py -index 7361a55ae..f0c311ba6 100644 ---- a/Cython/Compiler/Symtab.py -+++ b/Cython/Compiler/Symtab.py -@@ -2043,7 +2043,7 @@ class PyClassScope(ClassScope): - class CClassScope(ClassScope): - # Namespace of an extension type. - # -- # parent_type CClassType -+ # parent_type PyExtensionType - # #typeobj_cname string or None - # #objstruct_cname string - # method_table_cname string -@@ -2087,6 +2087,22 @@ class CClassScope(ClassScope): - return not self.parent_type.is_gc_simple - return False - -+ def needs_trashcan(self): -+ # If the trashcan directive is explicitly set to False, -+ # unconditionally disable the trashcan. -+ directive = self.directives.get('trashcan') -+ if directive is False: -+ return False -+ # If the directive is set to True and the class has Python-valued -+ # C attributes, then it should use the trashcan in tp_dealloc. -+ if directive and self.has_cyclic_pyobject_attrs: -+ return True -+ # Use the trashcan if the base class uses it -+ base_type = self.parent_type.base_type -+ if base_type and base_type.scope is not None: -+ return base_type.scope.needs_trashcan() -+ return self.parent_type.builtin_trashcan -+ - def needs_tp_clear(self): - """ - Do we need to generate an implementation for the tp_clear slot? Can -diff --git a/Cython/Utility/ExtensionTypes.c b/Cython/Utility/ExtensionTypes.c -index dc187ab49..f359165df 100644 ---- a/Cython/Utility/ExtensionTypes.c -+++ b/Cython/Utility/ExtensionTypes.c -@@ -119,6 +119,54 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) { - return r; - } - -+/////////////// PyTrashcan.proto /////////////// -+ -+// These macros are taken from https://github.com/python/cpython/pull/11841 -+// Unlike the Py_TRASHCAN_SAFE_BEGIN/Py_TRASHCAN_SAFE_END macros, they -+// allow dealing correctly with subclasses. -+ -+// This requires CPython version >= 2.7.4 -+// (or >= 3.2.4 but we don't support such old Python 3 versions anyway) -+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03080000 -+// https://github.com/python/cpython/pull/11841 merged so Cython reimplementation -+// is no longer necessary -+#define __Pyx_TRASHCAN_BEGIN Py_TRASHCAN_BEGIN -+#define __Pyx_TRASHCAN_END Py_TRASHCAN_END -+#elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070400 -+#define __Pyx_TRASHCAN_BEGIN_CONDITION(op, cond) \ -+ do { \ -+ PyThreadState *_tstate = NULL; \ -+ // If "cond" is false, then _tstate remains NULL and the deallocator -+ // is run normally without involving the trashcan -+ if (cond) { \ -+ _tstate = PyThreadState_GET(); \ -+ if (_tstate->trash_delete_nesting >= PyTrash_UNWIND_LEVEL) { \ -+ // Store the object (to be deallocated later) and jump past -+ // Py_TRASHCAN_END, skipping the body of the deallocator -+ _PyTrash_thread_deposit_object((PyObject*)(op)); \ -+ break; \ -+ } \ -+ ++_tstate->trash_delete_nesting; \ -+ } -+ // The body of the deallocator is here. -+#define __Pyx_TRASHCAN_END \ -+ if (_tstate) { \ -+ --_tstate->trash_delete_nesting; \ -+ if (_tstate->trash_delete_later && _tstate->trash_delete_nesting <= 0) \ -+ _PyTrash_thread_destroy_chain(); \ -+ } \ -+ } while (0); -+ -+#define __Pyx_TRASHCAN_BEGIN(op, dealloc) __Pyx_TRASHCAN_BEGIN_CONDITION(op, \ -+ Py_TYPE(op)->tp_dealloc == (destructor)(dealloc)) -+ -+#else -+// The trashcan is a no-op on other Python implementations -+// or old CPython versions -+#define __Pyx_TRASHCAN_BEGIN(op, dealloc) -+#define __Pyx_TRASHCAN_END -+#endif -+ - /////////////// CallNextTpDealloc.proto /////////////// - - static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc); -diff --git a/tests/run/trashcan.pyx b/tests/run/trashcan.pyx -new file mode 100644 -index 000000000..93a501ff8 ---- /dev/null -+++ b/tests/run/trashcan.pyx -@@ -0,0 +1,148 @@ -+# mode: run -+ -+cimport cython -+ -+ -+# Count number of times an object was deallocated twice. This should remain 0. -+cdef int double_deallocations = 0 -+def assert_no_double_deallocations(): -+ global double_deallocations -+ err = double_deallocations -+ double_deallocations = 0 -+ assert not err -+ -+ -+# Compute x = f(f(f(...(None)...))) nested n times and throw away the result. -+# The real test happens when exiting this function: then a big recursive -+# deallocation of x happens. We are testing two things in the tests below: -+# that Python does not crash and that no double deallocation happens. -+# See also https://github.com/python/cpython/pull/11841 -+def recursion_test(f, int n=2**20): -+ x = None -+ cdef int i -+ for i in range(n): -+ x = f(x) -+ -+ -+@cython.trashcan(True) -+cdef class Recurse: -+ """ -+ >>> recursion_test(Recurse) -+ >>> assert_no_double_deallocations() -+ """ -+ cdef public attr -+ cdef int deallocated -+ -+ def __init__(self, x): -+ self.attr = x -+ -+ def __dealloc__(self): -+ # Check that we're not being deallocated twice -+ global double_deallocations -+ double_deallocations += self.deallocated -+ self.deallocated = 1 -+ -+ -+cdef class RecurseSub(Recurse): -+ """ -+ >>> recursion_test(RecurseSub) -+ >>> assert_no_double_deallocations() -+ """ -+ cdef int subdeallocated -+ -+ def __dealloc__(self): -+ # Check that we're not being deallocated twice -+ global double_deallocations -+ double_deallocations += self.subdeallocated -+ self.subdeallocated = 1 -+ -+ -+@cython.freelist(4) -+@cython.trashcan(True) -+cdef class RecurseFreelist: -+ """ -+ >>> recursion_test(RecurseFreelist) -+ >>> recursion_test(RecurseFreelist, 1000) -+ >>> assert_no_double_deallocations() -+ """ -+ cdef public attr -+ cdef int deallocated -+ -+ def __init__(self, x): -+ self.attr = x -+ -+ def __dealloc__(self): -+ # Check that we're not being deallocated twice -+ global double_deallocations -+ double_deallocations += self.deallocated -+ self.deallocated = 1 -+ -+ -+# Subclass of list => uses trashcan by default -+# As long as https://github.com/python/cpython/pull/11841 is not fixed, -+# this does lead to double deallocations, so we skip that check. -+cdef class RecurseList(list): -+ """ -+ >>> RecurseList(42) -+ [42] -+ >>> recursion_test(RecurseList) -+ """ -+ def __init__(self, x): -+ super().__init__((x,)) -+ -+ -+# Some tests where the trashcan is NOT used. When the trashcan is not used -+# in a big recursive deallocation, the __dealloc__s of the base classs are -+# only run after the __dealloc__s of the subclasses. -+# We use this to detect trashcan usage. -+cdef int base_deallocated = 0 -+cdef int trashcan_used = 0 -+def assert_no_trashcan_used(): -+ global base_deallocated, trashcan_used -+ err = trashcan_used -+ trashcan_used = base_deallocated = 0 -+ assert not err -+ -+ -+cdef class Base: -+ def __dealloc__(self): -+ global base_deallocated -+ base_deallocated = 1 -+ -+ -+# Trashcan disabled by default -+cdef class Sub1(Base): -+ """ -+ >>> recursion_test(Sub1, 100) -+ >>> assert_no_trashcan_used() -+ """ -+ cdef public attr -+ -+ def __init__(self, x): -+ self.attr = x -+ -+ def __dealloc__(self): -+ global base_deallocated, trashcan_used -+ trashcan_used += base_deallocated -+ -+ -+@cython.trashcan(True) -+cdef class Middle(Base): -+ cdef public foo -+ -+ -+# Trashcan disabled explicitly -+@cython.trashcan(False) -+cdef class Sub2(Middle): -+ """ -+ >>> recursion_test(Sub2, 1000) -+ >>> assert_no_trashcan_used() -+ """ -+ cdef public attr -+ -+ def __init__(self, x): -+ self.attr = x -+ -+ def __dealloc__(self): -+ global base_deallocated, trashcan_used -+ trashcan_used += base_deallocated --- -2.37.1 (Apple Git-137.1) - diff --git a/build/pkgs/cython/patches/0001-rebased-PR2946.patch b/build/pkgs/cython/patches/0001-rebased-PR2946.patch deleted file mode 100644 index 36764e7291e..00000000000 --- a/build/pkgs/cython/patches/0001-rebased-PR2946.patch +++ /dev/null @@ -1,193 +0,0 @@ -From 0b69e95aa702fb9f52b285360d5c5ae5e7fbb745 Mon Sep 17 00:00:00 2001 -From: Dima Pasechnik -Date: Thu, 16 Mar 2023 22:35:09 +0000 -Subject: [PATCH] rebased PR2946 - ---- - Cython/Compiler/Main.py | 44 +++++++++++++++---- - Cython/Utils.py | 22 +++++++--- - runtests.py | 1 + - .../build/cythonize_pep420_namespace.srctree | 44 +++++++++++++++++++ - 4 files changed, 96 insertions(+), 15 deletions(-) - create mode 100644 tests/build/cythonize_pep420_namespace.srctree - -diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py -index 9c57452ba..1143ecf03 100644 ---- a/Cython/Compiler/Main.py -+++ b/Cython/Compiler/Main.py -@@ -809,32 +809,58 @@ def search_include_directories(dirs, qualified_name, suffix, pos, include=False) - else: - dirs = (Utils.find_root_package_dir(file_desc.filename),) + dirs - -+ # search for dotted filename e.g. /foo.bar.pxd - dotted_filename = qualified_name - if suffix: - dotted_filename += suffix - -+ for dirname in dirs: -+ path = os.path.join(dirname, dotted_filename) -+ if os.path.exists(path): -+ return path -+ -+ # search for filename in package structure e.g. /foo/bar.pxd or /foo/bar/__init__.pxd - if not include: -+ - names = qualified_name.split('.') - package_names = tuple(names[:-1]) - module_name = names[-1] - module_filename = module_name + suffix - package_filename = "__init__" + suffix - -- for dirname in dirs: -- path = os.path.join(dirname, dotted_filename) -- if os.path.exists(path): -- return path -- -- if not include: -- package_dir = Utils.check_package_dir(dirname, package_names) -+ # search for standard packages first - PEP420 -+ namespace_dirs = [] -+ for dirname in dirs: -+ package_dir, is_namespace = Utils.check_package_dir(dirname, package_names) - if package_dir is not None: -+ -+ if is_namespace: -+ namespace_dirs.append(package_dir) -+ continue -+ -+ # matches modules of the form: /foo/bar.pxd - path = os.path.join(package_dir, module_filename) - if os.path.exists(path): - return path -- path = os.path.join(package_dir, module_name, -- package_filename) -+ -+ # matches modules of the form: /foo/bar/__init__.pxd -+ path = os.path.join(package_dir, module_name, package_filename) - if os.path.exists(path): - return path -+ -+ # search for namespaces second - PEP420 -+ for package_dir in namespace_dirs: -+ -+ # matches modules of the form: /foo/bar.pxd -+ path = os.path.join(package_dir, module_filename) -+ if os.path.exists(path): -+ return path -+ -+ # matches modules of the form: /foo/bar/__init__.pxd -+ path = os.path.join(package_dir, module_name, package_filename) -+ if os.path.exists(path): -+ return path -+ - return None - - -diff --git a/Cython/Utils.py b/Cython/Utils.py -index 69563794c..77a48fbd7 100644 ---- a/Cython/Utils.py -+++ b/Cython/Utils.py -@@ -135,15 +135,19 @@ def find_root_package_dir(file_path): - return dir - - @cached_function --def check_package_dir(dir, package_names): -+def check_package_dir(dir_path, package_names): -+ namespace = True - for dirname in package_names: -- dir = os.path.join(dir, dirname) -- if not is_package_dir(dir): -- return None -- return dir -+ dir_path = os.path.join(dir_path, dirname) -+ has_init = contains_init(dir_path) -+ if not namespace and not has_init: -+ return None, False -+ elif has_init: -+ namespace = False -+ return dir_path, namespace - - @cached_function --def is_package_dir(dir_path): -+def contains_init(dir_path): - for filename in ("__init__.py", - "__init__.pyc", - "__init__.pyx", -@@ -152,6 +156,12 @@ def is_package_dir(dir_path): - if path_exists(path): - return 1 - -+ -+def is_package_dir(dir_path): -+ if contains_init(dir_path): -+ return 1 -+ -+ - @cached_function - def path_exists(path): - # try on the filesystem first -diff --git a/runtests.py b/runtests.py -index 91a0dd257..7d0446384 100755 ---- a/runtests.py -+++ b/runtests.py -@@ -415,6 +415,7 @@ VER_DEP_MODULES = { - 'run.special_methods_T561_py2' - ]), - (3,3) : (operator.lt, lambda x: x in ['build.package_compilation', -+ 'build.cythonize_pep420_namespace', - 'run.yield_from_py33', - 'pyximport.pyximport_namespace', - ]), -diff --git a/tests/build/cythonize_pep420_namespace.srctree b/tests/build/cythonize_pep420_namespace.srctree -new file mode 100644 -index 000000000..6a031e417 ---- /dev/null -+++ b/tests/build/cythonize_pep420_namespace.srctree -@@ -0,0 +1,44 @@ -+PYTHON setup.py build_ext --inplace -+PYTHON -c "import runner" -+ -+######## setup.py ######## -+ -+from Cython.Build.Dependencies import cythonize -+ -+from distutils.core import setup, Extension -+ -+setup( -+ ext_modules=cythonize([ -+ Extension("nsp.m1.a", ["nsp/m1/a.pyx"]), -+ Extension("nsp.m2.b", ["nsp/m2/b.pyx"]) -+ ]), -+) -+ -+######## nsp/m1/__init__.py ######## -+ -+######## nsp/m1/a.pyx ######## -+ -+cdef class A: -+ pass -+ -+######## nsp/m1/a.pxd ######## -+ -+cdef class A: -+ pass -+ -+######## nsp/m2/__init__.py ######## -+ -+######## nsp/m2/b.pyx ######## -+ -+from nsp.m1.a cimport A -+ -+cdef class B(A): -+ pass -+ -+######## runner.py ######## -+ -+from nsp.m1.a import A -+from nsp.m2.b import B -+ -+a = A() -+b = B() --- -2.37.1 (Apple Git-137.1) - From ad75f666bd777dca0628492819f99c998742f1bc Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 11:30:45 +0800 Subject: [PATCH 04/15] use cython legacy directives for sage --- src/sage_setup/cython_options.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage_setup/cython_options.py b/src/sage_setup/cython_options.py index 086aa070ca9..9725ce0e1af 100644 --- a/src/sage_setup/cython_options.py +++ b/src/sage_setup/cython_options.py @@ -10,13 +10,17 @@ def compiler_directives(profile: bool): auto_pickle=False, # Do not create __test__ dictionary automatically from docstrings autotestdict=False, + binding=False, + c_api_binop_methods=True, # Do not check for division by 0 (this is about 35% quicker than with check) cdivision=True, + cpow=True, # Embed a textual copy of the call signature in the docstring (to support tools like IPython) embedsignature=True, fast_getattr=True, # Use Python 3 (including source code semantics) for module compilation language_level="3", + legacy_implicit_noexcept=True, # Enable support for late includes (make declarations in Cython code available to C include files) preliminary_late_includes_cy28=True, # Add hooks for Python profilers into the compiled C code From 0044e67c50b53b2f75703375260f4dbe46309e6d Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 00:54:01 +0800 Subject: [PATCH 05/15] add cython3 patches for cysignals, cypari2, fpylll, and pplpy --- .../pkgs/cypari/patches/cython3-legacy.patch | 32 ++++++++++++++++ .../patches/cython3-fix-warning.patch | 13 +++++++ .../cysignals/patches/cython3-legacy.patch | 30 +++++++++++++++ .../pkgs/fpylll/patches/cython3-legacy.patch | 37 +++++++++++++++++++ build/pkgs/pplpy/patches/cython3-legacy.patch | 22 +++++++++++ .../pkgs/pplpy/patches/relative-import.patch | 21 +++++++++++ 6 files changed, 155 insertions(+) create mode 100644 build/pkgs/cypari/patches/cython3-legacy.patch create mode 100644 build/pkgs/cysignals/patches/cython3-fix-warning.patch create mode 100644 build/pkgs/cysignals/patches/cython3-legacy.patch create mode 100644 build/pkgs/fpylll/patches/cython3-legacy.patch create mode 100644 build/pkgs/pplpy/patches/cython3-legacy.patch create mode 100644 build/pkgs/pplpy/patches/relative-import.patch diff --git a/build/pkgs/cypari/patches/cython3-legacy.patch b/build/pkgs/cypari/patches/cython3-legacy.patch new file mode 100644 index 00000000000..41392fe80d7 --- /dev/null +++ b/build/pkgs/cypari/patches/cython3-legacy.patch @@ -0,0 +1,32 @@ +commit 8ef356a4eb936c37f55a5c501f3a955e6740c0c5 +Author: Gonzalo Tornaría +Date: Wed Jul 19 19:45:23 2023 -0300 + + cython3 support using legacy directives + +diff --git a/cypari2/gen.pyx b/cypari2/gen.pyx +index 247b1ad..75050a0 100644 +--- a/cypari2/gen.pyx ++++ b/cypari2/gen.pyx +@@ -329,7 +329,7 @@ cdef class Gen(Gen_base): + >>> pari = Pari() + >>> L = pari("vector(10,i,i^2)") + >>> L.__iter__() +- ++ <...generator object at ...> + >>> [x for x in L] + [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] + >>> list(L) +diff --git a/setup.py b/setup.py +index 2188711..455337f 100755 +--- a/setup.py ++++ b/setup.py +@@ -36,6 +36,8 @@ class build_ext(_build_ext): + "binding": True, + "cdivision": True, + "language_level": 2, ++ "legacy_implicit_noexcept": True, ++ "c_api_binop_methods": True, + } + + _build_ext.finalize_options(self) diff --git a/build/pkgs/cysignals/patches/cython3-fix-warning.patch b/build/pkgs/cysignals/patches/cython3-fix-warning.patch new file mode 100644 index 00000000000..98cad9625e4 --- /dev/null +++ b/build/pkgs/cysignals/patches/cython3-fix-warning.patch @@ -0,0 +1,13 @@ +diff --git a/src/cysignals/signals.pxd.in b/src/cysignals/signals.pxd.in +index c86e085..a98c8d1 100644 +--- a/src/cysignals/signals.pxd.in ++++ b/src/cysignals/signals.pxd.in +@@ -54,7 +54,7 @@ cdef extern from "macros.h" nogil: + # can be used to make Cython check whether there is a pending exception + # (PyErr_Occurred() is non-NULL). To Cython, it will look like + # cython_check_exception() actually raised the exception. +-cdef inline void cython_check_exception() nogil except *: ++cdef inline void cython_check_exception() except * nogil: + pass + + diff --git a/build/pkgs/cysignals/patches/cython3-legacy.patch b/build/pkgs/cysignals/patches/cython3-legacy.patch new file mode 100644 index 00000000000..274575d5d35 --- /dev/null +++ b/build/pkgs/cysignals/patches/cython3-legacy.patch @@ -0,0 +1,30 @@ +commit 9996a4028ddc7f9a5ffda3df65d5b7d3b7df8aa5 +Author: Gonzalo Tornaría +Date: Wed Jul 19 18:34:57 2023 -0300 + + cython3 support using legacy directives + +diff --git a/setup.py b/setup.py +index 37acdfc..f68270b 100755 +--- a/setup.py ++++ b/setup.py +@@ -157,13 +157,17 @@ class build_ext(_build_ext): + # Run Cython with -Werror on continuous integration services + # with Python 3.6 or later + from Cython.Compiler import Options +- Options.warning_errors = True ++ Options.warning_errors = False + + from Cython.Build.Dependencies import cythonize + return cythonize(extensions, + build_dir=cythonize_dir, + include_path=["src", os.path.join(cythonize_dir, "src")], +- compiler_directives=dict(binding=True, language_level=2)) ++ compiler_directives=dict( ++ binding=True, ++ language_level=2, ++ legacy_implicit_noexcept=True, ++ )) + + + class build_py(_build_py): diff --git a/build/pkgs/fpylll/patches/cython3-legacy.patch b/build/pkgs/fpylll/patches/cython3-legacy.patch new file mode 100644 index 00000000000..808c14e9c1b --- /dev/null +++ b/build/pkgs/fpylll/patches/cython3-legacy.patch @@ -0,0 +1,37 @@ +commit b6e12c2b0648e84b26dcf0aac507a5b4d9dde301 +Author: Gonzalo Tornaría +Date: Wed Jul 19 20:38:01 2023 -0300 + + cython3 support using legacy directives + +diff --git a/setup.py b/setup.py +index 274836f..8fc5af5 100755 +--- a/setup.py ++++ b/setup.py +@@ -123,7 +123,12 @@ class build_ext(_build_ext, object): + self.extensions, + include_path=["src"], + build_dir=self.cythonize_dir, +- compiler_directives={"binding": True, "embedsignature": True, "language_level": 2}, ++ compiler_directives={ ++ "binding": True, ++ "embedsignature": True, ++ "language_level": 2, ++ "legacy_implicit_noexcept": True, ++ }, + ) + super(build_ext, self).run() + +diff --git a/src/fpylll/fplll/enumeration_callback_helper.h b/src/fpylll/fplll/enumeration_callback_helper.h +index c099430..706162f 100644 +--- a/src/fpylll/fplll/enumeration_callback_helper.h ++++ b/src/fpylll/fplll/enumeration_callback_helper.h +@@ -5,7 +5,7 @@ + #include + #include + +-extern "C" { ++extern "C++" { + bool evaluator_callback_call_obj(PyObject *obj, int n, double *new_sol_coord); + } + diff --git a/build/pkgs/pplpy/patches/cython3-legacy.patch b/build/pkgs/pplpy/patches/cython3-legacy.patch new file mode 100644 index 00000000000..a038da16d6b --- /dev/null +++ b/build/pkgs/pplpy/patches/cython3-legacy.patch @@ -0,0 +1,22 @@ +commit e6f3e66154138ce3e31e803e74b8c71787c70acc +Author: Gonzalo Tornaría +Date: Wed Jul 19 20:47:52 2023 -0300 + + cython3 support using legacy directives + +diff --git a/setup.py b/setup.py +index 13d543b..55dcd34 100755 +--- a/setup.py ++++ b/setup.py +@@ -38,7 +38,11 @@ class build_ext(_build_ext): + self.extensions[:] = cythonize( + self.extensions, + include_path=sys.path, +- compiler_directives={'embedsignature': True}) ++ compiler_directives={ ++ 'embedsignature': True, ++ 'legacy_implicit_noexcept': True, ++ 'c_api_binop_methods': True, ++ }) + + _build_ext.run(self) diff --git a/build/pkgs/pplpy/patches/relative-import.patch b/build/pkgs/pplpy/patches/relative-import.patch new file mode 100644 index 00000000000..3c011203367 --- /dev/null +++ b/build/pkgs/pplpy/patches/relative-import.patch @@ -0,0 +1,21 @@ +From aaa28537fa7ea061ebb8d5131b1e23673eaf741d Mon Sep 17 00:00:00 2001 +From: Matthias Koeppe +Date: Sun, 31 Jul 2022 12:39:34 -0700 +Subject: [PATCH] ppl/bit_arrays.pxd: Use relative cimport + +--- + ppl/bit_arrays.pxd | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/ppl/bit_arrays.pxd b/ppl/bit_arrays.pxd +index eb57434..145a978 100644 +--- a/ppl/bit_arrays.pxd ++++ b/ppl/bit_arrays.pxd +@@ -1,4 +1,4 @@ +-from ppl_decl cimport * ++from .ppl_decl cimport * + + cdef class Bit_Row(object): + cdef PPL_Bit_Row *thisptr +-- +GitLab From bbe813486fd6777c2b7401aebbfa1602dbc285b6 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 11:29:28 +0800 Subject: [PATCH 06/15] add cython3 patch for scipy --- build/pkgs/scipy/patches/cython3-legacy.patch | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 build/pkgs/scipy/patches/cython3-legacy.patch diff --git a/build/pkgs/scipy/patches/cython3-legacy.patch b/build/pkgs/scipy/patches/cython3-legacy.patch new file mode 100644 index 00000000000..9abf0c02154 --- /dev/null +++ b/build/pkgs/scipy/patches/cython3-legacy.patch @@ -0,0 +1,91 @@ +diff --git a/scipy/linalg.pxd b/scipy/linalg.pxd +index 1f656b87..c7c49f9a 100644 +--- a/scipy/linalg.pxd ++++ b/scipy/linalg.pxd +@@ -1 +1 @@ +-from .linalg cimport cython_blas, cython_lapack ++from scipy.linalg cimport cython_blas, cython_lapack +diff --git a/scipy/meson.build b/scipy/meson.build +index 21ea04d5..71d54804 100644 +--- a/scipy/meson.build ++++ b/scipy/meson.build +@@ -197,7 +197,7 @@ _cython_tree = [ + fs.copyfile('special.pxd'), + ] + +-cython_args = ['-3', '--fast-fail', '--output-file', '@OUTPUT@', '--include-dir', '@BUILD_ROOT@', '@INPUT@'] ++cython_args = ['-3', '--fast-fail', '--directive', 'legacy_implicit_noexcept=True', '--output-file', '@OUTPUT@', '--include-dir', '@BUILD_ROOT@', '@INPUT@'] + cython_cplus_args = ['--cplus'] + cython_args + + cython_gen = generator(cython, +diff --git a/scipy/optimize/cython_optimize.pxd b/scipy/optimize/cython_optimize.pxd +index d5a0bdd7..d35f8da6 100644 +--- a/scipy/optimize/cython_optimize.pxd ++++ b/scipy/optimize/cython_optimize.pxd +@@ -7,5 +7,5 @@ + # support. Changing it causes an ABI forward-compatibility break + # (gh-11793), so we currently leave it as is (no further cimport + # statements should be used in this file). +-from .cython_optimize._zeros cimport ( ++from scipy.optimize.cython_optimize._zeros cimport ( + brentq, brenth, ridder, bisect, zeros_full_output) +diff --git a/scipy/optimize/meson.build b/scipy/optimize/meson.build +index 05db6a68..07d46fb9 100644 +--- a/scipy/optimize/meson.build ++++ b/scipy/optimize/meson.build +@@ -231,6 +231,10 @@ endif + + _dummy_init_optimize = fs.copyfile('__init__.py') + ++_cython_tree = [ ++ fs.copyfile('cython_optimize.pxd'), ++] ++ + opt_gen = generator(cython, + arguments : cython_args, + output : '@BASENAME@.c', +diff --git a/scipy/special.pxd b/scipy/special.pxd +index 62cb8280..1daa9fb3 100644 +--- a/scipy/special.pxd ++++ b/scipy/special.pxd +@@ -1 +1 @@ +-from .special cimport cython_special ++from scipy.special cimport cython_special +diff --git a/scipy/special/meson.build b/scipy/special/meson.build +index f92183f5..09ad0a4f 100644 +--- a/scipy/special/meson.build ++++ b/scipy/special/meson.build +@@ -362,7 +362,7 @@ py3.extension_module('_ufuncs_cxx', + [ufuncs_cxx_sources, + uf_cython_gen_cpp.process(cython_special[2]), # _ufuncs_cxx.pyx + ], +- cpp_args: cython_cpp_args, ++ cpp_args: [cython_cpp_args, '-DCYTHON_EXTERN_C=extern "C"'], + include_directories: [inc_np, '../_lib/boost', '../_lib', + '../_build_utils/src'], + link_args: version_link_args, +diff --git a/scipy/special/setup.py b/scipy/special/setup.py +index 7e8c9608..b38a6ec2 100644 +--- a/scipy/special/setup.py ++++ b/scipy/special/setup.py +@@ -103,7 +103,7 @@ def configuration(parent_package='',top_path=None): + sources=ufuncs_cxx_src, + depends=ufuncs_cxx_dep, + include_dirs=[curdir] + inc_dirs, +- define_macros=define_macros, ++ define_macros=define_macros + [('CYTHON_EXTERN_C', 'extern "C"')], + extra_info=get_info("npymath")) + ufuncs_cxx_ext._pre_build_hook = set_cxx_flags_hook + +diff --git a/tools/cythonize.py b/tools/cythonize.py +index 402824cb..7ad778da 100755 +--- a/tools/cythonize.py ++++ b/tools/cythonize.py +@@ -94,6 +94,7 @@ def process_pyx(fromfile, tofile, cwd): + flags = ['--fast-fail', '-3'] + if tofile.endswith('.cxx'): + flags += ['--cplus'] ++ flags += ['--directive', 'legacy_implicit_noexcept=true'] + + try: + try: From 543917591850414cb3b874353cbebd2c6b717e52 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 21 Aug 2023 11:06:20 +0800 Subject: [PATCH 07/15] add cython3 patch for numpy --- build/pkgs/numpy/patches/cython3-legacy.patch | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 build/pkgs/numpy/patches/cython3-legacy.patch diff --git a/build/pkgs/numpy/patches/cython3-legacy.patch b/build/pkgs/numpy/patches/cython3-legacy.patch new file mode 100644 index 00000000000..dfcb9c4a69c --- /dev/null +++ b/build/pkgs/numpy/patches/cython3-legacy.patch @@ -0,0 +1,12 @@ +diff --git a/tools/cythonize.py b/tools/cythonize.py +index 002b2fa..c04422e 100755 +--- a/tools/cythonize.py ++++ b/tools/cythonize.py +@@ -47,6 +47,7 @@ def process_pyx(fromfile, tofile): + flags = ['-3', '--fast-fail'] + if tofile.endswith('.cxx'): + flags.append('--cplus') ++ flags += ['--directive', 'legacy_implicit_noexcept=true'] + + subprocess.check_call( + [sys.executable, '-m', 'cython'] + flags + ["-o", tofile, fromfile]) From c65b3e35a96042f9ce6e9167852e88d2d71aedf0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Sep 2023 21:38:04 -0700 Subject: [PATCH 08/15] build/pkgs/scipy/patches/cython3-legacy.patch: Remove --- build/pkgs/scipy/patches/cython3-legacy.patch | 91 ------------------- 1 file changed, 91 deletions(-) delete mode 100644 build/pkgs/scipy/patches/cython3-legacy.patch diff --git a/build/pkgs/scipy/patches/cython3-legacy.patch b/build/pkgs/scipy/patches/cython3-legacy.patch deleted file mode 100644 index 9abf0c02154..00000000000 --- a/build/pkgs/scipy/patches/cython3-legacy.patch +++ /dev/null @@ -1,91 +0,0 @@ -diff --git a/scipy/linalg.pxd b/scipy/linalg.pxd -index 1f656b87..c7c49f9a 100644 ---- a/scipy/linalg.pxd -+++ b/scipy/linalg.pxd -@@ -1 +1 @@ --from .linalg cimport cython_blas, cython_lapack -+from scipy.linalg cimport cython_blas, cython_lapack -diff --git a/scipy/meson.build b/scipy/meson.build -index 21ea04d5..71d54804 100644 ---- a/scipy/meson.build -+++ b/scipy/meson.build -@@ -197,7 +197,7 @@ _cython_tree = [ - fs.copyfile('special.pxd'), - ] - --cython_args = ['-3', '--fast-fail', '--output-file', '@OUTPUT@', '--include-dir', '@BUILD_ROOT@', '@INPUT@'] -+cython_args = ['-3', '--fast-fail', '--directive', 'legacy_implicit_noexcept=True', '--output-file', '@OUTPUT@', '--include-dir', '@BUILD_ROOT@', '@INPUT@'] - cython_cplus_args = ['--cplus'] + cython_args - - cython_gen = generator(cython, -diff --git a/scipy/optimize/cython_optimize.pxd b/scipy/optimize/cython_optimize.pxd -index d5a0bdd7..d35f8da6 100644 ---- a/scipy/optimize/cython_optimize.pxd -+++ b/scipy/optimize/cython_optimize.pxd -@@ -7,5 +7,5 @@ - # support. Changing it causes an ABI forward-compatibility break - # (gh-11793), so we currently leave it as is (no further cimport - # statements should be used in this file). --from .cython_optimize._zeros cimport ( -+from scipy.optimize.cython_optimize._zeros cimport ( - brentq, brenth, ridder, bisect, zeros_full_output) -diff --git a/scipy/optimize/meson.build b/scipy/optimize/meson.build -index 05db6a68..07d46fb9 100644 ---- a/scipy/optimize/meson.build -+++ b/scipy/optimize/meson.build -@@ -231,6 +231,10 @@ endif - - _dummy_init_optimize = fs.copyfile('__init__.py') - -+_cython_tree = [ -+ fs.copyfile('cython_optimize.pxd'), -+] -+ - opt_gen = generator(cython, - arguments : cython_args, - output : '@BASENAME@.c', -diff --git a/scipy/special.pxd b/scipy/special.pxd -index 62cb8280..1daa9fb3 100644 ---- a/scipy/special.pxd -+++ b/scipy/special.pxd -@@ -1 +1 @@ --from .special cimport cython_special -+from scipy.special cimport cython_special -diff --git a/scipy/special/meson.build b/scipy/special/meson.build -index f92183f5..09ad0a4f 100644 ---- a/scipy/special/meson.build -+++ b/scipy/special/meson.build -@@ -362,7 +362,7 @@ py3.extension_module('_ufuncs_cxx', - [ufuncs_cxx_sources, - uf_cython_gen_cpp.process(cython_special[2]), # _ufuncs_cxx.pyx - ], -- cpp_args: cython_cpp_args, -+ cpp_args: [cython_cpp_args, '-DCYTHON_EXTERN_C=extern "C"'], - include_directories: [inc_np, '../_lib/boost', '../_lib', - '../_build_utils/src'], - link_args: version_link_args, -diff --git a/scipy/special/setup.py b/scipy/special/setup.py -index 7e8c9608..b38a6ec2 100644 ---- a/scipy/special/setup.py -+++ b/scipy/special/setup.py -@@ -103,7 +103,7 @@ def configuration(parent_package='',top_path=None): - sources=ufuncs_cxx_src, - depends=ufuncs_cxx_dep, - include_dirs=[curdir] + inc_dirs, -- define_macros=define_macros, -+ define_macros=define_macros + [('CYTHON_EXTERN_C', 'extern "C"')], - extra_info=get_info("npymath")) - ufuncs_cxx_ext._pre_build_hook = set_cxx_flags_hook - -diff --git a/tools/cythonize.py b/tools/cythonize.py -index 402824cb..7ad778da 100755 ---- a/tools/cythonize.py -+++ b/tools/cythonize.py -@@ -94,6 +94,7 @@ def process_pyx(fromfile, tofile, cwd): - flags = ['--fast-fail', '-3'] - if tofile.endswith('.cxx'): - flags += ['--cplus'] -+ flags += ['--directive', 'legacy_implicit_noexcept=true'] - - try: - try: From 84ad1a944b36173f050b6a3dd46c84269c31ed82 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 6 Sep 2023 16:04:37 -0700 Subject: [PATCH 09/15] build/pkgs/cython/dependencies: Add pythran as an order-only dep --- build/pkgs/cython/dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pkgs/cython/dependencies b/build/pkgs/cython/dependencies index 0738c2d7777..bda9b4d2579 100644 --- a/build/pkgs/cython/dependencies +++ b/build/pkgs/cython/dependencies @@ -1,4 +1,4 @@ -$(PYTHON) | $(PYTHON_TOOLCHAIN) +$(PYTHON) | $(PYTHON_TOOLCHAIN) pythran ---------- All lines of this file are ignored except the first. From d97caa613c751be4498eede257df2be0db1bef9c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 10 Sep 2023 14:56:21 -0700 Subject: [PATCH 10/15] Revert "build/pkgs/cython/dependencies: Add pythran as an order-only dep" This reverts commit 84ad1a944b36173f050b6a3dd46c84269c31ed82. --- build/pkgs/cython/dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pkgs/cython/dependencies b/build/pkgs/cython/dependencies index bda9b4d2579..0738c2d7777 100644 --- a/build/pkgs/cython/dependencies +++ b/build/pkgs/cython/dependencies @@ -1,4 +1,4 @@ -$(PYTHON) | $(PYTHON_TOOLCHAIN) pythran +$(PYTHON) | $(PYTHON_TOOLCHAIN) ---------- All lines of this file are ignored except the first. From 587b220d2383c61f0633bd8ddcf958d8017e853d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 10 Sep 2023 14:56:53 -0700 Subject: [PATCH 11/15] build/pkgs/pythran: Update to 0.14.0 --- build/pkgs/pythran/checksums.ini | 6 +++--- build/pkgs/pythran/package-version.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/pkgs/pythran/checksums.ini b/build/pkgs/pythran/checksums.ini index dc9beccf6b6..2a926b36347 100644 --- a/build/pkgs/pythran/checksums.ini +++ b/build/pkgs/pythran/checksums.ini @@ -1,5 +1,5 @@ tarball=pythran-VERSION.tar.gz -sha1=dd675e9ccc93379b529687328ca558d5617eb1c6 -md5=3090288af50566af75cb058d1878aaad -cksum=3968085663 +sha1=8f997393d123a6185dbf2be0ead588df004c6c4c +md5=2885a2974b9b523439761bfd8bc54f03 +cksum=1307669216 upstream_url=https://pypi.io/packages/source/p/pythran/pythran-VERSION.tar.gz diff --git a/build/pkgs/pythran/package-version.txt b/build/pkgs/pythran/package-version.txt index c317a91891f..a803cc227fe 100644 --- a/build/pkgs/pythran/package-version.txt +++ b/build/pkgs/pythran/package-version.txt @@ -1 +1 @@ -0.13.1 +0.14.0 From d92ae7ccc6622fa7742671d6713dcf0e997dda5d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 10 Sep 2023 15:13:58 -0700 Subject: [PATCH 12/15] build/pkgs/pythran/dependencies: Remove numpy --- build/pkgs/pythran/dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pkgs/pythran/dependencies b/build/pkgs/pythran/dependencies index 8a64589c0bc..b661bb4d3e4 100644 --- a/build/pkgs/pythran/dependencies +++ b/build/pkgs/pythran/dependencies @@ -1,4 +1,4 @@ -$(PYTHON) beniget gast ply numpy | $(PYTHON_TOOLCHAIN) +$(PYTHON) beniget gast ply | $(PYTHON_TOOLCHAIN) ---------- All lines of this file are ignored except the first. From fcc71993653ce62c705b9fd5fc3d793d3ae64163 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 10 Sep 2023 15:14:40 -0700 Subject: [PATCH 13/15] Revert "Revert "build/pkgs/cython/dependencies: Add pythran as an order-only dep"" This reverts commit d97caa613c751be4498eede257df2be0db1bef9c. --- build/pkgs/cython/dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pkgs/cython/dependencies b/build/pkgs/cython/dependencies index 0738c2d7777..bda9b4d2579 100644 --- a/build/pkgs/cython/dependencies +++ b/build/pkgs/cython/dependencies @@ -1,4 +1,4 @@ -$(PYTHON) | $(PYTHON_TOOLCHAIN) +$(PYTHON) | $(PYTHON_TOOLCHAIN) pythran ---------- All lines of this file are ignored except the first. From 64a4510546e8d19157122b22a780763691b49381 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 18 Sep 2023 14:35:59 -0700 Subject: [PATCH 14/15] src/sage/misc/cython.py: Hide Cython 3 warning with unpatched cysignals --- src/sage/misc/cython.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sage/misc/cython.py b/src/sage/misc/cython.py index 5f83f585c3a..347b2e896d8 100644 --- a/src/sage/misc/cython.py +++ b/src/sage/misc/cython.py @@ -21,6 +21,7 @@ import builtins import os +import re import sys import shutil @@ -396,6 +397,12 @@ def cython(filename, verbose=0, compile_message=False, raise RuntimeError(cython_messages.strip()) if verbose >= 0: + # triggered by Cython 3 with unpatched cysignals 1.11.2 + cython_messages = re.sub( + "^.*The keyword 'nogil' should appear at the end of the function signature line. " + "Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.\n", + "", cython_messages, 0, re.MULTILINE) + sys.stderr.write(cython_messages) sys.stderr.flush() From cb78fd95b03678f821bc575c683feb74f860105c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 20 Sep 2023 19:46:44 -0700 Subject: [PATCH 15/15] src/sage/matrix/matrix_gfpn_dense.pyx: Replace relative cimport --- src/sage/matrix/matrix_gfpn_dense.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/matrix/matrix_gfpn_dense.pyx b/src/sage/matrix/matrix_gfpn_dense.pyx index 49a556ba7d4..4cccf473de1 100644 --- a/src/sage/matrix/matrix_gfpn_dense.pyx +++ b/src/sage/matrix/matrix_gfpn_dense.pyx @@ -55,7 +55,7 @@ from sage.misc.randstate import current_randstate from sage.misc.randstate cimport randstate from sage.structure.element cimport Element, Matrix from sage.structure.richcmp import rich_to_bool -from .args cimport MatrixArgs_init +from sage.matrix.args cimport MatrixArgs_init from libc.string cimport memset, memcpy