X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fobjects.cl;h=7f10ab5ba30124e4a08f5e43edf5b7b4c3abbff8;hb=3dd32205c2d49f126223f5e9ad083093d0636de7;hp=f9651d468c53603e763012d736c524360e5838ad;hpb=11f2368e2aa756f12f698ce3f2d5182d2299dafc;p=uffi.git diff --git a/src/objects.cl b/src/objects.cl index f9651d4..7f10ab5 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.8 2002/03/18 22:47:57 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,13 +64,40 @@ 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)) #+cmu `(alien:deref ,ptr) #+lispworks `(fli:dereference ,ptr) #+allegro `(ff:fslot-value-typed ,type :c ,ptr) ) +#+lispworks ;; with LW, deref is a character +(defmacro ensure-char-character (obj) + obj + ) + +#+(or allegro cmu) +(defmacro ensure-char-character (obj) + `(code-char ,obj) + ) + +#+lispworks +(defmacro ensure-char-integer (obj) + `(char-code ,obj)) + +#+(or allegro cmu) +(defmacro ensure-char-integer (obj) + obj + ) ;; (* :char) dereference is already an integer + (defmacro pointer-address (obj) #+cmu `(system:sap-int (alien:alien-sap ,obj)) @@ -80,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))) + + +