[pypy-svn] r18060 - in pypy/dist/pypy: rpython rpython/test translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Sat Oct 1 16:43:25 CEST 2005
Author: arigo
Date: Sat Oct 1 16:43:17 2005
New Revision: 18060
Modified:
pypy/dist/pypy/rpython/rfloat.py
pypy/dist/pypy/rpython/test/test_rfloat.py
pypy/dist/pypy/translator/c/test/test_extfunc.py
Log:
Clean up the support for str(float) in RPython.
Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py (original)
+++ pypy/dist/pypy/rpython/rfloat.py Sat Oct 1 16:43:17 2005
@@ -5,7 +5,7 @@
from pypy.rpython.rmodel import IntegerRepr, BoolRepr
from pypy.rpython.robject import PyObjRepr, pyobj_repr
from pypy.rpython.lltype import PyObject, Array, Char
-from pypy.rpython.rstr import STR
+from pypy.rpython.rstr import STR, string_repr
from pypy.rpython.lltype import functionptr, FuncType, malloc
from pypy.rpython import rstr
from pypy.rpython.rmodel import log
@@ -135,31 +135,10 @@
rtype_float = rtype_pos
def ll_str(self, f):
- pyfloat = pyfloat_fromdouble_ptr(f)
- pystring = pyobject_str_ptr(pyfloat)
- stringsize = pystring_size_ptr(pystring)
-
- ret = malloc(STR, stringsize)
-
- tollchararray_ptr(pystring, ret.chars)
-
- return ret
-
-PyObjectPtr = Ptr(PyObject)
-
-pystring_size_ptr = functionptr(FuncType([PyObjectPtr], Signed),
- "PyString_Size",
- external="C")
-pyfloat_fromdouble_ptr = functionptr(FuncType([Float], PyObjectPtr),
- "PyFloat_FromDouble",
- external="C")
-pyobject_str_ptr = functionptr(FuncType([PyObjectPtr], PyObjectPtr),
- "PyObject_Str",
- external="C")
-tollchararray_ptr = functionptr(FuncType([PyObjectPtr, Ptr(Array(Char))], Void),
- "PyString_ToLLCharArray",
- external="C")
-
+ from pypy.rpython.module.ll_strtod import ll_strtod_formatd
+ return ll_strtod_formatd(percent_f, f)
+
+percent_f = string_repr.convert_const("%f")
#
# _________________________ Conversions _________________________
Modified: pypy/dist/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rfloat.py (original)
+++ pypy/dist/pypy/rpython/test/test_rfloat.py Sat Oct 1 16:43:17 2005
@@ -47,3 +47,10 @@
assert type(res) is int
res = interpret(fn, [2.34])
assert res == fn(2.34)
+
+def test_float2str():
+ def fn(f):
+ return str(f)
+
+ res = interpret(fn, [1.5])
+ assert ''.join(res.chars) == '%f' % 1.5
Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py Sat Oct 1 16:43:17 2005
@@ -304,6 +304,12 @@
assert f(1.5) == "1.50"
assert f(2.0) == "2.00"
+def test_rarith_float_to_str():
+ def fn(f):
+ return str(f)
+ f = compile(fn, [float])
+ assert f(1.5) == '%f' % 1.5
+
def test_lock():
import thread
import pypy.module.thread.rpython.exttable # for declare()/declaretype()
More information about the Pypy-commit
mailing list