Hi Luis,
Hello,
I went through all the code and here are my review notes. (In org-mode
format.) I suggest we tackle them incrementally, not necessarily in
this order. Meanwhile, I'll be tackling the missing bits in the new
convert-into-foreign-memory. Should we be having this discussion in
cffi-devel btw?
* cffi-fsbv.asd
What happens on #-unix?
(:cffi-grovel-file "libffi" :pathname #+unix "libffi-unix")
* fsbv/package.lisp
1. Regarding SIZET, I'd say we can define this type using a
keyword :SIZET.
2. cffi-fsbv calls and hooks into so many of CFFI internals. Should
we just use the CFFI package? I mean, the code is full of ::s.
* fsbv/libffi-unix.lisp
1. OSX ships with libffi. Is (cc-flags "-I/opt/local/include/")
necessary? (I guess it doesn't hurt. Just curious. Perhaps it
didn't ship with libffi in the past?)
2. Aren't :uint and :ushort equivalent to:
(ctype ushort "unsigned short")
(ctype unsigned "unsigned")?
3. Do we really need to grovel this stuff? Grovelling requires a C
compiler which is particularly tricky on Windows. It'd be nice to
avoid that requirement if possible. Didn't see anything in here
that seemed to *require* grovelling. Did I miss something?
* fsbv/build-in-type.lisp
1. Could we use DEFCVAR here to declare the various ffi_type_*
globals? (I think it'd be slightly clearer.)
2. Why do we have to cache pointers for FOREIGN-TYPE-ALIAS and
FOREIGN-ENUM? (But see my comments on fsbv/cstruct.lisp)
3. Why different LIBFFI-TYPE-POINTER for those two types?
FOREIGN-ENUM inherits from FOREIGN-TYPE-ALIAS.
* fsbv/cstruct.lisp
1. slots-in-order should be moved near FOREIGN-STRUCT-TYPE.
2. I think we should move libffi-type-pointer out of FOREIGN-TYPE
and centralize storage in an hash-table.
a) this simplifies implementation a little bit: it's weird that
pretty much all libffi-type-pointer methods have :AROUND
qualifiers.
b) makes it easy to avoid memory leaks when redefining/reloading
structure types. (Although this sort of leak is probably not a
huge issue, it's certainly inelegant.)
3. The code that creates ffi_types for structs could use some
refactoring. :-) I'll give it a go.
* fsbv/functions.lisp
1. I think this file can benefit from a little bit of refactoring.
2. I *think* we can move the indirection logic from the translation
methods onto FFCALL-BODY-LIBFFI, but it's not yet clear how that
can happen.
* fsbv/example.lisp
1. Need to clear the dead code and move it to examples/.
* src/functions.lisp
1. We can add a neat restart to *foreign-structures-by-value*.
* src/structures.lisp
1. As I've mentioned before, we should discuss how we can implement
this sort of functionality in a backwards-compatible way.
* src/early-types.lisp
1. missing expand-into-foreign-memory, and all the hooking up that
implies. Started working on that.
2. I think the :indirect keyword is delegating the responsibility to
the wrong place. All the type translations (in CFFI or in other
libraries) would have to be updated accordingly! As mentioned in
the fsbv/functions.lisp notes, I think we can handle the
indirection there. (It might require a slightly different way of
hooking up ffcall-body-libffi with foreign-funcall.)
* Nomenclature
I can forsee using libffi to deal with stuff like callbacks, long
long, varargs, etc. Should we rename cffi-fsbv to cffi-libffi?
* Wishlist
*** foreign-funcall-varargs and friends could use libffi
... to do proper varargs.
*** defcallbacks with structures...
--
Luís Oliveira
http://r42.eu/~luis/