Commits

Walton Hoops  committed f4d7e25

fix bugs in with-tag-file

  • Participants
  • Parent commits acb63d2

Comments (0)

Files changed (1)

File cl-taglib.lisp

 (defcfun (file-tag "taglib_file_tag") :pointer
   (file :pointer))
 
-;;; taglib_file_audioproperties
-(defcfun (file-save "taglib_file_save") :boolean
+(defcfun (file-audioproperties "taglib_file_audioproperties") :pointer
   (file :pointer))
 
+(defcfun (file-save "taglib_file_save") :boolean
+  (file :pointer))
 
-;;; BUG: var is evaluated multiple times
-;;; BUG: file is not closed if an error is thrown
-;;; BUG: returns no value
 (defmacro with-tag-file ((var path) &body body)
-  `(let ((,var-name (file-new ,path)))
-     ,@body
-     (file-free ,var-name)))
+  `(let ((,var (file-new ,path)))
+     (unwind-protect (progn
+		       ,@body)
+       (file-free ,var))))
 
-(defmacro taglib-accessor-for (slot type)
+(defmacro tag-accessor-for (slot type)
   (let ((function-name (intern (concatenate 'string "TAG-" (string slot))))
 	(foreign-name (string-downcase (concatenate 'string "taglib_tag_" (string slot))))
 	(foreign-set-name (string-downcase (concatenate 'string "taglib_tag_set_" (string slot)))))
 	  `(defun (setf ,function-name) (value tag)
 	    (foreign-funcall ,foreign-set-name :pointer tag ,type value :void)))))
 
-(taglib-accessor-for :title :string)
-(taglib-accessor-for :artist :string)
-(taglib-accessor-for :album :string)
-(taglib-accessor-for :comment :string)
-(taglib-accessor-for :genre :string)
-(taglib-accessor-for :year :uint)
-(taglib-accessor-for :track :uint)
+(tag-accessor-for :title :string)
+(tag-accessor-for :artist :string)
+(tag-accessor-for :album :string)
+(tag-accessor-for :comment :string)
+(tag-accessor-for :genre :string)
+(tag-accessor-for :year :uint)
+(tag-accessor-for :track :uint)