wanted: option to translate structs recursively
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CFFI |
New
|
Undecided
|
Unassigned |
Bug Description
it would be nice to have the option to completely translate a struct and all its contents to lisp data structures at once, for quick/simple bindings.
Attached patch is a partial implementation, but it doesn't handle shared structure/
example (using attached patch):
(defcstruct ivec2.1
(:x :int)
(:y :int))
(defcstruct (nested.1 :recursive t)
(ivec (:struct ivec2.1))
(ivecs (:struct ivec2.1) :count 2)
(ints :int :count 2))
(with-foreign-
(setf (mem-ref nested '(:struct nested.1))
'(ivec (:x 1 :y 2)
ivecs ((:x 11 :y 12) (:x 21 :y 22))
ints (100 101)))
(setf (mem-aref nested '(:struct nested.1) 1)
'(ivec (:x 1001 :y 1002)
ivecs ((:x 1011 :y 1012) (:x 1021 :y 1022))
ints (1100 1101)))
(list (mem-ref nested '(:struct nested.1))
(mem-aref nested '(:struct nested.1) 1)))
;; =>
'((INTS #(100 101) IVECS #((:Y 12 :X 11) (:Y 22 :X 21)) IVEC (:Y 2 :X 1))
(INTS #(1100 1101) IVECS #((:Y 1012 :X 1011) (:Y 1022 :X 1021))
IVEC (:Y 1002 :X 1001)))
Actually, I guess if it is only handling translation of the actual contents of the structure, it doesn't need circularity/sharing checks.
Sharing would imply pointers, and it can't recursively translate to pointers without some protocol to allow freeing them properly (particularly difficult with sharing in the general case with separate alloc/free).