[Openmcl-devel] Idiom for creating arrays of C structs

John Miller millejoh at mac.com
Tue Jun 2 21:09:04 PDT 2009


Are there any conventions/best practices to follow when working with  
arrays of C structs that are passed back and forth from foreign code?   
Sorry if this has already been discussed in the past, but nothing  
jumped out at me while browsing through the group's archives.

The code in the attached file seems to work on first appearance,  
creating an array of cpVect structures on a call to make-cpv-array.  I  
can do something like
	(%get-ptr ptr-returned-from-make-cpv-array (* index size-of-cpv- 
struct))
and get a cpVect structure back.  When I pass the MACPTR returned by  
make-cpv-array to foreign code, however, the block of memory  
apparently turns to mush.  A copy of the C code I am calling with my  
make-cpv-array MACPTR is also in the attached file along with some  
interactions with the Listener.

I guess that #<A Foreign Pointer (:* (:STRUCT :CP<V>ECT)) #x1EF61470>  
is not the same as a cpVect* verts, but I am at a loss to explain why  
and how to get the two to agree.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: struct-array.lisp
Type: application/octet-stream
Size: 2212 bytes
Desc: not available
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20090602/29832c89/attachment.obj>
-------------- next part --------------




A little background: I am trying to write an FFI in CCL for the  
Chipmunk physics library.  If any poor schmuck had actually downloaded  
the code that I prematurely uploaded to Google Code earlier they would  
have quickly found out that the demo with the square falling down the  
stairs doesn't work too realistically.  I believe this issue with the  
passing around arrays of C structs to be the cause.

Regards,
John


More information about the Openmcl-devel mailing list