def load_ool_module(): """ Compile an out-of-line module, return the corresponding ffi and module objects. """ from cffi import FFI defs = """ double sin(double x); double cos(double x); void vsSin(int n, float* x, float* y); void vdSin(int n, double* x, double* y); int foo(int a, int b, int c); """ source = """ static int foo(int a, int b, int c) { return a + b * c; } void vsSin(int n, float* x, float* y) { int i; for (i=0; i<n; i++) y[i] = sin(x[i]); } void vdSin(int n, double* x, double* y) { int i; for (i=0; i<n; i++) y[i] = sin(x[i]); } """ ffi = FFI() ffi.set_source('cffi_usecases_ool', source) ffi.cdef(defs, override=True) tmpdir = static_temp_directory('test_cffi') ffi.compile(tmpdir=tmpdir) sys.path.append(tmpdir) try: import cffi_usecases_ool as mod cffi_support.register_module(mod) return mod.ffi, mod finally: sys.path.remove(tmpdir)
def setUp(self): self.tmpdir = static_temp_directory('test_pycc') # Make sure temporary files and directories created by # distutils don't clutter the top-level /tmp tempfile.tempdir = self.tmpdir
def setUp(self): self.tmpdir = static_temp_directory('test_pycc')
int i; for (i=0; i<n; i++) y[i] = sin(x[i]); } void vdSin(int n, double* x, double* y) { int i; for (i=0; i<n; i++) y[i] = sin(x[i]); } """ ffi_ool = FFI() ffi.set_source('cffi_usecases_ool', source) ffi.cdef(defs, override=True) tmpdir = static_temp_directory('test_cffi') ffi.compile(tmpdir=tmpdir) sys.path.append(tmpdir) try: import cffi_usecases_ool cffi_support.register_module(cffi_usecases_ool) cffi_sin_ool = cffi_usecases_ool.lib.sin cffi_cos_ool = cffi_usecases_ool.lib.cos cffi_foo = cffi_usecases_ool.lib.foo vsSin = cffi_usecases_ool.lib.vsSin vdSin = cffi_usecases_ool.lib.vdSin finally: sys.path.remove(tmpdir) def use_cffi_sin(x):