This question follows from here . However, the previous question was formulated so poorly (actually erroneously) that it was suggested to ask again from scratch.
I have a table of pointers to C functions.
Some C-codes (let's call it lib-X) have a basic building block (let them call it an X-object). Each X object can call functions in this table.
These table functions usually have different signatures (see typedefs here ), although some functions may share the same signature. The table contains about 100 of these functions.
In C ++, I have an associated Final: Base class for every X object.
And I want to redirect these calls to the corresponding C ++ Final instance corresponding to the X-object, but I want to enclose this in try / catch, since the C ++ consumer can provide Final buggies.
So, I have a C ++ base class that has a virtual function for every record in the table.
Then I have a final C ++ class (maybe a lot: Final1 Final2 Final3, etc.) that comes from the base class.
So now I just need to write a handler that
Gets the first parameter "self" (which will always be a pointer to the X-object that called the function)
Gets the associated C ++ base class instance.
Inside the catch try block, the corresponding virtual function is called, forwarding all other parameters with
... which will actually cause an override in Final.
This is a bit like trying to understand the plot for Inception. lib-X is actually a Python runtime, although I am trying to keep the general.
The fact is that there are dozens of these functions, and this leads to some very dirty and actionless C ++ code - if I need to manually write a trampoline function for each of them, which looks like this:
extern "C" PyObject *call_handler( PyObject *self, PyObject *args, PyObject *kw ) { try { PythonExtensionBase *p = getPythonExtensionBase( self ); if( kw != NULL ) return new_reference_to( p->call( Object(args), :Object(kw) ) ); else return new_reference_to( p->call( Object(args), Object() ) ); } catch( Py::Exception & ) { return NULL;
(source here )
I am trying to create a compact design that allows this safe batumina.
My current progress [REMOVED, see answer below]