[gjs] gi/, gjs/: Do not use g_autofree



commit bcb5924661587f8b31d524b7bc035decd695e236
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Feb 15 19:18:21 2017 +0800

    gi/, gjs/: Do not use g_autofree
    
    g_autofree is a GCCism which means that it will not work on any compiler
    besides GCC and CLang.  As we are getting close to GNOME 3.24, this serves
    as a temporary patch so that we can work on changing the code to smart
    pointers which will handle the automatic releasing of allocations on the
    heap in the next dev cycle.
    
    Also, include tuple in gi/object.cpp as we are using items from there, and
    compilers such as Visual Studio expect one to be quite specific about
    the things that are included in the std namespace by including the headers
    specifically.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777597

 gi/boxed.cpp       |   21 ++++++++++++++++-----
 gi/fundamental.cpp |   16 ++++++++++++----
 gi/interface.cpp   |    9 +++++++--
 gi/ns.cpp          |    7 ++++++-
 gi/object.cpp      |   14 +++++++++++---
 gi/param.cpp       |    4 +++-
 gi/repo.cpp        |    9 +++++++--
 gi/union.cpp       |    9 +++++++--
 gjs/importer.cpp   |   18 +++++++++++++-----
 9 files changed, 82 insertions(+), 25 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index f910945..28d776e 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -121,7 +121,7 @@ boxed_resolve(JSContext       *context,
               bool            *resolved)
 {
     Boxed *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
 
     if (!gjs_get_string_id(context, id, &name)) {
         *resolved = false;
@@ -132,8 +132,10 @@ boxed_resolve(JSContext       *context,
     gjs_debug_jsprop(GJS_DEBUG_GBOXED, "Resolve prop '%s' hook obj %p priv %p",
                      name, obj.get(), priv);
 
-    if (priv == NULL)
+    if (priv == NULL) {
+        g_free(name);
         return false; /* wrong class */
+    }
 
     if (priv->gboxed == NULL) {
         /* We are the prototype, so look for methods and other class properties */
@@ -161,6 +163,7 @@ boxed_resolve(JSContext       *context,
                 if (gjs_define_function(context, obj, priv->gtype,
                                         (GICallableInfo *)method_info) == NULL) {
                     g_base_info_unref( (GIBaseInfo*) method_info);
+                    g_free(name);
                     return false;
                 }
 
@@ -181,6 +184,7 @@ boxed_resolve(JSContext       *context,
          */
         *resolved = false;
     }
+    g_free(name);
     return true;
 }
 
@@ -278,7 +282,7 @@ boxed_init_from_props(JSContext   *context,
     JS::RootedId prop_id(context);
     for (ix = 0, length = ids.length(); ix < length; ix++) {
         GIFieldInfo *field_info;
-        g_autofree char *name = NULL;
+        char *name = NULL;
 
         if (!gjs_get_string_id(context, ids[ix], &name))
             return false;
@@ -287,6 +291,7 @@ boxed_init_from_props(JSContext   *context,
         if (field_info == NULL) {
             gjs_throw(context, "No field %s on boxed type %s",
                       name, g_base_info_get_name((GIBaseInfo *)priv->info));
+            g_free(name);
             return false;
         }
 
@@ -294,11 +299,17 @@ boxed_init_from_props(JSContext   *context,
          * doesn't know that */
         prop_id = ids[ix];
         if (!gjs_object_require_property(context, props, "property list",
-                                         prop_id, &value))
+                                         prop_id, &value)) {
+            g_free(name);
             return false;
+        }
 
-        if (!boxed_set_field_from_value(context, priv, field_info, value))
+        if (!boxed_set_field_from_value(context, priv, field_info, value)) {
+            g_free(name);
             return false;
+        }
+
+        g_free(name);
     }
 
     return true;
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index e7dea2d..2a2d516 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -300,7 +300,7 @@ fundamental_instance_resolve(JSContext       *context,
                              bool            *resolved)
 {
     FundamentalInstance *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
 
     if (!gjs_get_string_id(context, id, &name)) {
         *resolved = false;
@@ -312,8 +312,10 @@ fundamental_instance_resolve(JSContext       *context,
                      "Resolve prop '%s' hook obj %p priv %p",
                      name, obj.get(), priv);
 
-    if (priv == NULL)
+    if (priv == NULL) {
+        g_free(name);
         return false; /* wrong class */
+    }
 
     if (!fundamental_is_prototype(priv)) {
         /* We are an instance, not a prototype, so look for
@@ -324,6 +326,7 @@ fundamental_instance_resolve(JSContext       *context,
          * hooks, not this resolve hook.
          */
         *resolved = false;
+        g_free(name);
         return true;
     }
 
@@ -352,6 +355,7 @@ fundamental_instance_resolve(JSContext       *context,
                           g_base_info_get_name((GIBaseInfo *) proto_priv->info));
                 g_base_info_unref((GIBaseInfo *) method_info);
                 *resolved = false;
+                g_free(name);
                 return true;
             }
 
@@ -364,6 +368,7 @@ fundamental_instance_resolve(JSContext       *context,
             if (gjs_define_function(context, obj, proto_priv->gtype,
                                     method_info) == NULL) {
                 g_base_info_unref((GIBaseInfo *) method_info);
+                g_free(name);
                 return false;
             }
 
@@ -375,8 +380,11 @@ fundamental_instance_resolve(JSContext       *context,
         *resolved = false;
     }
 
-    return fundamental_instance_resolve_interface(context, obj, resolved,
-                                                  proto_priv, name);
+    bool status =
+        fundamental_instance_resolve_interface(context, obj, resolved,
+                                               proto_priv, name);
+    g_free(name);
+    return status;
 }
 
 static bool
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 19ddaaf..cd4f9a7 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -111,7 +111,7 @@ interface_resolve(JSContext       *context,
                   bool            *resolved)
 {
     Interface *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
     GIFunctionInfo *method_info;
 
     if (!gjs_get_string_id(context, id, &name)) {
@@ -121,14 +121,17 @@ interface_resolve(JSContext       *context,
 
     priv = priv_from_js(context, obj);
 
-    if (priv == NULL)
+    if (priv == NULL) {
+        g_free(name);
         return false;
+    }
 
     /* If we have no GIRepository information then this interface was defined
      * from within GJS. In that case, it has no properties that need to be
      * resolved from within C code, as interfaces cannot inherit. */
     if (priv->info == NULL) {
         *resolved = false;
+        g_free(name);
         return true;
     }
 
@@ -140,6 +143,7 @@ interface_resolve(JSContext       *context,
                                     priv->gtype,
                                     (GICallableInfo*)method_info) == NULL) {
                 g_base_info_unref((GIBaseInfo*)method_info);
+                g_free(name);
                 return false;
             }
 
@@ -153,6 +157,7 @@ interface_resolve(JSContext       *context,
         *resolved = false;
     }
 
+    g_free(name);
     return true;
 }
 
diff --git a/gi/ns.cpp b/gi/ns.cpp
index c3b6967..124dd7e 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -54,7 +54,7 @@ ns_resolve(JSContext       *context,
            bool            *resolved)
 {
     Ns *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
     GIRepository *repo;
     GIBaseInfo *info;
     bool defined;
@@ -68,6 +68,7 @@ ns_resolve(JSContext       *context,
     if (strcmp(name, "valueOf") == 0 ||
         strcmp(name, "toString") == 0) {
         *resolved = false;
+        g_free(name);
         return true;
     }
 
@@ -78,6 +79,7 @@ ns_resolve(JSContext       *context,
 
     if (priv == NULL) {
         *resolved = false;  /* we are the prototype, or have the wrong class */
+        g_free(name);
         return true;
     }
 
@@ -86,6 +88,7 @@ ns_resolve(JSContext       *context,
     info = g_irepository_find_by_name(repo, priv->gi_namespace, name);
     if (info == NULL) {
         *resolved = false; /* No property defined, but no error either */
+        g_free(name);
         return true;
     }
 
@@ -103,12 +106,14 @@ ns_resolve(JSContext       *context,
                   g_base_info_get_name(info));
 
         g_base_info_unref(info);
+        g_free(name);
         return false;
     }
 
     /* we defined the property in this object? */
     g_base_info_unref(info);
     *resolved = defined;
+    g_free(name);
     return true;
 }
 
diff --git a/gi/object.cpp b/gi/object.cpp
index 585b813..a6866b2 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -28,6 +28,7 @@
 #include <set>
 #include <stack>
 #include <string.h>
+#include <tuple>
 #include <vector>
 
 #include "object.h"
@@ -653,7 +654,7 @@ object_instance_resolve_no_info(JSContext       *context,
     guint n_interfaces;
     guint i;
 
-    g_autofree GType *interfaces = g_type_interfaces(priv->gtype, &n_interfaces);
+    GType *interfaces = g_type_interfaces(priv->gtype, &n_interfaces);
     for (i = 0; i < n_interfaces; i++) {
         GIBaseInfo *base_info;
         GIInterfaceInfo *iface_info;
@@ -679,11 +680,13 @@ object_instance_resolve_no_info(JSContext       *context,
                 if (!gjs_define_function(context, obj, priv->gtype,
                                         (GICallableInfo *)method_info)) {
                     g_base_info_unref((GIBaseInfo*) method_info);
+                    g_free(interfaces);
                     return false;
                 }
 
                 g_base_info_unref((GIBaseInfo*) method_info);
                 *resolved = true;
+                g_free(interfaces);
                 return true;
             }
 
@@ -692,6 +695,7 @@ object_instance_resolve_no_info(JSContext       *context,
     }
 
     *resolved = false;
+    g_free(interfaces);
     return true;
 }
 
@@ -708,7 +712,7 @@ object_instance_resolve(JSContext       *context,
 {
     GIFunctionInfo *method_info;
     ObjectInstance *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
 
     if (!gjs_get_string_id(context, id, &name)) {
         *resolved = false;
@@ -737,11 +741,13 @@ object_instance_resolve(JSContext       *context,
          * check there.
          */
         *resolved = false;
+        g_free(name);
         return true;
     }
 
     if (priv->gobj != NULL) {
         *resolved = false;
+        g_free(name);
         return true;
     }
 
@@ -749,7 +755,9 @@ object_instance_resolve(JSContext       *context,
      * we need to look at exposing interfaces. Look up our interfaces through
      * GType data, and then hope that *those* are introspectable. */
     if (priv->info == NULL) {
-        return object_instance_resolve_no_info(context, obj, resolved, priv, name);
+        bool status = object_instance_resolve_no_info(context, obj, resolved, priv, name);
+        g_free(name);
+        return status;
     }
 
     if (g_str_has_prefix (name, "vfunc_")) {
diff --git a/gi/param.cpp b/gi/param.cpp
index c16cb9d..c80822a 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -57,7 +57,7 @@ param_resolve(JSContext       *context,
     GIObjectInfo *info = NULL;
     GIFunctionInfo *method_info;
     Param *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
     bool ret = false;
 
     if (!gjs_get_string_id(context, id, &name))
@@ -68,6 +68,7 @@ param_resolve(JSContext       *context,
     if (priv != NULL) {
         /* instance, not prototype */
         *resolved = false;
+        g_free(name);
         return true;
     }
 
@@ -100,6 +101,7 @@ param_resolve(JSContext       *context,
 
     ret = true;
  out:
+    g_free(name); 
     if (info != NULL)
         g_base_info_unref( (GIBaseInfo*)info);
 
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 155e49a..4e780fe 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -155,7 +155,7 @@ repo_resolve(JSContext       *context,
              bool            *resolved)
 {
     Repo *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
 
     if (!gjs_get_string_id(context, id, &name)) {
         *resolved = false;
@@ -166,6 +166,7 @@ repo_resolve(JSContext       *context,
     if (strcmp(name, "valueOf") == 0 ||
         strcmp(name, "toString") == 0) {
         *resolved = false;
+        g_free(name);
         return true;
     }
 
@@ -176,13 +177,17 @@ repo_resolve(JSContext       *context,
     if (priv == NULL) {
         /* we are the prototype, or have the wrong class */
         *resolved = false;
+        g_free(name);
         return true;
     }
 
-    if (!resolve_namespace_object(context, obj, id, name))
+    if (!resolve_namespace_object(context, obj, id, name)) {
+        g_free(name);
         return false;
+    }
 
     *resolved = true;
+    g_free(name);
     return true;
 }
 
diff --git a/gi/union.cpp b/gi/union.cpp
index f5aefae..de708da 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -60,7 +60,7 @@ union_resolve(JSContext       *context,
               bool            *resolved)
 {
     Union *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
 
     if (!gjs_get_string_id(context, id, &name)) {
         *resolved = false;
@@ -71,8 +71,10 @@ union_resolve(JSContext       *context,
     gjs_debug_jsprop(GJS_DEBUG_GBOXED, "Resolve prop '%s' hook obj %p priv %p",
                      name, obj.get(), priv);
 
-    if (priv == NULL)
+    if (priv == NULL) {
+        g_free(name);
         return false; /* wrong class */
+    }
 
     if (priv->gboxed != NULL) {
         /* We are an instance, not a prototype, so look for
@@ -83,6 +85,7 @@ union_resolve(JSContext       *context,
          * hooks, not this resolve hook.
          */
         *resolved = false;
+        g_free(name);
         return true;
     }
 
@@ -112,6 +115,7 @@ union_resolve(JSContext       *context,
                                     g_registered_type_info_get_g_type(priv->info),
                                     method_info) == NULL) {
                 g_base_info_unref( (GIBaseInfo*) method_info);
+                g_free(name);
                 return false;
             }
 
@@ -125,6 +129,7 @@ union_resolve(JSContext       *context,
         *resolved = false;
     }
 
+    g_free(name);
     return true;
 }
 
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 7b1957c..c8e08bf 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -72,7 +72,7 @@ importer_to_string(JSContext *cx,
                                  &module_path))
         return false;
 
-    g_autofree char *path = NULL;
+    char *path = NULL;
     GjsAutoChar output;
 
     if (module_path.isNull()) {
@@ -84,6 +84,7 @@ importer_to_string(JSContext *cx,
     }
 
     args.rval().setString(JS_NewStringCopyZ(cx, output));
+    g_free(path);
     return true;
 }
 
@@ -135,10 +136,11 @@ define_meta_properties(JSContext       *context,
         if (parent_module_path.isNull()) {
             module_path_buf = g_strdup(module_name);
         } else {
-            g_autofree char *parent_path = NULL;
+            char *parent_path = NULL;
             if (!gjs_string_to_utf8(context, parent_module_path, &parent_path))
                 return false;
             module_path_buf = g_strdup_printf("%s.%s", parent_path, module_name);
+            g_free(parent_path);
         }
         module_path.setString(JS_NewStringCopyZ(context, module_path_buf));
     }
@@ -281,12 +283,13 @@ module_to_string(JSContext *cx,
 
     g_assert(!module_path.isNull());
 
-    g_autofree char *path = NULL;
+    char *path = NULL;
     if (!gjs_string_to_utf8(cx, module_path, &path))
         return false;
     GjsAutoChar output = g_strdup_printf("[GjsModule %s]", path);
 
     args.rval().setString(JS_NewStringCopyZ(cx, output));
+    g_free(path);
     return true;
 }
 
@@ -787,7 +790,7 @@ importer_resolve(JSContext        *context,
                  bool             *resolved)
 {
     Importer *priv;
-    g_autofree char *name = NULL;
+    char *name = NULL;
     jsid module_init_name;
 
     module_init_name = gjs_context_get_const_string(context, GJS_STRING_MODULE_INIT);
@@ -804,6 +807,7 @@ importer_resolve(JSContext        *context,
         strcmp(name, "toString") == 0 ||
         strcmp(name, "__iterator__") == 0) {
         *resolved = false;
+        g_free(name);
         return true;
     }
     priv = priv_from_js(context, obj);
@@ -814,14 +818,18 @@ importer_resolve(JSContext        *context,
     if (priv == NULL) {
         /* we are the prototype, or have the wrong class */
         *resolved = false;
+        g_free(name);
         return true;
     }
 
     JSAutoRequest ar(context);
-    if (!do_import(context, obj, priv, name))
+    if (!do_import(context, obj, priv, name)) {
+        g_free(name);
         return false;
+    }
 
     *resolved = true;
+    g_free(name);
     return true;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]