[pypy-svn] r32546 - in pypy/dist/pypy/objspace/cpy: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Sep 21 00:12:30 CEST 2006
Author: cfbolz
Date: Thu Sep 21 00:12:25 2006
New Revision: 32546
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 newfloat and newlong to cpy object space
Modified: pypy/dist/pypy/objspace/cpy/capi.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/capi.py (original)
+++ pypy/dist/pypy/objspace/cpy/capi.py Thu Sep 21 00:12:25 2006
@@ -252,6 +252,10 @@
PyFloat_AsDouble.argtypes = [W_Object]
PyFloat_AsDouble.restype = c_double
+PyLong_FromLong = cpyapi.PyLong_FromLong
+PyLong_FromLong.argtypes = [c_long]
+PyLong_FromLong.restype = W_Object
+
PyLong_FromUnsignedLong = cpyapi.PyLong_FromUnsignedLong
PyLong_FromUnsignedLong.argtypes = [c_ulong]
PyLong_FromUnsignedLong.restype = W_Object
Modified: pypy/dist/pypy/objspace/cpy/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/objspace.py (original)
+++ pypy/dist/pypy/objspace/cpy/objspace.py Thu Sep 21 00:12:25 2006
@@ -69,7 +69,7 @@
return PyInt_FromLong(x)
if isinstance(x, str):
return PyString_FromStringAndSize(x, len(x))
- if isinstance(x, float):
+ if isinstance(x, float):
return PyFloat_FromDouble(x)
if isinstance(x, r_uint):
return PyLong_FromUnsignedLong(x)
@@ -189,6 +189,12 @@
def newint(self, intval):
return PyInt_FromLong(intval)
+ def newlong(self, intval):
+ return PyLong_FromLong(intval)
+
+ def newfloat(self, floatval):
+ return PyFloat_FromDouble(floatval)
+
def newdict(self):
return PyDict_New()
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 Thu Sep 21 00:12:25 2006
@@ -134,3 +134,16 @@
space = CPyObjSpace()
assert space.is_true(space.callable(space.w_int))
assert not space.is_true(space.callable(space.w_Ellipsis))
+
+def test_newfloat():
+ space = CPyObjSpace()
+ fl1 = space.wrap(1.4)
+ fl2 = space.newfloat(1.4)
+ assert space.is_true(space.eq(fl1, fl2))
+
+def test_newlong():
+ space = CPyObjSpace()
+ i1 = space.newlong(42)
+ i2 = space.newint(42)
+ assert space.is_true(space.eq(i1, i2))
+ assert space.is_true(space.ne(space.type(i1), space.type(i2)))
More information about the Pypy-commit
mailing list