gjs r42 - in trunk: gi gjs



Author: tko
Date: Thu Oct 23 17:13:27 2008
New Revision: 42
URL: http://svn.gnome.org/viewvc/gjs?rev=42&view=rev

Log:
Bug 557466 â Module name mangling considered harmful

	* gi/ns.c (gjs_define_ns):
	* gi/repo.c (resolve_namespace_object): Don't mangle namespace
	names, require them to be used case sensitive.
	* gjs/jsapi-util.h:
	* gjs/jsapi-util.c (gjs_fix_ns_name, gjs_unfix_ns_name):
	Remove as unwanted.

Modified:
   trunk/gi/ns.c
   trunk/gi/repo.c
   trunk/gjs/jsapi-util.c
   trunk/gjs/jsapi-util.h

Modified: trunk/gi/ns.c
==============================================================================
--- trunk/gi/ns.c	(original)
+++ trunk/gi/ns.c	Thu Oct 23 17:13:27 2008
@@ -287,35 +287,17 @@
               GIRepository *repo)
 {
     JSObject *ns;
-    char *fixed_ns_name, *unfixed_ns_name;
 
-    /* The idea here is to always define properties for both
-     * fixed (MyModule) and unfixed (myModule) namespace name
-     * format
-     */
-
-    fixed_ns_name = gjs_fix_ns_name(ns_name);
-    unfixed_ns_name = gjs_unfix_ns_name(ns_name);
-
-    ns = ns_new(context, fixed_ns_name, repo);
-
-    if (!JS_DefineProperty(context, in_object,
-                           fixed_ns_name, OBJECT_TO_JSVAL(ns),
-                           NULL, NULL,
-                           GJS_MODULE_PROP_FLAGS))
-        gjs_fatal("no memory to define ns property");
+    ns = ns_new(context, ns_name, repo);
 
     if (!JS_DefineProperty(context, in_object,
-                           unfixed_ns_name, OBJECT_TO_JSVAL(ns),
+                           ns_name, OBJECT_TO_JSVAL(ns),
                            NULL, NULL,
                            GJS_MODULE_PROP_FLAGS))
         gjs_fatal("no memory to define ns property");
 
     gjs_debug(GJS_DEBUG_GNAMESPACE,
-              "Defined namespace '%s' %p in GIRepository %p", fixed_ns_name, ns, in_object);
-
-    g_free(fixed_ns_name);
-    g_free(unfixed_ns_name);
+              "Defined namespace '%s' %p in GIRepository %p", ns_name, ns, in_object);
 
     return ns;
 }

Modified: trunk/gi/repo.c
==============================================================================
--- trunk/gi/repo.c	(original)
+++ trunk/gi/repo.c	Thu Oct 23 17:13:27 2008
@@ -58,7 +58,6 @@
 {
     GIRepository *repo;
     GError *error;
-    char *fixed_ns_name;
     JSContext *load_context;
     jsval versions_val;
     JSObject *versions;
@@ -74,32 +73,24 @@
 
     versions = JSVAL_TO_OBJECT(versions_val);
 
-    fixed_ns_name = gjs_fix_ns_name(ns_name);
-
     version = NULL;
     if (JS_GetProperty(load_context, versions, ns_name, &version_val) &&
         JSVAL_IS_STRING(version_val)) {
         version = gjs_string_get_ascii(version_val);
-    } else if (JS_GetProperty(load_context, versions, fixed_ns_name, &version_val) &&
-               JSVAL_IS_STRING(version_val)) {
-        version = gjs_string_get_ascii(version_val);
     }
 
     repo = g_irepository_get_default();
 
     error = NULL;
-    g_irepository_require(repo, fixed_ns_name, version, 0, &error);
+    g_irepository_require(repo, ns_name, version, 0, &error);
     if (error != NULL) {
         gjs_throw(context,
-                  "Requiring %s fixed as %s, version %s: %s",
-                  ns_name, fixed_ns_name, version?version:"none", error->message);
+                  "Requiring %s, version %s: %s",
+                  ns_name, version?version:"none", error->message);
         g_error_free(error);
-        g_free(fixed_ns_name);
         return JS_FALSE;
     }
 
-    g_free(fixed_ns_name);
-
     /* Defines a property on "obj" (the javascript repo object)
      * with the given namespace name, pointing to that namespace
      * in the repo.

Modified: trunk/gjs/jsapi-util.c
==============================================================================
--- trunk/gjs/jsapi-util.c	(original)
+++ trunk/gjs/jsapi-util.c	Thu Oct 23 17:13:27 2008
@@ -917,51 +917,3 @@
         return "<unknown>";
     }
 }
-
-/* ensure that the namespace name is in MyModule format */
-char *
-gjs_fix_ns_name(const char *ns_name)
-{
-    char *namespace;
-    gboolean is_glib;
-
-    if (strcmp(ns_name, "gIO") == 0) {
-        return g_strdup("Gio");
-    }
-
-    namespace = g_strdup(ns_name);
-
-    is_glib = (g_ascii_strcasecmp(ns_name, "glib") == 0);
-
-    namespace[0] = g_ascii_toupper(namespace[0]);
-
-    if (is_glib) {
-        namespace[1] = g_ascii_toupper(namespace[1]);
-    }
-
-    return namespace;
-}
-
-/* ensure that the namespace name is in myModule format */
-char *
-gjs_unfix_ns_name(const char *ns_name)
-{
-    char *namespace;
-    gboolean is_glib;
-
-    if (strcmp(ns_name, "Gio") == 0) {
-        return g_strdup("gIO");
-    }
-
-    namespace = g_strdup(ns_name);
-
-    is_glib = (g_ascii_strcasecmp(ns_name, "glib") == 0);
-
-    namespace[0] = g_ascii_tolower(namespace[0]);
-
-    if (is_glib) {
-        namespace[1] = g_ascii_tolower(namespace[1]);
-    }
-
-    return namespace;
-}

Modified: trunk/gjs/jsapi-util.h
==============================================================================
--- trunk/gjs/jsapi-util.h	(original)
+++ trunk/gjs/jsapi-util.h	Thu Oct 23 17:13:27 2008
@@ -203,9 +203,6 @@
                                               const char     **name_p);
 const char* gjs_get_type_name                (jsval            value);
 
-char*       gjs_fix_ns_name                  (const char      *ns_name);
-char*       gjs_unfix_ns_name                (const char      *ns_name);
-
 GjsRootedArray*   gjs_rooted_array_new        (void);
 void              gjs_rooted_array_append     (JSContext        *context,
                                                GjsRootedArray *array,



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