[gtk|demos/gtk-demo]/language-names.c: Fix build on non-GCC/CLang
authorChun-wei Fan <fanchunwei@src.gnome.org>
Wed, 28 Mar 2018 03:59:11 +0000 (11:59 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Mon, 2 Apr 2018 11:13:27 +0000 (19:13 +0800)
Remove g_auto*() usage from these sources and use the traditional
g_free(), as g_auto*() are GCCisms (or CLangisms).

Also, don't include unistd.h unconditionally and stop including
langinfo.h and dirent.h, since they seem to be unused.

https://bugzilla.gnome.org/show_bug.cgi?id=773299

demos/gtk-demo/language-names.c
gtk/language-names.c

index 0c0076bbd8f5e4b0d06328a00f9306bdcf2eb457..3cd9142d046f532d8e9ae6fc7beec14185e2eace 100644 (file)
@@ -2,12 +2,13 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <string.h>
 #include <errno.h>
-#include <dirent.h>
 #include <locale.h>
-#include <langinfo.h>
 #include <sys/stat.h>
 
 #include <glib.h>
@@ -173,9 +174,9 @@ languages_variant_init (const char *variant)
 {
   gboolean res;
   gsize    buf_len;
-  g_autofree char *buf = NULL;
-  g_autofree char *filename = NULL;
-  g_autoptr (GError) error = NULL;
+  char *buf = NULL;
+  char *filename = NULL;
+  GError *error = NULL;
 
   bindtextdomain (variant, ISO_CODES_LOCALESDIR);
   bind_textdomain_codeset (variant, "UTF-8");
@@ -185,19 +186,25 @@ languages_variant_init (const char *variant)
   res = g_file_get_contents (filename, &buf, &buf_len, &error);
   if (res)
     {
-      g_autoptr (GMarkupParseContext) ctx = NULL;
+      GMarkupParseContext *ctx = NULL;
       GMarkupParser parser = { languages_parse_start_tag, NULL, NULL, NULL, NULL };
 
       ctx = g_markup_parse_context_new (&parser, 0, NULL, NULL);
 
+      g_free (error);
       error = NULL;
       res = g_markup_parse_context_parse (ctx, buf, buf_len, &error);
+      g_free (ctx);
 
       if (!res)
         g_warning ("Failed to parse '%s': %s\n", filename, error->message);
     }
   else
     g_warning ("Failed to load '%s': %s\n", filename, error->message);
+
+  g_free (error);
+  g_free (filename);
+  g_free (buf);
 }
 
 static void
index 0c0076bbd8f5e4b0d06328a00f9306bdcf2eb457..6fa6eaa2f2cf98a0f3798a337e41a62eb43e3a20 100644 (file)
@@ -2,12 +2,14 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+
 #include <string.h>
 #include <errno.h>
-#include <dirent.h>
 #include <locale.h>
-#include <langinfo.h>
 #include <sys/stat.h>
 
 #include <glib.h>
@@ -173,9 +175,9 @@ languages_variant_init (const char *variant)
 {
   gboolean res;
   gsize    buf_len;
-  g_autofree char *buf = NULL;
-  g_autofree char *filename = NULL;
-  g_autoptr (GError) error = NULL;
+  char *buf = NULL;
+  char *filename = NULL;
+  GError *error = NULL;
 
   bindtextdomain (variant, ISO_CODES_LOCALESDIR);
   bind_textdomain_codeset (variant, "UTF-8");
@@ -185,19 +187,24 @@ languages_variant_init (const char *variant)
   res = g_file_get_contents (filename, &buf, &buf_len, &error);
   if (res)
     {
-      g_autoptr (GMarkupParseContext) ctx = NULL;
+      GMarkupParseContext *ctx = NULL;
       GMarkupParser parser = { languages_parse_start_tag, NULL, NULL, NULL, NULL };
 
       ctx = g_markup_parse_context_new (&parser, 0, NULL, NULL);
 
+      g_free (error);
       error = NULL;
       res = g_markup_parse_context_parse (ctx, buf, buf_len, &error);
+      g_free (ctx);
 
       if (!res)
         g_warning ("Failed to parse '%s': %s\n", filename, error->message);
     }
   else
     g_warning ("Failed to load '%s': %s\n", filename, error->message);
+
+  g_free (filename);
+  g_free (buf);
 }
 
 static void