[pypy-commit] pypy cpyext-cleanup: Move rawrefcount init code out of build_bridge()
rlamy
pypy.commits at gmail.com
Thu Jan 5 08:49:14 EST 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: cpyext-cleanup
Changeset: r89376:95ae01dcc691
Date: 2017-01-05 13:48 +0000
http://bitbucket.org/pypy/pypy/changeset/95ae01dcc691/
Log: Move rawrefcount init code out of build_bridge()
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -13,7 +13,9 @@
atexit_funcs = []
def setup_after_space_initialization(self):
- self.space.fromcache(State).build_api(self.space)
+ state = self.space.fromcache(State)
+ state.setup_rawrefcount()
+ state.build_api()
def startup(self, space):
space.fromcache(State).startup(space)
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1068,25 +1068,11 @@
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
- def dealloc_trigger():
- from pypy.module.cpyext.pyobject import decref
- print 'dealloc_trigger...'
- while True:
- ob = rawrefcount.next_dead(PyObject)
- if not ob:
- break
- print 'deallocating PyObject', ob
- decref(space, ob)
- print 'dealloc_trigger DONE'
- return "RETRY"
- rawrefcount.init(dealloc_trigger)
-
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
-
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
for name, (typ, expr) in GLOBALS.iteritems():
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
@@ -54,21 +54,25 @@
"Function returned an error result without setting an "
"exception")
- def build_api(self, space):
- """NOT_RPYTHON
- This function is called when at object space creation,
- and drives the compilation of the cpyext library
- """
- from pypy.module.cpyext import api
- state = self.space.fromcache(State)
+ def setup_rawrefcount(self):
+ space = self.space
if not self.space.config.translating:
- state.api_lib = str(api.build_bridge(self.space))
+ def dealloc_trigger():
+ from pypy.module.cpyext.pyobject import PyObject, decref
+ print 'dealloc_trigger...'
+ while True:
+ ob = rawrefcount.next_dead(PyObject)
+ if not ob:
+ break
+ print 'deallocating PyObject', ob
+ decref(space, ob)
+ print 'dealloc_trigger DONE'
+ return "RETRY"
+ rawrefcount.init(dealloc_trigger)
else:
- api.setup_library(self.space)
- #
- if self.space.config.translation.gc == "boehm":
- action = BoehmPyObjDeallocAction(self.space)
- self.space.actionflag.register_periodic_action(action,
+ if space.config.translation.gc == "boehm":
+ action = BoehmPyObjDeallocAction(space)
+ space.actionflag.register_periodic_action(action,
use_bytecode_counter=True)
else:
pyobj_dealloc_action = PyObjDeallocAction(space)
@@ -77,6 +81,17 @@
llhelper(rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER,
self.dealloc_trigger))
+ def build_api(self):
+ """NOT_RPYTHON
+ This function is called when at object space creation,
+ and drives the compilation of the cpyext library
+ """
+ from pypy.module.cpyext import api
+ if not self.space.config.translating:
+ self.api_lib = str(api.build_bridge(self.space))
+ else:
+ api.setup_library(self.space)
+
def install_dll(self, eci):
"""NOT_RPYTHON
Called when the dll has been compiled"""
More information about the pypy-commit
mailing list