From 9d1d5b5b75e403a7767b99706e08698f649bd3c7 Mon Sep 17 00:00:00 2001 From: "Liam M. Healy" Date: Sun, 5 Feb 2012 17:02:08 -0500 Subject: [PATCH] Rename system to cffi-libffi, add restart to default *foreign-structures-by-value* --- cffi-fsbv.asd => cffi-libffi.asd | 6 +-- fsbv/examples.lisp | 97 ------------------------------------ {fsbv => libffi}/built-in-types.lisp | 0 {fsbv => libffi}/cif.lisp | 0 {fsbv => libffi}/cstruct.lisp | 0 {fsbv => libffi}/functions.lisp | 0 {fsbv => libffi}/init.lisp | 0 {fsbv => libffi}/libffi-unix.lisp | 0 {fsbv => libffi}/libffi-win32.lisp | 0 src/functions.lisp | 5 +- 10 files changed, 7 insertions(+), 101 deletions(-) rename cffi-fsbv.asd => cffi-libffi.asd (95%) delete mode 100644 fsbv/examples.lisp rename {fsbv => libffi}/built-in-types.lisp (100%) rename {fsbv => libffi}/cif.lisp (100%) rename {fsbv => libffi}/cstruct.lisp (100%) rename {fsbv => libffi}/functions.lisp (100%) rename {fsbv => libffi}/init.lisp (100%) rename {fsbv => libffi}/libffi-unix.lisp (100%) rename {fsbv => libffi}/libffi-win32.lisp (100%) diff --git a/cffi-fsbv.asd b/cffi-libffi.asd similarity index 95% rename from cffi-fsbv.asd rename to cffi-libffi.asd index 20456a6..9b42e9d 100644 --- a/cffi-fsbv.asd +++ b/cffi-libffi.asd @@ -1,6 +1,6 @@ ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; -;;; cffi-fsbv.asd --- Foreign Structures By Value +;;; cffi-libffi.asd --- Foreign Structures By Value ;;; ;;; Copyright (C) 2011 Liam M. Healy ;;; @@ -31,13 +31,13 @@ (asdf:oos 'asdf:load-op :cffi-grovel) (asdf:oos 'asdf:load-op :trivial-features)) -(defsystem cffi-fsbv +(defsystem cffi-libffi :description "Foreign structures by value" :author "Liam Healy " :maintainer "Liam Healy " :defsystem-depends-on (#:trivial-features #:cffi-grovel) :components - ((:module fsbv + ((:module libffi :serial t :components ((:file "init") diff --git a/fsbv/examples.lisp b/fsbv/examples.lisp deleted file mode 100644 index a9b26f4..0000000 --- a/fsbv/examples.lisp +++ /dev/null @@ -1,97 +0,0 @@ -;; Examples of using CFFI-FSBV -;; Liam Healy 2009-04-07 22:13:34EDT examples.lisp -;; Time-stamp: <2011-10-02 20:19:25EDT examples.lisp> - -(in-package :cffi) ; cffi-test ? doesn't load - -;;; These examples are based on GSL functions using and returning complex numbers -;;; http://www.gnu.org/software/gsl/manual/html_node/Properties-of-complex-numbers.html -;;; http://www.gnu.org/software/gsl/manual/html_node/Complex-arithmetic-operators.html - -;;; Load the libraries -(cffi:load-foreign-library #+unix "libgslcblas.so") -(cffi:load-foreign-library #+unix "libgsl.so") - -;;; Define the foreign struct; see /usr/include/gsl/gsl_complex.h -(defcstruct (complex-double :class complex-type) - (dat :double :count 2)) - -(defmethod translate-into-foreign-memory ((value complex) (type complex-type) p) - (with-foreign-slots ((dat) p (:struct complex-double)) - (setf (cffi:mem-aref dat :double 0) (realpart value) - (cffi:mem-aref dat :double 1) (imagpart value)))) - -(defmethod translate-from-foreign (p (type complex-type)) - (with-foreign-slots ((dat) p (:struct complex-double)) - (complex (cffi:mem-aref dat :double 0) - (cffi:mem-aref dat :double 1)))) - -(defmethod free-translated-object (value (type complex-type) freep) - (declare (ignore freep type)) - (foreign-free value)) - -(foreign-funcall "gsl_complex_conjugate" - (:struct complex-double) #C(3.0d0 4.0d0) (:struct complex-double)) -(foreign-funcall "gsl_complex_abs" (:struct complex-double) #C(3.0d0 4.0d0) :double) - -;;; gsl_complex_abs: an example of a function that takes a complex -;;; number and returns a double-float -(defcfun (complex-abs "gsl_complex_abs") :double - (complex-number (:struct cffi::complex-double))) - -;;; gsl_complex_conjugate: an example of a function that takes a complex -;;; number and returns another complex number -(defcfun (complex-conjugate "gsl_complex_conjugate") (:struct cffi::complex-double) - "Find the complex conjugate of the given complex number." - (c (:struct cffi::complex-double))) - -(defcstruct (real-and-complex :class real-and-complex-type) - (r :double) - (c (:struct complex-double))) - -;;; (convert-to-foreign '(r 7.0d0 c #C(2.0d0 3.0d0)) '(:struct real-and-complex)) - - -#| - -;;; Real-and-complex: - - -(defmethod translate-into-foreign-memory (value (type real-and-complex-type) p) - (setf (foreign-slot-value p 'real-and-complex 'r) (first value)) - (convert-into-foreign-memory - (second value) - 'complex - (foreign-slot-pointer p 'real-and-complex 'c))) -(defmethod translate-from-foreign (p (type real-and-complex-type)) - (with-foreign-slots ((r c) p real-and-complex) - (list r c))) -(convert-to-foreign '(7.0d0 #C(2.0d0 3.0d0)) 'real-and-complex) -#.(SB-SYS:INT-SAP #X0063D450) -(convert-from-foreign * 'real-and-complex) -(7.0d0 #C(2.0d0 3.0d0)) - -;;;;;;;; Not yet checked: - -;;; gsl_complex_add: an example of a function that takes two complex -;;; numbers and returns another complex number -(defun complex-add (c1 c2) - (foreign-funcall "gsl_complex_add" complex c1 complex c2 complex)) - -;;; gsl_complex_add_real: an example of a function that takes one complex -;;; number and one real number and returns another complex number - -(defcfun (complex-add-real "gsl_complex_add_real") complex - "Add the real number to the complex number." - (c complex) (r :double)) - -;;; Definition of complex-add-real using the preparation from the -;;; defcfun above. -(defun complex-add-real-ff-prep (c r) - (foreign-funcall complex-add-real complex c :double r complex)) - -;;; Definition of complex-add-real re-preparing each call. -(defun complex-add-real-ff-noprep (c r) - (foreign-funcall "gsl_complex_add_real" complex c :double r complex)) -|# - diff --git a/fsbv/built-in-types.lisp b/libffi/built-in-types.lisp similarity index 100% rename from fsbv/built-in-types.lisp rename to libffi/built-in-types.lisp diff --git a/fsbv/cif.lisp b/libffi/cif.lisp similarity index 100% rename from fsbv/cif.lisp rename to libffi/cif.lisp diff --git a/fsbv/cstruct.lisp b/libffi/cstruct.lisp similarity index 100% rename from fsbv/cstruct.lisp rename to libffi/cstruct.lisp diff --git a/fsbv/functions.lisp b/libffi/functions.lisp similarity index 100% rename from fsbv/functions.lisp rename to libffi/functions.lisp diff --git a/fsbv/init.lisp b/libffi/init.lisp similarity index 100% rename from fsbv/init.lisp rename to libffi/init.lisp diff --git a/fsbv/libffi-unix.lisp b/libffi/libffi-unix.lisp similarity index 100% rename from fsbv/libffi-unix.lisp rename to libffi/libffi-unix.lisp diff --git a/fsbv/libffi-win32.lisp b/libffi/libffi-win32.lisp similarity index 100% rename from fsbv/libffi-win32.lisp rename to libffi/libffi-win32.lisp diff --git a/src/functions.lisp b/src/functions.lisp index 085da9f..366b71f 100644 --- a/src/functions.lisp +++ b/src/functions.lisp @@ -99,7 +99,10 @@ (defvar *foreign-structures-by-value* (lambda (&rest args) (declare (ignore args)) - (error "Unable to call structures by value; load CFFI-FSBV and retry.")) + (restart-case + (error "Unable to call structures by value without cffi-libffi loaded.") + (load-cffi-libffi () :report "Load cffi-libffi." + (asdf:operate 'asdf:load-op 'cffi-libffi)))) "A function that produces a form suitable for calling structures by value.") (defun foreign-funcall-form (thing options args pointerp) -- 2.11.4.GIT