X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/3d23e95206f063496153a0993f7f3199231613b6..b008da5a007572a07f736534e15a7a3845c97745:/glib/glib.lisp diff --git a/glib/glib.lisp b/glib/glib.lisp index ebc3b30..be287eb 100644 --- a/glib/glib.lisp +++ b/glib/glib.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: glib.lisp,v 1.33 2006/02/09 22:24:31 espen Exp $ +;; $Id: glib.lisp,v 1.34 2006/02/15 09:53:42 espen Exp $ (in-package "GLIB") @@ -48,10 +48,15 @@ to) (defmacro with-allocated-memory ((var size) &body body) - `(let ((,var (allocate-memory ,size))) - (unwind-protect - (progn ,@body) - (deallocate-memory ,var)))) + (if (constantp size) + (let ((alien (make-symbol "ALIEN"))) + `(with-alien ((,alien (array #+sbcl(sb-alien:unsigned 8) #+cmu(alien:unsigned 8) ,(eval size)))) + (let ((,var (alien-sap ,alien))) + ,@body))) + `(let ((,var (allocate-memory ,size))) + (unwind-protect + (progn ,@body) + (deallocate-memory ,var))))) ;;;; User data mechanism