gobject-introspection r457 - in trunk: . girepository giscanner tests tests/scanner tools



Author: walters
Date: Fri Aug 22 20:05:23 2008
New Revision: 457
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=457&view=rev

Log:
2008-08-22  Colin Walters  <walters verbum org>

	* girepository/girparser.c: Pass through
	recursive types.  Avoid overwriting errors.
	* giscanner/xmlwriter.py: Always write the
	XML header.
	* tests/*.gir: Adjust.
	* tests/scanner/Makefile.am: Build typelibs,
	and generate XML from those.  Once we
	have a good diff mechanism...
	* tests/scanner/*-expected.gir: Add XML
	header.
	* tools/g-ir-scanner: Accept --typelib-xml
	option.
	* tools/generate.c: Better defaults for transfer.


Modified:
   trunk/ChangeLog
   trunk/girepository/girparser.c
   trunk/giscanner/xmlwriter.py
   trunk/tests/boxed.gir
   trunk/tests/interface.gir
   trunk/tests/object.gir
   trunk/tests/scanner/Makefile.am
   trunk/tests/scanner/annotation-expected.gir
   trunk/tests/scanner/drawable-expected.gir
   trunk/tests/scanner/foo-expected.gir
   trunk/tests/scanner/utility-expected.gir
   trunk/tests/types.gir
   trunk/tests/xref1.gir
   trunk/tests/xref2.gir
   trunk/tools/g-ir-scanner
   trunk/tools/generate.c

Modified: trunk/girepository/girparser.c
==============================================================================
--- trunk/girepository/girparser.c	(original)
+++ trunk/girepository/girparser.c	Fri Aug 22 20:05:23 2008
@@ -57,7 +57,8 @@
   STATE_NAMESPACE_CONSTANT, /* 25 */
   STATE_CLASS_CONSTANT, 
   STATE_INTERFACE_CONSTANT,
-  STATE_ALIAS
+  STATE_ALIAS,
+  STATE_TYPE,
 } ParseState;
 
 typedef struct _ParseContext ParseContext;
@@ -72,6 +73,7 @@
   GIrModule *current_module;
   GIrNode *current_node;
   GIrNode *current_typed;
+  int type_depth;
 };
 
 #define MISSING_ATTRIBUTE(ctx,error,element,attribute)			        \
@@ -736,9 +738,19 @@
       param->transfer = FALSE;
       param->shallow_transfer = TRUE;
     }
-  else
+  else 
     {
-      param->transfer = TRUE;
+      if (transfer)
+	{
+	  if (strcmp (transfer, "full") != 0)
+	    g_warning ("Unknown transfer %s", transfer);
+	  else
+	    param->transfer = TRUE;
+	}
+      else if (param->in && !param->out)
+	param->transfer = FALSE;
+      else
+	param->transfer = TRUE;
       param->shallow_transfer = FALSE;
     }
 	  
