From: Sam S. <sd...@gn...> - 2004-02-23 15:20:33
|
> * Kaz Kylheku <xn...@nf...g> [2004-02-17 11:00:56 -0800]: > > On Tue, 17 Feb 2004, Sam Steingold wrote: > >> 2. How do I interface to >> <http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/matgetdir.shtml>? >> char **matGetDir(MATFile *mfp, int *num); >> What is the return value? >> Also, the documentation appears to indicate that what is actually >> returned is (char*[mxMAXNAM]), not (char**): why would they mention > > This is not possible; a C function cannot return an array. :) > > I suspect that your actual suspiction is that it might be > ``char (*)[mxMAXNAM]''. In other words, the pointer to an array of > mxMAXNAM characters (or a pointer to the first element of an > array of arrays, whose elements are arrays of mxMAXNAM characters). > >> mxCalloc() otherwise? > > They say: > > matGetDir returns a pointer to an internal array containing > pointers to the NULL-terminated names > > so it's clear that it's ``char **'', just like the return type says. > > They must do some funny allocation to allow you to blow this away with > just one call to their mxFree() function. The array of pointers and the > string data are all allocated in one memory block. Or perhaps the array > of pointers is dynamic, but the pointers are managed separately; maybe > the MATFile object owns these strings, and the dynamic array is just > used as a temporary object to retrieve the pointers in one call. > > They probably use their mxCalloc() function like this: > > char **arrayOfPointers = mxCalloc(numElements, > sizeof arrayOfPointers[0]); > > so the use of a calloc-like allocator does not support your > suspicion that it's not an array of pointers. so, what's the bottom line? how do I call this this via FFI? it does not appear that I can specify the function to free the data... -- Sam Steingold (http://www.podval.org/~sds) running w2k <http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/> <http://www.mideasttruth.com/> <http://www.honestreporting.com> nobody's life, liberty or property are safe while the legislature is in session |