Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r67130:178720ddcb24
Date: 2013-09-28 16:00 -0700
http://bitbucket.org/pypy/pypy/changeset/178720ddcb24/

Log:    rekill coerce

diff --git a/pypy/module/cpyext/number.py b/pypy/module/cpyext/number.py
--- a/pypy/module/cpyext/number.py
+++ b/pypy/module/cpyext/number.py
@@ -1,9 +1,8 @@
 from pypy.interpreter.error import OperationError
 from pypy.module.cpyext.api import cpython_api, CANNOT_FAIL, Py_ssize_t
-from pypy.module.cpyext.pyobject import PyObject, PyObjectP, from_ref, 
make_ref, Py_DecRef
+from pypy.module.cpyext.pyobject import PyObject
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.tool.sourcetools import func_with_new_name
-from pypy.module.cpyext.state import State
 
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyIndex_Check(space, w_obj):
@@ -57,39 +56,6 @@
     """
     return space.index(w_obj)
 
-@cpython_api([PyObjectP, PyObjectP], rffi.INT_real, error=CANNOT_FAIL)
-def PyNumber_CoerceEx(space, pp1, pp2):
-    """This function is similar to PyNumber_Coerce(), except that it returns
-    1 when the conversion is not possible and when no error is raised.
-    Reference counts are still not increased in this case."""
-    retVal = PyNumber_Coerce(space, pp1, pp2)
-    if retVal != 0:
-        return 1
-    return 0
-
-@cpython_api([PyObjectP, PyObjectP], rffi.INT_real, error=CANNOT_FAIL)
-def PyNumber_Coerce(space, pp1, pp2):
-    """This function takes the addresses of two variables of type PyObject*.  
If
-    the objects pointed to by *p1 and *p2 have the same type, increment their
-    reference count and return 0 (success). If the objects can be converted to 
a
-    common numeric type, replace *p1 and *p2 by their converted value (with
-    'new' reference counts), and return 0. If no conversion is possible, or if
-    some other error occurs, return -1 (failure) and don't increment the
-    reference counts.  The call PyNumber_Coerce(&o1, &o2) is equivalent to the
-    Python statement o1, o2 = coerce(o1, o2)."""
-    w_obj1 = from_ref(space, pp1[0])
-    w_obj2 = from_ref(space, pp2[0])
-    try:
-        w_res = space.coerce(w_obj1, w_obj2)
-    except (TypeError, OperationError):
-        state = space.fromcache(State)
-        state.clear_exception()
-        return -1
-    w_res1, w_res2 = space.unpackiterable(w_res, 2)
-    pp1[0] = make_ref(space, w_res1)
-    pp2[0] = make_ref(space, w_res2)
-    return 0
-
 def func_rename(newname):
     return lambda func: func_with_new_name(func, newname)
 
diff --git a/pypy/module/cpyext/test/test_number.py 
b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -1,7 +1,5 @@
 from rpython.rtyper.lltypesystem import lltype
 from pypy.module.cpyext.test.test_api import BaseApiTest
-from pypy.module.cpyext.pyobject import PyObjectP, from_ref, make_ref, 
Py_DecRef
-from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 
 class TestIterator(BaseApiTest):
     def test_check(self, space, api):
@@ -39,46 +37,6 @@
         assert w_l is None
         api.PyErr_Clear()
 
-    def test_coerce(self, space, api):
-        w_obj1 = space.wrap(123)
-        w_obj2 = space.wrap(456.789)
-        pp1 = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
-        pp1[0] = make_ref(space, w_obj1)
-        pp2 = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
-        pp2[0] = make_ref(space, w_obj2)
-        assert api.PyNumber_Coerce(pp1, pp2) == 0
-        assert space.str_w(space.repr(from_ref(space, pp1[0]))) == '123.0'
-        assert space.str_w(space.repr(from_ref(space, pp2[0]))) == '456.789'
-        Py_DecRef(space, pp1[0])
-        Py_DecRef(space, pp2[0])
-        lltype.free(pp1, flavor='raw')
-        # Yes, decrement twice since we decoupled between w_obj* and pp*[0].
-        Py_DecRef(space, w_obj1)
-        Py_DecRef(space, w_obj2)
-        lltype.free(pp2, flavor='raw')
-
-    def test_number_coerce_ex(self, space, api):
-        pl = make_ref(space, space.wrap(123))
-        pf = make_ref(space, space.wrap(42.))
-        ppl = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
-        ppf = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
-        ppl[0] = pl
-        ppf[0] = pf
-
-        ret = api.PyNumber_CoerceEx(ppl, ppf)
-        assert ret == 0
-
-        w_res = from_ref(space, ppl[0])
-
-        assert api.PyFloat_Check(w_res)
-        assert space.unwrap(w_res) == 123.
-        Py_DecRef(space, pl)
-        Py_DecRef(space, pf)
-        Py_DecRef(space, ppl[0])
-        Py_DecRef(space, ppf[0])
-        lltype.free(ppl, flavor='raw')
-        lltype.free(ppf, flavor='raw')
-
     def test_numbermethods(self, space, api):
         assert "ab" == space.unwrap(
             api.PyNumber_Add(space.wrap("a"), space.wrap("b")))
@@ -104,40 +62,3 @@
             api.PyNumber_Power(space.wrap(3), space.wrap(2), space.wrap(5)))
         assert 9 == space.unwrap(
             api.PyNumber_InPlacePower(space.wrap(3), space.wrap(2), 
space.w_None))
-
-class AppTestCNumber(AppTestCpythonExtensionBase):
-    def test_app_coerce(self):
-        mod = self.import_extension('foo', [
-            ("test_fail", "METH_NOARGS",
-             '''
-                PyObject * hello = PyString_FromString("hello");
-                PyObject * float1 = PyFloat_FromDouble(1.0);
-                int retVal = PyNumber_Coerce(&hello, &float1);
-                Py_DECREF(hello);
-                Py_DECREF(float1);
-                return PyInt_FromLong(retVal);
-            '''),
-            ("test", "METH_NOARGS",
-             '''
-                PyObject * float1p = PyFloat_FromDouble(1.0);
-                PyObject * int3p   = PyInt_FromLong(3);
-                PyObject * tupl = PyTuple_New(2);
-                PyObject float1 = *float1p;
-                PyObject int3 = *int3p;
-                int retVal = PyNumber_CoerceEx(&int3p, &float1p);
-                if (retVal == 0)
-                {
-                    PyTuple_SET_ITEM(tupl, 0, int3p);
-                    PyTuple_SET_ITEM(tupl, 1, float1p);
-                }
-                Py_DECREF(&int3);
-                Py_DECREF(&float1);
-                Py_DECREF(int3p);
-                Py_DECREF(float1p);
-                return tupl;
-            ''')])
-        assert mod.test_fail() == -1
-        '''tupl = mod.test()
-        assert tupl[0] == 3.
-        assert tupl[1] == 1.
-        assert isinstance(tupl[0], float)'''
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to