From e562ec45a61b6b60fdbacf609ece03d998452b95 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Mon, 6 Aug 2007 17:44:07 +0200 Subject: Minor cleanups. darcs-hash:ee74b33660af9dc6b1e0207285907211dd7e600a --- Lisp/libobjcl.lisp | 9 ++++----- Lisp/type-conversion.lisp | 12 +++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'Lisp') diff --git a/Lisp/libobjcl.lisp b/Lisp/libobjcl.lisp index fff0963..9591f8f 100644 --- a/Lisp/libobjcl.lisp +++ b/Lisp/libobjcl.lisp @@ -147,26 +147,25 @@ conventional case for namespace identifiers in Objective C." (defun find-objc-class-by-name (class-name) - (let ((obj-data (%objcl-find-class class-name))) + (with-foreign-objects ((obj-data (%objcl-find-class class-name))) (unwind-protect (if (null-pointer-p (foreign-slot-value (foreign-slot-value obj-data 'obj-data 'data) 'obj-data-union 'class-val)) nil - (obj-data->lisp obj-data)) - (dealloc-obj-data obj-data)))) + (obj-data->lisp obj-data))))) (defun objcl-class-name (class) (declare (type (or objc-class id exception) class)) - (with-foreign-objects ((obj-data class)) + (with-foreign-conversion ((obj-data class)) (%objcl-class-name obj-data))) (defun selector-name (selector) (declare (type selector selector)) - (with-foreign-objects ((obj-data selector)) + (with-foreign-conversion ((obj-data selector)) (%objcl-selector-name obj-data))) diff --git a/Lisp/type-conversion.lisp b/Lisp/type-conversion.lisp index 3ac1ce6..066fdd9 100644 --- a/Lisp/type-conversion.lisp +++ b/Lisp/type-conversion.lisp @@ -35,11 +35,21 @@ (otherwise value))))) +(defmacro with-foreign-conversion (bindings &body body) + `(with-foreign-objects + ,(mapcar #'(lambda (name-value-pair) + (destructuring-bind (name value) + name-value-pair + `(,name (lisp->obj-data ,value)))) + bindings) + ,@body)) + + (defmacro with-foreign-objects (bindings &body body) `(let ,(mapcar #'(lambda (name-value-pair) (destructuring-bind (name value) name-value-pair - `(,name (lisp->obj-data ,value)))) + `(,name ,value))) bindings) (unwind-protect (progn ,@body) -- cgit v1.2.3