r1612: *** empty log message ***
[uffi.git] / src / objects.cl
index b0b34f07ca98fb8191238cdf7f9fd8e5285c24eb..7f10ab5ba30124e4a08f5e43edf5b7b4c3abbff8 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: objects.cl,v 1.11 2002/03/21 14:49:14 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))
@@ -103,11 +110,11 @@ an array of TYPE with size SIZE."
 ;; 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)))
+  `(let ((,var (allocate-foreign-object ,type ,@etc)))
+    (unwind-protect
+        (progn ,@body)
+      (free-foreign-object ,var))))
+
 
 (defmacro with-foreign-objects (bindings &rest body)
   (if bindings