Alien callback thunk as ExternalAddress?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Alien callback thunk as ExternalAddress?

Schwab,Wilhelm K
I am getting near to jumping off the callback cliff.  My problem is that I have a generated external structure that expects a void pointer (actually a function pointer).  The setter sends #getHandle.  I tried to hot-wire that by defining CallbackThunk>>getHandle to answer the #address.

Is there a way to get an ExternalAddress that points to the thunk?  Should I even be asking this question? :)

Bill



Reply | Threaded
Open this post in threaded view
|

Re: Alien callback thunk as ExternalAddress?

Eliot Miranda-2


On Wed, Mar 21, 2012 at 4:01 PM, Schwab,Wilhelm K <[hidden email]> wrote:
I am getting near to jumping off the callback cliff.  My problem is that I have a generated external structure that expects a void pointer (actually a function pointer).  The setter sends #getHandle.  I tried to hot-wire that by defining CallbackThunk>>getHandle to answer the #address.

But FFICallbackThunk already implements address (inherited from Alien).  Why getHandle?
 

Is there a way to get an ExternalAddress that points to the thunk?  Should I even be asking this question? :)

I *think* it should be
    ExternalAddress new fromInteger: anFFICallbackThunk address
 

Bill






--
best,
Eliot

Reply | Threaded
Open this post in threaded view
|

Re: Alien callback thunk as ExternalAddress?

Schwab,Wilhelm K
Eliot,

I have a lot of FFI code already written, so I am hoping to drop Alien callbacks into FFI, and a structure is being a real pain.  I'll try you suggestion below, and then maybe alter the struct definition to contain integers vs. a pointer, into which FFI is making *certain* that I put only external addresses.

After moving to 1.3, I had to tweak some things where I originally passed null pointers, and now integers appear to be required :(  Similar forces might be at work here.  CogVM, Ubuntu Lucid.

Thanks!

Bill




From: [hidden email] [[hidden email]] on behalf of Eliot Miranda [[hidden email]]
Sent: Wednesday, March 21, 2012 8:18 PM
To: [hidden email]
Subject: Re: [Pharo-project] Alien callback thunk as ExternalAddress?



On Wed, Mar 21, 2012 at 4:01 PM, Schwab,Wilhelm K <[hidden email]> wrote:
I am getting near to jumping off the callback cliff.  My problem is that I have a generated external structure that expects a void pointer (actually a function pointer).  The setter sends #getHandle.  I tried to hot-wire that by defining CallbackThunk>>getHandle to answer the #address.

But FFICallbackThunk already implements address (inherited from Alien).  Why getHandle?
 

Is there a way to get an ExternalAddress that points to the thunk?  Should I even be asking this question? :)

I *think* it should be
    ExternalAddress new fromInteger: anFFICallbackThunk address
 

Bill






--
best,
Eliot

Reply | Threaded
Open this post in threaded view
|

Re: Alien callback thunk as ExternalAddress?

Schwab,Wilhelm K
In reply to this post by Eliot Miranda-2
Eliot,

It turns out that I had already done the #fromInteger: game, but your reply/confirmation gave me a brief second wind.  I added #asExternalAddress (doing the obvious thing given your reply) to both callback thunks and to GSL memory objects (handle bodies that have subclasses for vectors, wavelet entrails, etc.). I took one FFI call parameter from long to struct*.  That was interesting, because getHandle asInteger was giving me a *huge* number; the struct* argument worked where long failed me (it's usually the other way around).

I am now at the point of getting an error in a method being called from a callback!!!  That's a nice problem to have :)  Somehow, I have to figure out how to get one of my handle bodies wrapped around an Alien argument.  Whatever I do will also want to work with non-aliens because I call (with some trickery) the same method myself to generate sample data.

As Sig said, the debugger is available inside of callbacks - that's going to be a huge help.  It's time to shut down for the day or I will hate myself in the morning.

More to come.  Thanks!!!!

Bill





From: [hidden email] [[hidden email]] on behalf of Eliot Miranda [[hidden email]]
Sent: Wednesday, March 21, 2012 8:18 PM
To: [hidden email]
Subject: Re: [Pharo-project] Alien callback thunk as ExternalAddress?



On Wed, Mar 21, 2012 at 4:01 PM, Schwab,Wilhelm K <[hidden email]> wrote:
I am getting near to jumping off the callback cliff.  My problem is that I have a generated external structure that expects a void pointer (actually a function pointer).  The setter sends #getHandle.  I tried to hot-wire that by defining CallbackThunk>>getHandle to answer the #address.

But FFICallbackThunk already implements address (inherited from Alien).  Why getHandle?
 

Is there a way to get an ExternalAddress that points to the thunk?  Should I even be asking this question? :)

I *think* it should be
    ExternalAddress new fromInteger: anFFICallbackThunk address
 

Bill






--
best,
Eliot