Author: Matti Picus <[email protected]>
Branch:
Changeset: r93580:678518de33f8
Date: 2017-12-26 23:13 +0200
http://bitbucket.org/pypy/pypy/changeset/678518de33f8/
Log: api.Py_DecRef and api.PyTuple_New no longer exist, work around for
tests
diff --git a/pypy/module/cpyext/test/test_tupleobject.py
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -1,22 +1,24 @@
import py
from pypy.module.cpyext.pyobject import (
- PyObject, PyObjectP, make_ref, from_ref, incref)
+ PyObject, PyObjectP, make_ref, from_ref, incref, decref)
from pypy.module.cpyext.test.test_api import BaseApiTest, raises_w
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rlib.debug import FatalError
+from pypy.module.cpyext.state import State
from pypy.module.cpyext.tupleobject import (
PyTupleObject, PyTuple_Check, PyTuple_SetItem, PyTuple_Size)
class TestTupleObject(BaseApiTest):
- def test_tupleobject(self, space):
+ def test_tupleobject_base(self, space):
assert not PyTuple_Check(space, space.w_None)
with raises_w(space, SystemError):
- incref(space, space.w_None)
- PyTuple_SetItem(space, space.w_None, 0, space.w_None)
+ n = make_ref(space, space.w_None)
+ incref(space, n)
+ PyTuple_SetItem(space, n, 0, n)
atuple = space.newtuple([space.wrap(0), space.wrap(1),
space.wrap('yay')])
assert PyTuple_Size(space, atuple) == 3
@@ -24,9 +26,10 @@
PyTuple_Size(space, space.newlist([]))
def test_tuple_realize_refuses_nulls(self, space, api):
- py_tuple = api.PyTuple_New(1)
+ state = space.fromcache(State)
+ py_tuple = state.ccall("PyTuple_New", 1)
py.test.raises(FatalError, from_ref, space, py_tuple)
- api.Py_DecRef(py_tuple)
+ decref(space, py_tuple)
def test_tuple_resize(self, space, api):
w_42 = space.wrap(42)
@@ -34,7 +37,8 @@
w_44 = space.wrap(44)
ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
- py_tuple = api.PyTuple_New(3)
+ state = space.fromcache(State)
+ py_tuple = state.ccall("PyTuple_New", 3)
# inside py_tuple is an array of "PyObject *" items which each hold
# a reference
rffi.cast(PyTupleObject, py_tuple).c_ob_item[0] = make_ref(space, w_42)
@@ -45,9 +49,9 @@
assert space.int_w(space.len(w_tuple)) == 2
assert space.int_w(space.getitem(w_tuple, space.wrap(0))) == 42
assert space.int_w(space.getitem(w_tuple, space.wrap(1))) == 43
- api.Py_DecRef(ar[0])
+ decref(space, ar[0])
- py_tuple = api.PyTuple_New(3)
+ py_tuple = state.ccall("PyTuple_New", 3)
rffi.cast(PyTupleObject, py_tuple).c_ob_item[0] = make_ref(space, w_42)
rffi.cast(PyTupleObject, py_tuple).c_ob_item[1] = make_ref(space, w_43)
rffi.cast(PyTupleObject, py_tuple).c_ob_item[2] = make_ref(space, w_44)
@@ -61,19 +65,20 @@
assert space.int_w(space.len(w_tuple)) == 10
for i in range(10):
assert space.int_w(space.getitem(w_tuple, space.wrap(i))) == 42 + i
- api.Py_DecRef(ar[0])
+ decref(space, ar[0])
lltype.free(ar, flavor='raw')
def test_setitem(self, space, api):
- py_tuple = api.PyTuple_New(2)
+ state = space.fromcache(State)
+ py_tuple = state.ccall("PyTuple_New", 2)
api.PyTuple_SetItem(py_tuple, 0, make_ref(space, space.wrap(42)))
api.PyTuple_SetItem(py_tuple, 1, make_ref(space, space.wrap(43)))
w_tuple = from_ref(space, py_tuple)
assert space.eq_w(w_tuple, space.newtuple([space.wrap(42),
space.wrap(43)]))
- api.Py_DecRef(py_tuple)
+ decref(space, py_tuple)
def test_getslice(self, space, api):
w_tuple = space.newtuple([space.wrap(i) for i in range(10)])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit