def descr_callback(self, w_cdecl, w_python_callable, w_error, w_onerror): """\ Return a callback object or a decorator making such a callback object. 'cdecl' must name a C function pointer type. The callback invokes the specified 'python_callable' (which may be provided either directly or via a decorator). Important: the callback object must be manually kept alive for as long as the callback may be invoked from the C code.""" # w_ctype = self.ffi_type( w_cdecl, ACCEPT_STRING | ACCEPT_CTYPE | CONSIDER_FN_AS_FNPTR) space = self.space if not space.is_none(w_python_callable): return ccallback.make_callback(space, w_ctype, w_python_callable, w_error, w_onerror) else: # decorator mode: returns a single-argument function return space.appexec([w_ctype, w_error, w_onerror], """(ctype, error, onerror): import _cffi_backend return lambda python_callable: ( _cffi_backend.callback(ctype, python_callable, error, onerror))""")
def descr_callback(self, w_cdecl, w_python_callable, w_error, w_onerror): """\ Return a callback object or a decorator making such a callback object. 'cdecl' must name a C function pointer type. The callback invokes the specified 'python_callable' (which may be provided either directly or via a decorator). Important: the callback object must be manually kept alive for as long as the callback may be invoked from the C code.""" # w_ctype = self.ffi_type(w_cdecl, ACCEPT_STRING | ACCEPT_CTYPE | CONSIDER_FN_AS_FNPTR) space = self.space if not space.is_none(w_python_callable): return ccallback.make_callback(space, w_ctype, w_python_callable, w_error, w_onerror) else: # decorator mode: returns a single-argument function return space.appexec( [w_ctype, w_error, w_onerror], """(ctype, error, onerror): import _cffi_backend return lambda python_callable: ( _cffi_backend.callback(ctype, python_callable, error, onerror))""", )
def callback(space, w_ctype, w_callable, w_error=None, w_onerror=None): from pypy.module._cffi_backend.ccallback import make_callback return make_callback(space, w_ctype, w_callable, w_error, w_onerror)