Author: Armin Rigo <ar...@tunes.org> Branch: boehm-rawrefcount Changeset: r86924:c4bc3be86d15 Date: 2016-09-07 13:04 +0200 http://bitbucket.org/pypy/pypy/changeset/c4bc3be86d15/
Log: For Boehm, we can't pass the callback to rawrefcount.init() and we need instead to regularly check ourselves for dead objects. diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py --- a/pypy/module/cpyext/state.py +++ b/pypy/module/cpyext/state.py @@ -1,7 +1,7 @@ from rpython.rlib.objectmodel import we_are_translated from rpython.rtyper.lltypesystem import rffi, lltype from pypy.interpreter.error import OperationError, oefmt -from pypy.interpreter.executioncontext import AsyncAction +from pypy.interpreter import executioncontext from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.annlowlevel import llhelper from rpython.rlib.rdynload import DLLHANDLE @@ -14,8 +14,9 @@ self.reset() self.programname = lltype.nullptr(rffi.CCHARP.TO) self.version = lltype.nullptr(rffi.CCHARP.TO) - pyobj_dealloc_action = PyObjDeallocAction(space) - self.dealloc_trigger = lambda: pyobj_dealloc_action.fire() + if space.config.translation.gc != "boehm": + pyobj_dealloc_action = PyObjDeallocAction(space) + self.dealloc_trigger = lambda: pyobj_dealloc_action.fire() def reset(self): from pypy.module.cpyext.modsupport import PyMethodDef @@ -67,6 +68,11 @@ state.api_lib = str(api.build_bridge(self.space)) else: api.setup_library(self.space) + # + if self.space.config.translation.gc == "boehm": + action = BoehmPyObjDeallocAction(self.space) + self.space.actionflag.register_periodic_action(action, + use_bytecode_counter=True) def install_dll(self, eci): """NOT_RPYTHON @@ -84,8 +90,10 @@ from pypy.module.cpyext.api import init_static_data_translated if we_are_translated(): - rawrefcount.init(llhelper(rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER, - self.dealloc_trigger)) + if space.config.translation.gc != "boehm": + rawrefcount.init( + llhelper(rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER, + self.dealloc_trigger)) init_static_data_translated(space) setup_new_method_def(space) @@ -143,15 +151,23 @@ self.extensions[path] = w_copy -class PyObjDeallocAction(AsyncAction): +def _rawrefcount_perform(space): + from pypy.module.cpyext.pyobject import PyObject, decref + while True: + py_obj = rawrefcount.next_dead(PyObject) + if not py_obj: + break + decref(space, py_obj) + +class PyObjDeallocAction(executioncontext.AsyncAction): """An action that invokes _Py_Dealloc() on the dying PyObjects. """ + def perform(self, executioncontext, frame): + _rawrefcount_perform(self.space) +class BoehmPyObjDeallocAction(executioncontext.PeriodicAsyncAction): + # This variant is used with Boehm, which doesn't have the explicit + # callback. Instead we must periodically check ourselves. def perform(self, executioncontext, frame): - from pypy.module.cpyext.pyobject import PyObject, decref - - while True: - py_obj = rawrefcount.next_dead(PyObject) - if not py_obj: - break - decref(self.space, py_obj) + if we_are_translated(): + _rawrefcount_perform(self.space) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit