Skip to content

Commit

Permalink
Deprecate cffi-features.
Browse files Browse the repository at this point in the history
- Keep it around for backwards compatibility.
- Don't use it from CFFI itself or the test suite.
- Update the manual.
  • Loading branch information
luismbo committed Jul 29, 2008
1 parent 62c6a8a commit 0f40767
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 181 deletions.
6 changes: 3 additions & 3 deletions cffi.asd
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
((:module src
:serial t
:components
((:file "features")
#+openmcl (:file "cffi-openmcl")
(#+openmcl (:file "cffi-openmcl")
#+sbcl (:file "cffi-sbcl")
#+cmu (:file "cffi-cmucl")
#+scl (:file "cffi-scl")
Expand All @@ -56,7 +55,8 @@
(:file "enum")
(:file "strings")
(:file "functions")
(:file "foreign-vars")))))
(:file "foreign-vars")
(:file "features")))))

(defmethod operation-done-p ((o test-op) (c (eql (find-system :cffi))))
nil)
Expand Down
52 changes: 13 additions & 39 deletions doc/cffi-manual.texinfo
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ natively on all implementations. However, they are emulated by
@code{mem-ref} and @code{mem-set}.

When those types are @strong{not} available, the symbol
@code{cffi-features:no-long-long} is pushed into @code{*features*}.
@code{cffi-sys::no-long-long} is pushed into @code{*features*}.

