Replacing deprecated functions in libgpod
Daniele Forsi <[email protected]> Sun, 8 Jul 2012 15:01:49 +0200
| Newsgroups | gmane.comp.ipod.gtkpod |
|---|---|
| Message-ID | <CAN_we7NMRhJVsX1-rX1pjJ3gDuwHig98Pu_MVtcshxv5XnPiJQ@mail.gmail.com> |
Hello, When compiling libgpod on Debian unstable wheezy/sid I found that warnings are treated as errors and build fails because g_basename(), g_mapped_file_free() and gdk_pixbuf_unref() are deprecated, so I made the following patches and would like to know your opinion: shall I commit them or change something? Commit messages are long because of gcc error messages. Instead of g_basename() we can use g_path_get_basename() (as in the attached patch) or just use argv[0], which would be simpler and in most cases just as effective IMHO, or handle arguments with GOption which can be overkill for such small progams. Instead of g_mapped_file_free() we can add a preprocessor conditional (as in the attached patch) or bump the glib requirement to 2.22. Instead of gdk_pixbuf_unref we can use g_object_unref() (as in the attached patch) without conditionals because for what I understand requiring gdk-pixbuf-2.0 is enough. >From fc2ad71aa5ba6232edfe2c29d8bd0a19608109f1 Mon Sep 17 00:00:00 2001 From: Daniele Forsi <[email protected]> Date: Sun, 8 Jul 2012 12:32:17 +0200 Subject: [PATCH 1/3] Conditionally replace deprecated glib function Use g_mapped_file_unref() instead of g_mapped_file_free(). Fixes: db-parse-context.c: In function 'db_parse_context_destroy': db-parse-context.c:67:3: error: 'g_mapped_file_free' is deprecated (declared at /usr/include/glib-2.0/glib/gmappedfile.h:48): Use 'g_mapped_file_unref' instead [-Werror=deprecated-declarations] db-parse-context.c: In function 'db_parse_context_new_from_file': db-parse-context.c:218:3: error: 'g_mapped_file_free' is deprecated (declared at /usr/include/glib-2.0/glib/gmappedfile.h:48): Use 'g_mapped_file_unref' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors --- src/db-parse-context.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/db-parse-context.c b/src/db-parse-context.c index 88009c9..3005753 100644 --- a/src/db-parse-context.c +++ b/src/db-parse-context.c @@ -64,7 +64,11 @@ db_parse_context_destroy (DBParseContext *ctx) g_return_if_fail (ctx != NULL); if (ctx->mapped_file) { +#if GLIB_CHECK_VERSION (2,22,0) + g_mapped_file_unref (ctx->mapped_file); +#else g_mapped_file_free(ctx->mapped_file); +#endif } g_free (ctx); @@ -215,7 +219,11 @@ db_parse_context_new_from_file (const char *filename, Itdb_DB *db) device->byte_order); if (ctx == NULL) { +#if GLIB_CHECK_VERSION (2,22,0) + g_mapped_file_unref (mapped_file); +#else g_mapped_file_free(mapped_file); +#endif return NULL; } ctx->db = db; -- 1.7.10.4 >From d90cb7b7eb004c241cfa121c9d6912064513ab56 Mon Sep 17 00:00:00 2001 From: Daniele Forsi <[email protected]> Date: Sun, 8 Jul 2012 12:36:38 +0200 Subject: [PATCH 2/3] Replace deprecated gdk-pixbuf function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use g_object_unref() instead of gdk_pixbuf_unref() which is deprecated since gdk-pixbuf 2.0 and libgpod optionally depends on 2.6.0. Fixes: itdb_artwork.c: In function 'itdb_thumb_ipod_item_to_pixbuf': itdb_artwork.c:885:2: error: 'gdk_pixbuf_unref' is deprecated (declared at /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h:243): Use 'g_object_unref' instead [-Werror=deprecated-declarations] itdb_artwork.c:886:2: error: 'gdk_pixbuf_unref' is deprecated (declared at /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h:243): Use 'g_object_unref' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors test-covers.c: In function ‘save_itdb_thumb’: test-covers.c:56:9: error: ‘gdk_pixbuf_unref’ is deprecated (declared at /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h:243): Use 'g_object_unref' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors test-photos.c: In function ‘dump_thumbs’: test-photos.c:84:3: error: ‘gdk_pixbuf_unref’ is deprecated (declared at /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h:243): Use 'g_object_unref' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors --- src/itdb_artwork.c | 4 ++-- tests/test-covers.c | 2 +- tests/test-photos.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c index 2328840..54d6aae 100644 --- a/src/itdb_artwork.c +++ b/src/itdb_artwork.c @@ -882,8 +882,8 @@ gpointer itdb_thumb_ipod_item_to_pixbuf (Itdb_Device *device, pad_x, pad_y, width, height); pixbuf = gdk_pixbuf_copy (pixbuf_sub); - gdk_pixbuf_unref (pixbuf_full); - gdk_pixbuf_unref (pixbuf_sub); + g_object_unref (pixbuf_full); + g_object_unref (pixbuf_sub); return pixbuf; } diff --git a/tests/test-covers.c b/tests/test-covers.c index 20b4d7b..4d3a68f 100644 --- a/tests/test-covers.c +++ b/tests/test-covers.c @@ -53,7 +53,7 @@ save_itdb_thumb (Itdb_Track *track, GdkPixbuf *pixbuf, guint id) } g_print (" %s\n", filename); gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL); - gdk_pixbuf_unref (pixbuf); + g_object_unref (pixbuf); /* g_print ("Saved %s\n", filename); */ g_free (filename); } diff --git a/tests/test-photos.c b/tests/test-photos.c index 930e66b..b5bd89d 100644 --- a/tests/test-photos.c +++ b/tests/test-photos.c @@ -81,7 +81,7 @@ dump_thumbs (Itdb_PhotoDB *db, Itdb_Artwork *artwork, path = g_build_filename (dir, filename, NULL); g_free (filename); gdk_pixbuf_save (pixbuf, path, "png", NULL, NULL); - gdk_pixbuf_unref (pixbuf); + g_object_unref (pixbuf); g_free (path); } g_list_free (thumbnails); -- 1.7.10.4 >From f61b328c176bca8a42646a0553b3a4e4e0057eaf Mon Sep 17 00:00:00 2001 From: Daniele Forsi <[email protected]> Date: Sun, 8 Jul 2012 13:52:59 +0200 Subject: [PATCH 3/3] Replace deprecated glib function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use g_path_get_basename() instead of g_basename() which is deprecated since glib 2.2 and libgpod depends on 2.16. Fixes: read-sysinfoextended.c: In function ‘main’: read-sysinfoextended.c:81:7: error: ‘g_basename’ is deprecated (declared at /usr/include/glib-2.0/glib/gfileutils.h:159): Use 'g_path_get_basename' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors itdb_main.c: In function ‘main’: itdb_main.c:58:7: error: ‘g_basename’ is deprecated (declared at /usr/include/glib-2.0/glib/gfileutils.h:159): Use 'g_path_get_basename' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors test-ls.c: In function ‘main’: test-ls.c:124:17: error: ‘g_basename’ is deprecated (declared at /usr/include/glib-2.0/glib/gfileutils.h:159): Use 'g_path_get_basename' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors test-fw-id.c: In function ‘main’: test-fw-id.c:45:9: error: ‘g_basename’ is deprecated (declared at /usr/include/glib-2.0/glib/gfileutils.h:159): Use 'g_path_get_basename' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors get-timezone.c: In function ‘main’: get-timezone.c:31:9: error: ‘g_basename’ is deprecated (declared at /usr/include/glib-2.0/glib/gfileutils.h:159): Use 'g_path_get_basename' instead [-Werror=deprecated-declarations] cc1: all warnings being treated as errors --- tests/get-timezone.c | 7 ++++++- tests/itdb_main.c | 7 ++++++- tests/test-fw-id.c | 7 ++++++- tests/test-ls.c | 7 ++++++- tools/read-sysinfoextended.c | 7 ++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/get-timezone.c b/tests/get-timezone.c index e453ca3..75d77bf 100644 --- a/tests/get-timezone.c +++ b/tests/get-timezone.c @@ -28,7 +28,12 @@ int main (int argc, char **argv) if (argc >= 2) { mountpoint = argv[1]; } else { - g_print ("Usage: %s <mountpoint>\n\n", g_basename(argv[0])); + gchar *basename; + + basename = g_path_get_basename (argv[0]); + g_print ("Usage: %s <mountpoint>\n\n", basename); + g_free (basename); + return -1; } diff --git a/tests/itdb_main.c b/tests/itdb_main.c index e7723bb..9ae9b94 100644 --- a/tests/itdb_main.c +++ b/tests/itdb_main.c @@ -55,7 +55,12 @@ main (int argc, char *argv[]) if (infile == 0) { - printf ("Usage: %s <infile> [<outfile>]\n", g_basename(argv[0])); + gchar *basename; + + basename = g_path_get_basename (argv[0]); + printf ("Usage: %s <infile> [<outfile>]\n", basename); + g_free (basename); + exit (0); } diff --git a/tests/test-fw-id.c b/tests/test-fw-id.c index 7490001..68232c5 100644 --- a/tests/test-fw-id.c +++ b/tests/test-fw-id.c @@ -42,7 +42,12 @@ main (int argc, char *argv[]) char *fwid; if (argc < 2) { - g_print ("Usage: %s <mountpoint>\n", g_basename (argv[0])); + gchar *basename; + + basename = g_path_get_basename (argv[0]); + g_print ("Usage: %s <mountpoint>\n", basename); + g_free (basename); + return 1; } diff --git a/tests/test-ls.c b/tests/test-ls.c index e28cd9c..6ab35aa 100644 --- a/tests/test-ls.c +++ b/tests/test-ls.c @@ -118,10 +118,15 @@ main (int argc, char *argv[]) if (mountpoint == NULL) { + gchar *basename; + + basename = g_path_get_basename (argv[0]); g_print ("Usage: %s <mountpoint>|-l [<playlistname>]\n\n" "-l - List from the local repository (~" LOCALDB ")\n" "<playlistname> - name of the playlist to list (optional)\n", - g_basename(argv[0])); + basename); + g_free (basename); + exit (0); } diff --git a/tools/read-sysinfoextended.c b/tools/read-sysinfoextended.c index b3afd2c..3397ac4 100644 --- a/tools/read-sysinfoextended.c +++ b/tools/read-sysinfoextended.c @@ -78,7 +78,12 @@ main (int argc, char **argv) char *xml; if (argc < 3) { - g_print (_("usage: %s <device|uuid|bus device> <mountpoint>\n"), g_basename (argv[0])); + gchar *basename; + + basename = g_path_get_basename (argv[0]); + g_print (_("usage: %s <device|uuid|bus device> <mountpoint>\n"), basename); + g_free (basename); + return 1; } -- 1.7.10.4 -- Daniele Forsi ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/