[squeak-dev] Questions regarding FFI

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

[squeak-dev] Questions regarding FFI

Ricardo Moran
Sorry, I sent it with the wrong subject. Here I go again:

On Wed, May 13, 2009 at 3:41 PM, Ricardo Moran <[hidden email]> wrote:
Thanks for the reply, Mariano! I tried your advice but I ended up with some "Could not coerce arguments" errors and crashing the VM several times :P. 
However, I tried something like this:

IplImage>>free
SqueakCV apiReleaseImage: handle asByteArrayPointer.

SqueakCV>>apiReleaseImage: doublePointer 
<apicall: void 'cvReleaseImage' (byte*) module: 'cxcore110.dll'>
^ self externalCallFailed


It appears to be working. I don't know if this is the right way to do it, though. I don't know either if overriding #free is ok and it would not bring problems later...


> 2)      To finalize objects the OpenCV library defines some functions such
> as cvReleaseImage, cvReleaseMat, etc. As far as I can tell, these functions
> receive a pointer-to-pointer as argument. How can I declare such a method in
> Squeak? Having one object, how can I get the pointer to that object? Should
> I use the #getHandle method?
>

In OpenDBX we have a functions like this for example:

    long odbx_init(odbx_t**, char*, char*, char*)

This is how I declare it:

apiInitialize: handle backend: backend host: host port: port
    <cdecl: long 'odbx_init' (ulong* char* char* char*) module: 'opendbx'>
    ^self externalCallFailed

Remember a pinter to a pointer is a long :)

And then in the code I do something like this:

handleArray := WordArray with: 0.
    err := OpenDBX current
                apiInitialize: handleArray
                backend: self backend
                host: aConnection settings host
                port: aConnection settings port.

Notice the WordArray.

I have no idea of 1) and 3) sorry.

I hope this helps. If this do help, perhaps we can put it in FFI wiki page.

Cheers,

Mariano




Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Questions regarding FFI

Mariano Martinez Peck


On Wed, May 13, 2009 at 5:57 PM, Ricardo Moran <[hidden email]> wrote:
Sorry, I sent it with the wrong subject. Here I go again:

On Wed, May 13, 2009 at 3:41 PM, Ricardo Moran <[hidden email]> wrote:
Thanks for the reply, Mariano! I tried your advice but I ended up with some "Could not coerce arguments" errors and crashing the VM several times :P. 
However, I tried something like this:

IplImage>>free
SqueakCV apiReleaseImage: handle asByteArrayPointer.

SqueakCV>>apiReleaseImage: doublePointer 
<apicall: void 'cvReleaseImage' (byte*) module: 'cxcore110.dll'>
^ self externalCallFailed


It appears to be working. I don't know if this is the right way to do it, though. I don't know either if overriding #free is ok and it would not bring problems later...

Sorry about that ;)  I didn't know about byte and asByteArrayPointer. It would be nice someone tell us if this is a better idea or not and give us the reasons.

Mariano

 

> 2)      To finalize objects the OpenCV library defines some functions such
> as cvReleaseImage, cvReleaseMat, etc. As far as I can tell, these functions
> receive a pointer-to-pointer as argument. How can I declare such a method in
> Squeak? Having one object, how can I get the pointer to that object? Should
> I use the #getHandle method?
>

In OpenDBX we have a functions like this for example:

    long odbx_init(odbx_t**, char*, char*, char*)

This is how I declare it:

apiInitialize: handle backend: backend host: host port: port
    <cdecl: long 'odbx_init' (ulong* char* char* char*) module: 'opendbx'>
    ^self externalCallFailed

Remember a pinter to a pointer is a long :)

And then in the code I do something like this:

handleArray := WordArray with: 0.
    err := OpenDBX current
                apiInitialize: handleArray
                backend: self backend
                host: aConnection settings host
                port: aConnection settings port.

Notice the WordArray.

I have no idea of 1) and 3) sorry.

I hope this helps. If this do help, perhaps we can put it in FFI wiki page.

Cheers,

Mariano