public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* User data with closures?
@ 2013-03-01  4:34 The Devils Jester
  2013-03-01  4:49 ` Anthony Green
  0 siblings, 1 reply; 2+ messages in thread
From: The Devils Jester @ 2013-03-01  4:34 UTC (permalink / raw)
  To: libffi-discuss

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?

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?)

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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: User data with closures?
  2013-03-01  4:34 User data with closures? The Devils Jester
@ 2013-03-01  4:49 ` Anthony Green
  0 siblings, 0 replies; 2+ messages in thread
From: Anthony Green @ 2013-03-01  4:49 UTC (permalink / raw)
  To: The Devils Jester; +Cc: libffi-discuss

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-01  4:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-01  4:34 User data with closures? The Devils Jester
2013-03-01  4:49 ` Anthony Green

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).