Author: Armin Rigo <ar...@tunes.org> Branch: cpyext-gc-support-2 Changeset: r82264:2f74cfc0598e Date: 2016-02-15 15:03 +0100 http://bitbucket.org/pypy/pypy/changeset/2f74cfc0598e/
Log: Add one missing 'result_borrowed' to weakrefobject.py. Add comments to various other similar places 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 @@ -14,7 +14,8 @@ PyDict_Check, PyDict_CheckExact = build_type_checkers("Dict") -@cpython_api([PyObject, PyObject], PyObject, error=CANNOT_FAIL, result_borrowed=True) +@cpython_api([PyObject, PyObject], PyObject, error=CANNOT_FAIL, + result_borrowed=True) def PyDict_GetItem(space, w_dict, w_key): try: w_res = space.getitem(w_dict, w_key) @@ -22,7 +23,7 @@ return None # NOTE: this works so far because all our dict strategies store # *values* as full objects, which stay alive as long as the dict is - # alive and not modified. + # alive and not modified. So we can return a borrowed ref. return w_res @cpython_api([PyObject, PyObject, PyObject], rffi.INT_real, error=-1) @@ -61,7 +62,7 @@ w_res = None # NOTE: this works so far because all our dict strategies store # *values* as full objects, which stay alive as long as the dict is - # alive and not modified. + # alive and not modified. So we can return a borrowed ref. return w_res @cpython_api([PyObject, CONST_STRING], rffi.INT_real, error=-1) diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py --- a/pypy/module/cpyext/import_.py +++ b/pypy/module/cpyext/import_.py @@ -1,7 +1,6 @@ from pypy.interpreter import module from pypy.module.cpyext.api import ( generic_cpy_call, cpython_api, PyObject, CONST_STRING) -from pypy.module.cpyext.pyobject import borrow_from from rpython.rtyper.lltypesystem import lltype, rffi from pypy.interpreter.error import OperationError from pypy.interpreter.module import Module @@ -56,7 +55,7 @@ from pypy.module.imp.importing import reload return reload(space, w_mod) -@cpython_api([CONST_STRING], PyObject) +@cpython_api([CONST_STRING], PyObject, result_borrowed=True) def PyImport_AddModule(space, name): """Return the module object corresponding to a module name. The name argument may be of the form package.module. First check the modules @@ -74,14 +73,16 @@ w_mod = check_sys_modules_w(space, modulename) if not w_mod or space.is_w(w_mod, space.w_None): w_mod = Module(space, space.wrap(modulename)) - return borrow_from(None, w_mod) + space.setitem(space.sys.get('modules'), space.wrap(modulename), w_mod) + # return a borrowed ref --- assumes one copy in sys.modules + return w_mod -@cpython_api([], PyObject) +@cpython_api([], PyObject, result_borrowed=True) def PyImport_GetModuleDict(space): """Return the dictionary used for the module administration (a.k.a. sys.modules). Note that this is a per-interpreter variable.""" w_modulesDict = space.sys.get('modules') - return borrow_from(None, w_modulesDict) + return w_modulesDict # borrowed ref @cpython_api([rffi.CCHARP, PyObject], PyObject) def PyImport_ExecCodeModule(space, name, w_code): diff --git a/pypy/module/cpyext/listobject.py b/pypy/module/cpyext/listobject.py --- a/pypy/module/cpyext/listobject.py +++ b/pypy/module/cpyext/listobject.py @@ -51,7 +51,8 @@ "list index out of range")) w_list.ensure_object_strategy() # make sure we can return a borrowed obj # XXX ^^^ how does this interact with CPyListStrategy? - return w_list.getitem(index) + w_res = w_list.getitem(index) + return w_res # borrowed ref @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1) 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, borrow_from) + PyObject, PyObjectP, make_ref, from_ref, Py_DecRef) from pypy.module.cpyext.state import State from pypy.module.cpyext.import_ import PyImport_Import from rpython.rlib import rposix, jit @@ -33,7 +33,7 @@ state = space.fromcache(State) if state.operror is None: return None - return state.operror.w_type + return state.operror.w_type # borrowed ref @cpython_api([], lltype.Void) def PyErr_Clear(space): diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py --- a/pypy/module/cpyext/sequence.py +++ b/pypy/module/cpyext/sequence.py @@ -64,7 +64,7 @@ else: assert isinstance(w_obj, tupleobject.W_TupleObject) w_res = w_obj.wrappeditems[index] - return w_res + return w_res # borrowed ref @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL) def PySequence_Fast_GET_SIZE(space, w_obj): diff --git a/pypy/module/cpyext/tupleobject.py b/pypy/module/cpyext/tupleobject.py --- a/pypy/module/cpyext/tupleobject.py +++ b/pypy/module/cpyext/tupleobject.py @@ -4,7 +4,7 @@ build_type_checkers, PyObjectFields, cpython_struct, bootstrap_function) from pypy.module.cpyext.pyobject import (PyObject, PyObjectP, Py_DecRef, - borrow_from, make_ref, from_ref, decref, + make_ref, from_ref, decref, track_reference, make_typedescr, get_typedescr) from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall from pypy.objspace.std.tupleobject import W_TupleObject @@ -148,7 +148,7 @@ if index < 0 or index >= size: raise OperationError(space.w_IndexError, space.wrap("tuple index out of range")) - return ref.c_ob_item[index] + return ref.c_ob_item[index] # borrowed ref @cpython_api([PyObject], Py_ssize_t, error=-1) def PyTuple_Size(space, ref): 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 @@ -646,7 +646,7 @@ name = space.str_w(w_name) w_obj = w_type.lookup(name) # this assumes that w_obj is not dynamically created, but will stay alive - # until w_type is modified or dies + # until w_type is modified or dies. Assuming this, we return a borrowed ref return w_obj @cpython_api([PyTypeObjectPtr], lltype.Void) diff --git a/pypy/module/cpyext/weakrefobject.py b/pypy/module/cpyext/weakrefobject.py --- a/pypy/module/cpyext/weakrefobject.py +++ b/pypy/module/cpyext/weakrefobject.py @@ -1,5 +1,5 @@ from pypy.module.cpyext.api import cpython_api -from pypy.module.cpyext.pyobject import PyObject, borrow_from +from pypy.module.cpyext.pyobject import PyObject from pypy.module._weakref.interp__weakref import W_Weakref, proxy @cpython_api([PyObject, PyObject], PyObject) @@ -30,19 +30,19 @@ """ return proxy(space, w_obj, w_callback) -@cpython_api([PyObject], PyObject) +@cpython_api([PyObject], PyObject, result_borrowed=True) def PyWeakref_GetObject(space, w_ref): """Return the referenced object from a weak reference. If the referent is no longer live, returns None. This function returns a borrowed reference. """ - return PyWeakref_GET_OBJECT(space, w_ref) + return space.call_function(w_ref) # borrowed ref @cpython_api([PyObject], PyObject, result_borrowed=True) def PyWeakref_GET_OBJECT(space, w_ref): """Similar to PyWeakref_GetObject(), but implemented as a macro that does no error checking. """ - return space.call_function(w_ref) + return space.call_function(w_ref) # borrowed ref @cpython_api([PyObject], PyObject) def PyWeakref_LockObject(space, w_ref): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit