[squeak-dev] Re: Squeak-dev Digest, Vol 77, Issue 10

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

[squeak-dev] Re: Squeak-dev Digest, Vol 77, Issue 10

Ricardo Moran
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