[cells-cvs] CVS cells-gtk/cffi

ktilton ktilton at common-lisp.net
Mon Jan 28 23:59:26 UTC 2008


Update of /project/cells/cvsroot/cells-gtk/cffi
In directory clnet:/tmp/cvs-serv9292/cffi

Added Files:
	COPYRIGHT HEADER Makefile README TODO cffi-examples.asd 
	cffi-tests.asd cffi-uffi-compat.asd cffi.asd cffi.lpr 
Log Message:



--- /project/cells/cvsroot/cells-gtk/cffi/COPYRIGHT	2008/01/28 23:59:25	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/COPYRIGHT	2008/01/28 23:59:25	1.1
Copyright (C) 2005-2006, James Bielman  <jamesjb at jamesjb.com>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
--- /project/cells/cvsroot/cells-gtk/cffi/HEADER	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/HEADER	2008/01/28 23:59:26	1.1
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; filename --- description
;;;
;;; Copyright (C) 2005-2006, James Bielman  <jamesjb at jamesjb.com>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;


--- /project/cells/cvsroot/cells-gtk/cffi/Makefile	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/Makefile	2008/01/28 23:59:26	1.1
# -*- Mode: Makefile; tab-width: 3; indent-tabs-mode: t -*-
#
# Makefile --- Make targets for various tasks.
#
# Copyright (C) 2005-2006, James Bielman  <jamesjb at jamesjb.com>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#

# This way you can easily run the tests for different versions
# of each lisp with, e.g. ALLEGRO=/path/to/some/lisp make test-allegro
CMUCL    ?= lisp
OPENMCL  ?= openmcl
SBCL     ?= sbcl
CLISP    ?= clisp
ALLEGRO  ?= acl
SCL      ?= scl

shlibs:
	@$(MAKE) -wC tests shlibs

clean:
	@$(MAKE) -wC tests clean
	find . -name ".fasls" | xargs rm -rf
	find . \( -name "*.dfsl" -o -name "*.fasl" -o -name "*.fas" -o -name "*.lib" -o -name "*.x86f" -o -name "*.amd64f" -o -name "*.sparcf" -o -name "*.sparc64f" -o -name "*.hpf" -o -name "*.hp64f" -o -name "*.ppcf" -o -name "*.nfasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.lx64fsl" \) -exec rm {} \;

test-openmcl:
	@-$(OPENMCL) --load tests/run-tests.lisp

test-sbcl:
	@-$(SBCL) --noinform --load tests/run-tests.lisp

test-cmucl:
	@-$(CMUCL) -load tests/run-tests.lisp

test-scl:
	@-$(SCL) -load tests/run-tests.lisp

test-clisp:
	@-$(CLISP) -q -x '(load "tests/run-tests.lisp")'

test-clisp-modern:
	@-$(CLISP) -modern -q -x '(load "tests/run-tests.lisp")'

test-allegro:
	@-$(ALLEGRO) -L tests/run-tests.lisp

test: test-openmcl test-sbcl test-cmucl test-clisp

# vim: ft=make ts=3 noet
--- /project/cells/cvsroot/cells-gtk/cffi/README	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/README	2008/01/28 23:59:26	1.1

CFFI, the Common Foreign Function Interface, purports to be a portable
foreign function interface, similar in spirit to UFFI.

Unlike UFFI, CFFI requires only a small set of low-level functionality
from the Lisp implementation, such as calling a foreign function by
name, allocating foreign memory, and dereferencing pointers.

More complex tasks like accessing foreign structures can be done in
portable "user space" code, making use of the low-level memory access
operations defined by the implementation-specific bits.

CFFI also aims to be more efficient than UFFI when possible.  In
particular, UFFI's use of aliens in CMUCL and SBCL can be tricky to
get right.  CFFI avoids this by using system area pointers directly
instead of alien objects.  All foreign function definitions and uses
should compile without alien-value compiler notes in CMUCL/SBCL.
--- /project/cells/cvsroot/cells-gtk/cffi/TODO	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/TODO	2008/01/28 23:59:26	1.1
-*- 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.

