This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: generic "call-forwarding" closure


On Tue, May 12, 2009 at 11:28 PM, Anthony Green <green@redhat.com> wrote:
> nf2 wrote:
>>
>> Hi,
>>
>> I'm pretty new to libffi and got the following problem:
>>
>> For auto-generating C++ language bindings for C libraries i would like
>> to use a ffi closure to pass an extra user-data argument to the
>> callback handler (for callbacks, which don't provide a user_data arg).
>> I wonder if it would be possible to write a generic ffi closure, which
>> just appends a void * user_data to the argument list and passes the
>> call on with ffi_call (without knowledge about the other arguments)?
>>
>
> I'm not really following this. ?Could you please give an example of how
> you'd use this?
>

well - for instance i got the C callback

typedef void (*foo)(int a, int b);

and the callback register function:

void register_foo(foo callback);


i want to register the following callback handler, which has an
additional user_data parameter:

void my_foo(int a, int b, void * user_data);

thus i probably have to create a ffi closure which holds the user_data
and then calls my_foo(a, b, user_data). the problem is that i would
like to use this closure for all kind of callbacks with different
argument lists - therefore i cannot define the exact layout of the
particular parameters with ffi_prep_cif()).

my requirement would be a generic closure, which doesn't know about
the exact types of the parameters,  but - on invocation - just calls
another function pushing a copy of the parameters stack frame onto the
stack again,  extended with the user_data pointer...

Regards
Norbert


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]