How to pass a C structure to a C library callback?
Shockwave
vinfobag at gmail.com
Thu Mar 3 00:21:56 UTC 2011
Andrew, I know you probably know about this, but just as a reminder. When
the pointer/pmc is passed to the external C function, that C function won't
have access to the INTERP pointer. If a PMC is passed to the C function, it
may be difficult to extract the void*.
Regards
-----Original Message-----
From: Andrew Whitworth [mailto:wknight8111 at gmail.com]
Sent: Wednesday, March 02, 2011 4:27 PM
To: Peter Lobsinger
Cc: Shockwave; parrot-dev at lists.parrot.org
Subject: Re: How to pass a C structure to a C library callback?
On Wed, Mar 2, 2011 at 4:22 PM, Peter Lobsinger <plobsing at gmail.com> wrote:
> Passing around pointers as ints is not advisable. We have pointer
> wrapper PMC types for this. You can wrap a pointer by doing something
> such as:
>
> PMC *ptr_pmc = Parrot_pmc_new(interp, enum_class_Ptr);
> VTABLE_set_pointer(interp, ptr_pmc, (void *)wb);
>
> Sorry, I'm not sure what the embedding API equivalent is. Passing such
> PMCs to NCI functions will work properly.
There isn't anything obvious in the embedding API right now to do this. I'll
add in routines tonight to wrap a native pointer in a PMC.
--Andrew Whitworth
More information about the parrot-dev
mailing list