Author: Armin Rigo <[email protected]>
Branch: stacklet
Changeset: r46328:83ac79bf9a0e
Date: 2011-08-06 18:05 +0200
http://bitbucket.org/pypy/pypy/changeset/83ac79bf9a0e/
Log: Clean up: pass the 'config' object instead of the 'gcrootfinder'.
diff --git a/pypy/module/_stacklet/interp_stacklet.py
b/pypy/module/_stacklet/interp_stacklet.py
--- a/pypy/module/_stacklet/interp_stacklet.py
+++ b/pypy/module/_stacklet/interp_stacklet.py
@@ -15,11 +15,6 @@
def __init__(self, space, ec):
w_module = space.getbuiltinmodule('_stacklet')
self.space = space
- if (space.config.translation.gc == 'boehm'
- or space.config.translation.gc == 'ref'):
- self.gcrootfinder = 'n/a'
- else:
- self.gcrootfinder = space.config.translation.gcrootfinder
self.ec = ec
self.w_error = space.getattr(w_module, space.wrap('error'))
self.pending_exception = None
@@ -68,7 +63,8 @@
h = self.h
if h:
self.h = NULLHANDLE
- rstacklet.destroy(self.sthread.gcrootfinder, self.sthread.thrd, h)
+ space = self.sthread.space
+ rstacklet.destroy(space.config, self.sthread.thrd, h)
def consume_handle(self):
h = self.h
@@ -88,7 +84,7 @@
sthread = self.sthread
ec = sthread.ec
saved_frame_top = ec.topframeref
- h = rstacklet.switch(sthread.gcrootfinder, sthread.thrd, h)
+ h = rstacklet.switch(space.config, sthread.thrd, h)
ec.topframeref = saved_frame_top
return sthread.new_stacklet_object(h)
@@ -152,8 +148,7 @@
start_state.args = __args__
saved_frame_top = ec.topframeref
ec.topframeref = jit.vref_None
- h = rstacklet.new(sthread.gcrootfinder, sthread.thrd,
- new_stacklet_callback,
+ h = rstacklet.new(space.config, sthread.thrd, new_stacklet_callback,
lltype.nullptr(rffi.VOIDP.TO))
ec.topframeref = saved_frame_top
return sthread.new_stacklet_object(h)
diff --git a/pypy/rlib/rstacklet.py b/pypy/rlib/rstacklet.py
--- a/pypy/rlib/rstacklet.py
+++ b/pypy/rlib/rstacklet.py
@@ -55,22 +55,27 @@
# ____________________________________________________________
-def getgcclass(gcrootfinder):
+def getgcclass(config):
+ if (config is None or
+ config.translation.gc in ('ref', 'boehm', 'none')): # for tests
+ gcrootfinder = 'n/a'
+ else:
+ gcrootfinder = config.translation.gcrootfinder
gcrootfinder = gcrootfinder.replace('/', '_')
module = __import__('pypy.rlib._stacklet_%s' % gcrootfinder,
None, None, ['__doc__'])
return module.StackletGcRootFinder
getgcclass._annspecialcase_ = 'specialize:memo'
-def new(gcrootfinder, thrd, runfn, arg):
- c = getgcclass(gcrootfinder)
+def new(config, thrd, runfn, arg):
+ c = getgcclass(config)
return c.new(thrd, llhelper(run_fn, runfn), arg)
new._annspecialcase_ = 'specialize:arg(2)'
-def switch(gcrootfinder, thrd, h):
- c = getgcclass(gcrootfinder)
+def switch(config, thrd, h):
+ c = getgcclass(config)
return c.switch(thrd, h)
-def destroy(gcrootfinder, thrd, h):
- c = getgcclass(gcrootfinder)
+def destroy(config, thrd, h):
+ c = getgcclass(config)
c.destroy(thrd, h)
diff --git a/pypy/rlib/test/test_rstacklet.py b/pypy/rlib/test/test_rstacklet.py
--- a/pypy/rlib/test/test_rstacklet.py
+++ b/pypy/rlib/test/test_rstacklet.py
@@ -4,12 +4,10 @@
from pypy.translator.c.test.test_standalone import StandaloneTests
-STATUSMAX = 5000
-
-GCROOTFINDER = "n/a"
-
class Runner:
+ STATUSMAX = 5000
+ config = None
def init(self, seed):
self.thrd = rstacklet.newthread()
@@ -26,7 +24,7 @@
@here_is_a_test
def test_new(self):
print 'start'
- h = rstacklet.new(GCROOTFINDER, self.thrd, empty_callback,
+ h = rstacklet.new(self.config, self.thrd, empty_callback,
rffi.cast(rffi.VOIDP, 123))
print 'end', h
assert rstacklet.is_empty_handle(h)
@@ -40,11 +38,11 @@
@here_is_a_test
def test_simple_switch(self):
self.status = 0
- h = rstacklet.new(GCROOTFINDER, self.thrd, switchbackonce_callback,
+ h = rstacklet.new(self.config, self.thrd, switchbackonce_callback,
rffi.cast(rffi.VOIDP, 321))
assert not rstacklet.is_empty_handle(h)
self.nextstatus(2)
- h = rstacklet.switch(GCROOTFINDER, runner.thrd, h)
+ h = rstacklet.switch(self.config, runner.thrd, h)
self.nextstatus(4)
print 'end', h
assert rstacklet.is_empty_handle(h)
@@ -55,7 +53,7 @@
self.nextstep = -1
self.comefrom = -1
self.status = 0
- while self.status < STATUSMAX or self.any_alive():
+ while self.status < self.STATUSMAX or self.any_alive():
self.tasks[0].withdepth(self.random.genrand32() % 50)
def any_alive(self):
@@ -76,7 +74,7 @@
else:
res = 0
n = intmask(runner.random.genrand32() % 10)
- if n == self.n or (runner.status >= STATUSMAX and
+ if n == self.n or (runner.status >= runner.STATUSMAX and
not runner.tasks[n].h):
return 1
@@ -91,7 +89,7 @@
if not task.h:
# start a new stacklet
print "NEW", n
- h = rstacklet.new(GCROOTFINDER, runner.thrd,
+ h = rstacklet.new(runner.config, runner.thrd,
variousstackdepths_callback,
rffi.cast(rffi.VOIDP, n))
else:
@@ -99,7 +97,7 @@
print "switch to", n
h = task.h
task.h = lltype.nullptr(rstacklet.handle.TO)
- h = rstacklet.switch(GCROOTFINDER, runner.thrd, h)
+ h = rstacklet.switch(runner.config, runner.thrd, h)
print "back in self.n = %d, coming from %d" % (self.n,
runner.comefrom)
@@ -134,7 +132,7 @@
assert rffi.cast(lltype.Signed, arg) == 321
runner.nextstatus(1)
assert not rstacklet.is_empty_handle(h)
- h = rstacklet.switch(GCROOTFINDER, runner.thrd, h)
+ h = rstacklet.switch(runner.config, runner.thrd, h)
runner.nextstatus(3)
assert not rstacklet.is_empty_handle(h)
return h
@@ -192,8 +190,6 @@
class BaseTestStacklet(StandaloneTests):
def setup_class(cls):
- global GCROOTFINDER, STATUSMAX
- cls.old_values = GCROOTFINDER, STATUSMAX
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=True)
config.translation.gc = cls.gc
@@ -202,11 +198,12 @@
config.translation.gcrootfinder = cls.gcrootfinder
GCROOTFINDER = cls.gcrootfinder
cls.config = config
- STATUSMAX = 25000
+ cls.old_values = Runner.config, Runner.STATUSMAX
+ Runner.config = config
+ Runner.STATUSMAX = 25000
def teardown_class(cls):
- global GCROOTFINDER, STATUSMAX
- GCROOTFINDER, STATUSMAX = cls.old_values
+ Runner.config, Runner.STATUSMAX = cls.old_values
def test_demo1(self):
t, cbuilder = self.compile(entry_point)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit