[pypy-commit] pypy callback-jit: hack with 2 levels of wrappers
fijal
noreply at buildbot.pypy.org
Wed Dec 26 22:04:14 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: callback-jit
Changeset: r59576:5e84a61755b1
Date: 2012-12-26 23:03 +0200
http://bitbucket.org/pypy/pypy/changeset/5e84a61755b1/
Log: hack with 2 levels of wrappers
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -278,21 +278,26 @@
callable_name = getattr(callable, '__name__', '?')
if callbackholder is not None:
callbackholder.callbacks[callable] = True
+ callable_name_descr = str(callable).replace('"', '\\"')
args = ', '.join(['a%d' % i for i in range(len(TP.TO.ARGS))])
source = py.code.Source(r"""
- def wrapper(%s): # no *args - no GIL for mallocing the tuple
+ def inner_wrapper(%(args)s):
+ callback_hook = aroundstate.callback_hook
+ if callback_hook:
+ callback_hook("%(callable_name_descr)s")
+ return callable(%(args)s)
+ inner_wrapper._never_inline_ = True
+
+ def wrapper(%(args)s): # no *args - no GIL for mallocing the tuple
llop.gc_stack_bottom(lltype.Void) # marker for trackgcroot.py
if aroundstate is not None:
after = aroundstate.after
if after:
after()
- callback_hook = aroundstate.callback_hook
- if callback_hook:
- callback_hook(llstr("%s"))
# from now on we hold the GIL
stackcounter.stacks_counter += 1
try:
- result = callable(%s)
+ result = inner_wrapper(%(args)s)
except Exception, e:
os.write(2,
"Warning: uncaught exception in callback: %%s %%s\n" %%
@@ -310,7 +315,7 @@
# by llexternal, it is essential that no exception checking occurs
# after the call to before().
return result
- """ % (args, str(callable).replace('"', '\\"'), args))
+ """ % locals())
miniglobals = locals().copy()
miniglobals['Exception'] = Exception
miniglobals['os'] = os
More information about the pypy-commit
mailing list