;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
-;;;; Name: objects.cl
+;;;; Name: objects.lisp
;;;; Purpose: UFFI source to handle objects and pointers
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: objects.lisp,v 1.6 2002/11/23 18:01:57 kevin Exp $
+;;;; $Id: objects.lisp,v 1.16 2003/08/14 19:35:05 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
;;;; *************************************************************************
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
(defun size-of-foreign-type (type)
#+lispworks (fli:size-of type)
#+lispworks
`(fli:allocate-foreign-object :type ',(convert-from-uffi-type type :allocate) :nelems ,size)
#+allegro
- `(ff:allocate-fobject '(:array ,(convert-from-uffi-type (eval type) :allocate) ,(eval size)) :c)
+ `(ff:allocate-fobject (list :array (quote ,(convert-from-uffi-type type :allocate)) ,size) :c)
#+mcl
`(new-ptr (* ,size ,(size-of-foreign-type (convert-from-uffi-type type :allocation))))
)))
#+(or cmu scl) `(alien:deref ,ptr)
#+sbcl `(sb-alien:deref ,ptr)
#+lispworks `(fli:dereference ,ptr)
- #+allegro `(ff:fslot-value-typed (convert-from-uffi-type ,type :deref) :c ,ptr)
- #+mcl `(ccl:pref ,ptr (convert-from-uffi-type ,type :deref))
+ #+allegro `(ff:fslot-value-typed (quote ,(convert-from-uffi-type type :deref)) :c ,ptr)
+ #+mcl `(ccl:pref ,ptr ,(convert-from-uffi-type type :deref))
)
#+mcl
#+mcl
(defsetf deref-pointer deref-pointer-set)
-#+(or lispworks (and mcl (not openmcl))) ;; with LW, deref is a character
+#+lispworks
+(defmacro ensure-char-character (obj)
+ `(if (characterp ,obj) ,obj (code-char ,obj)))
+
+#+(and mcl (not openmcl))
(defmacro ensure-char-character (obj)
obj)
`(with-foreign-objects ((,var ,type))
,@body))
+#+lispworks
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+ `(fli:with-coerced-pointer (,binding-name
+ :type ',(convert-from-uffi-type (eval type) :type))
+ ,pointer
+ ,@body))
+
+#+(or cmu scl sbcl)
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+ `(let ((,binding-name
+ (#+(or cmu scl) alien:cast
+ #+sbcl sb-alien:cast
+ ,pointer (* ,(convert-from-uffi-type (eval type) :type)))))
+ ,@body))
+
+#+allegro
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+ (declare (ignore type))
+ `(let ((,binding-name ,pointer))
+ ,@body))
+
+#-(or lispworks cmu scl sbcl allegro)
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+ (declare (ignore binding-name pointer type))
+ '(error "WITH-CAST-POINTER not (yet) implemented for ~A"
+ (lisp-implementation-type)))
+