-*- Text -*-

This is a collection of TODO items and ideas in no particular order.

### Testing

-> Test uffi-compat with more UFFI libraries.
-> Write more FOREIGN-GLOBALS.SET.* tests.
-> Finish tests/random-tester.lisp
-> Write benchmarks comparing CFFI vs. native FFIs and also demonstrating
   performance of each platform.
-> Write more STRUCT.ALIGNMENT.* tests (namely involving the :LONG-LONG
   and :UNSIGNED-LONG-LONG types) and test them in more ABIs.
-> Run tests both interpreted (where it makes sense) and compiled.
-> Run tests with the different kinds of shared libraries available on
   MacOS X.

### Ports

-> Finish GCL port.
-> As of 2006-06-27, CVS ECL fails 31 tests on linux/x86 and 35 tests
   on darwin/ppc. Need to look into this.
-> Fix bugs in the Corman port.
-> Port to MCL.

### Features

-> Implement CFFI-SYS:%CLOSE-FOREIGN-LIBRARY for all supported Lisps and
   implement a higher-level CFFI:CLOSE-FOREIGN-LIBRARY.
-> Implement a declarative interface for FOREIGN-FUNCALL-PTR, similar to
   DEFCUN/FOREIGN-FUNCALL.
-> Figure out how to portably define types like: time_t, size_t, wchar_t, 
   etc... Likely to involve something like SB-GROVEL and possibly avoiding
   this step on known platforms?
-> [Lost Idea] Something involving finalizers?
-> Implement the proposed interfaces (see doc/).
-> Add the ability to specify the calling convention to the interface.
-> Implement CFFI-SYS:ERRNO-VALUE (name?).
-> Extend FOREIGN-SLOT-VALUE and make it accept multiple "indices" for
   directly accessing structs inside structs, arrays inside structs, etc...
-> Implement EXPLAIN-FOREIGN-SLOT-VALUE.
-> Implement :in/:out/:in-out for DEFCFUN (and FOREIGN-FUNCALL?).
-> Add support for multiple memory allocation schemes (like CLISP), namely
   support for allocating with malloc() (so that it can be freed on the C
   side)>
-> Extend DEFCVAR's symbol macro in order to handle memory (de)allocation
   automatically (see CLISP).
-> Implement byte swapping routines (see /usr/include/linux/byteorder)
-> [Lost Idea] Implement UB8-REF?
-> [Lost Idea] Something about MEM-READ-C-STRING returning multiple value?
-> Implement an array type? Useful when we're working with ranks >= 2?
-> Implement bitfields. To read: get the word, LDB it. To write: get the
   word, PDB it, put the word.
-> External encodings for the :STRING type. See:
   <http://article.gmane.org/gmane.lisp.cffi.devel/292>
-> Define a lisp type for pointers in the backends. Eg: for clisp:
     (deftype pointer-type (or ffi:foreign-address null))
   Useful for type declarations.
-> Warn about :void in places where it doesn't make sense.

### Underspecified Semantics

-> (setf (mem-ref ptr <aggregate-type> offset) <value>)
-> Review the interface for coherence across Lisps with regard to
   behaviour in "exceptional" situations. Eg: threads, dumping cores,
   accessing foreign symbols that don't exist, etc...
-> On Lispworks a Lisp float is a double and therefore won't necessarily
   fit in a C float. Figure out a way to handle this.
-> Allegro: callbacks' return values.
-> Lack of uniformity with regard to pointers. Allegro: 0 -> NULL.
   CLISP/Lispworks: NIL -> NULL.
-> Some lisps will accept a lisp float being passed to :double
   and a lisp double to :float. We should either coerce on lisps that
   don't accept this or check-type on lisps that do. Probably the former
   is better since on lispworks/x86 double == float.
-> What happens when the same library is loaded twice.

### Possible Optimizations

-> More compiler macros on some of the CFFI-SYS implementations.
-> Optimize UFFI-COMPAT when the vector stuff is implemented.
-> Being able to declare that some C int will always fit in a Lisp
   fixnum. Allegro has a :fixnum ftype and CMUCL/SBCL can use
   (unsigned-byte 29) others could perhaps behave like :int?
-> An option for defcfun to expand into a compiler macro which would
   allow the macroexpansion-time translators to look at the forms
   passed to the functions.

### Known Issues

-> CLISP FASL portability is broken. Fix this by placing LOAD-TIME-VALUE
   forms in the right places and moving other calculations to load-time.
   (eg: calculating struct size/alignment.) Ideally we'd only move them
   to load-time when we actually care about fasl portability.
     (defmacro maybe-load-time-value (form)
       (if <we care about fasl portability>
           `(load-time-value ,form)
           form))
-> cffi-tests.asd's :c-test-lib component is causing the whole testsuite
   to be recompiled everytime. Figure that out.
-> The (if (constantp foo) (do-something-with (eval foo)) ...) pattern
   used in many places throughout the code is apparently not 100% safe.
-> On ECL platforms without DFFI we need to build a non-linked version
   of libtest.
-> LOAD-FOREIGN-LIBRARY should give better errors. On ECL with DFFI
   it should show the error that %LOAD-FOREIGN-LIBRARY is signalling.
-> LOAD-FOREIGN-LIBRARY's USE restart is somewhat broken.

### Documentation

-> Fill the missing sections in the CFFI User Manual.
-> Update the CFFI-SYS Specification.
-> Generally improve the reference docs and examples.

### Other

-> Type-checking pointer interface.
