I try to make smart struct support in my project. It works. Now i can have foreign struct in lisp as lisp structures (defclass/defstruct).
The only problem for me is mem-ref. When there is an array of structs, I need to use something like cffi::aggregatep to set fact, that struct are positioned in row, not pointers to them.
But in that case I cannot set translator, because in cffi::mem-ref
110 (if (aggregatep ptype) 111 (inc-pointer ptr offset) 112 (let ((ctype (canonicalize ptype))) 113 #+cffi-sys::no-long-long 114 (when (or (eq ctype :long-long) (eq ctype :unsigned-long-long)) 115 (return-from mem-ref 116 (translate-from-foreign (%emulated-mem-ref-64 ptr ctype offset) 117 ptype))) 118 ;; normal branch 119 (translate-from-foreign (%mem-ref ptr ctype offset) ptype)))))
Can we change (inc-pointer ptr offset)
to (translate-from-foreign (inc-pointer ptr offset) ptype) ?
If it is really pointer it remains unchanged, but if translate-from is overrided for particular type one can get any information out, not just pointers.
Hello Клочков,
2012/1/22 Клочков Роман monk@slavsoft.surgut.ru:
The only problem for me is mem-ref. When there is an array of structs, I need to use something like cffi::aggregatep to set fact, that struct are positioned in row, not pointers to them.
This is an issue we're addressing in the 'fsbv' branch. There, when you define a FOO structure, (:STRUCT FOO) denotes the aggregate type, and plain FOO is deprecated but interpreted to mean (:POINTER (:STRUCT FOO)).
Cheers,