# Applying cfunc decorator to numba extension type

**URL:** <https://numba.discourse.group/t/applying-cfunc-decorator-to-numba-extension-type/2284>\
**Category:** Support: How do I do ...?\
**Created:** [November 21, 2023, 10:33pm UTC](https://numba.discourse.group/t/applying-cfunc-decorator-to-numba-extension-type/2284 "2023-11-21T22:33:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![agseaton](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/agseaton/32/939_2.png) [@agseaton](https://numba.discourse.group/u/agseaton)\
**Post date:** [November 21, 2023, 10:33pm UTC](https://numba.discourse.group/t/applying-cfunc-decorator-to-numba-extension-type/2284/1 "2023-11-21T22:33:45Z")

</div>

I’d like to create a JIT-compiled callback function that will be passed to a C++ library (via a pybind11 wrapper). The issue is that the library requires a callback that looks something like

bool callback\_func(cpp\_obj &obj);

where the cpp\_obj type is made available in python with pybind11.

By following the numba extension API documentation I’ve managed to get my callback function to jit compile via the @njit decorator, but I think what I really need is to use the @cfunc decorator (and the callback\_func.ctypes attribute) so that the library can call the callback without invoking the python interpreter.

Unfortunately, when I try this I get the error “TypeError: Cannot convert Numba type ‘cpp\_obj’ to ctypes type”.

Any thoughts on how I can get around this? Presumably I need to somehow define a ctypes type corresponding to the object and register that with numba?
