gobject-introspection r1079 - in trunk: . gir girepository giscanner tests/offsets



Author: walters
Date: Mon Feb  2 16:31:06 2009
New Revision: 1079
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=1079&view=rev

Log:
Bug 569408, Bug 568680 - Scanner misses fields (at least in GObject.Object)

The scanner misses all fields of the GObject struct -- there
are no <field> children of the <class> element for GObject in the GIR. This of
course yields wrong field offsets for all derived objects.

Added:
   trunk/gir/GObject-2.0.xpath
Modified:
   trunk/ChangeLog
   trunk/gir/Makefile.am
   trunk/girepository/giroffsets.c
   trunk/giscanner/glibtransformer.py
   trunk/giscanner/transformer.py
   trunk/tests/offsets/Makefile.am
   trunk/tests/offsets/offsets.h

Added: trunk/gir/GObject-2.0.xpath
==============================================================================
--- (empty file)
+++ trunk/gir/GObject-2.0.xpath	Mon Feb  2 16:31:06 2009
@@ -0,0 +1,3 @@
+/namespace/class[ name='Object']/field[ name='g_type_instance']
+/namespace/class[ name='Object']/field[ name='ref_count']
+/namespace/class[ name='Object']/field[ name='qdata']

Modified: trunk/gir/Makefile.am
==============================================================================
--- trunk/gir/Makefile.am	(original)
+++ trunk/gir/Makefile.am	Mon Feb  2 16:31:06 2009
@@ -70,6 +70,8 @@
 	    -DGOBJECT_COMPILATION \
             --pkg gobject-2.0 \
 	    $(GLIB_INCLUDEDIR)/gobject/*.h
+	$(SCANNER) $(SCANNER_ARGS) \
+	    --xpath-assertions=$(srcdir)/GObject-2.0.xpath GObject-2.0.gir
 BUILT_GIRSOURCES += GObject-2.0.gir
 
 # gmodule

Modified: trunk/girepository/giroffsets.c
==============================================================================
--- trunk/girepository/giroffsets.c	(original)
+++ trunk/girepository/giroffsets.c	Mon Feb  2 16:31:06 2009
@@ -357,8 +357,9 @@
 	}
       else if (member->type == G_IR_NODE_CALLBACK)
 	{
-	  size = ffi_type_pointer.size;
-	  alignment = ffi_type_pointer.alignment;
+          size = ALIGN (size, ffi_type_pointer.alignment);
+          alignment = MAX (alignment, ffi_type_pointer.alignment);
+	  size += ffi_type_pointer.size;
 	}
     }
 

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Mon Feb  2 16:31:06 2009
@@ -261,8 +261,20 @@
             parent_type_name = 'GObject'
             parent_gitype = self._resolve_gtypename(parent_type_name)
             symbol = 'g_initially_unowned_get_type'
+        else:
+            assert False
         gnode = GLibObject(node.name, parent_gitype, type_name, symbol, True)
-        gnode.fields.extend(node.fields)
+        if type_name == 'GObject':
+            gnode.fields.extend(node.fields)
+        else:
+            # http://bugzilla.gnome.org/show_bug.cgi?id=569408
+            # GInitiallyUnowned is actually a typedef for GObject, but
+            # that's not reflected in the GIR, where it appears as a
+            # subclass (as it appears in the GType hierarchy).  So
+            # what we do here is copy all of the GObject fields into
+            # GInitiallyUnowned so that struct offset computation
+            # works correctly.
+            gnode.fields = self._names.names['Object'][1].fields
         self._add_attribute(gnode)
         self._register_internal_type(type_name, gnode)
 

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Mon Feb  2 16:31:06 2009
@@ -478,45 +478,33 @@
         self._typedefs_ns[callback.name] = callback
         return callback
 
-    def _create_struct(self, symbol):
-        struct = self._typedefs_ns.get(symbol.ident, None)
-        if struct is None:
+    def _create_compound(self, klass, symbol):
+        compound = self._typedefs_ns.get(symbol.ident, None)
+        if compound is None:
             # This is a bit of a hack; really we should try
             # to resolve through the typedefs to find the real
             # name
             if symbol.ident.startswith('_'):
                 name = symbol.ident[1:]
+                compound = self._typedefs_ns.get(name, None)
             else:
                 name = symbol.ident
-            name = self.remove_prefix(name)
-            struct = Struct(name, symbol.ident)
+            if compound is None:
+                name = self.remove_prefix(name)
+                compound = klass(name, symbol.ident)
 
         for child in symbol.base_type.child_list:
             field = self._traverse_one(child)
             if field:
-                struct.fields.append(field)
+                compound.fields.append(field)
 
-        return struct
+        return compound
 
-    def _create_union(self, symbol):
-        union = self._typedefs_ns.get(symbol.ident, None)
-        if union is None:
-            # This is a bit of a hack; really we should try
-            # to resolve through the typedefs to find the real
-            # name
-            if symbol.ident.startswith('_'):
-                name = symbol.ident[1:]
-            else:
-                name = symbol.ident
-            name = self.remove_prefix(name)
-            union = Union(name, symbol.ident)
-
-        for child in symbol.base_type.child_list:
-            field = self._traverse_one(child)
-            if field:
-                union.fields.append(field)
+    def _create_struct(self, symbol):
+        return self._create_compound(Struct, symbol)
 
-        return union
+    def _create_union(self, symbol):
+        return self._create_compound(Union, symbol)
 
     def _create_callback(self, symbol):
         parameters = self._create_parameters(symbol.base_type.base_type)

Modified: trunk/tests/offsets/Makefile.am
==============================================================================
--- trunk/tests/offsets/Makefile.am	(original)
+++ trunk/tests/offsets/Makefile.am	Mon Feb  2 16:31:06 2009
@@ -20,6 +20,7 @@
 
 offsets-1.0.gir: liboffsets.la offsets.h $(SCANNER_BIN) $(SCANNER_LIBS) Makefile
 	$(CHECK_DEBUG) $(SCANNER) \
+	--include=GObject-2.0 \
         --libtool="$(LIBTOOL)" \
 	--library=offsets \
 	--namespace=offsets \
@@ -51,7 +52,7 @@
 ############################################################
 
 check-local: offsets-1.0.typelib
-	LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}$(builddir) GI_TYPELIB_PATH=$(builddir) \
+	LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}$(builddir) GI_TYPELIB_PATH=$(builddir):$(top_builddir)/gir \
 	  $(builddir)/gitestoffsets$(EXEEXT) offsets.compiled offsets.introspected
 	diff -u offsets.compiled offsets.introspected
 

Modified: trunk/tests/offsets/offsets.h
==============================================================================
--- trunk/tests/offsets/offsets.h	(original)
+++ trunk/tests/offsets/offsets.h	Mon Feb  2 16:31:06 2009
@@ -2,6 +2,7 @@
 #define __OFFSETS_H__
 
 #include <glib.h>
+#include <glib-object.h>
 #include <time.h>
 
 /* Test we get the alignment right for various basic types; we put
@@ -118,4 +119,22 @@
   gpointer some_ptrs[5];
 };
 
+/** Test object offsets
+ */
+
+typedef struct _OffsetsObj OffsetsObj;
+typedef struct _OffsetsObjClass OffsetsObjClass;
+
+struct _OffsetsObj
+{
+  GObject parent_instance;
+
+  GObject *other;
+};
+
+struct _OffsetsObjClass
+{
+  GObjectClass parent_class;
+};
+
 #endif /* __OFFSETS_H__ */



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