diff options
Diffstat (limited to 'Lisp')
-rw-r--r-- | Lisp/libobjcl.lisp | 8 | ||||
-rw-r--r-- | Lisp/type-conversion.lisp | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/Lisp/libobjcl.lisp b/Lisp/libobjcl.lisp index b38aa6e..041ddf3 100644 --- a/Lisp/libobjcl.lisp +++ b/Lisp/libobjcl.lisp @@ -84,13 +84,13 @@ objects or classes, let alone send messages to them. (defcfun ("objcl_find_class" %objcl-find-class) :pointer (class-name :string)) -(defcfun ("objcl_class_name" %objcl-class-name) :string +(defcfun ("objcl_class_name" %objcl-class-name) :pointer (class obj-data)) (defcfun ("objcl_find_selector" %objcl-find-selector) :pointer (selector-name :string)) -(defcfun ("objcl_selector_name" %objcl-selector-name) :string +(defcfun ("objcl_selector_name" %objcl-selector-name) :pointer (selector obj-data)) @@ -169,13 +169,13 @@ conventional case for namespace identifiers in Objective C." (defun objcl-class-name (class) (declare (type (or objc-class id exception) class)) (with-foreign-conversion ((obj-data class)) - (%objcl-class-name obj-data))) + (foreign-string-to-lisp/dealloc (%objcl-class-name obj-data)))) (defun selector-name (selector) (declare (type selector selector)) (with-foreign-conversion ((obj-data selector)) - (%objcl-selector-name obj-data))) + (foreign-string-to-lisp/dealloc (%objcl-selector-name obj-data)))) (defun find-selector (selector-name) diff --git a/Lisp/type-conversion.lisp b/Lisp/type-conversion.lisp index 066fdd9..a11a668 100644 --- a/Lisp/type-conversion.lisp +++ b/Lisp/type-conversion.lisp @@ -56,3 +56,12 @@ ,@(mapcar #'(lambda (name-value-pair) `(dealloc-obj-data ,(first name-value-pair))) bindings)))) + + +(defun foreign-string-to-lisp/dealloc (foreign-string) + "Convert a (possibly freshly allocated) C string into a Lisp string +and free the C string afterwards." + + (unwind-protect + (foreign-string-to-lisp foreign-string) + (foreign-string-free foreign-string))) |