[pypy-commit] pypy py3.5: Fix _PyLong_Sign() to accept any app-level 'int' object

arigo pypy.commits at gmail.com
Tue Apr 24 04:00:42 EDT 2018


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r94443:a07f07034d28
Date: 2018-04-24 10:00 +0200
http://bitbucket.org/pypy/pypy/changeset/a07f07034d28/

Log:	Fix _PyLong_Sign() to accept any app-level 'int' object

diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -2,7 +2,6 @@
 from pypy.module.cpyext.api import (
     cpython_api, PyObject, build_type_checkers_flags, Py_ssize_t,
     CONST_STRING, ADDR, CANNOT_FAIL)
-from pypy.objspace.std.longobject import W_LongObject
 from pypy.interpreter.error import OperationError, oefmt
 from rpython.rlib.rbigint import rbigint, InvalidSignednessError
 
@@ -234,8 +233,8 @@
 
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def _PyLong_Sign(space, w_long):
-    assert isinstance(w_long, W_LongObject)
-    return w_long.num.sign
+    bigint = space.bigint_w(w_long)
+    return bigint.sign
 
 CONST_UCHARP = lltype.Ptr(lltype.Array(rffi.UCHAR, hints={'nolength': True,
                                        'render_as_const': True}))
diff --git a/pypy/module/cpyext/test/test_longobject.py b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -136,6 +136,9 @@
         assert api._PyLong_Sign(space.wraplong(0L)) == 0
         assert api._PyLong_Sign(space.wraplong(2L)) == 1
         assert api._PyLong_Sign(space.wraplong(-2L)) == -1
+        assert api._PyLong_Sign(space.wrap(0)) == 0
+        assert api._PyLong_Sign(space.wrap(42)) == 1
+        assert api._PyLong_Sign(space.wrap(-42)) == -1
 
         assert api._PyLong_NumBits(space.wrap(0)) == 0
         assert api._PyLong_NumBits(space.wrap(1)) == 1


More information about the pypy-commit mailing list