[pypy-commit] pypy default: cpyext: add PyLong_AsSsize_t()
amauryfa
noreply at buildbot.pypy.org
Wed May 2 01:02:02 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r54846:fcff0efbb7a3
Date: 2012-04-30 22:44 +0200
http://bitbucket.org/pypy/pypy/changeset/fcff0efbb7a3/
Log: cpyext: add PyLong_AsSsize_t()
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
@@ -1,6 +1,7 @@
from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.module.cpyext.api import (cpython_api, PyObject, build_type_checkers,
- CONST_STRING, ADDR, CANNOT_FAIL)
+from pypy.module.cpyext.api import (
+ cpython_api, PyObject, build_type_checkers, Py_ssize_t,
+ CONST_STRING, ADDR, CANNOT_FAIL)
from pypy.objspace.std.longobject import W_LongObject
from pypy.interpreter.error import OperationError
from pypy.module.cpyext.intobject import PyInt_AsUnsignedLongMask
@@ -56,6 +57,14 @@
and -1 will be returned."""
return space.int_w(w_long)
+ at cpython_api([PyObject], Py_ssize_t, error=-1)
+def PyLong_AsSsize_t(space, w_long):
+ """Return a C Py_ssize_t representation of the contents of pylong. If
+ pylong is greater than PY_SSIZE_T_MAX, an OverflowError is raised
+ and -1 will be returned.
+ """
+ return space.int_w(w_long)
+
@cpython_api([PyObject], rffi.LONGLONG, error=-1)
def PyLong_AsLongLong(space, w_long):
"""
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1431,14 +1431,6 @@
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
- at cpython_api([PyObject], Py_ssize_t, error=-1)
-def PyLong_AsSsize_t(space, pylong):
- """Return a C Py_ssize_t representation of the contents of pylong. If
- pylong is greater than PY_SSIZE_T_MAX, an OverflowError is raised
- and -1 will be returned.
- """
- raise NotImplementedError
-
@cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
def PyMapping_DelItemString(space, o, key):
"""Remove the mapping for object key from the object o. Return -1 on
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
@@ -31,6 +31,11 @@
value = api.PyLong_AsUnsignedLong(w_value)
assert value == (sys.maxint - 1) * 2
+ def test_as_ssize_t(self, space, api):
+ w_value = space.newlong(2)
+ value = api.PyLong_AsSsize_t(w_value)
+ assert value == 2
+
def test_fromdouble(self, space, api):
w_value = api.PyLong_FromDouble(-12.74)
assert space.unwrap(w_value) == -12
More information about the pypy-commit
mailing list