@@ -1371,22 +1383,33 @@
 {
   const gchar *name;
 
-  if (strcmp (element_name, "type") != 0 ||
-      !(ctx->state == STATE_FUNCTION_PARAMETER ||
-	ctx->state == STATE_FUNCTION_RETURN || 
-	ctx->state == STATE_STRUCT_FIELD ||
-	ctx->state == STATE_UNION_FIELD ||
-	ctx->state == STATE_CLASS_PROPERTY ||
-	ctx->state == STATE_CLASS_FIELD ||
-	ctx->state == STATE_INTERFACE_FIELD ||
-	ctx->state == STATE_INTERFACE_PROPERTY ||
-	ctx->state == STATE_BOXED_FIELD ||
-	ctx->state == STATE_NAMESPACE_CONSTANT ||
-	ctx->state == STATE_CLASS_CONSTANT ||
-	ctx->state == STATE_INTERFACE_CONSTANT
-	))
+  if (strcmp (element_name, "type") != 0)
     return FALSE;
 
+  if (ctx->state == STATE_TYPE)
+    ctx->type_depth++;
+  else if (ctx->state == STATE_FUNCTION_PARAMETER ||
+	   ctx->state == STATE_FUNCTION_RETURN || 
+	   ctx->state == STATE_STRUCT_FIELD ||
+	   ctx->state == STATE_UNION_FIELD ||
+	   ctx->state == STATE_CLASS_PROPERTY ||
+	   ctx->state == STATE_CLASS_FIELD ||
+	   ctx->state == STATE_INTERFACE_FIELD ||
+	   ctx->state == STATE_INTERFACE_PROPERTY ||
+	   ctx->state == STATE_BOXED_FIELD ||
+	   ctx->state == STATE_NAMESPACE_CONSTANT ||
+	   ctx->state == STATE_CLASS_CONSTANT ||
+	   ctx->state == STATE_INTERFACE_CONSTANT
+	   )
+    {
+      state_switch (ctx, STATE_TYPE);
+      ctx->type_depth = 1;
+    }
+
+  /* FIXME handle recursive types */
+  if (ctx->type_depth > 1)
+    return TRUE;
+
   if (!ctx->current_typed)
     {
       g_set_error (error,
@@ -1395,7 +1418,7 @@
 		   "The element <type> is invalid here");
       return FALSE;
     }
-
+  
   name = find_attribute ("name", attribute_names, attribute_values);
 
   if (name == NULL)
@@ -2063,12 +2086,13 @@
 
   g_markup_parse_context_get_position (context, &line_number, &char_number);
 
-  g_set_error (error,
-	       G_MARKUP_ERROR,
-	       G_MARKUP_ERROR_UNKNOWN_ELEMENT,
-	       "Unexpected start tag '%s' on line %d char %d; current state=%d",
-	       element_name,
-	       line_number, char_number, ctx->state);
+  if (error && *error == NULL)
+    g_set_error (error,
+		 G_MARKUP_ERROR,
+		 G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+		 "Unexpected start tag '%s' on line %d char %d; current state=%d",
+		 element_name,
+		 line_number, char_number, ctx->state);
   
  out: ;
   if (*error) 
@@ -2380,6 +2404,15 @@
 	    }
 	}
       break;
+    case STATE_TYPE:
+      if (strcmp ("type", element_name) == 0)
+	{
+	  if (ctx->type_depth == 1)
+	    state_switch (ctx, ctx->prev_state);
+	  else
+	    ctx->type_depth -= 1;
+	  break;
+	}
     default:
       g_error ("Unhandled state %d in end_element_handler\n", ctx->state);
     }
@@ -2469,6 +2502,7 @@
 
   ctx.state = STATE_START;
   ctx.aliases = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+  ctx.type_depth = 0;
 
   context = g_markup_parse_context_new (&firstpass_parser, 0, &ctx, NULL);
 

Modified: trunk/giscanner/xmlwriter.py
==============================================================================
--- trunk/giscanner/xmlwriter.py	(original)
+++ trunk/giscanner/xmlwriter.py	Fri Aug 22 20:05:23 2008
@@ -27,6 +27,7 @@
 
     def __init__(self):
         self._data = StringIO()
+        self._data.write('<?xml version="1.0"?>\n')
         self._tag_stack = []
         self._indent = 0
         self._indent_unit = 2

Modified: trunk/tests/boxed.gir
==============================================================================
--- trunk/tests/boxed.gir	(original)
+++ trunk/tests/boxed.gir	Fri Aug 22 20:05:23 2008
@@ -23,13 +23,13 @@
             <type name="BoxedType1"/>
           </parameter>
           <parameter name="w" direction="in">
-            <type name="GList<boxed2*>*"/>
+            <type name="GList<boxed2>"/>
           </parameter>
           <parameter name="t" transfer="full" direction="in">
-            <type name="GHashTable<utf8,int64>*"/>
+            <type name="GHashTable<utf8,int64>"/>
           </parameter>
           <parameter name="e" transfer="full" direction="out">
