r1612: *** empty log message ***
[uffi.git] / src / objects.cl
index 1ac0ad8b4080f6c1836a10b69eb447d2be3b9693..7f10ab5ba30124e4a08f5e43edf5b7b4c3abbff8 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: objects.cl,v 1.10 2002/03/21 07:56:45 kevin Exp $
+;;;; $Id: objects.cl,v 1.12 2002/03/21 15:57:01 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -64,6 +64,13 @@ an array of TYPE with size SIZE."
   #+lispworks `(fli:make-pointer :address 0 :type ,type)
   )
 
+(defmacro char-array-to-pointer (obj)
+  #+cmu `(alien:cast ,obj (* (alien:unsigned 8)))
+  #+lispworks `(fli:make-pointer :type '(:unsigned :char)
+                               :address (fli:pointer-address ,obj))
+  #+allegro obj
+  )
+
 (defmacro deref-pointer (ptr type)
   "Returns a object pointed"
   #+(or cmu lispworks) (declare (ignore type))
@@ -100,19 +107,21 @@ an array of TYPE with size SIZE."
   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 ((,var (allocate-foreign-object ,type ,@etc)))
+    (unwind-protect
+        (progn ,@body)
+      (free-foreign-object ,var))))
 
-(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)))
+
+           
+