Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the trashcan for class Gen (needs Cython 3) #77

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Requirements:
or install from source.
- Python >= 3.9
- pip
- `cysignals <https://pypi.python.org/pypi/cysignals/>`_ >= 1.7
- Cython >= 3.0

Install cypari2 via the Python Package Index (PyPI) via

Expand Down
2 changes: 0 additions & 2 deletions cypari2/closure.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Examples:
# https://www.gnu.org/licenses/
# ****************************************************************************

from __future__ import absolute_import, division, print_function

from cysignals.signals cimport sig_on, sig_off, sig_block, sig_unblock, sig_error

from cpython.tuple cimport *
Expand Down
2 changes: 0 additions & 2 deletions cypari2/convert.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ some bit shuffling.
# https://www.gnu.org/licenses/
# ****************************************************************************

from __future__ import absolute_import, division, print_function

from cysignals.signals cimport sig_on, sig_off, sig_error

from cpython.version cimport PY_MAJOR_VERSION
Expand Down
1 change: 1 addition & 0 deletions cypari2/gen.pxd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cimport cython
from cpython.object cimport PyObject
from .types cimport GEN, pari_sp

Expand Down
3 changes: 1 addition & 2 deletions cypari2/gen.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ AUTHORS:
# https://www.gnu.org/licenses/
# ****************************************************************************

from __future__ import absolute_import, division, print_function

cimport cython

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


@cython.trashcan(True)
cdef class Gen(Gen_base):
"""
Wrapper for a PARI ``GEN`` with memory management.
Expand Down
2 changes: 1 addition & 1 deletion cypari2/handle_error.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AUTHORS:
# https://www.gnu.org/licenses/
# ****************************************************************************

from __future__ import absolute_import, division, print_function
from cpython cimport PyErr_Occurred

from cysignals.signals cimport sig_block, sig_unblock, sig_error

Expand Down
11 changes: 9 additions & 2 deletions cypari2/pari_instance.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ Reset default precision for the following tests:

>>> pari.set_real_precision_bits(53)

Test the trashcan mechanism (without the trashcan, this would cause
a stack overflow):

>>> pari.allocatemem(2**27, silent=True)
>>> L = [pari(i) for i in range(2**20)]
>>> x = pari.Pi()
>>> del L
>>> del x

Test that interrupts work properly:

>>> pari.allocatemem(8000000, 2**29)
Expand Down Expand Up @@ -275,8 +284,6 @@ Test that changing the stack size using ``default`` works properly:
# https://www.gnu.org/licenses/
# ****************************************************************************

from __future__ import absolute_import, division

import sys
from libc.stdio cimport *
cimport cython
Expand Down
1 change: 0 additions & 1 deletion cypari2/stack.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Memory management for Gens on the PARI stack or the heap
# http://www.gnu.org/licenses/
# ****************************************************************************

from __future__ import absolute_import, division, print_function
cimport cython

from cpython.ref cimport PyObject
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools",
"Cython>=0.29",
"Cython>=3.0",
"cysignals>=1.7"]
# We need access to the autogen package at build time.
# Hence we declare a custom build backend.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def finalize_options(self):
"autotestdict.cdef": True,
"binding": True,
"cdivision": True,
"language_level": 2,
"legacy_implicit_noexcept": True,
"c_api_binop_methods": True,
"language_level": "3str",
}

_build_ext.finalize_options(self)
Expand Down
Loading