-            <type name="GError*"/>
+            <type name="GError"/>
           </parameter>
         </parameters>
       </method>
@@ -39,7 +39,7 @@
         </return-value>
         <parameters>
           <parameter name="box" direction="in">
-            <type name="boxed2*"/>
+            <type name="boxed2"/>
           </parameter>
           <parameter name="val" transfer="full" direction="inout">
             <type name="uint"/>

Modified: trunk/tests/interface.gir
==============================================================================
--- trunk/tests/interface.gir	(original)
+++ trunk/tests/interface.gir	Fri Aug 22 20:05:23 2008
@@ -10,11 +10,11 @@
       </requires>
       <method name="method1" symbol="method1">
         <return-value transfer="full">
-          <type name="Iface2*"/>
+          <type name="Iface2"/>
         </return-value>
         <parameters>
           <parameter name="param1" transfer="full" direction="in">
-            <type name="Iface2*"/>
+            <type name="Iface2"/>
           </parameter>
         </parameters>
       </method>
@@ -27,7 +27,7 @@
         </return-value>
         <parameters>
           <parameter name="obj" transfer="full" direction="in">
-            <type name="Iface2*"/>
+            <type name="Iface2"/>
           </parameter>
         </parameters>
       </glib:signal>
@@ -37,17 +37,17 @@
         </return-value>
         <parameters>
           <parameter name="obj" transfer="full" direction="in">
-            <type name="Iface1*"/>
+            <type name="Iface1"/>
           </parameter>
         </parameters>
       </glib:signal>
       <vfunc name="vfunc1" offset="10">
         <return-value transfer="full">
-          <type name="Iface2*"/>
+          <type name="Iface2"/>
         </return-value>
         <parameters>
           <parameter name="param1" transfer="full" direction="in">
-            <type name="Iface2*"/>
+            <type name="Iface2"/>
           </parameter>
         </parameters>
       </vfunc>

Modified: trunk/tests/object.gir
==============================================================================
--- trunk/tests/object.gir	(original)
+++ trunk/tests/object.gir	Fri Aug 22 20:05:23 2008
@@ -31,9 +31,9 @@
           </parameter>
         </parameters>
       </glib:signal>
-      <vfunc name="vfunc1" offset="20" transfer="none">
+      <vfunc name="vfunc1" offset="20">
         <return-value>
-          <type name="Object2*"/>
+          <type name="Object2"/>
         </return-value>
         <parameters>
           <parameter name="param1" direction="in">
@@ -41,9 +41,9 @@
           </parameter>
         </parameters>
       </vfunc>
-      <vfunc name="vfunc2" offset="24" transfer="none">
+      <vfunc name="vfunc2" offset="24">
         <return-value>
-          <type name="Object2*"/>
+          <type name="Object2"/>
         </return-value>
         <parameters>
           <parameter name="param1" direction="in">

Modified: trunk/tests/scanner/Makefile.am
==============================================================================
--- trunk/tests/scanner/Makefile.am	(original)
+++ trunk/tests/scanner/Makefile.am	Fri Aug 22 20:05:23 2008
@@ -1,3 +1,6 @@
+CLEANFILES = 
+EXTRA_DIST =
+
 # We need to build a shared library, which can be dlopened
 # it does not work with noinst_LTLIBRARIES
 testlib_LTLIBRARIES = 		\
@@ -28,8 +31,8 @@
 libutility_la_LDFLAGS = -module -avoid-version
 libutility_la_LIBADD = $(GOBJECT_LIBS)
 
-CLEANFILES = utility.gir foo.gir
-EXTRA_DIST = utility-expected.gir foo-expected.gir
+GIRS = utility.gir annotation.gir foo.gir
+EXTRA_DIST += $(GIRS:.gir=-expected.gir)
 
 SCANNER = $(top_srcdir)/tools/g-ir-scanner
 SCANNER_LIBS = \
