[pypy-commit] pypy default: cpyext: implement PyLong_FromSize_t

amauryfa noreply at buildbot.pypy.org
Sun Mar 24 11:26:49 CET 2013


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r62719:cd5ce30edd5a
Date: 2013-03-24 11:25 +0100
http://bitbucket.org/pypy/pypy/changeset/cd5ce30edd5a/

Log:	cpyext: implement PyLong_FromSize_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
@@ -23,6 +23,13 @@
     """
     return space.newlong(val)
 
+ at cpython_api([rffi.SIZE_T], PyObject)
+def PyLong_FromSize_t(space, val):
+    """Return a new PyLongObject object from a C size_t, or NULL on
+    failure.
+    """
+    return space.wrap(val)
+
 @cpython_api([rffi.LONGLONG], PyObject)
 def PyLong_FromLongLong(space, val):
     """Return a new PyLongObject object from a C long long, or NULL
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
@@ -1395,13 +1395,6 @@
     """
     raise NotImplementedError
 
- at cpython_api([rffi.SIZE_T], PyObject)
-def PyLong_FromSize_t(space, v):
-    """Return a new PyLongObject object from a C size_t, or
-    NULL on failure.
-    """
-    raise NotImplementedError
-
 @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real], PyObject)
 def PyLong_FromUnicode(space, u, length, base):
     """Convert a sequence of Unicode digits to a Python long integer value.  The first
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
@@ -146,6 +146,15 @@
         assert module.from_longlong() == -1
         assert module.from_unsignedlonglong() == (1<<64) - 1
 
+    def test_from_size_t(self):
+        module = self.import_extension('foo', [
+            ("from_unsignedlong", "METH_NOARGS",
+             """
+                 return PyLong_FromSize_t((size_t)-1);
+             """)])
+        import sys
+        assert module.from_unsignedlong() == 2 * sys.maxint + 1
+
     def test_fromstring(self):
         module = self.import_extension('foo', [
             ("from_string", "METH_NOARGS",


More information about the pypy-commit mailing list