This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

how to wrap a nested struct in cffi?

3 posts · 3192 views

here is the way CvMemStorage is defined in OpenCV


typedef struct CvMemStorage
{
int signature;
CvMemBlock* bottom; /* First allocated block.
*/
CvMemBlock* top; /* Current memory block - top of the stack.
*/
struct CvMemStorage* parent; /* We get new blocks from parent as needed.
*/
int block_size; /* Block size.
*/
int free_space; /* Remaining free space in current block.
*/
}
CvMemStorage;


bu i get


unknown CFFI type: (:STRUCT CV-MEM-STORAGE).
[Condition of type SIMPLE-ERROR]


when i wrap like this....i know lisp is known for recursion how do i bypass this

(defcstruct cv-mem-storage
(signature :int)
(bottom (:pointer (:struct cv-mem-block)))
(top (:pointer (:struct cv-mem-block)))
(parent (:pointer (:struct cv-mem-storage)))
(block-size :int)
(free-space :int))

Re: how to wrap a nested struct in cffi?

CFFI doesn't support cyclic definitions. Just leave the parent pointer unspecified, it should work.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Re: how to wrap a nested struct in cffi?

thanks for your help ....you were right it did