changeset 2111:ac599b9b0490

Use GLib types; Also g_free() MUST be used when memory is allocated via any of the GLib functions! Using libc free() does not go through glib's memory allocator.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 20 Oct 2007 23:18:42 +0300
parents a6232f98dc38
children c1a825ee8cec
files src/musepack/libmpc.cxx
diffstat 1 files changed, 48 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/musepack/libmpc.cxx	Sat Oct 20 21:07:21 2007 +0300
+++ b/src/musepack/libmpc.cxx	Sat Oct 20 23:18:42 2007 +0300
@@ -275,7 +275,7 @@
     gtk_widget_destroy (widgets.configBox);
 }
 
-static int mpcIsOurFile(char* p_Filename)
+static gint mpcIsOurFile(gchar* p_Filename)
 {
     VFSFile *file;
     gchar magic[3];
@@ -290,7 +290,7 @@
     return 0;
 }
 
-static int mpcIsOurFD(char* p_Filename, VFSFile* file)
+static gint mpcIsOurFD(gchar* p_Filename, VFSFile* file)
 {
     gchar magic[3];
     aud_vfs_fread(magic, 1, 3, file);
@@ -341,14 +341,14 @@
     lockRelease();
 }
 
-static int mpcGetTime(InputPlayback *data)
+static gint mpcGetTime(InputPlayback *data)
 {
     if(!isAlive())
         return -1;
     return data->output->output_time();
 }
 
-static Tuple *mpcGetSongTuple(char* p_Filename)
+static Tuple *mpcGetSongTuple(gchar* p_Filename)
 {
     VFSFile *input = aud_vfs_fopen(p_Filename, "rb");
     Tuple *tuple = NULL;
@@ -389,9 +389,9 @@
     }
     else
     {
-        char* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename);
+        gchar* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename);
         perror(temp);
-        free(temp);
+        g_free(temp);
     }
 
     return tuple;
@@ -414,23 +414,23 @@
     }
     else
     {
-        char* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename);
+        gchar* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename);
         perror(temp);
-        free(temp);
+        g_free(temp);
     }
 }
 
 static void freeTags(MpcInfo& tags)
 {
-    free(tags.title);
-    free(tags.artist);
-    free(tags.album);
-    free(tags.comment);
-    free(tags.genre);
-    free(tags.date);
+    g_free(tags.title);
+    g_free(tags.artist);
+    g_free(tags.album);
+    g_free(tags.comment);
+    g_free(tags.genre);
+    g_free(tags.date);
 }
 
-static MpcInfo getTags(const char* p_Filename)
+static MpcInfo getTags(const gchar* p_Filename)
 {
     gchar *pRealFilename = g_filename_from_uri(p_Filename, NULL, NULL);
     File oFile(pRealFilename ? pRealFilename : p_Filename, false);
@@ -588,9 +588,9 @@
             mpc_reader_setup_file_vfs(&reader, input);
             mpc_streaminfo_read(&info, &reader.reader);
 
-            int time = static_cast<int> (mpc_streaminfo_get_length(&info));
-            int minutes = time / 60;
-            int seconds = time % 60;
+            gint time = static_cast<int> (mpc_streaminfo_get_length(&info));
+            gint minutes = time / 60;
+            gint seconds = time % 60;
 
             mpcGtkPrintLabel(streamLabel,    _("Streamversion %d"), info.stream_version);
             mpcGtkPrintLabel(encoderLabel,   _("Encoder: %s"), info.encoder);
@@ -611,30 +611,30 @@
             gtk_entry_set_text(GTK_ENTRY(albumEntry),   tags.album);
             gtk_entry_set_text(GTK_ENTRY(commentEntry), tags.comment);
             gtk_entry_set_text(GTK_ENTRY(genreEntry),   tags.genre);
-            char* entry = g_strdup_printf ("%d", tags.track);
+            gchar* entry = g_strdup_printf ("%d", tags.track);
             gtk_entry_set_text(GTK_ENTRY(trackEntry), entry);
-            free(entry);
+            g_free(entry);
             entry = g_strdup_printf ("%d", tags.year);
             gtk_entry_set_text(GTK_ENTRY(yearEntry), entry);
-            free(entry);
+            g_free(entry);
             entry = g_filename_display_name(p_Filename);
             gtk_entry_set_text(GTK_ENTRY(fileEntry), entry);
-            free(entry);
+            g_free(entry);
             freeTags(tags);
             aud_vfs_fclose(input);
         }
         else
         {
-            char* temp = g_strdup_printf("[xmms-musepack] mpcFileInfoBox is unable to read tags from %s", p_Filename);
+            gchar* temp = g_strdup_printf("[xmms-musepack] mpcFileInfoBox is unable to read tags from %s", p_Filename);
             perror(temp);
-            free(temp);
+            g_free(temp);
         }
 
