X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=inline;f=src%2Fobjects.cl;h=b0b34f07ca98fb8191238cdf7f9fd8e5285c24eb;hb=4054fe997dbce15071a1d2b96a082b4a4a5a8363;hp=fdecab26d91c9909582a8bfdaffa8f84389be4f9;hpb=e1ba5e8ff148275ed252b179f43a4b045c1dcaf6;p=uffi.git diff --git a/src/objects.cl b/src/objects.cl index fdecab2..b0b34f0 100644 --- a/src/objects.cl +++ b/src/objects.cl @@ -7,7 +7,7 @@ ;;;; 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 ;;;; @@ -74,22 +74,21 @@ an array of TYPE with size SIZE." #+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) @@ -101,19 +100,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 ((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))) + + +