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: User data with closures?


On Thu, Feb 28, 2013 at 11:34 PM, The Devils Jester
<thedevilsjester@gmail.com> wrote:
> The ffi_prep_closure_loc function allows you to specify a pointer to
> user data which becomes part of the closure function.  I use this as
> an identification so that multiple objects can call the same closure
> and I can react to them in the closure function.
>
> My question is, is there a 'normal' way to set this data after the
> ffi_prep_closure_loc function has been called?

No, there's no support for that today.

> If not, would it be safe to create a "container" struct which holds my
> id, pass a pointer to a variable of that structs type, and change the
> value in the pointed to struct later?  (and would that achieve this
> goal?)

That should work.

> Baring either of those, do additional calls to ffi_prep_closure_loc
> completely recreate the closure?  What I mean is typically I call that
> function once, and then call the actual "created" function whenever I
> need to, but if I were to call ffi_prep_closure_loc every time before
> I call the "created" function, would that be a trivial call, or is it
> recreating the closure function with each call?

It would recreate the closure function each time.

AG


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