Commits

shuerhaaken  committed 2edf857

add null checks and update bindings

  • Participants
  • Parent commits 1b07e81

Comments (0)

Files changed (5)

+commit 1b07e81aa68f78b3e369b0653242b04927a15463
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Tue Apr 16 19:49:14 2013 +0200
+
+    use proper empty strings in return values to avoid issues
+
 commit fe1e350e0877344dbbfeea3a9becba17adcd2dfc
 Author: Jörn Magens <shuerhaaken@googlemail.com>
 Date:   Fri Apr 5 11:12:41 2013 +0200

File bindings/c/taginfo_c.cc

     int j = 0;
     for(StringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
         array[j] = ::strdup((*it).toCString(false));
-        if(stringManagementEnabled)
+        if(stringManagementEnabled && array[j])
             strings.prepend(array[j]);
         j++;
     }
     const Info *i = reinterpret_cast<const Info *>(info);
     String artist = i->get_artist();
     char *s = ::strdup(artist.toCString(true));
-    if(stringManagementEnabled)
+    if(stringManagementEnabled && s)
         strings.prepend(s);
     return s;
 }
     const Info *i = reinterpret_cast<const Info *>(info);
     String album = i->get_album();
     char *s = ::strdup(album.toCString(true));
-    if(stringManagementEnabled)
+    if(stringManagementEnabled && s)
         strings.prepend(s);
     return s;
 }
     const Info *i = reinterpret_cast<const Info *>(info);
     String title = i->get_title();
     char *s = ::strdup(title.toCString(true));
-    if(stringManagementEnabled)
+    if(stringManagementEnabled && s)
         strings.prepend(s);
     return s;
 }
     const Info *i = reinterpret_cast<const Info *>(info);
     String album_artist = i->get_album_artist();
     char *s = ::strdup(album_artist.toCString(true));
-    if(stringManagementEnabled)
+    if(stringManagementEnabled && s)
         strings.prepend(s);
     return s;
 }
     const Info *i = reinterpret_cast<const Info *>(info);
     String comments = i->get_comments();
     char *s = ::strdup(comments.toCString(true));
-    if(stringManagementEnabled)
+    if(stringManagementEnabled && s)
         strings.prepend(s);
     return s;
 }
     i->set_comments(String(comment, String::UTF8));
 }
 
+char * taginfo_info_get_composer(const TagInfo_Info *info) {
+    const Info *i = reinterpret_cast<const Info *>(info);
+    String composer = i->get_composer();
+    char *s = ::strdup(composer.toCString(true));
+    if(stringManagementEnabled && s)
+        strings.prepend(s);
+    return s;
+}
+void taginfo_info_set_taginfo_info_set_composer(TagInfo_Info *info, const char *composer) {
+    Info *i = reinterpret_cast<Info *>(info);
+    i->set_composer(String(composer, String::UTF8));
+}
+
 char * taginfo_info_get_genre(const TagInfo_Info *info) {
     const Info *i = reinterpret_cast<const Info *>(info);
     String genre = i->get_genre();
     char *s = ::strdup(genre.toCString(true));
-    if(stringManagementEnabled)
+    if(stringManagementEnabled && s)
         strings.prepend(s);
     return s;
 }
     const Info *i = reinterpret_cast<const Info *>(info);
     String lyrics = i->get_lyrics();
     char *s = ::strdup(lyrics.toCString(true));
-    if(stringManagementEnabled)
+    if(stringManagementEnabled && s)
         strings.prepend(s);
     return s;
 }

File bindings/c/taginfo_c.h

 char *taginfo_info_get_comment(const TagInfo_Info *info);
 void  taginfo_info_set_comment(TagInfo_Info *info, const char *comment);
 
+char *taginfo_info_get_composer(const TagInfo_Info *info);
+void  taginfo_info_set_composer(TagInfo_Info *info, const char *composer);
+
 char *taginfo_info_get_genre(const TagInfo_Info *info);
 void  taginfo_info_set_genre(TagInfo_Info *info, const char *genre);
 

File bindings/vala/libtaginfo_c.vapi

 			[CCode (cname = "taginfo_info_set_comment")]
 			set;
 		}
+		public string composer {
+			[CCode (cname = "taginfo_info_get_composer")]
+			owned get;
+			[CCode (cname = "taginfo_info_set_composer")]
+			set;
+		}
 		public bool is_compilation {
 			[CCode (cname = "taginfo_info_get_is_compilation")]
 			get;

File tests/ctest_read/main.c

 {
     TagInfo_Info *info;
     
-    char val[200] = TESTDIR "samples/sample.flac";
+    char val[200] = TESTDIR "samples/sample_no-tags.flac";
     info = taginfo_info_factory_make(val);
     
     if(info == NULL)
         return 1; //EXIT_FAILURE
     
+    taginfo_info_enable_string_management(1);
+    
     if(taginfo_info_read(info)) {
         char* name = taginfo_info_get_title(info);
-        free(name);
+        char* album = taginfo_info_get_album(info);
+        /*free(name);*/
         char* comment = taginfo_info_get_comment(info);
-        free(comment);
+        char* composer = taginfo_info_get_composer(info);
+        /*free(comment);*/
     }
     else {
         taginfo_info_free(info);
         return 1; //EXIT_FAILURE
     }
+    taginfo_info_free_strings();
     taginfo_info_free(info);
     return 0; //EXIT_SUCCESS
 }