In [1]:
%load_ext Cython

In [12]:
%%cython -a
from ctypes import CDLL, cast, c_double, c_void_p, CFUNCTYPE
sharelib = CDLL('/home/rotis/git/pycalphad/research/sharelib.so')
prototype = CFUNCTYPE(c_double, c_double, c_double)
functions = [prototype((f, sharelib)) for f in ('add', 'subtract', 'multiply', 'divide')]
cdef long[4] funcptrs
for i in range(4):
    funcptrs[i] = (cast(functions[i], c_void_p).value)

ctypedef double (*addfunc)(double x, double y)
cpdef double doubler(double a, double b, long[:] funcs):
    cdef double result = 0
    for i in range(4):
        result += (<addfunc>funcs[i])(a, b)
    return result
cdef args = (6, 10, funcptrs)
print(doubler(*args))


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-d51ff163b19e> in <module>()
----> 1 get_ipython().run_cell_magic('cython', '-a', "from ctypes import CDLL, cast, c_double, c_void_p, CFUNCTYPE\nsharelib = CDLL('/home/rotis/git/pycalphad/research/sharelib.so')\nprototype = CFUNCTYPE(c_double, c_double, c_double)\nfunctions = [prototype((f, sharelib)) for f in ('add', 'subtract', 'multiply', 'divide')]\ncdef long[4] funcptrs\nfor i in range(4):\n    funcptrs[i] = (cast(functions[i], c_void_p).value)\n\nctypedef double (*addfunc)(double x, double y)\ncpdef double doubler(double a, double b, long[:] funcs):\n    cdef double result = 0\n    for i in range(4):\n        result += (<addfunc>funcs[i])(a, b)\n    return result\nargs = (6, 10, funcptrs)\nprint(doubler(*args))")

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2291             magic_arg_s = self.var_expand(line, stack_depth)
   2292             with self.builtin_trap:
-> 2293                 result = fn(magic_arg_s, cell)
   2294             return result
   2295 

<decorator-gen-127> in cython(self, line, cell)

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/site-packages/Cython/Build/IpythonMagic.py in cython(self, line, cell)
    279             self._code_cache[key] = module_name
    280 
--> 281         module = imp.load_dynamic(module_name, module_path)
    282         self._import_all(module)
    283 

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/imp.py in load_dynamic(name, path, file)
    340         spec = importlib.machinery.ModuleSpec(
    341             name=name, loader=loader, origin=path)
--> 342         return _load(spec)
    343 
    344 else:

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/importlib/_bootstrap.py in _load(spec)

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/importlib/_bootstrap.py in _load_unlocked(spec)

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/importlib/_bootstrap.py in module_from_spec(spec)

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/importlib/_bootstrap_external.py in create_module(self, spec)

/home/rotis/anaconda/envs/calphadpy3/lib/python3.5/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

_cython_magic_8cfebc669676cf4a3128c09380b1cbf9.pyx in init _cython_magic_8cfebc669676cf4a3128c09380b1cbf9 (/home/rotis/.cache/ipython/cython/_cython_magic_8cfebc669676cf4a3128c09380b1cbf9.c:14994)()

_cython_magic_8cfebc669676cf4a3128c09380b1cbf9.pyx in _cython_magic_8cfebc669676cf4a3128c09380b1cbf9.doubler (/home/rotis/.cache/ipython/cython/_cython_magic_8cfebc669676cf4a3128c09380b1cbf9.c:1656)()

stringsource in View.MemoryView.memoryview_cwrapper (/home/rotis/.cache/ipython/cython/_cython_magic_8cfebc669676cf4a3128c09380b1cbf9.c:7653)()

stringsource in View.MemoryView.memoryview.__cinit__ (/home/rotis/.cache/ipython/cython/_cython_magic_8cfebc669676cf4a3128c09380b1cbf9.c:3928)()

TypeError: a bytes-like object is required, not 'list'

In [ ]: