Author: Armin Rigo <[email protected]>
Branch: cpyext-avoid-roundtrip
Changeset: r92698:51b3443b1148
Date: 2017-10-10 11:11 +0200
http://bitbucket.org/pypy/pypy/changeset/51b3443b1148/
Log: (antocuni, arigo)
Try to be less magic and avoid the basic functions like decref()
accepting both PyObjects and W_Roots.
Rename Py_DecRef() to decref().
diff --git a/pypy/module/cpyext/bufferobject.py
b/pypy/module/cpyext/bufferobject.py
--- a/pypy/module/cpyext/bufferobject.py
+++ b/pypy/module/cpyext/bufferobject.py
@@ -4,7 +4,7 @@
from pypy.module.cpyext.api import (
cpython_api, Py_ssize_t, cpython_struct, bootstrap_function, slot_function,
PyObjectFields, PyObject)
-from pypy.module.cpyext.pyobject import make_typedescr, Py_DecRef, make_ref
+from pypy.module.cpyext.pyobject import make_typedescr, decref, make_ref
from pypy.module.array.interp_array import ArrayBuffer
from pypy.objspace.std.bufferobject import W_Buffer
@@ -76,7 +76,7 @@
def buffer_dealloc(space, py_obj):
py_buf = rffi.cast(PyBufferObject, py_obj)
if py_buf.c_b_base:
- Py_DecRef(space, py_buf.c_b_base)
+ decref(space, py_buf.c_b_base)
else:
rffi.free_charp(rffi.cast(rffi.CCHARP, py_buf.c_b_ptr))
from pypy.module.cpyext.object import _dealloc
diff --git a/pypy/module/cpyext/bytearrayobject.py
b/pypy/module/cpyext/bytearrayobject.py
--- a/pypy/module/cpyext/bytearrayobject.py
+++ b/pypy/module/cpyext/bytearrayobject.py
@@ -7,8 +7,8 @@
PyVarObjectFields, Py_ssize_t, CONST_STRING, CANNOT_FAIL)
from pypy.module.cpyext.pyerrors import PyErr_BadArgument
from pypy.module.cpyext.pyobject import (
- PyObject, PyObjectP, Py_DecRef, make_ref, from_ref,
- make_typedescr, get_typedescr, Py_IncRef)
+ PyObject, PyObjectP, make_ref, from_ref,
+ make_typedescr, get_typedescr)
# Type PyByteArrayObject represents a mutable array of bytes.
# The Python API is that of a sequence;
# the bytes are mapped to ints in [0, 256).
diff --git a/pypy/module/cpyext/bytesobject.py
b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -5,8 +5,8 @@
PyVarObjectFields, Py_ssize_t, CONST_STRING, CANNOT_FAIL, slot_function)
from pypy.module.cpyext.pyerrors import PyErr_BadArgument
from pypy.module.cpyext.pyobject import (
- PyObject, PyObjectP, Py_DecRef, make_ref, from_ref, track_reference,
- make_typedescr, get_typedescr, as_pyobj, Py_IncRef, get_w_obj_and_decref,
+ PyObject, PyObjectP, decref, make_ref, from_ref, track_reference,
+ make_typedescr, get_typedescr, as_pyobj, get_w_obj_and_decref,
pyobj_has_w_obj)
from pypy.objspace.std.bytesobject import W_BytesObject
@@ -215,7 +215,7 @@
try:
py_newstr = new_empty_str(space, newsize)
except MemoryError:
- Py_DecRef(space, ref[0])
+ decref(space, ref[0])
ref[0] = lltype.nullptr(PyObject.TO)
raise
to_cp = newsize
@@ -224,7 +224,7 @@
to_cp = oldsize
for i in range(to_cp):
py_newstr.c_ob_sval[i] = py_str.c_ob_sval[i]
- Py_DecRef(space, ref[0])
+ decref(space, ref[0])
ref[0] = rffi.cast(PyObject, py_newstr)
return 0
@@ -260,7 +260,7 @@
try:
PyString_Concat(space, ref, newpart)
finally:
- Py_DecRef(space, newpart)
+ decref(space, newpart)
@cpython_api([PyObject, PyObject], PyObject)
def PyString_Format(space, w_format, w_args):
@@ -294,7 +294,7 @@
alias."""
w_str = from_ref(space, string[0])
w_str = space.new_interned_w_str(w_str)
- Py_DecRef(space, string[0])
+ decref(space, string[0])
string[0] = make_ref(space, w_str)
@cpython_api([PyObject, CONST_STRING, CONST_STRING], PyObject)
diff --git a/pypy/module/cpyext/classobject.py
b/pypy/module/cpyext/classobject.py
--- a/pypy/module/cpyext/classobject.py
+++ b/pypy/module/cpyext/classobject.py
@@ -2,7 +2,8 @@
from pypy.module.cpyext.api import (
PyObjectFields, CANNOT_FAIL,
cpython_api, bootstrap_function, build_type_checkers)
-from pypy.module.cpyext.pyobject import PyObject, make_ref, from_ref,
Py_DecRef, make_typedescr
+from pypy.module.cpyext.pyobject import (
+ PyObject, make_ref, from_ref, make_typedescr)
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
from pypy.module.__builtin__.interp_classobj import W_ClassObject,
W_InstanceObject
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -9,7 +9,7 @@
bootstrap_function, slot_function)
from pypy.module.cpyext.pyobject import (PyObject, PyObjectP, as_pyobj,
make_typedescr, track_reference, create_ref, from_ref, decref,
- Py_IncRef)
+ incref)
from pypy.module.cpyext.object import _dealloc
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
@@ -267,7 +267,7 @@
decref(space, py_dict.c__tmpkeys)
w_keys = space.call_method(space.w_dict, "keys", w_dict)
py_dict.c__tmpkeys = create_ref(space, w_keys)
- Py_IncRef(space, py_dict.c__tmpkeys)
+ incref(space, py_dict.c__tmpkeys)
else:
if not py_dict.c__tmpkeys:
# pos should have been 0, cannot fail so return 0
diff --git a/pypy/module/cpyext/frameobject.py
b/pypy/module/cpyext/frameobject.py
--- a/pypy/module/cpyext/frameobject.py
+++ b/pypy/module/cpyext/frameobject.py
@@ -3,7 +3,7 @@
cpython_api, bootstrap_function, PyObjectFields, cpython_struct,
CANNOT_FAIL, slot_function)
from pypy.module.cpyext.pyobject import (
- PyObject, Py_DecRef, make_ref, from_ref, track_reference,
+ PyObject, decref, make_ref, from_ref, track_reference,
make_typedescr, get_typedescr)
from pypy.module.cpyext.state import State
from pypy.module.cpyext.pystate import PyThreadState
@@ -43,9 +43,9 @@
def frame_dealloc(space, py_obj):
py_frame = rffi.cast(PyFrameObject, py_obj)
py_code = rffi.cast(PyObject, py_frame.c_f_code)
- Py_DecRef(space, py_code)
- Py_DecRef(space, py_frame.c_f_globals)
- Py_DecRef(space, py_frame.c_f_locals)
+ decref(space, py_code)
+ decref(space, py_frame.c_f_globals)
+ decref(space, py_frame.c_f_locals)
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
diff --git a/pypy/module/cpyext/funcobject.py b/pypy/module/cpyext/funcobject.py
--- a/pypy/module/cpyext/funcobject.py
+++ b/pypy/module/cpyext/funcobject.py
@@ -4,7 +4,7 @@
cpython_api, bootstrap_function, cpython_struct, build_type_checkers,
slot_function)
from pypy.module.cpyext.pyobject import (
- PyObject, make_ref, from_ref, Py_DecRef, make_typedescr)
+ PyObject, make_ref, from_ref, decref, make_typedescr)
from rpython.rlib.unroll import unrolling_iterable
from pypy.interpreter.error import OperationError
from pypy.interpreter.function import Function, Method
@@ -60,7 +60,7 @@
@slot_function([PyObject], lltype.Void)
def function_dealloc(space, py_obj):
py_func = rffi.cast(PyFunctionObject, py_obj)
- Py_DecRef(space, py_func.c_func_name)
+ decref(space, py_func.c_func_name)
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
@@ -79,8 +79,8 @@
@slot_function([PyObject], lltype.Void)
def code_dealloc(space, py_obj):
py_code = rffi.cast(PyCodeObject, py_obj)
- Py_DecRef(space, py_code.c_co_name)
- Py_DecRef(space, py_code.c_co_filename)
+ decref(space, py_code.c_co_name)
+ decref(space, py_code.c_co_filename)
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
diff --git a/pypy/module/cpyext/methodobject.py
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -14,7 +14,7 @@
cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts,
build_type_checkers)
from pypy.module.cpyext.pyobject import (
- Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
+ decref, from_ref, make_ref, as_pyobj, make_typedescr)
PyMethodDef = cts.gettype('PyMethodDef')
PyCFunction = cts.gettype('PyCFunction')
@@ -38,8 +38,8 @@
@slot_function([PyObject], lltype.Void)
def cfunction_dealloc(space, py_obj):
py_func = rffi.cast(PyCFunctionObject, py_obj)
- Py_DecRef(space, py_func.c_m_self)
- Py_DecRef(space, py_func.c_m_module)
+ decref(space, py_func.c_m_self)
+ decref(space, py_func.c_m_module)
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
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,6 +1,6 @@
from pypy.interpreter.error import OperationError, oefmt
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, PyObjectP, from_ref, make_ref
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.tool.sourcetools import func_with_new_name
from pypy.module.cpyext.state import State
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -5,7 +5,7 @@
Py_TPFLAGS_HEAPTYPE, Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT,
Py_GE, CONST_STRING, FILEP, fwrite, c_only)
from pypy.module.cpyext.pyobject import (
- PyObject, PyObjectP, from_ref, Py_IncRef, Py_DecRef,
+ PyObject, PyObjectP, from_ref, incref, decref,
get_typedescr)
from pypy.module.cpyext.typeobject import PyTypeObjectPtr
from pypy.module.cpyext.pyerrors import PyErr_NoMemory, PyErr_BadInternalCall
@@ -55,7 +55,7 @@
obj_voidp = rffi.cast(rffi.VOIDP, obj)
generic_cpy_call(space, pto.c_tp_free, obj_voidp)
if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
- Py_DecRef(space, rffi.cast(PyObject, pto))
+ decref(space, rffi.cast(PyObject, pto))
@cpython_api([PyObject], PyObjectP, error=CANNOT_FAIL)
def _PyObject_GetDictPtr(space, op):
@@ -267,7 +267,7 @@
@cpython_api([PyObject], PyObject, result_is_ll=True)
def PyObject_SelfIter(space, ref):
"""Undocumented function, this is what CPython does."""
- Py_IncRef(space, ref)
+ incref(space, ref)
return ref
@cpython_api([PyObject, PyObject], PyObject)
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -6,7 +6,7 @@
from pypy.module.cpyext.api import cpython_api, CANNOT_FAIL, CONST_STRING
from pypy.module.exceptions.interp_exceptions import W_RuntimeWarning
from pypy.module.cpyext.pyobject import (
- PyObject, PyObjectP, make_ref, from_ref, Py_DecRef)
+ PyObject, PyObjectP, make_ref, from_ref, decref)
from pypy.module.cpyext.state import State
from pypy.module.cpyext.import_ import PyImport_Import
from rpython.rlib import rposix, jit
@@ -65,7 +65,7 @@
ptraceback[0] = lltype.nullptr(PyObject.TO)
@cpython_api([PyObject, PyObject, PyObject], lltype.Void)
-def PyErr_Restore(space, w_type, w_value, w_traceback):
+def PyErr_Restore(space, py_type, py_value, py_traceback):
"""Set the error indicator from the three objects. If the error
indicator is
already set, it is cleared first. If the objects are NULL, the error
indicator is cleared. Do not pass a NULL type and non-NULL value or
@@ -80,13 +80,13 @@
error indicator temporarily; use PyErr_Fetch() to save the current
exception state."""
state = space.fromcache(State)
+ w_type = get_w_obj_and_decref(py_type)
+ w_value = get_w_obj_and_decref(py_value)
+ w_traceback = get_w_obj_and_decref(py_traceback) #XXX do something with
that
if w_type is None:
state.clear_exception()
return
state.set_exception(OperationError(w_type, w_value))
- Py_DecRef(space, w_type)
- Py_DecRef(space, w_value)
- Py_DecRef(space, w_traceback)
@cpython_api([PyObjectP, PyObjectP, PyObjectP], lltype.Void)
def PyErr_NormalizeException(space, exc_p, val_p, tb_p):
@@ -108,8 +108,8 @@
w_evalue = space.w_None
operr = OperationError(w_etype, w_evalue)
operr.normalize_exception(space)
- Py_DecRef(space, exc_p[0])
- Py_DecRef(space, val_p[0])
+ decref(space, exc_p[0])
+ decref(space, val_p[0])
exc_p[0] = make_ref(space, operr.w_type)
val_p[0] = make_ref(space, operr.get_w_value(space))
@@ -390,7 +390,7 @@
ptraceback[0] = lltype.nullptr(PyObject.TO)
@cpython_api([PyObject, PyObject, PyObject], lltype.Void)
-def PyErr_SetExcInfo(space, w_type, w_value, w_traceback):
+def PyErr_SetExcInfo(space, py_type, py_value, py_traceback):
"""---Cython extension---
Set the exception info, as known from ``sys.exc_info()``. This refers
@@ -406,6 +406,9 @@
restore the exception state temporarily. Use
:c:func:`PyErr_GetExcInfo` to read the exception state.
"""
+ w_type = get_w_obj_and_decref(py_type)
+ w_value = get_w_obj_and_decref(py_value)
+ w_traceback = get_w_obj_and_decref(py_traceback)
if w_value is None or space.is_w(w_value, space.w_None):
operror = None
else:
@@ -419,9 +422,6 @@
#
ec = space.getexecutioncontext()
ec.set_sys_exc_info(operror)
- Py_DecRef(space, w_type)
- Py_DecRef(space, w_value)
- Py_DecRef(space, w_traceback)
@cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
def PyOS_InterruptOccurred(space):
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
@@ -41,7 +41,7 @@
# Don't increase refcount for non-heaptypes
flags = rffi.cast(lltype.Signed, pytype.c_tp_flags)
if flags & Py_TPFLAGS_HEAPTYPE:
- Py_IncRef(space, w_type)
+ incref(space, pytype)
if pytype:
size = pytype.c_tp_basicsize
@@ -186,7 +186,7 @@
"""
Ties together a PyObject and an interpreter object.
The PyObject's refcnt is increased by REFCNT_FROM_PYPY.
- The reference in 'py_obj' is not stolen! Remember to Py_DecRef()
+ The reference in 'py_obj' is not stolen! Remember to decref()
it is you need to.
"""
# XXX looks like a PyObject_GC_TRACK
@@ -244,8 +244,8 @@
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
+ assert not is_pyobj(w_obj)
if w_obj is not None:
- assert not is_pyobj(w_obj)
py_obj = rawrefcount.from_obj(PyObject, w_obj)
if not py_obj:
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
@@ -278,46 +278,36 @@
hop.exception_cannot_occur()
return hop.inputconst(lltype.Bool, hop.s_result.const)
[email protected]()
-def get_pyobj_and_incref(space, obj, w_userdata=None, immortal=False):
- if is_pyobj(obj):
- pyobj = rffi.cast(PyObject, obj)
- at_least = 1
- else:
- pyobj = as_pyobj(space, obj, w_userdata, immortal=immortal)
- at_least = rawrefcount.REFCNT_FROM_PYPY
- if pyobj:
- assert pyobj.c_ob_refcnt >= at_least
+def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
+ pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
+ if pyobj: # != NULL
+ assert pyobj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY
pyobj.c_ob_refcnt += 1
- keepalive_until_here(obj)
+ keepalive_until_here(w_obj)
return pyobj
[email protected]()
-def make_ref(space, obj, w_userdata=None, immortal=False):
- """Increment the reference counter of the PyObject and return it.
- Can be called with either a PyObject or a W_Root.
+def make_ref(space, w_obj, w_userdata=None, immortal=False):
+ """Turn the W_Root into a corresponding PyObject. You should
+ decref the returned PyObject later. Note that it is often the
+ case, but not guaranteed, that make_ref() returns always the
+ same PyObject for the same W_Root; for example, integers.
"""
- if not is_pyobj(obj):
- w_obj = obj
- if w_obj is not None and space.type(w_obj) is space.w_int:
- state = space.fromcache(State)
- intval = space.int_w(w_obj)
- return state.C.PyInt_FromLong(intval)
- return get_pyobj_and_incref(space, obj, w_userdata, immortal=False)
+ assert not is_pyobj(w_obj)
+ if w_obj is not None and space.type(w_obj) is space.w_int:
+ state = space.fromcache(State)
+ intval = space.int_w(w_obj)
+ return state.C.PyInt_FromLong(intval)
+ return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
@specialize.ll()
-def get_w_obj_and_decref(space, obj):
+def get_w_obj_and_decref(space, pyobj):
"""Decrement the reference counter of the PyObject and return the
- corresponding W_Root object (so the reference count is at least
- REFCNT_FROM_PYPY and cannot be zero). Can be called with either
- a PyObject or a W_Root.
+ corresponding W_Root object (so the reference count after the decref
+ is at least REFCNT_FROM_PYPY and cannot be zero).
"""
- if is_pyobj(obj):
- pyobj = rffi.cast(PyObject, obj)
- w_obj = from_ref(space, pyobj)
- else:
- w_obj = obj
- pyobj = as_pyobj(space, w_obj)
+ assert is_pyobj(pyobj)
+ pyobj = rffi.cast(PyObject, pyobj)
+ w_obj = from_ref(space, pyobj)
if pyobj:
pyobj.c_ob_refcnt -= 1
assert pyobj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY
@@ -326,30 +316,30 @@
@specialize.ll()
-def incref(space, obj):
- get_pyobj_and_incref(space, obj)
+def incref(space, pyobj):
+ assert is_pyobj(pyobj)
+ pyobj = rffi.cast(PyObject, pyobj)
+ assert pyobj.c_ob_refcnt >= 1
+ pyobj.c_ob_refcnt += 1
@specialize.ll()
-def decref(space, obj):
+def decref(space, pyobj):
from pypy.module.cpyext.api import generic_cpy_call
- if is_pyobj(obj):
- obj = rffi.cast(PyObject, obj)
- if obj:
- assert obj.c_ob_refcnt > 0
- assert obj.c_ob_pypy_link == 0 or obj.c_ob_refcnt >
rawrefcount.REFCNT_FROM_PYPY
- obj.c_ob_refcnt -= 1
- if obj.c_ob_refcnt == 0:
- state = space.fromcache(State)
- generic_cpy_call(space, state.C._Py_Dealloc, obj)
- #else:
- # w_obj = rawrefcount.to_obj(W_Root, ref)
- # if w_obj is not None:
- # assert obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY
- else:
- get_w_obj_and_decref(space, obj)
+ assert is_pyobj(pyobj)
+ pyobj = rffi.cast(PyObject, pyobj)
+ if pyobj:
+ assert pyobj.c_ob_refcnt > 0
+ assert (pyobj.c_ob_pypy_link == 0 or
+ pyobj.c_ob_refcnt > rawrefcount.REFCNT_FROM_PYPY)
+ pyobj.c_ob_refcnt -= 1
+ if pyobj.c_ob_refcnt == 0:
+ state = space.fromcache(State)
+ generic_cpy_call(space, state.C._Py_Dealloc, pyobj)
+ #else:
+ # w_obj = rawrefcount.to_obj(W_Root, ref)
+ # if w_obj is not None:
+ # assert pyobj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY
-Py_IncRef = incref # XXX remove me and kill all the Py_IncRef usages from
RPython
-Py_DecRef = decref # XXX remove me and kill all the Py_DecRef usages from
RPython
@cpython_api([PyObject], lltype.Void)
def _Py_NewReference(space, obj):
diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py
--- a/pypy/module/cpyext/pystate.py
+++ b/pypy/module/cpyext/pystate.py
@@ -1,6 +1,6 @@
from pypy.module.cpyext.api import (
cpython_api, CANNOT_FAIL, cpython_struct)
-from pypy.module.cpyext.pyobject import PyObject, Py_DecRef, make_ref
+from pypy.module.cpyext.pyobject import PyObject, decref, make_ref
from pypy.interpreter.error import OperationError
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rlib import rthread
@@ -75,7 +75,7 @@
def ThreadState_dealloc(ts, space):
assert space is not None
- Py_DecRef(space, ts.c_dict)
+ decref(space, ts.c_dict)
ThreadStateCapsule = encapsulator(PyThreadState.TO,
dealloc=ThreadState_dealloc)
@@ -319,7 +319,7 @@
interpreter lock must be held."""
if not space.config.translation.thread:
raise NoThreads
- Py_DecRef(space, tstate.c_dict)
+ decref(space, tstate.c_dict)
tstate.c_dict = lltype.nullptr(PyObject.TO)
space.threadlocals.leave_thread(space)
space.getexecutioncontext().cleanup_cpyext_state()
diff --git a/pypy/module/cpyext/pytraceback.py
b/pypy/module/cpyext/pytraceback.py
--- a/pypy/module/cpyext/pytraceback.py
+++ b/pypy/module/cpyext/pytraceback.py
@@ -4,7 +4,7 @@
cpython_api, bootstrap_function, cpython_struct,
slot_function)
from pypy.module.cpyext.pyobject import (
- PyObject, make_ref, from_ref, Py_DecRef, make_typedescr)
+ PyObject, make_ref, from_ref, decref, make_typedescr)
from pypy.module.cpyext.frameobject import PyFrameObject
from pypy.interpreter.error import OperationError
from pypy.interpreter.pytraceback import PyTraceback
@@ -44,7 +44,7 @@
@slot_function([PyObject], lltype.Void)
def traceback_dealloc(space, py_obj):
py_traceback = rffi.cast(PyTracebackObject, py_obj)
- Py_DecRef(space, rffi.cast(PyObject, py_traceback.c_tb_next))
- Py_DecRef(space, rffi.cast(PyObject, py_traceback.c_tb_frame))
+ decref(space, rffi.cast(PyObject, py_traceback.c_tb_next))
+ decref(space, rffi.cast(PyObject, py_traceback.c_tb_frame))
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
diff --git a/pypy/module/cpyext/setobject.py b/pypy/module/cpyext/setobject.py
--- a/pypy/module/cpyext/setobject.py
+++ b/pypy/module/cpyext/setobject.py
@@ -2,7 +2,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import (cpython_api, Py_ssize_t, CANNOT_FAIL,
build_type_checkers)
-from pypy.module.cpyext.pyobject import (PyObject, PyObjectP, Py_DecRef,
+from pypy.module.cpyext.pyobject import (PyObject, PyObjectP,
make_ref, from_ref)
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
from pypy.objspace.std.setobject import W_SetObject, W_FrozensetObject, newset
diff --git a/pypy/module/cpyext/sliceobject.py
b/pypy/module/cpyext/sliceobject.py
--- a/pypy/module/cpyext/sliceobject.py
+++ b/pypy/module/cpyext/sliceobject.py
@@ -3,7 +3,7 @@
cpython_api, cpython_struct, bootstrap_function, build_type_checkers,
CANNOT_FAIL, Py_ssize_t, Py_ssize_tP, PyObjectFields, slot_function)
from pypy.module.cpyext.pyobject import (
- Py_DecRef, PyObject, make_ref, make_typedescr)
+ decref, PyObject, make_ref, make_typedescr)
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
from pypy.interpreter.error import OperationError
from pypy.objspace.std.sliceobject import W_SliceObject
@@ -41,9 +41,9 @@
"""Frees allocated PyBytesObject resources.
"""
py_slice = rffi.cast(PySliceObject, py_obj)
- Py_DecRef(space, py_slice.c_start)
- Py_DecRef(space, py_slice.c_stop)
- Py_DecRef(space, py_slice.c_step)
+ decref(space, py_slice.c_start)
+ decref(space, py_slice.c_stop)
+ decref(space, py_slice.c_step)
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
diff --git a/pypy/module/cpyext/structmember.py
b/pypy/module/cpyext/structmember.py
--- a/pypy/module/cpyext/structmember.py
+++ b/pypy/module/cpyext/structmember.py
@@ -5,7 +5,7 @@
from pypy.module.cpyext.api import ADDR, PyObjectP, cpython_api, CONST_STRING
from pypy.module.cpyext.intobject import PyInt_AsLong, PyInt_AsUnsignedLong
from pypy.module.cpyext.pyerrors import PyErr_Occurred
-from pypy.module.cpyext.pyobject import PyObject, Py_DecRef, from_ref, make_ref
+from pypy.module.cpyext.pyobject import PyObject, decref, from_ref, make_ref
from pypy.module.cpyext.bytesobject import (
PyString_FromString, PyString_FromStringAndSize)
from pypy.module.cpyext.floatobject import PyFloat_AsDouble
@@ -123,7 +123,7 @@
elif member_type in [T_OBJECT, T_OBJECT_EX]:
array = rffi.cast(PyObjectP, addr)
if array[0]:
- Py_DecRef(space, array[0])
+ decref(space, array[0])
array[0] = make_ref(space, w_value)
else:
raise oefmt(space.w_SystemError, "bad memberdescr type")
diff --git a/pypy/module/cpyext/test/test_bufferobject.py
b/pypy/module/cpyext/test/test_bufferobject.py
--- a/pypy/module/cpyext/test/test_bufferobject.py
+++ b/pypy/module/cpyext/test/test_bufferobject.py
@@ -2,7 +2,6 @@
from pypy.module.cpyext.test.test_api import BaseApiTest
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.module.cpyext.api import PyObject
-from pypy.module.cpyext.pyobject import Py_DecRef
class AppTestBufferObject(AppTestCpythonExtensionBase):
def test_FromMemory(self):
diff --git a/pypy/module/cpyext/test/test_bytesobject.py
b/pypy/module/cpyext/test/test_bytesobject.py
--- a/pypy/module/cpyext/test/test_bytesobject.py
+++ b/pypy/module/cpyext/test/test_bytesobject.py
@@ -10,7 +10,7 @@
PyString_AsEncodedObject, PyString_AsDecodedObject, _PyString_Eq,
_PyString_Join)
from pypy.module.cpyext.api import PyObjectP, PyObject, Py_ssize_tP,
generic_cpy_call
-from pypy.module.cpyext.pyobject import Py_DecRef, from_ref, make_ref
+from pypy.module.cpyext.pyobject import decref, from_ref, make_ref
from pypy.module.cpyext.buffer import PyObject_AsCharBuffer
from pypy.module.cpyext.api import PyTypeObjectPtr
@@ -485,7 +485,7 @@
assert py_str.c_ob_size == 10
assert py_str.c_ob_sval[1] == 'b'
assert py_str.c_ob_sval[10] == '\x00'
- Py_DecRef(space, ar[0])
+ decref(space, ar[0])
lltype.free(ar, flavor='raw')
def test_string_buffer(self, space):
@@ -504,7 +504,7 @@
assert generic_cpy_call(space, c_buf.c_bf_getreadbuffer,
py_obj, 0, ref) == 10
lltype.free(ref, flavor='raw')
- Py_DecRef(space, py_obj)
+ decref(space, py_obj)
def test_Concat(self, space):
ref = make_ref(space, space.wrap('abc'))
@@ -530,7 +530,7 @@
PyString_ConcatAndDel(space, ptr, ref2)
assert space.str_w(from_ref(space, ptr[0])) == 'abcdef'
assert ref2.c_ob_refcnt == prev_refcnf - 1
- Py_DecRef(space, ptr[0])
+ decref(space, ptr[0])
ptr[0] = lltype.nullptr(PyObject.TO)
ref2 = make_ref(space, space.wrap('foo'))
prev_refcnf = ref2.c_ob_refcnt
@@ -555,7 +555,7 @@
assert rffi.charp2str(bufp[0]) == 'text'
lltype.free(bufp, flavor='raw')
lltype.free(lenp, flavor='raw')
- Py_DecRef(space, ref)
+ decref(space, ref)
def test_intern(self, space):
buf = rffi.str2charp("test")
diff --git a/pypy/module/cpyext/test/test_methodobject.py
b/pypy/module/cpyext/test/test_methodobject.py
--- a/pypy/module/cpyext/test/test_methodobject.py
+++ b/pypy/module/cpyext/test/test_methodobject.py
@@ -2,7 +2,7 @@
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.module.cpyext.methodobject import PyMethodDef
from pypy.module.cpyext.api import ApiFunction
-from pypy.module.cpyext.pyobject import PyObject, make_ref, Py_DecRef
+from pypy.module.cpyext.pyobject import PyObject, make_ref
from pypy.module.cpyext.methodobject import (
PyDescr_NewMethod, PyCFunction)
from rpython.rtyper.lltypesystem import rffi, lltype
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
@@ -4,7 +4,7 @@
from pypy.interpreter.error import OperationError
from pypy.module.cpyext.test.test_api import BaseApiTest
from pypy.module.cpyext.pyobject import (
- PyObjectP, from_ref, make_ref, Py_DecRef)
+ PyObjectP, from_ref, make_ref, decref)
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.module.cpyext.number import (
PyIndex_Check, PyNumber_Check, PyNumber_Long, PyNumber_Int,
@@ -66,10 +66,10 @@
#
# We need to decref twice because PyNumber_Coerce does an incref and
# possibly changes the content of pp1 and pp2
- Py_DecRef(space, p1)
- Py_DecRef(space, pp1[0])
- Py_DecRef(space, p2)
- Py_DecRef(space, pp2[0])
+ decref(space, p1)
+ decref(space, pp1[0])
+ decref(space, p2)
+ decref(space, pp2[0])
lltype.free(pp1, flavor='raw')
lltype.free(pp2, flavor='raw')
@@ -88,10 +88,10 @@
assert PyFloat_Check(space, 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])
+ decref(space, pl)
+ decref(space, pf)
+ decref(space, ppl[0])
+ decref(space, ppf[0])
lltype.free(ppl, flavor='raw')
lltype.free(ppf, flavor='raw')
diff --git a/pypy/module/cpyext/test/test_structseq.py
b/pypy/module/cpyext/test/test_structseq.py
--- a/pypy/module/cpyext/test/test_structseq.py
+++ b/pypy/module/cpyext/test/test_structseq.py
@@ -2,7 +2,6 @@
from pypy.module.cpyext.test.test_api import BaseApiTest
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.module.cpyext.api import PyObject
-from pypy.module.cpyext.pyobject import Py_DecRef
class AppTestStructSeq(AppTestCpythonExtensionBase):
def test_StructSeq(self):
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -5,7 +5,7 @@
from pypy.module.cpyext.unicodeobject import (
Py_UNICODE, PyUnicodeObject, new_empty_unicode)
from pypy.module.cpyext.api import PyObjectP, PyObject
-from pypy.module.cpyext.pyobject import Py_DecRef, from_ref
+from pypy.module.cpyext.pyobject import decref, from_ref
from rpython.rtyper.lltypesystem import rffi, lltype
import sys, py
from pypy.module.cpyext.unicodeobject import *
@@ -220,7 +220,7 @@
res = PyUnicode_FromStringAndSize(space, s, 4)
w_res = from_ref(space, res)
- Py_DecRef(space, res)
+ decref(space, res)
assert space.unwrap(w_res) == u'sp\x09m'
rffi.free_charp(s)
@@ -243,7 +243,7 @@
assert py_uni.c_length == 10
assert py_uni.c_str[1] == 'b'
assert py_uni.c_str[10] == '\x00'
- Py_DecRef(space, ar[0])
+ decref(space, ar[0])
lltype.free(ar, flavor='raw')
def test_AsUTF8String(self, space):
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -29,7 +29,7 @@
from pypy.module.cpyext.modsupport import convert_method_defs
from pypy.module.cpyext.pyobject import (
PyObject, make_ref, from_ref, get_typedescr, make_typedescr,
- track_reference, Py_DecRef, as_pyobj)
+ track_reference, decref, as_pyobj)
from pypy.module.cpyext.slotdefs import (
slotdefs_for_tp_slots, slotdefs_for_wrappers, get_slot_tp_function,
llslot)
@@ -367,11 +367,11 @@
if not space.is_true(w_kwds):
w_kwds = None
+ subtype = rffi.cast(PyTypeObjectPtr, make_ref(space, w_subtype))
try:
- subtype = rffi.cast(PyTypeObjectPtr, make_ref(space, w_subtype))
w_obj = generic_cpy_call(space, tp_new, subtype, w_args, w_kwds)
finally:
- Py_DecRef(space, w_subtype)
+ decref(space, subtype)
return w_obj
@specialize.memo()
@@ -465,7 +465,7 @@
return PyMember_GetOne(
space, rffi.cast(rffi.CCHARP, pyref), self.member)
finally:
- Py_DecRef(space, pyref)
+ decref(space, pyref)
def member_delete(self, space, w_self):
assert isinstance(self, W_MemberDescr)
@@ -475,7 +475,7 @@
PyMember_SetOne(
space, rffi.cast(rffi.CCHARP, pyref), self.member, None)
finally:
- Py_DecRef(space, pyref)
+ decref(space, pyref)
def member_setter(self, space, w_self, w_value):
assert isinstance(self, W_MemberDescr)
@@ -485,7 +485,7 @@
PyMember_SetOne(
space, rffi.cast(rffi.CCHARP, pyref), self.member, w_value)
finally:
- Py_DecRef(space, pyref)
+ decref(space, pyref)
class W_PyCTypeObject(W_TypeObject):
@jit.dont_look_inside
@@ -571,7 +571,7 @@
pyref = make_ref(space, w_str)
ref[0] = PyString_AsString(space, pyref)
# Stolen reference: the object has better exist somewhere else
- Py_DecRef(space, pyref)
+ decref(space, pyref)
return space.len_w(w_str)
@slot_function([PyObject, Py_ssize_t, rffi.VOIDPP], lltype.Signed, error=-1)
@@ -584,7 +584,7 @@
pyref = make_ref(space, w_str)
ref[0] = PyUnicode_AS_UNICODE(space, pyref)
# Stolen reference: the object has better exist somewhere else
- Py_DecRef(space, pyref)
+ decref(space, pyref)
return PyUnicode_GET_DATA_SIZE(space, w_str)
@slot_function([PyObject, Py_ssize_t, rffi.CCHARPP], lltype.Signed, error=-1)
@@ -646,14 +646,14 @@
from pypy.module.cpyext.object import _dealloc
obj_pto = rffi.cast(PyTypeObjectPtr, obj)
base_pyo = rffi.cast(PyObject, obj_pto.c_tp_base)
- Py_DecRef(space, obj_pto.c_tp_bases)
- Py_DecRef(space, obj_pto.c_tp_mro)
- Py_DecRef(space, obj_pto.c_tp_cache) # let's do it like cpython
- Py_DecRef(space, obj_pto.c_tp_dict)
+ decref(space, obj_pto.c_tp_bases)
+ decref(space, obj_pto.c_tp_mro)
+ decref(space, obj_pto.c_tp_cache) # let's do it like cpython
+ decref(space, obj_pto.c_tp_dict)
if obj_pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
heaptype = rffi.cast(PyHeapTypeObject, obj)
- Py_DecRef(space, heaptype.c_ht_name)
- Py_DecRef(space, base_pyo)
+ decref(space, heaptype.c_ht_name)
+ decref(space, base_pyo)
_dealloc(space, obj)
@@ -664,7 +664,7 @@
if metatype:
flags = rffi.cast(lltype.Signed, metatype.c_tp_flags)
if not flags & Py_TPFLAGS_HEAPTYPE:
- Py_DecRef(space, w_metatype)
+ decref(space, metatype)
heaptype = lltype.malloc(PyHeapTypeObject.TO,
flavor='raw', zero=True,
@@ -756,7 +756,7 @@
flags = rffi.cast(lltype.Signed, pto.c_tp_flags)
if pto.c_tp_base != base_object_pto or flags & Py_TPFLAGS_HEAPTYPE:
pto.c_tp_new = pto.c_tp_base.c_tp_new
- Py_DecRef(space, base_object_pyo)
+ decref(space, base_object_pyo)
pto.c_tp_flags |= Py_TPFLAGS_READY
return pto
@@ -829,7 +829,7 @@
if not pto_as.c_bf_releasebuffer:
pto_as.c_bf_releasebuffer = base_as.c_bf_releasebuffer
finally:
- Py_DecRef(space, base_pyo)
+ decref(space, base_pyo)
def _type_realize(space, py_obj):
"""
@@ -922,7 +922,7 @@
pto.c_tp_getattro = llslot(space, PyObject_GenericGetAttr)
if w_obj.is_cpytype():
- Py_DecRef(space, pto.c_tp_dict)
+ decref(space, pto.c_tp_dict)
w_dict = w_obj.getdict(space)
# pass in the w_obj to convert any values that are
# unbound GetSetProperty into bound PyGetSetDescrObject
diff --git a/pypy/module/cpyext/unicodeobject.py
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -7,7 +7,7 @@
CONST_WSTRING, slot_function, cts, parse_dir)
from pypy.module.cpyext.pyerrors import PyErr_BadArgument
from pypy.module.cpyext.pyobject import (
- PyObject, PyObjectP, Py_DecRef, make_ref, from_ref, track_reference,
+ PyObject, PyObjectP, decref, make_ref, from_ref, track_reference,
make_typedescr, get_typedescr)
from pypy.module.cpyext.bytesobject import PyString_Check
from pypy.module.sys.interp_encoding import setdefaultencoding
@@ -84,7 +84,7 @@
@slot_function([PyObject], lltype.Void)
def unicode_dealloc(space, py_obj):
py_unicode = rffi.cast(PyUnicodeObject, py_obj)
- Py_DecRef(space, py_unicode.c_defenc)
+ decref(space, py_unicode.c_defenc)
if py_unicode.c_str:
lltype.free(py_unicode.c_str, flavor="raw")
@@ -460,7 +460,7 @@
try:
py_newuni = new_empty_unicode(space, newsize)
except MemoryError:
- Py_DecRef(space, ref[0])
+ decref(space, ref[0])
ref[0] = lltype.nullptr(PyObject.TO)
raise
to_cp = newsize
@@ -469,7 +469,7 @@
to_cp = oldsize
for i in range(to_cp):
py_newuni.c_str[i] = py_uni.c_str[i]
- Py_DecRef(space, ref[0])
+ decref(space, ref[0])
ref[0] = rffi.cast(PyObject, py_newuni)
return 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit