[pypy-svn] r28274 - in pypy/dist/pypy/objspace/cpy: . test

hpk at codespeak.net hpk at codespeak.net
Sun Jun 4 17:23:18 CEST 2006


Author: hpk
Date: Sun Jun  4 17:23:18 2006
New Revision: 28274

Modified:
   pypy/dist/pypy/objspace/cpy/capi.py
   pypy/dist/pypy/objspace/cpy/objspace.py
   pypy/dist/pypy/objspace/cpy/test/test_objspace.py
Log:
add support for wrapping and unwrapping floats 


Modified: pypy/dist/pypy/objspace/cpy/capi.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/capi.py	(original)
+++ pypy/dist/pypy/objspace/cpy/capi.py	Sun Jun  4 17:23:18 2006
@@ -157,6 +157,14 @@
 PyInt_AsLong.argtypes = [W_Object]
 PyInt_AsLong.restype = c_long
 
+PyFloat_FromDouble = cpyapi.PyFloat_FromDouble
+PyFloat_FromDouble.argtypes = [c_double]
+PyFloat_FromDouble.restype = W_Object
+
+PyFloat_AsDouble = cpyapi.PyFloat_AsDouble 
+PyFloat_AsDouble.argtypes = [W_Object]
+PyFloat_AsDouble.restype = c_double 
+
 
 ###################################################
 # ____________________ Strings ____________________

Modified: pypy/dist/pypy/objspace/cpy/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/objspace.py	(original)
+++ pypy/dist/pypy/objspace/cpy/objspace.py	Sun Jun  4 17:23:18 2006
@@ -49,6 +49,8 @@
             return PyInt_FromLong(x)
         if isinstance(x, str):
             return PyString_FromStringAndSize(x, len(x))
+        if isinstance(x, float): 
+            return PyFloat_FromDouble(x)
         raise TypeError("wrap(%r)" % (x,))
     wrap._annspecialcase_ = "specialize:wrap"
 
@@ -70,6 +72,7 @@
     getitem = staticmethod(PyObject_GetItem)
     setitem = staticmethod(PyObject_SetItem)
     int_w   = staticmethod(PyInt_AsLong)
+    float_w = staticmethod(PyFloat_AsDouble)
     str_w   = staticmethod(PyString_AsString)
     iter    = staticmethod(PyObject_GetIter)
     type    = staticmethod(PyObject_Type)

Modified: pypy/dist/pypy/objspace/cpy/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/test/test_objspace.py	(original)
+++ pypy/dist/pypy/objspace/cpy/test/test_objspace.py	Sun Jun  4 17:23:18 2006
@@ -10,6 +10,13 @@
     wback = space.getitem(d,wk1)
     assert space.eq_w(wback,wone)
 
+def test_wrap():
+    space = CPyObjSpace()
+    w_res = space.add(space.wrap(1.0), space.wrap(1.5))
+    assert space.eq_w(w_res, space.wrap(2.5))
+    res = space.float_w(w_res)
+    assert res == 2.5 
+
 def test_demo():
     from pypy.module._demo import demo
     space = CPyObjSpace()



More information about the Pypy-commit mailing list