Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r67019:e971012143a5
Date: 2013-09-17 14:10 -0700
http://bitbucket.org/pypy/pypy/changeset/e971012143a5/
Log: store (app-level) pyfuncs in a cache and simply callback returns
diff --git a/pypy/module/cppyy/capi/cint_capi.py
b/pypy/module/cppyy/capi/cint_capi.py
--- a/pypy/module/cppyy/capi/cint_capi.py
+++ b/pypy/module/cppyy/capi/cint_capi.py
@@ -100,7 +100,9 @@
return obj.space.call_method(w_1, m2)
### TF1 ----------------------------------------------------------------------
-tfn_pyfuncs = {}
+class State(object):
+ def __init__(self, space):
+ self.tfn_pyfuncs = {}
_tfn_install = rffi.llexternal(
"cppyy_tfn_install",
@@ -138,11 +140,11 @@
raise TypeError("2nd argument is not a valid python callable")
fid = _tfn_install(funcname, npar)
- tfn_pyfuncs[fid] = pyfunc
+ state = space.fromcache(State)
+ state.tfn_pyfuncs[fid] = pyfunc
newargs_w = [args_w[1], space.wrap(fid), args_w[3], args_w[4],
space.wrap(npar)]
except (OperationError, TypeError, IndexError):
newargs_w = args_w[1:] # drop class
- pass
# return control back to the original, unpythonized overload
ol = tf1_class.get_overload("TF1")
@@ -407,11 +409,12 @@
# TODO: it actually can fail ...
@cpython_api([rffi.LONG, rffi.INT, rffi.DOUBLEP, rffi.DOUBLEP], rffi.DOUBLE,
error=CANNOT_FAIL)
def cppyy_tfn_callback(space, idx, npar, a0, a1):
- pyfunc = tfn_pyfuncs[idx]
+ state = space.fromcache(State)
+ pyfunc = state.tfn_pyfuncs[idx]
npar = int(npar)
from pypy.module._rawffi.interp_rawffi import unpack_simple_shape
- from pypy.module._rawffi.array import W_Array, W_ArrayInstance
+ from pypy.module._rawffi.array import W_Array
arr = space.interp_w(W_Array, unpack_simple_shape(space, space.wrap('d')))
address = rffi.cast(rffi.ULONG, a0)
arg0 = arr.fromaddress(space, address, 4)
@@ -422,7 +425,7 @@
result = space.call_function(pyfunc, arg0, arg1)
else:
result = space.call_function(pyfunc, arg0)
+ dresult = space.float_w(result)
except Exception:
- # TODO: error handling here ..
- return -1.
- return space.float_w(result)
+ dresult = -1.; # TODO: error handling here ..
+ return dresult
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit