;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: objects.cl,v 1.9 2002/03/19 16:42:59 kevin Exp $
+;;;; $Id: objects.cl,v 1.11 2002/03/21 14:49:14 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
#+lispworks ;; with LW, deref is a character
(defmacro ensure-char-character (obj)
- "Ensures that the dereference of a :char is a character"
+ obj
)
#+(or allegro cmu)
(defmacro ensure-char-character (obj)
- "Ensures that the dereference of a :char is a character"
`(code-char ,obj)
)
#+lispworks
(defmacro ensure-char-integer (obj)
- "Ensures that the dereference of a :char is a character"
`(char-code ,obj))
#+(or allegro cmu)
(defmacro ensure-char-integer (obj)
+ obj
) ;; (* :char) dereference is already an integer
(defmacro pointer-address (obj)
obj
)
-#|
-(defmacro allocate-byte-array (nsize)
- #+cmu
- `(alien:make-alien (alien:unsigned 8) ,nsize)
- #+lispworks
- `(fli:allocate-foreign-object :type :byte :nelems ,nsize)
- #+allegro
- `(ff:allocate-fobject (array :byte ,nsize))
-)
+;; Simple first pass. Will later create optimized routines for
+;; various platforms.
+(defmacro with-foreign-object ((var type &rest etc) &rest body)
+ (let ((result (gensym)))
+ `(let* ((,var (allocate-foreign-object ,type ,@etc))
+ (,result (progn ,@body)))
+ (free-foreign-object ,var)
+ ,result)))
-(defmacro deref-byte-array (array position)
- #+cmu `(alien:deref ,array ,position)
- #+lispworks `(fli:dereference ,array :index ,position)
- #+allegro `(ff:fslot-value-typed '(:array :byte) :c ,array ,position)
-)
-|#
+(defmacro with-foreign-objects (bindings &rest body)
+ (if bindings
+ `(with-foreign-object ,(car bindings)
+ (with-foreign-objects ,(cdr bindings)
+ ,@body))
+ `(progn ,@body)))
+
+
+