summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2007-08-06 18:11:08 +0200
committerMatthias Benkard <code@mail.matthias.benkard.de>2007-08-06 18:11:08 +0200
commite7524b783a7e2219e16c64dde7a9f965b75ed970 (patch)
tree0a2428ad4dff3ee4fa924a2b2dd0839523618342
parentb423c77db3caafb5eeb55cf185893aba8c23b842 (diff)
If necessary, deallocate a C string after converting it.
darcs-hash:4f83783092400107dd9b58671d11d4cb6a9d5214
-rw-r--r--Lisp/libobjcl.lisp8
-rw-r--r--Lisp/type-conversion.lisp9
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)))