[pypy-svn] commit/pypy: ademan: Added support for PyFloat_FromString() and test
Bitbucket
commits-noreply at bitbucket.org
Sat Dec 18 04:50:47 CET 2010
1 new changeset in pypy:
http://bitbucket.org/pypy/pypy/changeset/898b357c14ba/
changeset: r40118:898b357c14ba
branch: psycopg2compatibility
user: ademan
date: 2010-12-18 04:43:48
summary: Added support for PyFloat_FromString() and test
affected #: 3 files (1.4 KB)
--- a/pypy/module/cpyext/floatobject.py Wed Dec 08 19:49:07 2010 +0000
+++ b/pypy/module/cpyext/floatobject.py Fri Dec 17 19:43:48 2010 -0800
@@ -3,6 +3,8 @@
build_type_checkers)
from pypy.interpreter.error import OperationError
+from pypy.objspace.std.strutil import interp_string_to_float, ParseStringError
+
PyFloat_Check, PyFloat_CheckExact = build_type_checkers("Float")
@cpython_api([lltype.Float], PyObject)
@@ -25,3 +27,17 @@
Returns the o converted to a float object on success, or NULL on failure.
This is the equivalent of the Python expression float(o)."""
return space.float(w_obj)
+
+ at cpython_api([PyObject, rffi.CCHARPP], PyObject)
+def PyFloat_FromString(space, str, pend):
+ """Create a PyFloatObject object based on the string value in str, or
+ NULL on failure. The pend argument is ignored. It remains only for
+ backward compatibility."""
+
+ str = rffi.charp2str(str)
+ try:
+ float_value = interp_string_to_float(space, str)
+ except ParseStringError, e:
+ return None
+ return space.wrap(float_value)
+
--- a/pypy/module/cpyext/stubs.py Wed Dec 08 19:49:07 2010 +0000
+++ b/pypy/module/cpyext/stubs.py Fri Dec 17 19:43:48 2010 -0800
@@ -928,13 +928,6 @@
failure; the appropriate exception will be set."""
raise NotImplementedError
- at cpython_api([PyObject, rffi.CCHARPP], PyObject)
-def PyFloat_FromString(space, str, pend):
- """Create a PyFloatObject object based on the string value in str, or
- NULL on failure. The pend argument is ignored. It remains only for
- backward compatibility."""
- raise NotImplementedError
-
@cpython_api([rffi.VOIDP_real], PyObject)
def PyFloat_GetInfo(space, info):
"""Return a structseq instance which contains information about the
--- a/pypy/module/cpyext/test/test_floatobject.py Wed Dec 08 19:49:07 2010 +0000
+++ b/pypy/module/cpyext/test/test_floatobject.py Fri Dec 17 19:43:48 2010 -0800
@@ -1,4 +1,6 @@
from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.module.cpyext.api import PyObject
class TestFloatObject(BaseApiTest):
def test_floatobject(self, space, api):
@@ -17,3 +19,18 @@
return 42.5
assert space.eq_w(api.PyNumber_Float(space.wrap(Coerce())),
space.wrap(42.5))
+
+ def test_from_string(self, space, api):
+ def test_number(n, expectfail=False):
+ np = lltype.nullptr(rffi.CCHARPP.TO)
+ n_str = rffi.str2charp(str(n))
+ f = api.PyFloat_FromString(n_str, np)
+ rffi.free_charp(n_str)
+ if expectfail:
+ assert f == None
+ else:
+ assert space.eq_w(f, space.wrap(n))
+
+ test_number(0.0)
+ test_number(42.0)
+ test_number("abcd", True)
Repository URL: https://bitbucket.org/pypy/pypy/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the Pypy-commit
mailing list