Skip to content

Commit ab770a8

Browse files
authored
Merge pull request #177 from antonio-rojas/cython-3.1
Fix build with Cython 3.1
2 parents 37acf81 + e5f411f commit ab770a8

File tree

2 files changed

+6
-42
lines changed

2 files changed

+6
-42
lines changed

cypari2/convert.pyx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ some bit shuffling.
4242
from cysignals.signals cimport sig_on, sig_off, sig_error
4343

4444
from cpython.version cimport PY_MAJOR_VERSION
45-
from cpython.int cimport PyInt_AS_LONG, PyInt_FromLong
45+
from cpython.long cimport PyLong_AsLong, PyLong_FromLong
4646
from cpython.longintrepr cimport (_PyLong_New,
4747
digit, PyLong_SHIFT, PyLong_MASK)
4848
from libc.limits cimport LONG_MIN, LONG_MAX
@@ -353,7 +353,7 @@ cdef PyInt_FromGEN(GEN g):
353353
reset_avma()
354354

355355
if not signe(g):
356-
return PyInt_FromLong(0)
356+
return PyLong_FromLong(0)
357357

358358
cdef ulong u
359359
if PY_MAJOR_VERSION == 2:
@@ -365,10 +365,10 @@ cdef PyInt_FromGEN(GEN g):
365365
# Check that <long>(u) or <long>(-u) does not overflow
366366
if signe(g) >= 0:
367367
if u <= <ulong>LONG_MAX:
368-
return PyInt_FromLong(u)
368+
return PyLong_FromLong(u)
369369
else:
370370
if u <= -<ulong>LONG_MIN:
371-
return PyInt_FromLong(-u)
371+
return PyLong_FromLong(-u)
372372

373373
# Result does not fit in a C long
374374
res = PyLong_FromINT(g)
@@ -545,13 +545,9 @@ cdef GEN PyObject_AsGEN(x) except? NULL:
545545
sig_on()
546546
g = gp_read_str(<bytes>x)
547547
sig_off()
548-
elif isinstance(x, long):
549-
sig_on()
550-
g = PyLong_AS_GEN(x)
551-
sig_off()
552548
elif isinstance(x, int):
553549
sig_on()
554-
g = PyInt_AS_GEN(x)
550+
g = PyLong_AS_GEN(x)
555551
sig_off()
556552
elif isinstance(x, float):
557553
sig_on()
@@ -609,11 +605,8 @@ def integer_to_gen(x):
609605
... if pari(long(x)) != pari(x) or pari(int(x)) != pari(x):
610606
... print(x)
611607
"""
612-
if isinstance(x, long):
613-
sig_on()
614-
return new_gen(PyLong_AS_GEN(x))
615608
if isinstance(x, int):
616609
sig_on()
617-
return new_gen(stoi(PyInt_AS_LONG(x)))
610+
return new_gen(PyLong_AS_GEN(x))
618611
raise TypeError("integer_to_gen() needs an int or long "
619612
"argument, not {}".format(type(x).__name__))

cypari2/gen.pyx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,35 +1966,6 @@ cdef class Gen(Gen_base):
19661966
from sage.libs.pari.convert_sage import gen_to_sage
19671967
return gen_to_sage(self, locals)
19681968

1969-
def __long__(self):
1970-
"""
1971-
Convert ``self`` to a Python ``long``.
1972-
1973-
Examples:
1974-
1975-
>>> from cypari2 import Pari
1976-
>>> pari = Pari()
1977-
>>> import sys
1978-
1979-
>>> if sys.version_info.major == 3:
1980-
... long = int
1981-
>>> assert isinstance(long(pari(0)), long)
1982-
>>> assert long(pari(0)) == 0
1983-
>>> assert long(pari(10)) == 10
1984-
>>> assert long(pari(-10)) == -10
1985-
>>> assert long(pari(123456789012345678901234567890)) == 123456789012345678901234567890
1986-
>>> assert long(pari(-123456789012345678901234567890)) == -123456789012345678901234567890
1987-
>>> assert long(pari(2**31-1)) == 2147483647
1988-
>>> assert long(pari(-2**31)) == -2147483648
1989-
>>> assert long(pari("Pol(10)")) == 10
1990-
>>> assert long(pari("Mod(2, 7)")) == 2
1991-
"""
1992-
x = gen_to_integer(self)
1993-
if isinstance(x, long):
1994-
return x
1995-
else:
1996-
return long(x)
1997-
19981969
def __float__(self):
19991970
"""
20001971
Return Python float.

0 commit comments

Comments
 (0)