[pypy-svn] r73723 - pypy/branch/cpython-extension/pypy/module/cpyext
xoraxax at codespeak.net
xoraxax at codespeak.net
Wed Apr 14 01:19:09 CEST 2010
Author: xoraxax
Date: Wed Apr 14 01:19:08 2010
New Revision: 73723
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/api.py
Log:
Insert call_external_function into generic_cpy_call. Translation to be checked.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py Wed Apr 14 01:19:08 2010
@@ -715,6 +715,29 @@
unrolling_arg_types = unrolling_iterable(enumerate(FT.ARGS))
RESULT_TYPE = FT.RESULT
+ # copied and modified from rffi.py
+ # The around-handlers are releasing the GIL in a threaded pypy.
+ # We need tons of care to ensure that no GC operation and no
+ # exception checking occurs while the GIL is released.
+ argnames = ', '.join(['a%d' % i for i in range(len(FT.ARGS))])
+ source = py.code.Source("""
+ def call_external_function(funcptr, %(argnames)s):
+ # NB. it is essential that no exception checking occurs here!
+ res = funcptr(%(argnames)s)
+ return res
+ """ % locals())
+ miniglobals = {'__name__': __name__, # for module name propagation
+ }
+ exec source.compile() in miniglobals
+ call_external_function = miniglobals['call_external_function']
+ call_external_function._dont_inline_ = True
+ call_external_function._annspecialcase_ = 'specialize:ll'
+ call_external_function._gctransformer_hint_close_stack_ = True
+ call_external_function = func_with_new_name(call_external_function,
+ 'ccall_' + name)
+ # don't inline, as a hack to guarantee that no GC pointer is alive
+ # anywhere in call_external_function
+
@specialize.ll()
def generic_cpy_call(space, func, *args):
boxed_args = ()
@@ -733,7 +756,7 @@
boxed_args += (arg,)
else:
boxed_args += (arg,)
- result = func(*boxed_args)
+ result = call_external_function(func, *boxed_args)
try:
if RESULT_TYPE is PyObject:
if result is None:
More information about the Pypy-commit
mailing list