X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/3005806e61162b6f55a29bd7b40fcf2bcc8c35fc..79c7839653d89bae3d5d7ef490ef32dd5d248b30:/glib/glib.lisp diff --git a/glib/glib.lisp b/glib/glib.lisp index c57882a..0caa70d 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.32 2006-02-06 18:12:19 espen Exp $ +;; $Id: glib.lisp,v 1.34 2006-02-15 09:53:42 espen Exp $ (in-package "GLIB") @@ -47,6 +47,17 @@ #+sbcl(system-area-ub8-copy from 0 to 0 length) to) +(defmacro with-allocated-memory ((var size) &body body) + (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