Skip to content

Commit f51596b

Browse files
author
Matthias Köppe
authored
Merge pull request #77 from sagemath/cython3
Use the trashcan for class Gen (needs Cython 3)
2 parents f43c3b2 + 2889a3e commit f51596b

File tree

10 files changed

+16
-12
lines changed

10 files changed

+16
-12
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Requirements:
4848
or install from source.
4949
- Python >= 3.9
5050
- pip
51+
- `cysignals <https://pypi.python.org/pypi/cysignals/>`_ >= 1.7
52+
- Cython >= 3.0
5153

5254
Install cypari2 via the Python Package Index (PyPI) via
5355

cypari2/closure.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ Examples:
3131
# https://www.gnu.org/licenses/
3232
# ****************************************************************************
3333

34-
from __future__ import absolute_import, division, print_function
35-
3634
from cysignals.signals cimport sig_on, sig_off, sig_block, sig_unblock, sig_error
3735

3836
from cpython.tuple cimport *

cypari2/convert.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ some bit shuffling.
3939
# https://www.gnu.org/licenses/
4040
# ****************************************************************************
4141

42-
from __future__ import absolute_import, division, print_function
43-
4442
from cysignals.signals cimport sig_on, sig_off, sig_error
4543

4644
from cpython.version cimport PY_MAJOR_VERSION

cypari2/gen.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cimport cython
12
from cpython.object cimport PyObject
23
from .types cimport GEN, pari_sp
34

cypari2/gen.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ AUTHORS:
5555
# https://www.gnu.org/licenses/
5656
# ****************************************************************************
5757

58-
from __future__ import absolute_import, division, print_function
59-
6058
cimport cython
6159

6260
from cpython.object cimport (Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, PyTypeObject)
@@ -143,6 +141,7 @@ cdef extern from *:
143141
GEN old_nfbasis(GEN x, GEN * y, GEN p)
144142

145143

144+
@cython.trashcan(True)
146145
cdef class Gen(Gen_base):
147146
"""
148147
Wrapper for a PARI ``GEN`` with memory management.

cypari2/handle_error.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ AUTHORS:
2121
# https://www.gnu.org/licenses/
2222
# ****************************************************************************
2323

24-
from __future__ import absolute_import, division, print_function
24+
from cpython cimport PyErr_Occurred
2525

2626
from cysignals.signals cimport sig_block, sig_unblock, sig_error
2727

cypari2/pari_instance.pyx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ Reset default precision for the following tests:
243243
244244
>>> pari.set_real_precision_bits(53)
245245
246+
Test the trashcan mechanism (without the trashcan, this would cause
247+
a stack overflow):
248+
249+
>>> pari.allocatemem(2**27, silent=True)
250+
>>> L = [pari(i) for i in range(2**20)]
251+
>>> x = pari.Pi()
252+
>>> del L
253+
>>> del x
254+
246255
Test that interrupts work properly:
247256
248257
>>> pari.allocatemem(8000000, 2**29)
@@ -275,8 +284,6 @@ Test that changing the stack size using ``default`` works properly:
275284
# https://www.gnu.org/licenses/
276285
# ****************************************************************************
277286

278-
from __future__ import absolute_import, division
279-
280287
import sys
281288
from libc.stdio cimport *
282289
cimport cython

cypari2/stack.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Memory management for Gens on the PARI stack or the heap
1414
# http://www.gnu.org/licenses/
1515
# ****************************************************************************
1616

17-
from __future__ import absolute_import, division, print_function
1817
cimport cython
1918

2019
from cpython.ref cimport PyObject

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = ["setuptools",
3-
"Cython>=0.29",
3+
"Cython>=3.0",
44
"cysignals>=1.7"]
55
# We need access to the autogen package at build time.
66
# Hence we declare a custom build backend.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def finalize_options(self):
3535
"autotestdict.cdef": True,
3636
"binding": True,
3737
"cdivision": True,
38-
"language_level": 2,
3938
"legacy_implicit_noexcept": True,
4039
"c_api_binop_methods": True,
40+
"language_level": "3str",
4141
}
4242

4343
_build_ext.finalize_options(self)

0 commit comments

Comments
 (0)