[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

Hi, I’m trying to make a Squeak interface to OpenCV, the computer vision library, and I have a few newbie questions about FFI:

1)      I managed to make an ExternalStructure for the IplImage and other simple structs such as CvScalar, CvSize, etc. I have a problem when trying to make the ExternalStructure for CvMat, which represents a matrix, because some members are unions. What should I do to make an ExternalStructure with unions?

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?

3)      Some OpenCV functions are declared as inline functions. I haven’t been able to access those functions from Squeak. Is this an expected behavior?

So far, these are the problems I encounter. As you may see from the questions above my knowledge of Squeak, FFI and C is pretty limited, so I would be very thankful if someone could give me a hand with these issues.

Thanks, bye



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Questions regarding FFI

Mariano Martinez Peck

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