Author: Armin Rigo <[email protected]>
Branch: cpyext-gc-support
Changeset: r80220:41178972cbf5
Date: 2015-10-14 22:15 +0200
http://bitbucket.org/pypy/pypy/changeset/41178972cbf5/
Log: Pass a few tests from test_number.
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
@@ -77,17 +77,17 @@
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])
+ w_obj1 = from_ref(pp1[0])
+ w_obj2 = from_ref(pp2[0])
try:
w_res = space.coerce(w_obj1, w_obj2)
- except (TypeError, OperationError):
+ except 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)
+ pp1[0] = make_ref(w_res1)
+ pp2[0] = make_ref(w_res2)
return 0
def func_rename(newname):
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -338,18 +338,10 @@
# ZZZ: use an ExtRegistryEntry to constant-fold is_pyobj()
-def make_ref(space, w_obj):
- ZZZ
- assert isinstance(w_obj, W_Root)
- state = space.fromcache(RefcountState)
- try:
- py_obj = state.py_objects_w2r[w_obj]
- except KeyError:
- py_obj = create_ref(space, w_obj)
- track_reference(space, py_obj, w_obj)
- else:
- Py_IncRef(space, py_obj)
- return py_obj
+def make_ref(w_obj):
+ pyobj = as_pyobj(w_obj)
+ pyobj.c_ob_refcnt += 1
+ return pyobj
def ZZZ_from_ref(space, ref):
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
@@ -43,23 +43,23 @@
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)
+ pp1[0] = make_ref(w_obj1)
pp2 = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
- pp2[0] = make_ref(space, w_obj2)
+ pp2[0] = make_ref(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])
+ assert space.str_w(space.repr(from_ref(pp1[0]))) == '123.0'
+ assert space.str_w(space.repr(from_ref(pp2[0]))) == '456.789'
+ Py_DecRef(space, pp1[0]) # for the refs returned by PyNumber_Coerce
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_obj1) # for the make_ref() above
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.))
+ pl = make_ref(space.wrap(123))
+ pf = make_ref(space.wrap(42.))
ppl = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
ppf = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
ppl[0] = pl
@@ -68,7 +68,7 @@
ret = api.PyNumber_CoerceEx(ppl, ppf)
assert ret == 0
- w_res = from_ref(space, ppl[0])
+ w_res = from_ref(ppl[0])
assert api.PyFloat_Check(w_res)
assert space.unwrap(w_res) == 123.
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit