diff options
author | Colin Walters <walters@verbum.org> | 2008-08-22 20:05:23 +0000 |
---|---|---|
committer | Colin Walters <walters@src.gnome.org> | 2008-08-22 20:05:23 +0000 |
commit | ff4f7d4662069dc12633fb1e0720cd5cf8c9accf (patch) | |
tree | acab0140b4f11a79d10c8b8a9b93b1233ea8bbc1 | |
parent | d63fa8f926d209d3580e61e733d292cf6b1e316d (diff) | |
download | gobject-introspection-ff4f7d4662069dc12633fb1e0720cd5cf8c9accf.tar.gz |
Pass through recursive types. Avoid overwriting errors. Always write the
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.
svn path=/trunk/; revision=457
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | girepository/girparser.c | 82 | ||||
-rw-r--r-- | giscanner/xmlwriter.py | 1 | ||||
-rw-r--r-- | tests/boxed.gir | 8 | ||||
-rw-r--r-- | tests/interface.gir | 12 | ||||
-rw-r--r-- | tests/object.gir | 8 | ||||
-rw-r--r-- | tests/scanner/Makefile.am | 20 | ||||
-rw-r--r-- | tests/scanner/annotation-expected.gir | 1 | ||||
-rw-r--r-- | tests/scanner/drawable-expected.gir | 1 | ||||
-rw-r--r-- | tests/scanner/foo-expected.gir | 1 | ||||
-rw-r--r-- | tests/scanner/utility-expected.gir | 1 | ||||
-rw-r--r-- | tests/types.gir | 8 | ||||
-rw-r--r-- | tests/xref1.gir | 2 | ||||
-rw-r--r-- | tests/xref2.gir | 2 | ||||
-rwxr-xr-x | tools/g-ir-scanner | 20 | ||||
-rw-r--r-- | tools/generate.c | 27 |
16 files changed, 147 insertions, 63 deletions
@@ -1,3 +1,19 @@ +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. + 2008-08-22 Johan Dahlin <johan@gnome.org> * configure.ac: diff --git a/girepository/girparser.c b/girepository/girparser.c index 917d37d8..9a321d2c 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -57,7 +57,8 @@ typedef enum 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 @@ struct _ParseContext GIrModule *current_module; GIrNode *current_node; GIrNode *current_typed; + int type_depth; }; #define MISSING_ATTRIBUTE(ctx,error,element,attribute) \ @@ -736,9 +738,19 @@ start_parameter (GMarkupParseContext *context, 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 @@ start_type (GMarkupParseContext *context, { 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 @@ start_type (GMarkupParseContext *context, "The element <type> is invalid here"); return FALSE; } - + name = find_attribute ("name", attribute_names, attribute_values); if (name == NULL) @@ -2063,12 +2086,13 @@ start_element_handler (GMarkupParseContext *context, 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 @@ end_element_handler (GMarkupParseContext *context, } } 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 @@ g_ir_parse_string (const gchar *buffer, 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); diff --git a/giscanner/xmlwriter.py b/giscanner/xmlwriter.py index 6b94a4d6..eb17c619 100644 --- a/giscanner/xmlwriter.py +++ b/giscanner/xmlwriter.py @@ -27,6 +27,7 @@ class XMLWriter(object): def __init__(self): self._data = StringIO() + self._data.write('<?xml version="1.0"?>\n') self._tag_stack = [] self._indent = 0 self._indent_unit = 2 diff --git a/tests/boxed.gir b/tests/boxed.gir index 0184ec60..70ca0e3c 100644 --- a/tests/boxed.gir +++ b/tests/boxed.gir @@ -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"/> diff --git a/tests/interface.gir b/tests/interface.gir index 74fd4205..a22cd72d 100644 --- a/tests/interface.gir +++ b/tests/interface.gir @@ -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> diff --git a/tests/object.gir b/tests/object.gir index 99ca0c3b..981883fb 100644 --- a/tests/object.gir +++ b/tests/object.gir @@ -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"> diff --git a/tests/scanner/Makefile.am b/tests/scanner/Makefile.am index 1ec12c19..028cf660 100644 --- a/tests/scanner/Makefile.am +++ b/tests/scanner/Makefile.am @@ -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_CFLAGS = $(GOBJECT_CFLAGS) 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 @@ drawable.gir: libdrawable.la drawable.h $(SCANNER) $(SCANNER_LIBS) $(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 @@ utility.gir: libutility.la utility.h $(SCANNER) $(SCANNER_LIBS) 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 @@ post-check: 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 diff --git a/tests/scanner/annotation-expected.gir b/tests/scanner/annotation-expected.gir index a4704d68..40dde3ac 100644 --- a/tests/scanner/annotation-expected.gir +++ b/tests/scanner/annotation-expected.gir @@ -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" diff --git a/tests/scanner/drawable-expected.gir b/tests/scanner/drawable-expected.gir index 0bf5f9ad..ef7a1b5f 100644 --- a/tests/scanner/drawable-expected.gir +++ b/tests/scanner/drawable-expected.gir @@ -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" diff --git a/tests/scanner/foo-expected.gir b/tests/scanner/foo-expected.gir index 41970da7..a7bc4386 100644 --- a/tests/scanner/foo-expected.gir +++ b/tests/scanner/foo-expected.gir @@ -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" diff --git a/tests/scanner/utility-expected.gir b/tests/scanner/utility-expected.gir index b6cc89a7..e682450f 100644 --- a/tests/scanner/utility-expected.gir +++ b/tests/scanner/utility-expected.gir @@ -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" diff --git a/tests/types.gir b/tests/types.gir index 1c5b9028..23890a8c 100644 --- a/tests/types.gir +++ b/tests/types.gir @@ -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> diff --git a/tests/xref1.gir b/tests/xref1.gir index a55d4807..275e30fa 100644 --- a/tests/xref1.gir +++ b/tests/xref1.gir @@ -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> diff --git a/tests/xref2.gir b/tests/xref2.gir index 841fbb71..06ec6513 100644 --- a/tests/xref2.gir +++ b/tests/xref2.gir @@ -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> diff --git a/tools/g-ir-scanner b/tools/g-ir-scanner index d5356304..8951aa1f 100755 --- a/tools/g-ir-scanner +++ b/tools/g-ir-scanner @@ -71,8 +71,11 @@ def _get_option_parser(): 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 _get_option_parser(): 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 @@ def main(args): 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') diff --git a/tools/generate.c b/tools/generate.c index b419cf51..44346ce1 100644 --- a/tools/generate.c +++ b/tools/generate.c @@ -279,22 +279,19 @@ write_callable_info (const gchar *namespace, 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)) |