I'm writing an application working with plugins. There are two types of plugins: Engine
and Model
. Engine
objects have an update()
method that call the Model.velocity()
method.
For performance reasons these methods are allowed to be written in C. This means that sometimes they will be written in Python and sometimes written in C.
The problem is that this forces to do an expensive Python function call of Model.velocity()
in Engine.update()
(and also reacquiring the GIL). I thought about adding something like Model.get_velocity_c_func()
to the API, that would allow Model
implementations to return a pointer to the C version of their velocity()
method if available, making possible for Engine
to do a faster C function call.
What data type should I use to pass the function pointer ? And is this a good design at all, maybe there is an easier way ?