Use callable cache for signal and vfunc closures
Submitted by Simon Feltman
To accomplish marshaling unification we need to do a bit of re-structuring of the callable cache so that it can provide a means for reverse marshaling of callbacks and vfuncs. The idea is to follow a strait forward OO programming approach with a base class "CallableCache" and various sub-classes to handle the different marshaling scenarios.
Initial sketch of the class hierarchy:
CallableCache FunctionCache ConstructorCache CCallbackCache FunctionWithInstanceCache MethodCache VFuncCache CallbackCache ClosureCache SignalClosureCache VFuncCallbackCache
These classes essentially match the "PyGIFunctionType" enum which is already stored as PyGICallableCache::function_type. The difference is instead of spreading conditional logic based on type throughout the code, we use specialized virtual functions in the various sub-classes to handle the same logic. See: https://git.gnome.org/browse/pygobject/tree/gi/pygi-cache.h?id=3.12.0#n72
CallableCache: Handles basic management of argument cache lists.
FunctionCache: The idea is this will handle any specializations or common functionality for callables which wrap external C functions that can be called from Python. It is unclear if this will be needed.
ConstructorCache: Specializes first argument type checking to require the class which is stripped away in invoke state init. https://git.gnome.org/browse/pygobject/tree/gi/pygi-invoke.c?id=3.12.0#n274
CCallbackCache: Specializes callable_info_invoke and additionally sets user_data: https://git.gnome.org/browse/pygobject/tree/gi/pygi-invoke.c?id=3.12.0#n725
FunctionWithInstanceCache: Handles common specializations of vfuncs and methods for dealing with instance arguments. https://git.gnome.org/browse/pygobject/tree/gi/pygi-cache.c?id=3.12.0#n503
CallbackCache: Common base class for wrapping Python functions which are called from C. This branch of the hierarchy handles the creation of ffi callbacks which gives us the possibility to remove the contents of pygi-argument.c and re-use argument marshaling iteration from the exiting cache mechanisms for things like: https://git.gnome.org/browse/pygobject/tree/gi/pygi-closure.c?id=3.12.0#n333 https://git.gnome.org/browse/pygobject/tree/gi/pygi-signal-closure.c?id=3.12.0#n68
ClosureCache: SignalClosureCache: VFuncCallbackCache: It is unclear what specializations will be needed here. One thing to note is an idea that for signal closures, we will no longer need to use GValue marshaling and instead generate ffi callbacks like we do for regular closures. Then use GCClosure which should perform better.