X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=sidebyside;f=src%2Fobjects.cl;h=b510b35bcd47f9627f0b1d46445c389d9bb85797;hb=379a7c3e7b8249ace498d8733c87a3f575a7c799;hp=b0b34f07ca98fb8191238cdf7f9fd8e5285c24eb;hpb=4054fe997dbce15071a1d2b96a082b4a4a5a8363;p=uffi.git diff --git a/src/objects.cl b/src/objects.cl index b0b34f0..b510b35 100644 --- a/src/objects.cl +++ b/src/objects.cl @@ -1,4 +1,4 @@ -;;;; -*- Mode: ANSI-Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; @@ -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.14 2002/03/22 20:51:08 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,14 +107,23 @@ an array of TYPE with size SIZE." obj ) -;; 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 with-foreign-object ((var type) &rest body) + #-(or cmu lispworks) ; default version + `(let ((,var (allocate-foreign-object ,type))) + (unwind-protect + (progn ,@body) + (free-foreign-object ,var))) + #+cmu + (let ((obj (gensym))) + `(alien:with-alien ((,obj ,(convert-from-uffi-type type :allocate))) + (let ((,var (alien:addr ,obj))) + ,@body))) + #+lispworks + `(fli:with-dynamic-foreign-objects ((,var ,(convert-from-uffi-type + type :allocate))) + ,@body) + ) + (defmacro with-foreign-objects (bindings &rest body) (if bindings