@ForeignType{:uchar}
@ForeignType{:ushort}
Expand Down Expand Up @@ -5097,7 +5097,7 @@ foreign functions.
@item
Corman Lisp does not support @code{foreign-funcall}. On
implementations that @strong{don't} support @code{foreign-funcall}
@code{cffi-features:no-foreign-funcall} will be present in
@code{cffi-sys::no-foreign-funcall} will be present in
@code{*features*}. Note: in these Lisps you can still use the
@code{defcfun} interface.
@end itemize
Expand Down Expand Up @@ -5192,7 +5192,7 @@ foreign functions.
@item
Corman Lisp does not support @code{foreign-funcall}. On
implementations that @strong{don't} support @code{foreign-funcall}
@code{cffi-features:no-foreign-funcall} will be present in
@code{cffi-sys::no-foreign-funcall} will be present in
@code{*features*}. Note: in these Lisps you can still use the
@code{defcfun} interface.
@end itemize
Expand Down Expand Up @@ -5410,14 +5410,11 @@ Creates a new library designator called @var{name}. The
When trying to load the library @var{name}, the relevant function
searches the @var{load-clause}s in order for the first one where
@var{feature} evaluates to true. That happens for any of the
following situations:@footnote{This is described in
@code{cffi-feature-p} in @file{libraries.lisp}.}
following situations:

@enumerate 1
@item
If @var{feature} is a symbol (idiomatically a keyword), a symbol with
the same name, but interned into the @code{cffi-features} package, is
present in @code{common-lisp:*features*}.
If @var{feature} is a symbol present in @code{common-lisp:*features*}.

@item
If @var{feature} is a list, depending on @code{(first @var{feature})},
Expand Down Expand Up @@ -5957,7 +5954,7 @@ forms. For example:
@end deffn

@lisp
#+cffi-features:freebsd
#+freebsd
(progn
(constant (ev-enable "EV_ENABLE"))
(constant (ev-disable "EV_DISABLE")))
Expand Down Expand Up @@ -6171,54 +6168,31 @@ C @code{struct}s cannot be passed by value.
@node Platform-specific features
@appendix Platform-specific features

@cffi{} does some platform tests on loading. The details vary between
Lisps; in fact, the purpose is to unify the list of available platform
features for use elsewhere in the @cffi{} code. These features are
also part of the public interface; see @ref{define-foreign-library}.

The exact meanings of the features follow. Though you will usually
refer to these symbols as keywords, @cffi{} internally views them in
the package @code{cffi-features}.
Whenever a backend doesn't support one of @cffi{}'s features, a
specific symbol is pushed onto @code{common-lisp:*features*}. The
meanings of these symbol follow.

@table @var
@item flat-namespace
@item cffi-sys::flat-namespace
This Lisp has a flat namespace for foreign symbols meaning that you
won't be able to load two different libraries with homograph functions
and successfully differentiate them through the @code{:library}
option to @code{defcfun}, @code{defcvar}, etc@dots{}

@item darwin
This operating system is Darwin or a derivative thereof, such as
Mac @acronym{OS X}.

@item no-foreign-funcall
@item cffi-sys::no-foreign-funcall
The macro @code{foreign-funcall} is @strong{not} available. On such
platforms, the only way to call a foreign function is through
@code{defcfun}. @xref{foreign-funcall}, and @ref{defcfun}.

@item no-long-long
@item cffi-sys::no-long-long
The C @code{long long} type is @strong{not} available as a foreign
type.

@item no-stdcall
@item cffi-sys::no-stdcall
This Lisp doesn't support the @code{stdcall} calling convention. Note
that it only makes sense to support @code{stdcall} on (32-bit) x86
platforms.

@item ppc32
The underlying @acronym{CPU} architecture is 32-bit PowerPC.

@item unix
This operating system is a @sc{unix}-like, such as
@acronym{GNU}/Linux, Darwin, or even Cygwin on Lisps that show the
@sc{unix}-like interface provided by Cygwin to Lisp code.

@item windows
This operating system is Windows.

@item x86
The underlying @acronym{CPU} architecture is x86, such as on
processors from Intel or @acronym{AMD}.
@end table


Expand Down
6 changes: 2 additions & 4 deletions src/cffi-allegro.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@

;;;# Mis-features

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(cffi-features:no-long-long
cffi-features:flat-namespace)))
(pushnew 'no-long-long *features*)
(pushnew 'flat-namespace *features*)

;;;# Symbol Case

Expand Down
2 changes: 1 addition & 1 deletion src/cffi-clisp.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
;; of foreign types part of the public interface in CLisp. :-)
(defun %foreign-type-alignment (type)
"Return the structure alignment in bytes of foreign TYPE."
#+(and cffi-features:darwin cffi-features:ppc32)
#+(and darwin ppc)
(case type
((:double :long-long :unsigned-long-long)
(return-from %foreign-type-alignment 8)))
Expand Down
6 changes: 2 additions & 4 deletions src/cffi-cmucl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@

(in-package #:cffi-sys)

;;;# Features
;;;# Misfeatures

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(cffi-features:flat-namespace)))
(pushnew 'flat-namespace *features*)

;;;# Symbol Case

Expand Down
8 changes: 3 additions & 5 deletions src/cffi-corman.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@

(in-package #:cffi-sys)

;;;# Mis-features
;;;# Misfeatures

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(cffi-features:no-long-long
cffi-features:no-foreign-funcall)))
(pushnew 'no-long-long *features*)
(pushnew 'no-foreign-funcall *features*)

;;;$ Symbol Case

Expand Down
6 changes: 2 additions & 4 deletions src/cffi-ecl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@

;;;# Mis-features

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(#-x86-64 cffi-features:no-long-long
cffi-features:flat-namespace)))
(pushnew 'no-long-long *features*)
(pushnew 'flat-namespace *features*)

;;;# Symbol Case

Expand Down
6 changes: 2 additions & 4 deletions src/cffi-lispworks.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@

(in-package #:cffi-sys)

;;;# Mis-features
;;;# Misfeatures

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(#-lispworks-64bit cffi-features:no-long-long)))
#-lispworks-64bit (pushnew 'no-long-long *features*)

;;;# Symbol Case

Expand Down
6 changes: 2 additions & 4 deletions src/cffi-openmcl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@

(in-package #:cffi-sys)

;;;# Mis-features
;;;# Misfeatures

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(cffi-features:flat-namespace)))
(pushnew 'flat-namespace *features*)

;;;# Symbol Case

Expand Down
6 changes: 2 additions & 4 deletions src/cffi-sbcl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@

(in-package #:cffi-sys)

;;;# Mis-features
;;;# Misfeatures

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(cffi-features:flat-namespace)))
(pushnew 'flat-namespace *features*)

;;;# Symbol Case

Expand Down
4 changes: 1 addition & 3 deletions src/cffi-scl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@

;;;# Mis-features

(eval-when (:compile-toplevel :load-toplevel :execute)
(mapc (lambda (feature) (pushnew feature *features*))
'(cffi-features:flat-namespace)))
(pushnew 'flat-namespace *features*)

;;;# Symbol Case

Expand Down
13 changes: 9 additions & 4 deletions src/features.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
;;; *features*. See each cffi-*.lisp file.
;;;
;;; Not anymore, I think we should use TRIVIAL-FEATURES for the
;;; platform features instead. Less pain. And maybe the
;;; CFFI-specific features should be in the CFFI-SYS package,
;;; unexported? This is here now for backwards compatibility.
;;; platform features instead. Less pain. CFFI-FEATURES is now
;;; deprecated and this code will stay here for a while for backwards
;;; compatibility purposes, to be removed in a future release.

(defpackage #:cffi-features
(:use #:cl)
Expand Down Expand Up @@ -103,4 +103,9 @@ that belong to the CFFI-FEATURES package."
#+sparc sparc
#+sparc64 sparc64
#+hppa hppa
#+hppa64 hppa64))
#+hppa64 hppa64
#+cffi-sys::no-long-long no-long-long
#+cffi-sys::flat-namespace flat-namespace
#+cffi-sys::no-foreign-funcall no-foreign-funcall
#+cffi-sys::no-stdcall no-stdcall
))
12 changes: 6 additions & 6 deletions src/libraries.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
;;;
;;; This information is stored in the *FOREIGN-LIBRARIES* hashtable
;;; and when the library is loaded through LOAD-FOREIGN-LIBRARY (or
;;; USE-FOREIGN-LIBRARY) the first clause matched by CFFI-FEATURE-P is
;;; USE-FOREIGN-LIBRARY) the first clause matched by FEATUREP is
;;; processed.

(defvar *foreign-libraries* (make-hash-table :test 'eq)
Expand All @@ -117,7 +117,7 @@
(setf (gethash name *foreign-libraries*) value))

(defun %foreign-library-spec (lib)
(assoc-if #'cffi-feature-p (slot-value lib 'spec)))
(assoc-if #'featurep (slot-value lib 'spec)))

(defun foreign-library-spec (lib)
(second (%foreign-library-spec lib)))
Expand Down Expand Up @@ -211,17 +211,17 @@ none of alternatives were successfully loaded."
(fl-error "Unable to load any of the alternatives:~% ~S" library-list))

(defparameter *cffi-feature-suffix-map*
'((cffi-features:windows . ".dll")
(cffi-features:darwin . ".dylib")
(cffi-features:unix . ".so")
'((:windows . ".dll")
(:darwin . ".dylib")
(:unix . ".so")
(t . ".so"))
"Mapping of OS feature keywords to shared library suffixes.")

(defun default-library-suffix ()
"Return a string to use as default library suffix based on the
operating system. This is used to implement the :DEFAULT option.
This will need to be extended as we test on more OSes."
(or (cdr (assoc-if #'cffi-feature-p *cffi-feature-suffix-map*))
(or (cdr (assoc-if #'featurep *cffi-feature-suffix-map*))
(fl-error "Unable to determine the default library suffix on this OS.")))

(defun load-foreign-library-helper (name thing)
Expand Down
18 changes: 9 additions & 9 deletions src/types.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
(define-built-in-foreign-type :double)
(define-built-in-foreign-type :void)

#-cffi-features:no-long-long
#-cffi-sys::no-long-long
(progn
(define-built-in-foreign-type :long-long)
(define-built-in-foreign-type :unsigned-long-long))
Expand All @@ -53,7 +53,7 @@
;;; A possibly better, certainly faster though more intrusive,
;;; alternative is available here:
;;; <http://article.gmane.org/gmane.lisp.cffi.devel/1091>
#+cffi-features:no-long-long
#+cffi-sys::no-long-long
(eval-when (:compile-toplevel :load-toplevel :execute)
(defclass emulated-llong-type (foreign-type) ())
(defmethod foreign-type-size ((tp emulated-llong-type)) 8)
Expand Down Expand Up @@ -96,7 +96,7 @@
value))

;;; When some lisp other than SCL supports :long-double we should
;;; use #-cffi-features:no-long-double here instead.
;;; use #-cffi-sys::no-long-double here instead.
#+(and scl long-float) (define-built-in-foreign-type :long-double)

;;;# Foreign Pointers
Expand All @@ -110,7 +110,7 @@ we don't return its 'value' but a pointer to it, which is PTR itself."
(if (aggregatep ptype)
(inc-pointer ptr offset)
(let ((ctype (canonicalize ptype)))
#+cffi-features:no-long-long
#+cffi-sys::no-long-long
(when (or (eq ctype :long-long) (eq ctype :unsigned-long-long))
(return-from mem-ref
(translate-from-foreign (%emulated-mem-ref-64 ptr ctype offset)
Expand All @@ -124,7 +124,7 @@ we don't return its 'value' but a pointer to it, which is PTR itself."
(let* ((parsed-type (parse-type (eval type)))
(ctype (canonicalize parsed-type)))
;; Bail out when using emulated long long types.
#+cffi-features:no-long-long
#+cffi-sys::no-long-long
(when (member ctype '(:long-long :unsigned-long-long))
(return-from mem-ref form))
(if (aggregatep parsed-type)
Expand All @@ -136,7 +136,7 @@ we don't return its 'value' but a pointer to it, which is PTR itself."
"Set the value of TYPE at OFFSET bytes from PTR to VALUE."
(let* ((ptype (parse-type type))
(ctype (canonicalize ptype)))
#+cffi-features:no-long-long
#+cffi-sys::no-long-long
(when (or (eq ctype :long-long) (eq ctype :unsigned-long-long))
(return-from mem-set
(%emulated-mem-set-64 (translate-to-foreign value ptype)
Expand Down Expand Up @@ -177,7 +177,7 @@ to open-code (SETF MEM-REF) forms."
(let* ((parsed-type (parse-type (eval type)))
(ctype (canonicalize parsed-type)))
;; Bail out when using emulated long long types.
#+cffi-features:no-long-long
#+cffi-sys::no-long-long
(when (member ctype '(:long-long :unsigned-long-long))
(return-from mem-set form))
`(%mem-set ,(expand-to-foreign value parsed-type) ,ptr ,ctype ,offset))
Expand Down Expand Up @@ -821,8 +821,8 @@ The buffer has dynamic extent and may be stack allocated."
'foreign-boolean-type :actual-type
(ecase (canonicalize-foreign-type base-type)
((:char :unsigned-char :int :unsigned-int :long :unsigned-long
#-cffi-features:no-long-long :long-long
#-cffi-features:no-long-long :unsigned-long-long) base-type))))
#-cffi-sys::no-long-long :long-long
#-cffi-sys::no-long-long :unsigned-long-long) base-type))))

(defmethod translate-to-foreign (value (type foreign-boolean-type))
(if value 1 0))
Expand Down
Loading

0 comments on commit 0f40767

Please sign in to comment.