@@ -56,7 +59,7 @@
 	$(libdrawable_la_SOURCES) \
 	 --output $@
 
-foo.gir: libfoo.la foo.h $(SCANNER) $(SCANNER_LIBS)
+foo.gir: utility.gir libfoo.la foo.h $(SCANNER) $(SCANNER_LIBS)
 	$(CHECK_DEBUG) $(SCANNER) -v \
 	--include=$(top_srcdir)/gir/GLib.gir \
 	--include=$(top_srcdir)/gir/GObject.gir \
@@ -80,6 +83,16 @@
 check-%.gir: %.gir
 	@diff -u -U 10 $(srcdir)/$*-expected.gir $*.gir && echo "* $*.gir"
 
+%.typelib: %.gir
+	$(top_builddir)/tools/g-ir-compiler $< --raw -o $@
+	$(SCANNER) --typelib-xml $< > $<.tmp && mv $<.tmp $<.txml
+
+check-%.typelib: %.typelib
+
+
+TYPELIBS = $(GIRS:.gir=.typelib)
+CLEANFILES += $(TYPELIBS)
+
 pre-check:
 	@if test "$(top_builddir)" != "$(top_srcdir)"; then \
 	   cp $(top_srcdir)/giscanner/*.py $(top_builddir)/giscanner; \
@@ -97,6 +110,7 @@
 check-local: pre-check
 check-local: check-utility.gir check-annotation.gir check-drawable.gir 
 check-local: check-foo.gir
+check-local: $(TYPELIBS)
 check-local: post-check
 
 .PHONY: annotation.gir drawable.gir foo.gir utility.gir 

Modified: trunk/tests/scanner/annotation-expected.gir
==============================================================================
--- trunk/tests/scanner/annotation-expected.gir	(original)
+++ trunk/tests/scanner/annotation-expected.gir	Fri Aug 22 20:05:23 2008
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
 <repository version="1.0"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";

Modified: trunk/tests/scanner/drawable-expected.gir
==============================================================================
--- trunk/tests/scanner/drawable-expected.gir	(original)
+++ trunk/tests/scanner/drawable-expected.gir	Fri Aug 22 20:05:23 2008
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
 <repository version="1.0"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";

Modified: trunk/tests/scanner/foo-expected.gir
==============================================================================
--- trunk/tests/scanner/foo-expected.gir	(original)
+++ trunk/tests/scanner/foo-expected.gir	Fri Aug 22 20:05:23 2008
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
 <repository version="1.0"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";

Modified: trunk/tests/scanner/utility-expected.gir
==============================================================================
--- trunk/tests/scanner/utility-expected.gir	(original)
+++ trunk/tests/scanner/utility-expected.gir	Fri Aug 22 20:05:23 2008
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
 <repository version="1.0"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";

Modified: trunk/tests/types.gir
==============================================================================
--- trunk/tests/types.gir	(original)
+++ trunk/tests/types.gir	Fri Aug 22 20:05:23 2008
@@ -7,10 +7,10 @@
     <function name="lart" symbol="lart">
       <return-type type="gboolean" />
       <parameters>
-        <parameter name="box" type="gint*" transfer="full" direction="in" />
-        <parameter name="val" type="gint*" transfer="full" direction="inout" />
-        <parameter name="w" type="GList<gint*>*" transfer="full" direction="in" />
-        <parameter name="t" type="GHashTable<utf8,gint64>*" transfer="full" direction="in" />
+        <parameter name="box" type="gint" transfer="full" direction="in" />
+        <parameter name="val" type="gint" transfer="full" direction="inout" />
+        <parameter name="w" type="GList<gint>" transfer="full" direction="in" />
+        <parameter name="t" type="GHashTable<utf8,gint64>" transfer="full" direction="in" />
       </parameters>
     </function>
   </namespace>

Modified: trunk/tests/xref1.gir
==============================================================================
--- trunk/tests/xref1.gir	(original)
+++ trunk/tests/xref1.gir	Fri Aug 22 20:05:23 2008
@@ -12,7 +12,7 @@
       </return-value>
       <parameters>
         <parameter name="p1" transfer="full" direction="in">
-	  <type name="Bar.Boxed*"/>
+	  <type name="Bar.Boxed"/>
         </parameter>
       </parameters>
     </function>

Modified: trunk/tests/xref2.gir
==============================================================================
--- trunk/tests/xref2.gir	(original)
+++ trunk/tests/xref2.gir	Fri Aug 22 20:05:23 2008
@@ -12,7 +12,7 @@
       </return-value>
       <parameters>
         <parameter name="p1" transfer="full" direction="in">
-	  <type name="Foo.Boxed*"/>
+	  <type name="Foo.Boxed"/>
         </parameter>
       </parameters>
     </function>

Modified: trunk/tools/g-ir-scanner
==============================================================================
--- trunk/tools/g-ir-scanner	(original)
+++ trunk/tools/g-ir-scanner	Fri Aug 22 20:05:23 2008
@@ -71,8 +71,11 @@
                       action="store_true", dest="verbose",
                       help="be verbose")
     parser.add_option("", "--noclosure",
-                      action="store_true", dest="noclosure",# default=True,
+                      action="store_true", dest="noclosure",
                       help="do not delete unknown types")
+    parser.add_option("", "--typelib-xml",
+                      action="store_true", dest="typelib_xml",
+                      help="Just convert GIR to typelib XML")
 
 
     group = optparse.OptionGroup(parser, "Preprocessor options")
@@ -94,6 +97,18 @@
 def _error(msg):
     raise SystemExit('ERROR: %s' % (msg, ))
 
+def typelib_xml_strip(path):
+    from giscanner.girparser import C_NS
+    c_ns_key = '{%s}' % (C_NS, )
+
+    from xml.etree.cElementTree import parse
+    doc = parse(open(path))
+    for node in doc.getiterator():
+        for attrib in list(node.attrib):
+            if attrib.startswith(c_ns_key):
+                del node.attrib[attrib]
+    doc.write(sys.stdout)
+    return 0
 
 def main(args):
     parser = _get_option_parser()
@@ -102,6 +117,9 @@
     if len(args) <= 1:
         _error('Need at least one filename')
 
+    if options.typelib_xml:
+        return typelib_xml_strip(args[1])
+
     if not options.namespace_name:
         _error('Namespace name missing')
 

Modified: trunk/tools/generate.c
==============================================================================
--- trunk/tools/generate.c	(original)
+++ trunk/tools/generate.c	Fri Aug 22 20:05:23 2008
@@ -279,22 +279,19 @@
       g_fprintf (file, "%*s    <parameter name=\"%s\"",
 		 indent, "", g_base_info_get_name ((GIBaseInfo *) arg));
       
-      if (g_type_info_is_pointer (type))
+      switch (g_arg_info_get_ownership_transfer (arg))
 	{
-	  switch (g_arg_info_get_ownership_transfer (arg))
-	    {
-	    case GI_TRANSFER_NOTHING:
-	      break;
-	    case GI_TRANSFER_CONTAINER:
-	      g_fprintf (file, " transfer=\"shallow\"");
-	      break;
-	    case GI_TRANSFER_EVERYTHING:
-	      g_fprintf (file, " transfer=\"full\"");
-	      break;
-	    default:
-	      g_assert_not_reached ();
-	    }
-	}	      
+	case GI_TRANSFER_NOTHING:
+	  break;
+	case GI_TRANSFER_CONTAINER:
+	  g_fprintf (file, " transfer=\"shallow\"");
+	  break;
+	case GI_TRANSFER_EVERYTHING:
+	  g_fprintf (file, " transfer=\"full\"");
+	  break;
+	default:
+	  g_assert_not_reached ();
+	}
       
       g_fprintf (file, " direction=\"");
       switch (g_arg_info_get_direction (arg))



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