wlav avatar wlav committed e971012

store (app-level) pyfuncs in a cache and simply callback returns

Comments (0)

Files changed (1)

pypy/module/cppyy/capi/cint_capi.py

     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",
             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")
 # 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)
             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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.