[pypy-svn] r73304 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

exarkun at codespeak.net exarkun at codespeak.net
Fri Apr 2 20:45:28 CEST 2010


Author: exarkun
Date: Fri Apr  2 20:45:26 2010
New Revision: 73304

Added:
   pypy/branch/cpython-extension/pypy/module/cpyext/longobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_longobject.py
Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
Log:
Implement PyLong_FromLong

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	Fri Apr  2 20:45:26 2010
@@ -42,6 +42,7 @@
 import pypy.module.cpyext.tupleobject
 import pypy.module.cpyext.dictobject
 import pypy.module.cpyext.intobject
+import pypy.module.cpyext.longobject
 import pypy.module.cpyext.listobject
 import pypy.module.cpyext.sequence
 import pypy.module.cpyext.eval

Added: pypy/branch/cpython-extension/pypy/module/cpyext/longobject.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/longobject.py	Fri Apr  2 20:45:26 2010
@@ -0,0 +1,11 @@
+
+from pypy.rpython.lltypesystem import lltype
+from pypy.module.cpyext.api import cpython_api, PyObject
+
+
+ at cpython_api([lltype.Signed], PyObject)
+def PyLong_FromLong(space, val):
+    """Return a new PyLongObject object from v, or NULL on failure."""
+    return space.wrap(val)
+
+

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	Fri Apr  2 20:45:26 2010
@@ -3549,11 +3549,6 @@
     """
     raise NotImplementedError
 
- at cpython_api([{long}], PyObject)
-def PyLong_FromLong(space, v):
-    """Return a new PyLongObject object from v, or NULL on failure."""
-    raise NotImplementedError
-
 @cpython_api([{unsigned long}], PyObject)
 def PyLong_FromUnsignedLong(space, v):
     """Return a new PyLongObject object from a C unsigned long, or

Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_longobject.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_longobject.py	Fri Apr  2 20:45:26 2010
@@ -0,0 +1,17 @@
+
+import sys
+
+from pypy.objspace.std.intobject import W_IntObject
+from pypy.objspace.std.longobject import W_LongObject
+from pypy.module.cpyext.test.test_api import BaseApiTest
+
+
+class TestLongObject(BaseApiTest):
+    def test_FromLong(self, space, api):
+        value = api.PyLong_FromLong(3)
+        assert isinstance(value, W_IntObject)
+        assert space.unwrap(value) == 3
+
+        value = api.PyLong_FromLong(sys.maxint + 1)
+        assert isinstance(value, W_LongObject)
+        assert space.unwrap(value) == sys.maxint + 1



More information about the Pypy-commit mailing list