### 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.
--- /project/cells/cvsroot/cells-gtk/cffi/cffi-examples.asd	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/cffi-examples.asd	2008/01/28 23:59:26	1.1
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-examples.asd --- ASDF system definition for CFFI examples.
;;;
;;; Copyright (C) 2005-2006, James Bielman  <jamesjb at jamesjb.com>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;

(defpackage #:cffi-examples-system
  (:use #:cl #:asdf))
(in-package #:cffi-examples-system)

(defsystem cffi-examples
  :description "CFFI Examples"
  :author "James Bielman  <jamesjb at jamesjb.com>"
  :components 
  ((:module examples
    :components
    ((:file "examples")
     (:file "gethostname")
     (:file "gettimeofday"))))
  :depends-on (cffi))
--- /project/cells/cvsroot/cells-gtk/cffi/cffi-tests.asd	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/cffi-tests.asd	2008/01/28 23:59:26	1.1
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-tests.asd --- ASDF system definition for CFFI unit tests.
;;;
;;; Copyright (C) 2005-2006, James Bielman  <jamesjb at jamesjb.com>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;

(defpackage #:cffi-tests-system
  (:use #:cl #:asdf))
(in-package #:cffi-tests-system)

(defvar *tests-dir* (append (pathname-directory *load-truename*) '("tests")))

(defclass c-test-lib (c-source-file)
  ())

(defmethod perform ((o load-op) (c c-test-lib))
  nil)

(defmethod perform ((o load-source-op) (c c-test-lib))
  nil)

(defmethod perform ((o compile-op) (c c-test-lib))
  #-(or win32 mswindows)
  (unless (zerop (run-shell-command
                   #-freebsd "cd ~A; make"
                   #+freebsd "cd ~A; gmake"
                   (namestring (make-pathname :name nil :type nil
                                              :directory *tests-dir*))))
    (error 'operation-error :component c :operation o)))

(defsystem cffi-tests
  :description "Unit tests for CFFI."
  :depends-on (cffi rt)
  :components
  ((:module "tests"
    :serial t
    :components
    ((:c-test-lib "libtest")
     (:file "package")
     (:file "bindings")
     (:file "funcall")
     (:file "defcfun")
     (:file "callbacks")
     (:file "foreign-globals")
     (:file "memory")
     (:file "struct")
     (:file "union")
     (:file "enum")
     (:file "misc-types")
     (:file "misc")))))

(defun run-cffi-tests (&key (compiled nil))
  (funcall (intern (symbol-name '#:run-cffi-tests) '#:cffi-tests)
           :compiled compiled))

(defmethod perform ((o test-op) (c (eql (find-system :cffi-tests))))
  (unless (and (run-cffi-tests :compiled nil)
               (run-cffi-tests :compiled t))
    (error "test-op failed.")))

;;; vim: ft=lisp et
--- /project/cells/cvsroot/cells-gtk/cffi/cffi-uffi-compat.asd	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/cffi-uffi-compat.asd	2008/01/28 23:59:26	1.1
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;;
;;; cffi-uffi-compat.asd --- ASDF system definition for CFFI-UFFI-COMPAT.
;;;
;;; Copyright (C) 2005-2006, James Bielman  <jamesjb at jamesjb.com>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;

(defpackage #:cffi-uffi-compat-system
  (:use #:cl #:asdf))

[12 lines skipped]
--- /project/cells/cvsroot/cells-gtk/cffi/cffi.asd	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/cffi.asd	2008/01/28 23:59:26	1.1

[80 lines skipped]
--- /project/cells/cvsroot/cells-gtk/cffi/cffi.lpr	2008/01/28 23:59:26	NONE
+++ /project/cells/cvsroot/cells-gtk/cffi/cffi.lpr	2008/01/28 23:59:26	1.1

[178 lines skipped]



More information about the Cells-cvs mailing list