gobject-introspection r621 - in trunk: giscanner tests/scanner



Author: walters
Date: Sat Sep 20 00:03:38 2008
New Revision: 621
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=621&view=rev

Log:
Bug 552390: Handle capitialization like "DBus" more robustly

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.


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

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Sat Sep 20 00:03:38 2008
@@ -31,7 +31,7 @@
 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 @@
 
     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 @@
         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 @@
             # 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

Modified: trunk/giscanner/utils.py
==============================================================================
--- trunk/giscanner/utils.py	(original)
+++ trunk/giscanner/utils.py	Sat Sep 20 00:03:38 2008
@@ -37,6 +37,13 @@
     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")
 
 

Modified: trunk/tests/scanner/foo-expected.gir
==============================================================================
--- trunk/tests/scanner/foo-expected.gir	(original)
+++ trunk/tests/scanner/foo-expected.gir	Sat Sep 20 00:03:38 2008
@@ -252,6 +252,21 @@
         <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"/>

Modified: trunk/tests/scanner/foo.c
==============================================================================
--- trunk/tests/scanner/foo.c	(original)
+++ trunk/tests/scanner/foo.c	Sat Sep 20 00:03:38 2008
@@ -253,3 +253,33 @@
 {
 
 }
+
+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;
+}

Modified: trunk/tests/scanner/foo.h
==============================================================================
--- trunk/tests/scanner/foo.h	(original)
+++ trunk/tests/scanner/foo.h	Sat Sep 20 00:03:38 2008
@@ -110,6 +110,11 @@
 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;



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