Bug 552390: Handle capitialization like "DBus" more robustly
authorColin Walters <walters@src.gnome.org>
Sat, 20 Sep 2008 00:03:38 +0000 (00:03 +0000)
committerColin Walters <walters@src.gnome.org>
Sat, 20 Sep 2008 00:03:38 +0000 (00:03 +0000)
The to_underscores function was designed for use against prefixed
names; we need a separate function which will convert names like
DBusFoo into dbus_foo, not d_bus_foo.

svn path=/trunk/; revision=621

giscanner/glibtransformer.py
giscanner/utils.py
tests/scanner/foo-expected.gir
tests/scanner/foo.c
tests/scanner/foo.h

index ae0d6bef3e53e1bc2a8609dd55094cb3118162ca..0cde76d606eb1bb731acc4787f972757d3e1fabf 100644 (file)
@@ -31,7 +31,7 @@ from .transformer import Names
 from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
                       GLibInterface, GLibObject, GLibSignal, GLibBoxedStruct,
                       GLibBoxedUnion, GLibBoxedOther, type_names)
-from .utils import extract_libtool, to_underscores
+from .utils import extract_libtool, to_underscores, to_underscores_noprefix
 
 
 SYMBOL_BLACKLIST = [
@@ -157,7 +157,8 @@ class GLibTransformer(object):
 
     def _register_internal_type(self, type_name, node):
         self._names.type_names[type_name] = (None, node)
-        self._uscore_type_names[to_underscores(type_name).lower()] = node
+        uscored = to_underscores(type_name).lower()
+        self._uscore_type_names[uscored] = node
         # Besides the straight underscore conversion, we also try
         # removing the underscores from the namespace as a possible C
         # mapping; e.g. it's webkit_web_view, not web_kit_web_view
@@ -165,6 +166,7 @@ class GLibTransformer(object):
         prefix = type_name[:-len(suffix)]
         no_uscore_prefixed = (prefix + '_' + to_underscores(suffix)).lower()
         self._uscore_type_names[no_uscore_prefixed] = node
+        print "ADDING USCORED: %r %r" % (uscored, no_uscore_prefixed)
 
     # Helper functions
 
@@ -321,7 +323,7 @@ class GLibTransformer(object):
             # method name
             argtype = target_arg.type.ctype.replace('*', '')
             name = self._transformer.strip_namespace_object(argtype)
-            name_uscore = to_underscores(name).lower()
+            name_uscore = to_underscores_noprefix(name).lower()
             name_offset = func.symbol.find(name_uscore)
             if name_offset < 0:
                 return None
index 1a45c75da8328c75f4e7eef9328e69c45d9a02e5..c2f6e5d804473076ec0e3883e5499202f24b3196 100644 (file)
@@ -37,6 +37,13 @@ def to_underscores(name):
     return name
 
 
+def to_underscores_noprefix(name):
+    """Like to_underscores, but designed for "unprefixed" names.
+    to_underscores("DBusFoo") => dbus_foo, not d_bus_foo."""
+    name = _upperstr_pat1.sub(r'\1_\2', name)
+    name = _upperstr_pat2.sub(r'\1_\2', name)
+    return name
+
 _libtool_pat = re.compile("dlname='([A-z0-9\.\-\+]+)'\n")
 
 
index 6ad8205c53fe7405a56e224fea1151f27457f042..14d3911fb9d32a9b35ebc659970f85d1ec494d57 100644 (file)
         <type name="Boxed" c:type="FooBoxed*"/>
       </return-value>
     </function>
+    <record name="DBusData"
+            c:type="FooDBusData"
+            glib:type-name="FooDBusData"
+            glib:get-type="foo_dbus_data_get_type">
+      <method name="method" c:identifier="foo_dbus_data_method">
+        <return-value>
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="dbusdata">
+            <type name="DBusData" c:type="FooDBusData*"/>
+          </parameter>
+        </parameters>
+      </method>
+    </record>
     <callback name="Callback" c:type="FooCallback">
       <return-value>
         <type name="boolean" c:type="gboolean"/>
index 8fa09212ae07a3a2c4aff26a48ca2ed9f787d942..3ea4fbdf1c697262db521516b9b14090647ae7c7 100644 (file)
@@ -253,3 +253,33 @@ foo_boxed_method (FooBoxed *boxed)
 {
 
 }
+
+struct _FooDBusData
+{
+  double private;
+};
+
+FooDBusData *
+foo_dbus_data_copy (const FooDBusData *boxed)
+{
+  return (FooDBusData *)g_memdup (boxed, sizeof (FooDBusData));
+}
+
+void
+foo_dbus_data_free (FooBoxed *boxed)
+{
+  g_slice_free (FooDBusData, boxed);
+}
+
+
+GType
+foo_dbus_data_get_type (void)
+{
+  static GType our_type = 0;
+  
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static ("FooDBusData",
+                                            (GBoxedCopyFunc) foo_dbus_data_copy,
+                                            (GBoxedFreeFunc) foo_dbus_data_free);
+  return our_type;
+}
index 3c1e753a875698042776cebd918993895198ba6d..a2c6ddb29e30709b15a735d0be28bd439d3b253b 100644 (file)
@@ -110,6 +110,11 @@ GType                 foo_boxed_get_type       (void) G_GNUC_CONST;
 FooBoxed*             foo_boxed_new            (void);
 void                  foo_boxed_method         (FooBoxed* boxed);
 
+/* This one tests capitalization handling with respect to DBus */
+typedef struct _FooDBusData FooDBusData;
+GType                 foo_dbus_data_get_type       (void) G_GNUC_CONST;
+void                  foo_dbus_data_method         (FooDBusData* dbusdata);
+
 /* FIXME: Scanner does not support this yet
 const char *FOO_CONSTANT_STR = "foo-constant-str";
 const int FOO_CONSTANT_INT = 10;