[cffi-devel] CFFI-USER: Dereferencing an address to a pointer array ... ? SOLVED!

Frank Goenninger frgo at mac.com
Sat Nov 17 19:57:27 UTC 2007


Well, one should pass the address of the pointer via

(cffi:pointer-address ... )

and everything is fine...

Frank


Am 17.11.2007 um 20:30 schrieb Frank Goenninger:

> * PGP Signed: 11/17/07 at 20:30:52
>
> Hi all:
>
> I have in C  in a library:
>
> typedef struct  __tsPMDevInfo
> {
>    ... some slots in here; don't matter ...
>
> } tsPMDevInfo, *ptsPMDevInfoPtr;
>
> //  
> ---------------------------------------------------------------------- 
> --
> // nFindPMs -- Find PM Devices on all available serials
> //  
> ---------------------------------------------------------------------- 
> ---
>
> int nFindPMs( ptsPMDevInfoPtr **pppsPMDevInfoArray,
>                           int *pnNrPMsFound )
> {
>   int nRC = 0;
>
>   ptsPMDevInfoPtr *ppsPMDevInfoArray = NULL;
>
>  .... Here, memory gets allocated and
>  ppsPMDevInfoArray points to an array of
> pointers to struct tsPMDevInfo !
>
>   if( pppsPMDevInfoArray != NULL )
>     *pppsPMDevInfoArray = ppsPMDevInfoArray;
>
>   if( pnNrPMsFound != NULL )
>     *pnNrPMsFound = nNrPMs;
>
>   if( nNrPMs > 0 )
>     nRC = PMIO_RC_OK;
>   else
>     nRC = PMIO_RC_NO_PM_FOUND;
>
>   return nRC;
> }
>
> In Lisp-land I do (simplified):
>
> (defcfun ("nFindPMs" %nFindPMs) pmio-rc
>   (ppsPMDevInfoPtr :pointer)
>   (pnNrPMs         :pointer))
>
> (defun find-pms (ppsPMDevInfoPtr pnNrPMs)
>   (%nFindPMs ppsPMDevInfoPtr pnNrPMs))
>
> I do get a valid value for the nr of PMs back with
>
> (mem-ref pnNrPMs :int 0)
>
> But I am unable to get a valid foreign pointer back for  
> ppsPMDevInfoPtr :
>
> (mem-ref ppsPMDebInfoPtr :pointer 0)
>
> always returns an invalid value (no valid memory address). So, the  
> question is: How do I return a pointer to an array of pointers ?
> In C land everything is OK and the pointer array is valid: check  
> via ppsPMDebInfoPtr[0] -> This is the pointer to a valid struct  
> tsPMDevInfo.
>
> Thx for any pointers ;-) !!!
>
> Frank
>
>
>
> * Frank Goenninger<frgo at mac.com>
> * 0xED320F02:0x05AE0907
> _______________________________________________
> cffi-devel mailing list
> cffi-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel
>
>
> * PGP Signed: 11/17/07 at 20:30:52
> * text/plain body
> * Frank Goenninger<frgo at mac.com>
> * 0xED320F02:0x05AE0907

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20071117/ab6daced/attachment.sig>


More information about the cffi-devel mailing list