-	char* name = g_filename_display_basename(p_Filename);
-        char* text = g_strdup_printf(_("File Info - %s"), name);
-        free(name);
+	gchar* name = g_filename_display_basename(p_Filename);
+        gchar* text = g_strdup_printf(_("File Info - %s"), name);
+        g_free(name);
         gtk_window_set_title(GTK_WINDOW(infoBox), text);
-        free(text);
+        g_free(text);
 
         gtk_widget_show_all(infoBox);
     }
@@ -645,11 +645,11 @@
     va_list args;
 
     va_start(args, format);
-    char* temp = g_strdup_vprintf(format, args);
+    gchar* temp = g_strdup_vprintf(format, args);
     va_end(args);
 
     gtk_label_set_text(GTK_LABEL(widget), temp);
-    free(temp);
+    g_free(temp);
 }
 
 static GtkWidget* mpcGtkTagLabel(const char* p_Text, int a, int b, int c, int d, GtkWidget* p_Box)
@@ -703,11 +703,11 @@
     File oFile(gtk_entry_get_text(GTK_ENTRY(widgets.fileEntry)));
     Tag* poTag = oFile.tag();
 
-    char* cAlbum   = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.albumEntry)));
-    char* cArtist  = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.artistEntry)));
-    char* cTitle   = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.titleEntry)));
-    char* cGenre   = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.genreEntry)));
-    char* cComment = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.commentEntry)));
+    gchar* cAlbum   = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.albumEntry)));
+    gchar* cArtist  = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.artistEntry)));
+    gchar* cTitle   = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.titleEntry)));
+    gchar* cGenre   = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.genreEntry)));
+    gchar* cComment = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.commentEntry)));
 
     const String album   = String(cAlbum,   TagLib::String::UTF8);
     const String artist  = String(cArtist,  TagLib::String::UTF8);
@@ -723,11 +723,11 @@
     poTag->setYear(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.yearEntry))));
     poTag->setTrack(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.trackEntry))));
 
-    free(cAlbum);
-    free(cArtist);
-    free(cTitle);
-    free(cGenre);
-    free(cComment);
+    g_free(cAlbum);
+    g_free(cArtist);
+    g_free(cTitle);
+    g_free(cGenre);
+    g_free(cComment);
 
     oFile.save();
     closeInfoBox(NULL, NULL);
@@ -739,25 +739,25 @@
     widgets.infoBox = NULL;
 }
 
-static char* mpcGenerateTitle(const MpcInfo& p_Tags, char* p_Filename)
+static char* mpcGenerateTitle(const MpcInfo& p_Tags, gchar* p_Filename)
 {
     Tuple* tuple = mpcGetSongTuple(p_Filename);
 
-    char* title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
+    gchar* title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
 
     aud_tuple_free((void *) tuple);
     return title;
 }
 
-static void* endThread(char* p_FileName, VFSFile * p_FileHandle, bool release)
+static void* endThread(gchar* p_FileName, VFSFile * p_FileHandle, bool release)
 {
-    free(p_FileName);
+    g_free(p_FileName);
     if(release)
         lockRelease();
     if(mpcDecoder.isError)
     {
         perror(mpcDecoder.isError);
-        free(mpcDecoder.isError);
+        g_free(mpcDecoder.isError);
         mpcDecoder.isError = NULL;
     }
     setAlive(false);
@@ -765,7 +765,7 @@
         aud_vfs_fclose(p_FileHandle);
     if(track.display)
     {
-        free(track.display);
+        g_free(track.display);
         track.display = NULL;
     }
     return 0;
@@ -827,7 +827,7 @@
 
     lockRelease();
 
-    int counter = 2 * track.sampleFreq / 3;
+    gint counter = 2 * track.sampleFreq / 3;
     while (isAlive())
     {
         if (getOffset() != -1)
@@ -838,7 +838,7 @@
 
         lockAcquire();
         short iPlaying = MpcPlugin.output->buffer_playing()? 1 : 0;
-        int iFree = MpcPlugin.output->buffer_free();
+        gint iFree = MpcPlugin.output->buffer_free();
         if (!mpcDecoder.isPause &&  iFree >= ((1152 * 4) << iPlaying))
         {
             unsigned status = processBuffer(data, sampleBuffer, xmmsBuffer, decoder);