From 34f49b2ca982ca159c6bd6b1178b3fe63b18d20a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 9 May 2005 14:24:46 +0000 Subject: [PATCH 01/99] Initial revision --- girepository/src/generate.c | 999 ++++++++++++++++++++++++++++++++++++ 1 file changed, 999 insertions(+) create mode 100644 girepository/src/generate.c diff --git a/girepository/src/generate.c b/girepository/src/generate.c new file mode 100644 index 0000000000..7d86365608 --- /dev/null +++ b/girepository/src/generate.c @@ -0,0 +1,999 @@ +/* GObject introspection: IDL generator + * + * Copyright (C) 2005 Matthias Clasen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include +#include +#include + +#include "girepository.h" + +gboolean raw = FALSE; +gchar **input = NULL; +gchar *output = NULL; + +static void +write_type_info (GITypeInfo *info, + FILE *file) +{ + gint tag; + gint i; + GITypeInfo *type; + + const gchar* basic[] = { + "void", + "gboolean", + "gint8", + "guint8", + "gint16", + "guint16", + "gint32", + "guint32", + "gint64", + "guint64", + "gfloat", + "gdouble", + "gchar", + "GString", + "gint", + "guint", + "glong", + "gulong" + }; + + tag = g_type_info_get_tag (info); + + if (tag < 20) + g_print ("%s%s", basic[tag], g_type_info_is_pointer (info) ? "*" : ""); + else if (tag == 20) + { + gint length; + + type = g_type_info_get_param_type (info, 0); + write_type_info (type, file); + g_print ("["); + + length = g_type_info_get_array_length (info); + + if (length >= 0) + g_print ("length=%d", length); + + if (g_type_info_is_zero_terminated (info)) + g_print ("%szero-terminated=1", length >= 0 ? "," : ""); + + g_print ("]"); + g_base_info_unref ((GIBaseInfo *)type); + } + else if (tag == 21) + { + GIBaseInfo *iface = g_type_info_get_interface (info); + g_print ("%s%s", + g_base_info_get_name (iface), + g_type_info_is_pointer (info) ? "*" : ""); + g_base_info_unref (iface); + } + else if (tag == 22) + { + type = g_type_info_get_param_type (info, 0); + g_print ("GList<"); + write_type_info (type, file); + g_print (">"); + g_base_info_unref ((GIBaseInfo *)type); + } + else if (tag == 23) + { + type = g_type_info_get_param_type (info, 0); + g_print ("GSList<"); + write_type_info (type, file); + g_print (">"); + g_base_info_unref ((GIBaseInfo *)type); + } + else if (tag == 24) + { + type = g_type_info_get_param_type (info, 0); + g_print ("GHashTable<"); + write_type_info (type, file); + g_base_info_unref ((GIBaseInfo *)type); + type = g_type_info_get_param_type (info, 1); + g_print(","); + write_type_info (type, file); + g_print (">"); + g_base_info_unref ((GIBaseInfo *)type); + } + else if (tag == 25) + { + g_print ("GError<"); + for (i = 0; i < g_type_info_get_n_error_domains (info); i++) + { + GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); + g_print ("%s%s", i ? "," : "", g_base_info_get_name ((GIBaseInfo *)ed)); + g_base_info_unref ((GIBaseInfo *)ed); + } + g_print (">"); + } +} + +static void +write_field_info (GIFieldInfo *info, + FILE *file) +{ + const gchar *name; + GIFieldInfoFlags flags; + gint size; + gint offset; + GITypeInfo *type; + + name = g_base_info_get_name ((GIBaseInfo *)info); + flags = g_field_info_get_flags (info); + size = g_field_info_get_size (info); + offset = g_field_info_get_offset (info); + + g_print (" \n"); +} + +static void +write_callable_info (GICallableInfo *info, + FILE *file, + gint indent) +{ + GITypeInfo *type; + gint i; + + g_fprintf (file, "%*s \n"); + + if (g_callable_info_get_n_args (info) > 0) + { + g_fprintf (file, "%*s \n", indent, ""); + for (i = 0; i < g_callable_info_get_n_args (info); i++) + { + GIArgInfo *arg = g_callable_info_get_arg (info, i); + + g_fprintf (file, "%*s \n"); + + g_base_info_unref ((GIBaseInfo *)arg); + } + + g_fprintf (file, "%*s \n", indent, ""); + } +} + +static void +write_function_info (GIFunctionInfo *info, + FILE *file, + gint indent) +{ + GIFunctionInfoFlags flags; + const gchar *tag; + const gchar *name; + const gchar *cname; + gboolean deprecated; + + flags = g_function_info_get_flags (info); + name = g_base_info_get_name ((GIBaseInfo *)info); + cname = g_function_info_get_symbol (info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + if (flags & GI_FUNCTION_IS_CONSTRUCTOR) + tag = "constructor"; + else if (flags & GI_FUNCTION_IS_METHOD) + tag = "method"; + else + tag = "function"; + + g_fprintf (file, "%*s<%s name=\"%s\" cname=\"%s\"", + indent, "", tag, name, cname); + + if (flags & GI_FUNCTION_IS_SETTER) + g_fprintf (file, " type=\"setter\""); + else if (flags & GI_FUNCTION_IS_GETTER) + g_fprintf (file, " type=\"getter\""); + + if (deprecated) + g_fprintf (file, " deprecated=\"1\""); + + g_fprintf (file, ">\n"); + write_callable_info ((GICallableInfo*)info, file, indent); + g_fprintf (file, "%*s\n", indent, "", tag); +} + +static void +write_callback_info (GICallbackInfo *info, + FILE *file, + gint indent) +{ + GIFunctionInfoFlags flags; + const gchar *name; + gboolean deprecated; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + g_fprintf (file, "%*s\n"); + write_callable_info ((GICallableInfo*)info, file, indent); + g_fprintf (file, "%*s\n", indent, ""); +} + +static void +write_struct_info (GIStructInfo *info, + FILE *file) +{ + const gchar *name; + const gchar *type_name; + const gchar *type_init; + gboolean deprecated; + gint i; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) + { + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + + g_fprintf (file, " \n"); + + for (i = 0; i < g_struct_info_get_n_fields (info); i++) + { + GIFieldInfo *field = g_struct_info_get_field (info, i); + write_field_info (field, file); + g_base_info_unref ((GIBaseInfo *)field); + } + + for (i = 0; i < g_struct_info_get_n_methods (info); i++) + { + GIFunctionInfo *function = g_struct_info_get_method (info, i); + write_function_info (function, file, 6); + g_base_info_unref ((GIBaseInfo *)function); + } + + if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) + g_fprintf (file, " \n"); + else + g_fprintf (file, " \n"); +} + +static void +write_value_info (GIValueInfo *info, + FILE *file) +{ + const gchar *name; + const gchar *short_name; + glong value; + gboolean deprecated; + + name = g_base_info_get_name ((GIBaseInfo *)info); + short_name = g_value_info_get_short_name (info); + value = g_value_info_get_value (info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + g_print (" \n"); +} + +static void +write_constant_info (GIConstantInfo *info, + FILE *file, + gint indent) +{ + GITypeInfo *type; + const gchar *name; + gboolean deprecated; + GArgument value; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + g_print ("%*s\n"); + + g_base_info_unref ((GIBaseInfo *)type); +} + + +static void +write_enum_info (GIEnumInfo *info, + FILE *file) +{ + const gchar *name; + const gchar *type_name; + const gchar *type_init; + gboolean deprecated; + gint i; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + + if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) + g_fprintf (file, " \n"); + + for (i = 0; i < g_enum_info_get_n_values (info); i++) + { + GIValueInfo *value = g_enum_info_get_value (info, i); + write_value_info (value, file); + g_base_info_unref ((GIBaseInfo *)value); + } + + if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) + g_fprintf (file, " \n"); + else + g_fprintf (file, " \n"); +} + +static void +write_signal_info (GISignalInfo *info, + FILE *file) +{ + GSignalFlags flags; + const gchar *name; + gboolean deprecated; + + name = g_base_info_get_name ((GIBaseInfo *)info); + flags = g_signal_info_get_flags (info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + g_fprintf (file, " \n"); + + write_callable_info ((GICallableInfo*)info, file, 6); + g_fprintf (file, " \n"); +} + +static void +write_vfunc_info (GIVFuncInfo *info, + FILE *file) +{ + GIVFuncInfoFlags flags; + const gchar *name; + gboolean deprecated; + + name = g_base_info_get_name ((GIBaseInfo *)info); + flags = g_vfunc_info_get_flags (info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + g_fprintf (file, " \n"); + + write_callable_info ((GICallableInfo*)info, file, 6); + g_fprintf (file, " \n"); +} + +static void +write_property_info (GIPropertyInfo *info, + FILE *file) +{ + GParamFlags flags; + const gchar *name; + gboolean deprecated; + GITypeInfo *type; + + name = g_base_info_get_name ((GIBaseInfo *)info); + flags = g_property_info_get_flags (info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + g_fprintf (file, " \n"); +} + +static void +write_object_info (GIObjectInfo *info, + FILE *file) +{ + const gchar *name; + const gchar *parent; + const gchar *type_name; + const gchar *type_init; + gboolean deprecated; + GIObjectInfo *pnode; + gint i; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + pnode = g_object_info_get_parent (info); + if (pnode) + parent = g_base_info_get_name ((GIBaseInfo *)pnode); + else + parent = NULL; + g_base_info_unref ((GIBaseInfo *)pnode); + + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + g_fprintf (file, " \n"); + + if (g_object_info_get_n_interfaces (info) > 0) + { + g_fprintf (file, " \n"); + for (i = 0; i < g_object_info_get_n_interfaces (info); i++) + { + GIInterfaceInfo *imp = g_object_info_get_interface (info, i); + g_fprintf (file, " \n", + g_base_info_get_name ((GIBaseInfo*)imp)); + g_base_info_unref ((GIBaseInfo*)imp); + } + g_fprintf (file, " \n"); + } + + for (i = 0; i < g_object_info_get_n_fields (info); i++) + { + GIFieldInfo *field = g_object_info_get_field (info, i); + write_field_info (field, file); + g_base_info_unref ((GIBaseInfo *)field); + } + + for (i = 0; i < g_object_info_get_n_methods (info); i++) + { + GIFunctionInfo *function = g_object_info_get_method (info, i); + write_function_info (function, file, 6); + g_base_info_unref ((GIBaseInfo *)function); + } + + for (i = 0; i < g_object_info_get_n_properties (info); i++) + { + GIPropertyInfo *prop = g_object_info_get_property (info, i); + write_property_info (prop, file); + g_base_info_unref ((GIBaseInfo *)prop); + } + + for (i = 0; i < g_object_info_get_n_signals (info); i++) + { + GISignalInfo *signal = g_object_info_get_signal (info, i); + write_signal_info (signal, file); + g_base_info_unref ((GIBaseInfo *)signal); + } + + for (i = 0; i < g_object_info_get_n_vfuncs (info); i++) + { + GIVFuncInfo *vfunc = g_object_info_get_vfunc (info, i); + write_vfunc_info (vfunc, file); + g_base_info_unref ((GIBaseInfo *)vfunc); + } + + for (i = 0; i < g_object_info_get_n_constants (info); i++) + { + GIConstantInfo *constant = g_object_info_get_constant (info, i); + write_constant_info (constant, file, 6); + g_base_info_unref ((GIBaseInfo *)constant); + } + + g_fprintf (file, " \n"); +} + +static void +write_interface_info (GIInterfaceInfo *info, + FILE *file) +{ + const gchar *name; + const gchar *type_name; + const gchar *type_init; + gboolean deprecated; + gint i; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + g_fprintf (file, " \n"); + + if (g_interface_info_get_n_prerequisites (info) > 0) + { + g_fprintf (file, " \n"); + for (i = 0; i < g_interface_info_get_n_prerequisites (info); i++) + { + GIBaseInfo *req = g_interface_info_get_prerequisite (info, i); + + if (g_base_info_get_type (req) == GI_INFO_TYPE_INTERFACE) + g_fprintf (file, " \n", + g_base_info_get_name (req)); + else + g_fprintf (file, " \n", + g_base_info_get_name (req)); + + g_base_info_unref (req); + } + g_fprintf (file, " \n"); + } + + for (i = 0; i < g_interface_info_get_n_methods (info); i++) + { + GIFunctionInfo *function = g_interface_info_get_method (info, i); + write_function_info (function, file, 6); + g_base_info_unref ((GIBaseInfo *)function); + } + + for (i = 0; i < g_interface_info_get_n_properties (info); i++) + { + GIPropertyInfo *prop = g_interface_info_get_property (info, i); + write_property_info (prop, file); + g_base_info_unref ((GIBaseInfo *)prop); + } + + for (i = 0; i < g_interface_info_get_n_signals (info); i++) + { + GISignalInfo *signal = g_interface_info_get_signal (info, i); + write_signal_info (signal, file); + g_base_info_unref ((GIBaseInfo *)signal); + } + + for (i = 0; i < g_interface_info_get_n_vfuncs (info); i++) + { + GIVFuncInfo *vfunc = g_interface_info_get_vfunc (info, i); + write_vfunc_info (vfunc, file); + g_base_info_unref ((GIBaseInfo *)vfunc); + } + + for (i = 0; i < g_interface_info_get_n_constants (info); i++) + { + GIConstantInfo *constant = g_interface_info_get_constant (info, i); + write_constant_info (constant, file, 6); + g_base_info_unref ((GIBaseInfo *)constant); + } + + g_fprintf (file, " \n"); +} + +static void +write_error_domain_info (GIErrorDomainInfo *info, + FILE *file) +{ + GIBaseInfo *enum_; + const gchar *name, *quark, *codes; + + name = g_base_info_get_name ((GIBaseInfo *)info); + quark = g_error_domain_info_get_quark (info); + enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info); + codes = g_base_info_get_name (enum_); + g_base_info_unref (enum_); + + g_fprintf (file, + " \n", + name, quark, codes); +} + +static void +write_repository (GIRepository *repository, + gboolean needs_prefix) +{ + FILE *file; + gchar **namespaces; + gint i, j; + + namespaces = g_irepository_get_namespaces (repository); + + if (output == NULL) + file = stdout; + else + { + gchar *filename; + + if (needs_prefix) + filename = g_strdup_printf ("%s-%s", namespaces[0], output); + else + filename = g_strdup (output); + file = g_fopen (filename, "w"); + + if (file == NULL) + { + g_fprintf (stderr, "failed to open '%s': %s\n", + filename, g_strerror (errno)); + g_free (filename); + + return; + } + + g_free (filename); + } + + g_fprintf (file, "\n"); + g_fprintf (file, "\n"); + + for (i = 0; namespaces[i]; i++) + { + g_fprintf (file, " \n", namespaces[i]); + + for (j = 0; j < g_irepository_get_n_infos (repository, namespaces[i]); j++) + { + GIBaseInfo *info = g_irepository_get_info (repository, namespaces[i], j); + switch (g_base_info_get_type (info)) + { + case GI_INFO_TYPE_FUNCTION: + write_function_info ((GIFunctionInfo *)info, file, 4); + break; + + case GI_INFO_TYPE_CALLBACK: + write_callback_info ((GICallbackInfo *)info, file, 4); + break; + + case GI_INFO_TYPE_STRUCT: + case GI_INFO_TYPE_BOXED: + write_struct_info ((GIStructInfo *)info, file); + break; + + case GI_INFO_TYPE_ENUM: + case GI_INFO_TYPE_FLAGS: + write_enum_info ((GIEnumInfo *)info, file); + break; + + case GI_INFO_TYPE_CONSTANT: + write_constant_info ((GIConstantInfo *)info, file, 4); + break; + + case GI_INFO_TYPE_OBJECT: + write_object_info ((GIObjectInfo *)info, file); + break; + + case GI_INFO_TYPE_INTERFACE: + write_interface_info ((GIInterfaceInfo *)info, file); + break; + + case GI_INFO_TYPE_ERROR_DOMAIN: + write_error_domain_info ((GIErrorDomainInfo *)info, file); + break; + } + + g_base_info_unref (info); + } + + g_fprintf (file, " \n"); + } + + g_fprintf (file, "\n"); + + if (output != NULL) + fclose (file); + + g_strfreev (namespaces); +} + +static GOptionEntry options[] = +{ + { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "handle raw metadata", NULL }, + { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, + { NULL, } +}; + +static const guchar * +load_metadata (const gchar *filename, + void **dlhandle) +{ + guchar *metadata; + void *handle; + char *error; + + handle = dlopen (filename, RTLD_LAZY); + metadata = dlsym (handle, "_G_METADATA"); + + error = dlerror (); + + if (dlhandle) + *dlhandle = handle; + + if (error) + { + g_fprintf (stderr, + "Could not load metadata from '%s': %s\n", + filename, error); + + return NULL; + } + + return metadata; +} + +int +main (int argc, char *argv[]) +{ + GOptionContext *context; + GError *error = NULL; + gboolean needs_prefix; + gint i; + + g_type_init (); + + g_metadata_check_sanity (); + + context = g_option_context_new (""); + g_option_context_add_main_entries (context, options, NULL); + g_option_context_parse (context, &argc, &argv, &error); + + if (!input) + { + g_fprintf (stderr, "no input files\n"); + + return 1; + } + + for (i = 0; input[i]; i++) + { + void *dlhandle = NULL; + const guchar *metadata; + + if (raw) + { + if (!g_file_get_contents (input[i], (gchar **)&metadata, NULL, &error)) + { + g_fprintf (stderr, "failed to read '%s': %s\n", + input[i], error->message); + g_clear_error (&error); + continue; + } + } + else + { + metadata = load_metadata (input[i], &dlhandle); + if (!metadata) + { + g_fprintf (stderr, "failed to load metadata from '%s'\n", + input[i]); + continue; + } + } + + if (input[i + 1] && output) + needs_prefix = TRUE; + else + needs_prefix = FALSE; + + g_irepository_register (g_irepository_get_default (), metadata); + write_repository (g_irepository_get_default (), needs_prefix); + g_irepository_unregister (g_irepository_get_default (), metadata); + + if (dlhandle) + { + dlclose (dlhandle); + dlhandle = NULL; + } + + /* when writing to stdout, stop after the first module */ + if (input[i + 1] && !output) + { + g_fprintf (stderr, "warning, %d modules omitted\n", + g_strv_length (input) - 1); + + break; + } + } + + return 0; +} -- GitLab From f1ad63b7626909dba5134107c533d6d1e63bcffe Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 9 May 2005 14:24:46 +0000 Subject: [PATCH 02/99] Import the GObject introspection prototype -- GitLab From bf4631bf285d9ba18066c3a406bdcbdfda678dc5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 9 May 2005 19:32:10 +0000 Subject: [PATCH 03/99] Clean up handling of names. All elements have a "name", only the elements 2005-05-09 Matthias Clasen * gidl.dtd: Clean up handling of names. All elements have a "name", only the elements corresponding to actual callable functions (function, method, constructor), have an additional "symbol" attribute holding the dlsym()-able function name. * src/generate.c: Adapt to generate xml matching the new dtd. * src/gidlparser.c: * src/gidlnode.c: Adapt to parse the new dtd. * tests/*.test: Adjust to the new dtd. * metadata-format.txt: * src/gmetadata.h: Remove the short_name field from the ValueBlob. * src/gmetadata.c: Shrink size of ValueBlob to 12. * src/girepository.h: * src/ginfo.c (g_value_info_get_short_name): Removed --- girepository/src/generate.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 7d86365608..2fe3730dbe 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -147,7 +147,7 @@ write_field_info (GIFieldInfo *info, size = g_field_info_get_size (info); offset = g_field_info_get_offset (info); - g_print (" Date: Thu, 12 May 2005 22:49:59 +0000 Subject: [PATCH 04/99] Some fixes --- girepository/src/generate.c | 267 +++++++++++++++++++++--------------- 1 file changed, 158 insertions(+), 109 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 2fe3730dbe..990b670021 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -31,9 +31,21 @@ gboolean raw = FALSE; gchar **input = NULL; gchar *output = NULL; +static void +write_type_name (const gchar *namespace, + GIBaseInfo *info, + FILE *file) +{ + if (strcmp (namespace, g_base_info_get_namespace (info)) != 0) + g_fprintf (file, "%s.", g_base_info_get_namespace (info)); + + g_fprintf (file, "%s", g_base_info_get_name (info)); +} + static void -write_type_info (GITypeInfo *info, - FILE *file) +write_type_info (const gchar *namespace, + GITypeInfo *info, + FILE *file) { gint tag; gint i; @@ -63,77 +75,80 @@ write_type_info (GITypeInfo *info, tag = g_type_info_get_tag (info); if (tag < 20) - g_print ("%s%s", basic[tag], g_type_info_is_pointer (info) ? "*" : ""); + g_fprintf (file, "%s%s", basic[tag], g_type_info_is_pointer (info) ? "*" : ""); else if (tag == 20) { gint length; type = g_type_info_get_param_type (info, 0); - write_type_info (type, file); - g_print ("["); + write_type_info (namespace, type, file); + g_fprintf (file, "["); length = g_type_info_get_array_length (info); if (length >= 0) - g_print ("length=%d", length); + g_fprintf (file, "length=%d", length); if (g_type_info_is_zero_terminated (info)) - g_print ("%szero-terminated=1", length >= 0 ? "," : ""); + g_fprintf (file, "%szero-terminated=1", length >= 0 ? "," : ""); - g_print ("]"); + g_fprintf (file, "]"); g_base_info_unref ((GIBaseInfo *)type); } else if (tag == 21) { GIBaseInfo *iface = g_type_info_get_interface (info); - g_print ("%s%s", - g_base_info_get_name (iface), - g_type_info_is_pointer (info) ? "*" : ""); + write_type_name (namespace, iface, file); + if (g_type_info_is_pointer (info)) + g_fprintf (file, "*"); g_base_info_unref (iface); } else if (tag == 22) { type = g_type_info_get_param_type (info, 0); - g_print ("GList<"); - write_type_info (type, file); - g_print (">"); + g_fprintf (file, "GList<"); + write_type_info (namespace, type, file); + g_fprintf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } else if (tag == 23) { type = g_type_info_get_param_type (info, 0); - g_print ("GSList<"); - write_type_info (type, file); - g_print (">"); + g_fprintf (file, "GSList<"); + write_type_info (namespace, type, file); + g_fprintf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } else if (tag == 24) { type = g_type_info_get_param_type (info, 0); - g_print ("GHashTable<"); - write_type_info (type, file); + g_fprintf (file, "GHashTable<"); + write_type_info (namespace, type, file); g_base_info_unref ((GIBaseInfo *)type); type = g_type_info_get_param_type (info, 1); - g_print(","); - write_type_info (type, file); - g_print (">"); + g_fprintf (file, ","); + write_type_info (namespace, type, file); + g_fprintf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } else if (tag == 25) { - g_print ("GError<"); + g_fprintf (file, "GError<"); for (i = 0; i < g_type_info_get_n_error_domains (info); i++) { GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); - g_print ("%s%s", i ? "," : "", g_base_info_get_name ((GIBaseInfo *)ed)); + if (i > 0) + g_fprintf (file, ","); + write_type_name (namespace, (GIBaseInfo *)ed, file); g_base_info_unref ((GIBaseInfo *)ed); } - g_print (">"); + g_fprintf (file, ">"); } } static void -write_field_info (GIFieldInfo *info, +write_field_info (const gchar *namespace, + GIFieldInfo *info, FILE *file) { const gchar *name; @@ -147,25 +162,27 @@ write_field_info (GIFieldInfo *info, size = g_field_info_get_size (info); offset = g_field_info_get_offset (info); - g_print (" \n"); + g_fprintf (file, "\" />\n"); } static void -write_callable_info (GICallableInfo *info, +write_callable_info (const gchar *namespace, + GICallableInfo *info, FILE *file, gint indent) { @@ -175,10 +192,30 @@ write_callable_info (GICallableInfo *info, g_fprintf (file, "%*s \n"); + g_fprintf (file, "\""); + + if (g_type_info_is_pointer (type)) + { + switch (g_callable_info_get_caller_owns (info)) + { + case GI_TRANSFER_NOTHING: + g_fprintf (file, " transfer=\"none\""); + 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, "/>\n"); if (g_callable_info_get_n_args (info) > 0) { @@ -191,7 +228,7 @@ write_callable_info (GICallableInfo *info, indent, "", g_base_info_get_name ((GIBaseInfo *) arg)); type = g_arg_info_get_type (arg); - write_type_info (type, file); + write_type_info (namespace, type, file); g_base_info_unref ((GIBaseInfo *)type); g_fprintf (file, "\""); @@ -232,7 +269,8 @@ write_callable_info (GICallableInfo *info, } static void -write_function_info (GIFunctionInfo *info, +write_function_info (const gchar *namespace, + GIFunctionInfo *info, FILE *file, gint indent) { @@ -266,12 +304,13 @@ write_function_info (GIFunctionInfo *info, g_fprintf (file, " deprecated=\"1\""); g_fprintf (file, ">\n"); - write_callable_info ((GICallableInfo*)info, file, indent); + write_callable_info (namespace, (GICallableInfo*)info, file, indent); g_fprintf (file, "%*s\n", indent, "", tag); } static void -write_callback_info (GICallbackInfo *info, +write_callback_info (const gchar *namespace, + GICallbackInfo *info, FILE *file, gint indent) { @@ -288,12 +327,13 @@ write_callback_info (GICallbackInfo *info, g_fprintf (file, " deprecated=\"1\""); g_fprintf (file, ">\n"); - write_callable_info ((GICallableInfo*)info, file, indent); + write_callable_info (namespace, (GICallableInfo*)info, file, indent); g_fprintf (file, "%*s\n", indent, ""); } static void -write_struct_info (GIStructInfo *info, +write_struct_info (const gchar *namespace, + GIStructInfo *info, FILE *file) { const gchar *name; @@ -323,14 +363,14 @@ write_struct_info (GIStructInfo *info, for (i = 0; i < g_struct_info_get_n_fields (info); i++) { GIFieldInfo *field = g_struct_info_get_field (info, i); - write_field_info (field, file); + write_field_info (namespace, field, file); g_base_info_unref ((GIBaseInfo *)field); } for (i = 0; i < g_struct_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_struct_info_get_method (info, i); - write_function_info (function, file, 6); + write_function_info (namespace, function, file, 6); g_base_info_unref ((GIBaseInfo *)function); } @@ -341,7 +381,8 @@ write_struct_info (GIStructInfo *info, } static void -write_value_info (GIValueInfo *info, +write_value_info (const gchar *namespace, + GIValueInfo *info, FILE *file) { const gchar *name; @@ -353,16 +394,17 @@ write_value_info (GIValueInfo *info, value = g_value_info_get_value (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_print (" \n"); + g_fprintf (file, " />\n"); } static void -write_constant_info (GIConstantInfo *info, +write_constant_info (const gchar *namespace, + GIConstantInfo *info, FILE *file, gint indent) { @@ -374,10 +416,10 @@ write_constant_info (GIConstantInfo *info, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_print ("%*s\n"); - write_callable_info ((GICallableInfo*)info, file, 6); + write_callable_info (namespace, (GICallableInfo*)info, file, 6); g_fprintf (file, " \n"); } static void -write_vfunc_info (GIVFuncInfo *info, +write_vfunc_info (const gchar *namespace, + GIVFuncInfo *info, FILE *file) { GIVFuncInfoFlags flags; @@ -550,12 +595,13 @@ write_vfunc_info (GIVFuncInfo *info, g_fprintf (file, ">\n"); - write_callable_info ((GICallableInfo*)info, file, 6); + write_callable_info (namespace, (GICallableInfo*)info, file, 6); g_fprintf (file, " \n"); } static void -write_property_info (GIPropertyInfo *info, +write_property_info (const gchar *namespace, + GIPropertyInfo *info, FILE *file) { GParamFlags flags; @@ -590,18 +636,18 @@ write_property_info (GIPropertyInfo *info, type = g_property_info_get_type (info); g_fprintf (file, " type=\""); - write_type_info (type, file); + write_type_info (namespace, type, file); g_fprintf (file, "\""); g_fprintf (file, "/>\n"); } static void -write_object_info (GIObjectInfo *info, +write_object_info (const gchar *namespace, + GIObjectInfo *info, FILE *file) { const gchar *name; - const gchar *parent; const gchar *type_name; const gchar *type_init; gboolean deprecated; @@ -611,19 +657,18 @@ write_object_info (GIObjectInfo *info, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - pnode = g_object_info_get_parent (info); - if (pnode) - parent = g_base_info_get_name ((GIBaseInfo *)pnode); - else - parent = NULL; - g_base_info_unref ((GIBaseInfo *)pnode); - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); g_fprintf (file, " \n", - g_base_info_get_name ((GIBaseInfo*)imp)); + g_fprintf (file, " \n"); g_base_info_unref ((GIBaseInfo*)imp); } g_fprintf (file, " \n"); @@ -648,42 +694,42 @@ write_object_info (GIObjectInfo *info, for (i = 0; i < g_object_info_get_n_fields (info); i++) { GIFieldInfo *field = g_object_info_get_field (info, i); - write_field_info (field, file); + write_field_info (namespace, field, file); g_base_info_unref ((GIBaseInfo *)field); } for (i = 0; i < g_object_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_object_info_get_method (info, i); - write_function_info (function, file, 6); + write_function_info (namespace, function, file, 6); g_base_info_unref ((GIBaseInfo *)function); } for (i = 0; i < g_object_info_get_n_properties (info); i++) { GIPropertyInfo *prop = g_object_info_get_property (info, i); - write_property_info (prop, file); + write_property_info (namespace, prop, file); g_base_info_unref ((GIBaseInfo *)prop); } for (i = 0; i < g_object_info_get_n_signals (info); i++) { GISignalInfo *signal = g_object_info_get_signal (info, i); - write_signal_info (signal, file); + write_signal_info (namespace, signal, file); g_base_info_unref ((GIBaseInfo *)signal); } for (i = 0; i < g_object_info_get_n_vfuncs (info); i++) { GIVFuncInfo *vfunc = g_object_info_get_vfunc (info, i); - write_vfunc_info (vfunc, file); + write_vfunc_info (namespace, vfunc, file); g_base_info_unref ((GIBaseInfo *)vfunc); } for (i = 0; i < g_object_info_get_n_constants (info); i++) { GIConstantInfo *constant = g_object_info_get_constant (info, i); - write_constant_info (constant, file, 6); + write_constant_info (namespace, constant, file, 6); g_base_info_unref ((GIBaseInfo *)constant); } @@ -691,7 +737,8 @@ write_object_info (GIObjectInfo *info, } static void -write_interface_info (GIInterfaceInfo *info, +write_interface_info (const gchar *namespace, + GIInterfaceInfo *info, FILE *file) { const gchar *name; @@ -721,12 +768,11 @@ write_interface_info (GIInterfaceInfo *info, GIBaseInfo *req = g_interface_info_get_prerequisite (info, i); if (g_base_info_get_type (req) == GI_INFO_TYPE_INTERFACE) - g_fprintf (file, " \n", - g_base_info_get_name (req)); + g_fprintf (file, " \n", - g_base_info_get_name (req)); - + g_fprintf (file, " \n"); g_base_info_unref (req); } g_fprintf (file, " \n"); @@ -735,35 +781,35 @@ write_interface_info (GIInterfaceInfo *info, for (i = 0; i < g_interface_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_interface_info_get_method (info, i); - write_function_info (function, file, 6); + write_function_info (namespace, function, file, 6); g_base_info_unref ((GIBaseInfo *)function); } for (i = 0; i < g_interface_info_get_n_properties (info); i++) { GIPropertyInfo *prop = g_interface_info_get_property (info, i); - write_property_info (prop, file); + write_property_info (namespace, prop, file); g_base_info_unref ((GIBaseInfo *)prop); } for (i = 0; i < g_interface_info_get_n_signals (info); i++) { GISignalInfo *signal = g_interface_info_get_signal (info, i); - write_signal_info (signal, file); + write_signal_info (namespace, signal, file); g_base_info_unref ((GIBaseInfo *)signal); } for (i = 0; i < g_interface_info_get_n_vfuncs (info); i++) { GIVFuncInfo *vfunc = g_interface_info_get_vfunc (info, i); - write_vfunc_info (vfunc, file); + write_vfunc_info (namespace, vfunc, file); g_base_info_unref ((GIBaseInfo *)vfunc); } for (i = 0; i < g_interface_info_get_n_constants (info); i++) { GIConstantInfo *constant = g_interface_info_get_constant (info, i); - write_constant_info (constant, file, 6); + write_constant_info (namespace, constant, file, 6); g_base_info_unref ((GIBaseInfo *)constant); } @@ -771,21 +817,22 @@ write_interface_info (GIInterfaceInfo *info, } static void -write_error_domain_info (GIErrorDomainInfo *info, +write_error_domain_info (const gchar *namespace, + GIErrorDomainInfo *info, FILE *file) { GIBaseInfo *enum_; - const gchar *name, *quark, *codes; + const gchar *name, *quark; name = g_base_info_get_name ((GIBaseInfo *)info); quark = g_error_domain_info_get_quark (info); enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info); - codes = g_base_info_get_name (enum_); - g_base_info_unref (enum_); - g_fprintf (file, - " \n", - name, quark, codes); + " \n"); + g_base_info_unref (enum_); } static void @@ -794,6 +841,7 @@ write_repository (GIRepository *repository, { FILE *file; gchar **namespaces; + gchar *ns; gint i, j; namespaces = g_irepository_get_namespaces (repository); @@ -827,45 +875,46 @@ write_repository (GIRepository *repository, for (i = 0; namespaces[i]; i++) { - g_fprintf (file, " \n", namespaces[i]); + ns = namespaces[i]; + g_fprintf (file, " \n", ns); - for (j = 0; j < g_irepository_get_n_infos (repository, namespaces[i]); j++) + for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) { - GIBaseInfo *info = g_irepository_get_info (repository, namespaces[i], j); + GIBaseInfo *info = g_irepository_get_info (repository, ns, j); switch (g_base_info_get_type (info)) { case GI_INFO_TYPE_FUNCTION: - write_function_info ((GIFunctionInfo *)info, file, 4); + write_function_info (ns, (GIFunctionInfo *)info, file, 4); break; case GI_INFO_TYPE_CALLBACK: - write_callback_info ((GICallbackInfo *)info, file, 4); + write_callback_info (ns, (GICallbackInfo *)info, file, 4); break; case GI_INFO_TYPE_STRUCT: case GI_INFO_TYPE_BOXED: - write_struct_info ((GIStructInfo *)info, file); + write_struct_info (ns, (GIStructInfo *)info, file); break; case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: - write_enum_info ((GIEnumInfo *)info, file); + write_enum_info (ns, (GIEnumInfo *)info, file); break; case GI_INFO_TYPE_CONSTANT: - write_constant_info ((GIConstantInfo *)info, file, 4); + write_constant_info (ns, (GIConstantInfo *)info, file, 4); break; case GI_INFO_TYPE_OBJECT: - write_object_info ((GIObjectInfo *)info, file); + write_object_info (ns, (GIObjectInfo *)info, file); break; case GI_INFO_TYPE_INTERFACE: - write_interface_info ((GIInterfaceInfo *)info, file); + write_interface_info (ns, (GIInterfaceInfo *)info, file); break; case GI_INFO_TYPE_ERROR_DOMAIN: - write_error_domain_info ((GIErrorDomainInfo *)info, file); + write_error_domain_info (ns, (GIErrorDomainInfo *)info, file); break; } -- GitLab From 02ef0d66f2479db4767110d18084a645e19eeec8 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 13 May 2005 02:54:03 +0000 Subject: [PATCH 05/99] Generate consistent end tags. * src/generate.c: Generate consistent end tags. * tests/*: Update --- girepository/src/generate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 990b670021..2a9ffd6302 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -215,7 +215,7 @@ write_callable_info (const gchar *namespace, } } - g_fprintf (file, "/>\n"); + g_fprintf (file, " />\n"); if (g_callable_info_get_n_args (info) > 0) { @@ -259,7 +259,7 @@ write_callable_info (const gchar *namespace, if (g_arg_info_is_optional (arg)) g_fprintf (file, " optional=\"1\""); - g_fprintf (file, "/>\n"); + g_fprintf (file, " />\n"); g_base_info_unref ((GIBaseInfo *)arg); } @@ -639,7 +639,7 @@ write_property_info (const gchar *namespace, write_type_info (namespace, type, file); g_fprintf (file, "\""); - g_fprintf (file, "/>\n"); + g_fprintf (file, " />\n"); } static void -- GitLab From 264b3adc76f3dcb7407fbe98c2f8bb7ecd00f0f1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 13 May 2005 17:31:10 +0000 Subject: [PATCH 06/99] Update testcases. 2005-05-13 Matthias Clasen * tests/*: Update testcases. * src/generate.c (write_callable_info): Don't forget to write transfer and null-ok attributes for return types and parameters. * src/girepository.h: * src/ginfo.c (g_callable_info_may_return_null): New function to find out if a function may return NULL. --- girepository/src/generate.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 2a9ffd6302..0f87a973cf 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -214,7 +214,9 @@ write_callable_info (const gchar *namespace, g_assert_not_reached (); } } - + if (g_callable_info_may_return_null (info)) + g_fprintf (file, "null-ok=\"1\""); + g_fprintf (file, " />\n"); if (g_callable_info_get_n_args (info) > 0) @@ -229,9 +231,27 @@ write_callable_info (const gchar *namespace, type = g_arg_info_get_type (arg); write_type_info (namespace, type, file); - g_base_info_unref ((GIBaseInfo *)type); g_fprintf (file, "\""); + if (g_type_info_is_pointer (type)) + { + switch (g_arg_info_get_ownership_transfer (arg)) + { + case GI_TRANSFER_NOTHING: + g_fprintf (file, " transfer=\"none\""); + 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_base_info_unref ((GIBaseInfo *)type); + g_fprintf (file, " direction=\""); switch (g_arg_info_get_direction (arg)) { -- GitLab From 45cf94a492c3e3b2074b64f7da8861050dfc4a64 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 15 May 2005 04:30:43 +0000 Subject: [PATCH 07/99] Add union.test. 2005-05-15 Matthias Clasen * tests/roundtrips.sh (SIMPLE_TESTS): Add union.test. * tests/union.test: Add a union test. * src/generate.c: Handle unions. * src/girepository.h: * src/ginfo.c: Add GIUnionInfo and functions to access it. * src/gidlnode.c: Handle GIdlNodeUnion nodes. * src/gidlparser.c (start_union): Parse elements. * src/gidlnode.h: Add a GIdlNodeUnion. * gidl.dtd: Add a element. * src/gmetadata.c (g_metadata_check_sanity): Check union_blob_size. * src/gmetadata.h: Add union_blob_size to Header, add a UnionBlob. * metadata-format.txt: Add a UnionBlob. --- girepository/src/generate.c | 174 ++++++++++++++++++++++++++++-------- 1 file changed, 135 insertions(+), 39 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 0f87a973cf..c3cb30c9a5 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -146,9 +146,16 @@ write_type_info (const gchar *namespace, } } +static void +write_constant_value (const gchar *namespace, + GITypeInfo *info, + GArgument *argument, + FILE *file); + static void write_field_info (const gchar *namespace, GIFieldInfo *info, + GIConstantInfo *branch, FILE *file) { const gchar *name; @@ -156,6 +163,7 @@ write_field_info (const gchar *namespace, gint size; gint offset; GITypeInfo *type; + GArgument value; name = g_base_info_get_name ((GIBaseInfo *)info); flags = g_field_info_get_flags (info); @@ -177,7 +185,18 @@ write_field_info (const gchar *namespace, write_type_info (namespace, type, file); g_base_info_unref ((GIBaseInfo *)type); - g_fprintf (file, "\" />\n"); + g_fprintf (file, "\""); + + if (branch) + { + g_fprintf (file, " branch=\""); + type = g_constant_info_get_type (branch); + g_constant_info_get_value (branch, &value); + write_constant_value (namespace, type, &value, file); + g_fprintf (file, "\""); + } + + g_fprintf (file," />\n"); } static void @@ -383,7 +402,7 @@ write_struct_info (const gchar *namespace, for (i = 0; i < g_struct_info_get_n_fields (info); i++) { GIFieldInfo *field = g_struct_info_get_field (info, i); - write_field_info (namespace, field, file); + write_field_info (namespace, field, NULL, file); g_base_info_unref ((GIBaseInfo *)field); } @@ -423,77 +442,86 @@ write_value_info (const gchar *namespace, } static void -write_constant_info (const gchar *namespace, - GIConstantInfo *info, - FILE *file, - gint indent) +write_constant_value (const gchar *namespace, + GITypeInfo *type, + GArgument *value, + FILE *file) { - GITypeInfo *type; - const gchar *name; - gboolean deprecated; - GArgument value; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - g_fprintf (file, "%*sv_boolean); break; case GI_TYPE_TAG_INT8: - g_fprintf (file, "%d", value.v_int8); + g_fprintf (file, "%d", value->v_int8); break; case GI_TYPE_TAG_UINT8: - g_fprintf (file, "%d", value.v_uint8); + g_fprintf (file, "%d", value->v_uint8); break; case GI_TYPE_TAG_INT16: - g_fprintf (file, "%" G_GINT16_FORMAT, value.v_int16); + g_fprintf (file, "%" G_GINT16_FORMAT, value->v_int16); break; case GI_TYPE_TAG_UINT16: - g_fprintf (file, "%" G_GUINT16_FORMAT, value.v_uint16); + g_fprintf (file, "%" G_GUINT16_FORMAT, value->v_uint16); break; case GI_TYPE_TAG_INT32: - g_fprintf (file, "%" G_GINT32_FORMAT, value.v_int32); + g_fprintf (file, "%" G_GINT32_FORMAT, value->v_int32); break; case GI_TYPE_TAG_UINT32: - g_fprintf (file, "%" G_GUINT32_FORMAT, value.v_uint32); + g_fprintf (file, "%" G_GUINT32_FORMAT, value->v_uint32); break; case GI_TYPE_TAG_INT64: - g_fprintf (file, "%" G_GINT64_FORMAT, value.v_int64); + g_fprintf (file, "%" G_GINT64_FORMAT, value->v_int64); break; case GI_TYPE_TAG_UINT64: - g_fprintf (file, "%" G_GUINT64_FORMAT, value.v_uint64); + g_fprintf (file, "%" G_GUINT64_FORMAT, value->v_uint64); break; case GI_TYPE_TAG_FLOAT: - g_fprintf (file, "%f", value.v_float); + g_fprintf (file, "%f", value->v_float); break; case GI_TYPE_TAG_DOUBLE: - g_fprintf (file, "%Lf", value.v_double); + g_fprintf (file, "%Lf", value->v_double); break; case GI_TYPE_TAG_STRING: - g_fprintf (file, "%s", value.v_string); + g_fprintf (file, "%s", value->v_string); break; case GI_TYPE_TAG_INT: - g_fprintf (file, "%d", value.v_int); + g_fprintf (file, "%d", value->v_int); break; case GI_TYPE_TAG_UINT: - g_fprintf (file, "%d", value.v_uint); + g_fprintf (file, "%d", value->v_uint); break; case GI_TYPE_TAG_LONG: - g_fprintf (file, "%ld", value.v_long); + g_fprintf (file, "%ld", value->v_long); break; case GI_TYPE_TAG_ULONG: - g_fprintf (file, "%ld", value.v_ulong); + g_fprintf (file, "%ld", value->v_ulong); break; } +} + +static void +write_constant_info (const gchar *namespace, + GIConstantInfo *info, + FILE *file, + gint indent) +{ + GITypeInfo *type; + const gchar *name; + gboolean deprecated; + GArgument value; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + g_fprintf (file, "%*s\n"); g_base_info_unref ((GIBaseInfo *)type); @@ -714,7 +742,7 @@ write_object_info (const gchar *namespace, for (i = 0; i < g_object_info_get_n_fields (info); i++) { GIFieldInfo *field = g_object_info_get_field (info, i); - write_field_info (namespace, field, file); + write_field_info (namespace, field, NULL, file); g_base_info_unref ((GIBaseInfo *)field); } @@ -855,6 +883,67 @@ write_error_domain_info (const gchar *namespace, g_base_info_unref (enum_); } +static void +write_union_info (const gchar *namespace, + GIUnionInfo *info, + FILE *file) +{ + const gchar *name; + const gchar *type_name; + const gchar *type_init; + gboolean deprecated; + gint i; + + name = g_base_info_get_name ((GIBaseInfo *)info); + deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + + g_fprintf (file, " \n"); + + if (g_union_info_is_discriminated (info)) + { + gint offset; + GITypeInfo *type; + + offset = g_union_info_get_discriminator_offset (info); + type = g_union_info_get_discriminator_type (info); + + g_fprintf (file, " \n"); + g_base_info_unref ((GIBaseInfo *)type); + } + + for (i = 0; i < g_union_info_get_n_fields (info); i++) + { + GIFieldInfo *field = g_union_info_get_field (info, i); + GIConstantInfo *constant = g_union_info_get_discriminator (info, i); + write_field_info (namespace, field, constant, file); + g_base_info_unref ((GIBaseInfo *)field); + if (constant) + g_base_info_unref ((GIBaseInfo *)constant); + } + + for (i = 0; i < g_union_info_get_n_methods (info); i++) + { + GIFunctionInfo *function = g_union_info_get_method (info, i); + write_function_info (namespace, function, file, 6); + g_base_info_unref ((GIBaseInfo *)function); + } + + g_fprintf (file, " \n"); +} + static void write_repository (GIRepository *repository, gboolean needs_prefix) @@ -915,7 +1004,11 @@ write_repository (GIRepository *repository, case GI_INFO_TYPE_BOXED: write_struct_info (ns, (GIStructInfo *)info, file); break; - + + case GI_INFO_TYPE_UNION: + write_union_info (ns, (GIUnionInfo *)info, file); + break; + case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: write_enum_info (ns, (GIEnumInfo *)info, file); @@ -936,6 +1029,9 @@ write_repository (GIRepository *repository, case GI_INFO_TYPE_ERROR_DOMAIN: write_error_domain_info (ns, (GIErrorDomainInfo *)info, file); break; + + default: + g_error ("unknown info type %d\n", g_base_info_get_type (info)); } g_base_info_unref (info); -- GitLab From 45405a6143719d1fa405e3d8474fd5da8dfc95d5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 19 May 2005 19:05:05 +0000 Subject: [PATCH 08/99] Add gdk-pixbuf.gidl as an example, and fix the code to handle it. --- girepository/src/generate.c | 73 ++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index c3cb30c9a5..121a61c887 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -106,43 +106,66 @@ write_type_info (const gchar *namespace, else if (tag == 22) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GList<"); - write_type_info (namespace, type, file); - g_fprintf (file, ">"); - g_base_info_unref ((GIBaseInfo *)type); + g_fprintf (file, "GList"); + if (type) + { + g_fprintf (file, "<"); + write_type_info (namespace, type, file); + g_fprintf (file, ">"); + g_base_info_unref ((GIBaseInfo *)type); + } + g_fprintf (file, "*"); } else if (tag == 23) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GSList<"); - write_type_info (namespace, type, file); - g_fprintf (file, ">"); - g_base_info_unref ((GIBaseInfo *)type); + g_fprintf (file, "GSList"); + if (type) + { + g_fprintf (file, "<"); + write_type_info (namespace, type, file); + g_fprintf (file, ">"); + g_base_info_unref ((GIBaseInfo *)type); + } + g_fprintf (file, "*"); } else if (tag == 24) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GHashTable<"); - write_type_info (namespace, type, file); - g_base_info_unref ((GIBaseInfo *)type); - type = g_type_info_get_param_type (info, 1); - g_fprintf (file, ","); - write_type_info (namespace, type, file); - g_fprintf (file, ">"); - g_base_info_unref ((GIBaseInfo *)type); + g_fprintf (file, "GHashTable"); + if (type) + { + g_fprintf (file, "<"); + write_type_info (namespace, type, file); + g_base_info_unref ((GIBaseInfo *)type); + type = g_type_info_get_param_type (info, 1); + g_fprintf (file, ","); + write_type_info (namespace, type, file); + g_fprintf (file, ">"); + g_base_info_unref ((GIBaseInfo *)type); + } + g_fprintf (file, "*"); } else if (tag == 25) { - g_fprintf (file, "GError<"); - for (i = 0; i < g_type_info_get_n_error_domains (info); i++) + gint n; + + g_fprintf (file, "GError"); + n = g_type_info_get_n_error_domains (info); + if (n > 0) { - GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); - if (i > 0) - g_fprintf (file, ","); - write_type_name (namespace, (GIBaseInfo *)ed, file); - g_base_info_unref ((GIBaseInfo *)ed); + g_fprintf (file, "<"); + for (i = 0; i < n; i++) + { + GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); + if (i > 0) + g_fprintf (file, ","); + write_type_name (namespace, (GIBaseInfo *)ed, file); + g_base_info_unref ((GIBaseInfo *)ed); + } + g_fprintf (file, ">"); } - g_fprintf (file, ">"); + g_fprintf (file, "*"); } } @@ -234,7 +257,7 @@ write_callable_info (const gchar *namespace, } } if (g_callable_info_may_return_null (info)) - g_fprintf (file, "null-ok=\"1\""); + g_fprintf (file, " null-ok=\"1\""); g_fprintf (file, " />\n"); -- GitLab From 1ae704b2b74d52ea6b3173956ffdc009a321372b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 21 May 2005 00:08:27 +0000 Subject: [PATCH 09/99] Basic type cleanup --- girepository/src/generate.c | 43 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 121a61c887..dac7c65c07 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -62,20 +62,24 @@ write_type_info (const gchar *namespace, "guint32", "gint64", "guint64", + "gint", + "guint", + "glong", + "gulong", + "gssize", + "gsize", "gfloat", "gdouble", - "gchar", - "GString", - "gint", - "guint", - "glong", - "gulong" + "utf8", + "filename" }; tag = g_type_info_get_tag (info); - if (tag < 20) + if (tag < 18) g_fprintf (file, "%s%s", basic[tag], g_type_info_is_pointer (info) ? "*" : ""); + else if (tag < 20) + g_fprintf (file, "%s", basic[tag]); else if (tag == 20) { gint length; @@ -499,15 +503,6 @@ write_constant_value (const gchar *namespace, case GI_TYPE_TAG_UINT64: g_fprintf (file, "%" G_GUINT64_FORMAT, value->v_uint64); break; - case GI_TYPE_TAG_FLOAT: - g_fprintf (file, "%f", value->v_float); - break; - case GI_TYPE_TAG_DOUBLE: - g_fprintf (file, "%Lf", value->v_double); - break; - case GI_TYPE_TAG_STRING: - g_fprintf (file, "%s", value->v_string); - break; case GI_TYPE_TAG_INT: g_fprintf (file, "%d", value->v_int); break; @@ -520,6 +515,22 @@ write_constant_value (const gchar *namespace, case GI_TYPE_TAG_ULONG: g_fprintf (file, "%ld", value->v_ulong); break; + case GI_TYPE_TAG_SSIZE: + g_fprintf (file, "%z", value->v_ssize); + break; + case GI_TYPE_TAG_SIZE: + g_fprintf (file, "%z", value->v_size); + break; + case GI_TYPE_TAG_FLOAT: + g_fprintf (file, "%f", value->v_float); + break; + case GI_TYPE_TAG_DOUBLE: + g_fprintf (file, "%Lf", value->v_double); + break; + case GI_TYPE_TAG_UTF8: + case GI_TYPE_TAG_FILENAME: + g_fprintf (file, "%s", value->v_string); + break; } } -- GitLab From b1cf4d87c9bc13d51969e52abf900a77b769ce12 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 22 May 2005 04:22:51 +0000 Subject: [PATCH 10/99] Add struct offsets to field and vfunc elements. 2005-05-22 Matthias Clasen * tests/*: Add struct offsets to field and vfunc elements. * src/generate.c (write_vfunc_info): Write offset information for vfuncs. * src/gidlnode.c (g_idl_node_build_metadata): Write the struct offsets into the metadata. * src/gidlparser.c: Parse the offset attributes of field and vfunc elements. * src/gidlnode.h: Add offset members to field and vfunc nodes. --- girepository/src/generate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index dac7c65c07..9b74180228 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -657,10 +657,12 @@ write_vfunc_info (const gchar *namespace, GIVFuncInfoFlags flags; const gchar *name; gboolean deprecated; + gint offset; name = g_base_info_get_name ((GIBaseInfo *)info); flags = g_vfunc_info_get_flags (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + offset = g_vfunc_info_get_offset (info); g_fprintf (file, " \n"); write_callable_info (namespace, (GICallableInfo*)info, file, 6); -- GitLab From 94d45e70a05e0ed93a0a430e73a0625dc8d928fc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 24 May 2005 20:45:26 +0000 Subject: [PATCH 11/99] Fix a segfault --- girepository/src/generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 9b74180228..56d7ecd954 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -752,8 +752,8 @@ write_object_info (const gchar *namespace, g_fprintf (file, " parent=\""); write_type_name (namespace, (GIBaseInfo *)pnode, file); g_fprintf (file, "\"" ); + g_base_info_unref ((GIBaseInfo *)pnode); } - g_base_info_unref ((GIBaseInfo *)pnode); g_fprintf (file, " type-name=\"%s\" get-type=\"%s\"", type_name, type_init); -- GitLab From 00a6f8ada0431a73eea4316dcdd3991ee4d94b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20Sch=C3=B6nfeld?= Date: Tue, 3 Oct 2006 14:38:07 +0000 Subject: [PATCH 12/99] Hush compiler warnings about return values, signedness mismatches, unused * src/compiler.c, src/generate.c, src/gidlnode.c, src/gidlparser.c, src/ginfo.c, src/girepository.c, tests/invoke/invoke.c, test/invoke/testfns.c: Hush compiler warnings about return values, signedness mismatches, unused variables, and unhandles enum values in switch statements. * tests/invoke/Makefile.am: Don't install the invoke test program. Add -I ../../src to the cflags used for the test functions files. --- girepository/src/generate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 56d7ecd954..2ce33cdc6b 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -20,12 +20,14 @@ #include #include +#include #include #include #include #include "girepository.h" +#include "gmetadata.h" gboolean raw = FALSE; gchar **input = NULL; @@ -380,7 +382,6 @@ write_callback_info (const gchar *namespace, FILE *file, gint indent) { - GIFunctionInfoFlags flags; const gchar *name; gboolean deprecated; @@ -452,7 +453,6 @@ write_value_info (const gchar *namespace, FILE *file) { const gchar *name; - const gchar *short_name; glong value; gboolean deprecated; @@ -460,7 +460,7 @@ write_value_info (const gchar *namespace, value = g_value_info_get_value (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, " v_ulong); break; case GI_TYPE_TAG_SSIZE: - g_fprintf (file, "%z", value->v_ssize); + g_fprintf (file, "%zd", value->v_ssize); break; case GI_TYPE_TAG_SIZE: - g_fprintf (file, "%z", value->v_size); + g_fprintf (file, "%zd", value->v_size); break; case GI_TYPE_TAG_FLOAT: g_fprintf (file, "%f", value->v_float); break; case GI_TYPE_TAG_DOUBLE: - g_fprintf (file, "%Lf", value->v_double); + g_fprintf (file, "%f", value->v_double); break; case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: g_fprintf (file, "%s", value->v_string); break; + default: + g_assert_not_reached (); } } -- GitLab From 2b0304b86591fed6a061d8f42d50bda25a1130b1 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 6 Dec 2007 00:16:15 +0000 Subject: [PATCH 13/99] reviewed by: Johan Dahlin 2007-12-06 Gustavo J. A. M. Carneiro reviewed by: Johan Dahlin * configure.ac: * gobject-introspection.pc.in: * src/Makefile.am: * src/compiler.c: (format_output), (write_out_metadata), (main): * src/gen-introspect.c: (main): * src/gen-introspect.h: * src/generate.c: (write_callable_info), (write_repository), (load_metadata), (main): * src/gidlmodule.c: (g_idl_module_new), (g_idl_module_build_metadata): * src/gidlmodule.h: * src/gidlparser.c: (start_element_handler): * src/ginfo.c: (g_info_new), (g_info_from_entry), (g_base_info_get_name), (g_base_info_get_namespace), (g_base_info_is_deprecated), (g_base_info_get_annotation), (g_base_info_get_metadata), (g_function_info_get_symbol), (g_function_info_get_flags), (g_function_info_get_property), (g_function_info_get_vfunc), (signature_offset), (g_type_info_new), (g_callable_info_may_return_null), (g_callable_info_get_caller_owns), (g_callable_info_get_n_args), (g_callable_info_get_arg), (g_arg_info_get_direction), (g_arg_info_is_return_value), (g_arg_info_is_dipper), (g_arg_info_is_optional), (g_arg_info_may_be_null), (g_arg_info_get_ownership_transfer), (g_type_info_is_pointer), (g_type_info_get_tag), (g_type_info_get_param_type), (g_type_info_get_interface), (g_type_info_get_array_length), (g_type_info_is_zero_terminated), (g_type_info_get_n_error_domains), (g_type_info_get_error_domain), (g_error_domain_info_get_quark), (g_error_domain_info_get_codes), (g_value_info_get_value), (g_field_info_get_flags), (g_field_info_get_size), (g_field_info_get_offset), (g_registered_type_info_get_type_name), (g_registered_type_info_get_type_init), (g_struct_info_get_n_fields), (g_struct_info_get_field), (g_struct_info_get_n_methods), (g_struct_info_get_method), (find_method), (g_struct_info_find_method), (g_enum_info_get_n_values), (g_enum_info_get_value), (g_object_info_get_parent), (g_object_info_get_type_name), (g_object_info_get_type_init), (g_object_info_get_n_interfaces), (g_object_info_get_interface), (g_object_info_get_n_fields), (g_object_info_get_field), (g_object_info_get_n_properties), (g_object_info_get_property), (g_object_info_get_n_methods), (g_object_info_get_method), (g_object_info_find_method), (g_object_info_get_n_signals), (g_object_info_get_signal), (g_object_info_get_n_vfuncs), (g_object_info_get_vfunc), (g_object_info_get_n_constants), (g_object_info_get_constant), (g_interface_info_get_n_prerequisites), (g_interface_info_get_prerequisite), (g_interface_info_get_n_properties), (g_interface_info_get_property), (g_interface_info_get_n_methods), (g_interface_info_get_method), (g_interface_info_find_method), (g_interface_info_get_n_signals), (g_interface_info_get_signal), (g_interface_info_get_n_vfuncs), (g_interface_info_get_vfunc), (g_interface_info_get_n_constants), (g_interface_info_get_constant), (g_property_info_get_flags), (g_signal_info_get_flags), (g_signal_info_get_class_closure), (g_signal_info_true_stops_emit), (g_vfunc_info_get_flags), (g_vfunc_info_get_offset), (g_vfunc_info_get_signal), (g_constant_info_get_value), (g_union_info_get_n_fields), (g_union_info_get_field), (g_union_info_get_n_methods), (g_union_info_get_method), (g_union_info_is_discriminated), (g_union_info_get_discriminator_offset), (g_union_info_get_discriminator): * src/ginvoke.c: (g_function_info_invoke): * src/girepository.c: (g_irepository_register), (g_irepository_unregister), (g_irepository_get_default), (count_interfaces), (g_irepository_get_n_infos), (find_interface), (g_irepository_get_info), (g_irepository_find_by_name), (g_irepository_get_shared_library), (g_irepository_build_search_path), (g_irepository_register_file), (g_irepository_error_quark): * src/girepository.h: * src/gmetadata.c: (g_metadata_get_dir_entry), (g_metadata_check_sanity), (validate_header), (validate_array_type_blob), (validate_iface_type_blob), (validate_param_type_blob), (validate_error_type_blob), (validate_type_blob), (validate_arg_blob), (validate_signature_blob), (validate_function_blob), (validate_callback_blob), (validate_constant_blob), (validate_value_blob), (validate_field_blob), (validate_property_blob), (validate_signal_blob), (validate_vfunc_blob), (validate_struct_blob), (validate_enum_blob), (validate_object_blob), (validate_interface_blob), (validate_errordomain_blob), (validate_union_blob), (validate_blob), (validate_directory), (validate_annotations), (g_metadata_validate), (_g_metadata_init), (g_metadata_new_from_memory), (g_metadata_new_from_const_memory), (g_metadata_new_from_mapped_file), (g_metadata_free), (g_metadata_set_module), (g_metadata_get_namespace): * src/gmetadata.h: * tests/Makefile.am: * tests/invoke/Makefile.am: * tests/invoke/invoke-namespace-find.sh: * tests/invoke/invoke.c: (main): Add a namespace/shared library mapping. fixes #313268. svn path=/trunk/; revision=66 --- girepository/src/generate.c | 70 ++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/girepository/src/generate.c b/girepository/src/generate.c index 2ce33cdc6b..8ae6fc3556 100644 --- a/girepository/src/generate.c +++ b/girepository/src/generate.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-file-style: "gnu"; -*- */ /* GObject introspection: IDL generator * * Copyright (C) 2005 Matthias Clasen @@ -241,7 +242,6 @@ write_callable_info (const gchar *namespace, type = g_callable_info_get_return_type (info); write_type_info (namespace, type, file); - g_base_info_unref ((GIBaseInfo *)type); g_fprintf (file, "\""); @@ -262,6 +262,7 @@ write_callable_info (const gchar *namespace, g_assert_not_reached (); } } + g_base_info_unref ((GIBaseInfo *)type); if (g_callable_info_may_return_null (info)) g_fprintf (file, " null-ok=\"1\""); @@ -1023,8 +1024,14 @@ write_repository (GIRepository *repository, for (i = 0; namespaces[i]; i++) { + const gchar *shared_library; ns = namespaces[i]; - g_fprintf (file, " \n", ns); + shared_library = g_irepository_get_shared_library (repository, ns); + if (shared_library) + g_fprintf (file, " \n", + ns, shared_library); + else + g_fprintf (file, " \n", ns); for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) { @@ -1097,29 +1104,33 @@ static GOptionEntry options[] = static const guchar * load_metadata (const gchar *filename, - void **dlhandle) + GModule **dlhandle, + gsize *len) { - guchar *metadata; - void *handle; - char *error; + guchar *metadata; + gsize *metadata_size; + GModule *handle; - handle = dlopen (filename, RTLD_LAZY); - metadata = dlsym (handle, "_G_METADATA"); + handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); + if (!g_module_symbol (handle, "_G_METADATA", (gpointer *) &metadata)) + { + g_printerr ("Could not load metadata from '%s': %s\n", + filename, g_module_error ()); + return NULL; + } - error = dlerror (); + if (!g_module_symbol (handle, "_G_METADATA_SIZE", (gpointer *) &metadata_size)) + { + g_printerr ("Could not load metadata from '%s': %s\n", + filename, g_module_error ()); + return NULL; + } + *len = *metadata_size; + if (dlhandle) *dlhandle = handle; - if (error) - { - g_fprintf (stderr, - "Could not load metadata from '%s': %s\n", - filename, error); - - return NULL; - } - return metadata; } @@ -1130,6 +1141,7 @@ main (int argc, char *argv[]) GError *error = NULL; gboolean needs_prefix; gint i; + GMetadata *data; g_type_init (); @@ -1148,12 +1160,13 @@ main (int argc, char *argv[]) for (i = 0; input[i]; i++) { - void *dlhandle = NULL; + GModule *dlhandle = NULL; const guchar *metadata; + gsize len; if (raw) { - if (!g_file_get_contents (input[i], (gchar **)&metadata, NULL, &error)) + if (!g_file_get_contents (input[i], (gchar **)&metadata, &len, &error)) { g_fprintf (stderr, "failed to read '%s': %s\n", input[i], error->message); @@ -1163,7 +1176,7 @@ main (int argc, char *argv[]) } else { - metadata = load_metadata (input[i], &dlhandle); + metadata = load_metadata (input[i], &dlhandle, &len); if (!metadata) { g_fprintf (stderr, "failed to load metadata from '%s'\n", @@ -1177,13 +1190,22 @@ main (int argc, char *argv[]) else needs_prefix = FALSE; - g_irepository_register (g_irepository_get_default (), metadata); + data = g_metadata_new_from_const_memory (metadata, len); + { + GError *error = NULL; + if (!g_metadata_validate (data, &error)) { + g_printerr ("metadata not valid: %s\n", error->message); + g_clear_error (&error); + } + } + g_irepository_register (g_irepository_get_default (), data); write_repository (g_irepository_get_default (), needs_prefix); - g_irepository_unregister (g_irepository_get_default (), metadata); + g_irepository_unregister (g_irepository_get_default (), + g_metadata_get_namespace (data)); if (dlhandle) { - dlclose (dlhandle); + g_module_close (dlhandle); dlhandle = NULL; } -- GitLab From a7d0962d46ca0d4178743d92ceacf73358020624 Mon Sep 17 00:00:00 2001 From: Rob Taylor Date: Fri, 8 Feb 2008 15:31:03 +0000 Subject: [PATCH 14/99] Added: Added: Renamed to tools/Makefile.am: Renamed to tools/compiler.c: 2008-02-08 Rob Taylor * Makefile.am: * configure.ac: * gidl/Makefile.am: Added: * girepository/Makefile.am: Added: * src/Makefile.am: Renamed to tools/Makefile.am: * src/compiler.c: Renamed to tools/compiler.c: * src/g-idl-offsets.pl: Renamed to tools/g-idl-offsets.pl: * src/generate.c: Renamed to tools/generate.c: * src/gidlmodule.c: Renamed to tools/gidlmodule.c: * src/gidlmodule.h: Renamed to tools/gidlmodule.h: * src/gidlnode.c: Renamed to tools/gidlnode.c: * src/gidlnode.h: Renamed to tools/gidlnode.h: * src/gidlparser.c: Renamed to tools/gidlparser.c: * src/gidlparser.h: Renamed to tools/gidlparser.h: * src/gidlwriter.c: Renamed to tools/gidlwriter.c: * src/gidlwriter.h: Renamed to tools/gidlwriter.h: * src/ginfo.c: Renamed to girepository/ginfo.c: * src/ginvoke.c: Renamed to girepository/ginvoke.c: * src/girepository.c: Renamed to girepository/girepository.c: * src/girepository.h: Renamed to girepository/girepository.h: * src/gmetadata.c: Renamed to girepository/gmetadata.c: * src/gmetadata.h: Renamed to girepository/gmetadata.h: * src/scanner.c: Renamed to tools/scanner.c: * src/scanner.h: Renamed to tools/scanner.h: * src/scannerlexer.l: Renamed to tools/scannerlexer.l: * src/scannerparser.y: Renamed to tools/scannerparser.y: * tests/invoke/Makefile.am: Split src/ into girepository/ and tools/ * Makefile.am: * configure.ac: * girepository/Makefile.am: * tests/Makefile.am: * tests/invoke/Makefile.am: * tests/parser/Makefile.am: * tests/roundtrips.sh: * tools/Makefile.am: Make distcheck work. svn path=/trunk/; revision=104 --- girepository/{src => tools}/generate.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename girepository/{src => tools}/generate.c (100%) diff --git a/girepository/src/generate.c b/girepository/tools/generate.c similarity index 100% rename from girepository/src/generate.c rename to girepository/tools/generate.c -- GitLab From 9e6472853a72b857f47d94c344171b9a734c2d39 Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Mon, 10 Mar 2008 17:44:06 +0000 Subject: [PATCH 15/99] girepository/ginvoke.c girepository/girepository.h 2008-02-21 Mark Doffman * girepository/ginvoke.c * girepository/girepository.h * girepository/gmetadata.c * girepository/gmetadata.h * tools/generate.c * tools/gidlparser.c Modify TYPE_TAG_INTERFACE to TYPE_TAG_SYMBOL to avoid confusion with the interface blob. * tools/generate.c * tools/gidlparser.c Remove magic numbers and replace with type-tag enumeration symbols. * girepository/gmetadata.c Add validate declaration. WARNING: This commit does not compile. It is a partial change. svn path=/trunk/; revision=129 --- girepository/tools/generate.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 8ae6fc3556..0a3c3a5a39 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -79,11 +79,11 @@ write_type_info (const gchar *namespace, tag = g_type_info_get_tag (info); - if (tag < 18) + if (tag < TYPE_TAG_UTF8) g_fprintf (file, "%s%s", basic[tag], g_type_info_is_pointer (info) ? "*" : ""); - else if (tag < 20) + else if (tag <= TYPE_TAG_FILENAME) g_fprintf (file, "%s", basic[tag]); - else if (tag == 20) + else if (tag == TYPE_TAG_ARRAY) { gint length; @@ -102,7 +102,7 @@ write_type_info (const gchar *namespace, g_fprintf (file, "]"); g_base_info_unref ((GIBaseInfo *)type); } - else if (tag == 21) + else if (tag == TYPE_TAG_SYMBOL) { GIBaseInfo *iface = g_type_info_get_interface (info); write_type_name (namespace, iface, file); @@ -110,7 +110,7 @@ write_type_info (const gchar *namespace, g_fprintf (file, "*"); g_base_info_unref (iface); } - else if (tag == 22) + else if (tag == TYPE_TAG_LIST) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GList"); @@ -123,7 +123,7 @@ write_type_info (const gchar *namespace, } g_fprintf (file, "*"); } - else if (tag == 23) + else if (tag == TYPE_TAG_SLIST) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GSList"); @@ -136,7 +136,7 @@ write_type_info (const gchar *namespace, } g_fprintf (file, "*"); } - else if (tag == 24) + else if (tag == TYPE_TAG_HASH) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GHashTable"); @@ -153,7 +153,7 @@ write_type_info (const gchar *namespace, } g_fprintf (file, "*"); } - else if (tag == 25) + else if (tag == TYPE_TAG_ERROR) { gint n; @@ -532,8 +532,11 @@ write_constant_value (const gchar *namespace, case GI_TYPE_TAG_FILENAME: g_fprintf (file, "%s", value->v_string); break; + case GI_TYPE_TAG_SYMBOL: + g_fprintf (file, "%s", value->v_string); + break; default: - g_assert_not_reached (); + g_warning ("Could not get type tag for constant"); } } -- GitLab From e56744c9073bc9cf1127bad90b01a25236893e8f Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Mon, 10 Mar 2008 17:47:20 +0000 Subject: [PATCH 16/99] girepository/ginfo.c girepository/girepository.h tools/generate.c 2008-02-21 Mark Doffman * girepository/ginfo.c * girepository/girepository.h * tools/generate.c Add a function to check if an enum is registered or not. Previously anything testing this relied on the g-type string offset having a value of 0. * girepository/gmetadata.c * girepository/gmetadata.h * tools/generate.c Remove unneccesary or erroneous checks. There were two metadata validation checks which made sure that the blob sizes were the same as some magic numbers compiled into the code. This is wrong as it breaks any forwards compatibility that may be possible. Checks were also present that made sure that unregistered type blobs had a value of 0 in the g-type offset field. This is unneccessary. If a type blob is unregistered then any value in its g-type field is simply invalid. WARNING: This commit does not compile. It is a partial change. svn path=/trunk/; revision=132 --- girepository/tools/generate.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 0a3c3a5a39..7c4569759b 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -574,16 +574,22 @@ write_enum_info (const gchar *namespace, FILE *file) { const gchar *name; - const gchar *type_name; - const gchar *type_init; + const gchar *type_name = NULL; + const gchar *type_init = NULL; gboolean deprecated; gint i; name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + /* Make sure this is a registered enum before filling out the + * GType information + */ + if (g_enum_info_is_registered ((GIEnumInfo *)info)) + { + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + } if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) g_fprintf (file, " Date: Mon, 10 Mar 2008 17:47:26 +0000 Subject: [PATCH 17/99] girepository/ginfo.c tools/generate.c 2008-02-21 Mark Doffman * girepository/ginfo.c * tools/generate.c Change the way that external references with no namespace are dealt with. External references with no namespace are placed into the XML as-if they are a local reference. This is temporary, but helps with roundtrip tests. WARNING: This commit does not compile. It is a partial change. svn path=/trunk/; revision=134 --- girepository/tools/generate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 7c4569759b..0f6db6b0fa 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -39,7 +39,8 @@ write_type_name (const gchar *namespace, GIBaseInfo *info, FILE *file) { - if (strcmp (namespace, g_base_info_get_namespace (info)) != 0) + if (g_base_info_get_namespace (info) != 0 && + strcmp (namespace, g_base_info_get_namespace (info)) != 0) g_fprintf (file, "%s.", g_base_info_get_namespace (info)); g_fprintf (file, "%s", g_base_info_get_name (info)); -- GitLab From cff3cc7ad963539cc42819e1dbac3219f346f5d4 Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Mon, 10 Mar 2008 17:47:29 +0000 Subject: [PATCH 18/99] tools/quote-file.sh tools/compiler.c tools/generate.c 2008-02-22 Mark Doffman * tools/quote-file.sh * tools/compiler.c * tools/generate.c Move to using the 'C' struct compiler code. WARNING: This commit does not compile. It is a partial change. svn path=/trunk/; revision=135 --- girepository/tools/generate.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 0f6db6b0fa..adb2e24b3d 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1117,12 +1117,17 @@ load_metadata (const gchar *filename, GModule **dlhandle, gsize *len) { - guchar *metadata; + gpointer metadata; gsize *metadata_size; GModule *handle; - handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); - if (!g_module_symbol (handle, "_G_METADATA", (gpointer *) &metadata)) + handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); + if (!handle) + { + g_printerr("Could not load module '%s'\n", filename); + return NULL; + } + if (!g_module_symbol (handle, "_G_METADATA", &metadata)) { g_printerr ("Could not load metadata from '%s': %s\n", filename, g_module_error ()); @@ -1141,7 +1146,7 @@ load_metadata (const gchar *filename, if (dlhandle) *dlhandle = handle; - return metadata; + return *((const guchar **) metadata); } int @@ -1169,7 +1174,7 @@ main (int argc, char *argv[]) for (i = 0; input[i]; i++) { GModule *dlhandle = NULL; - const guchar *metadata; + const guchar *metadata = NULL; gsize len; if (raw) -- GitLab From c7c1c96c2b482a95b26c455179354ed402092b66 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Tue, 11 Mar 2008 14:25:08 +0000 Subject: [PATCH 19/99] Remove most global variables 2008-03-11 Johan Dahlin * tools/compiler.c: * tools/generate.c: Remove most global variables svn path=/trunk/; revision=153 --- girepository/tools/generate.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index adb2e24b3d..f55731ee37 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -30,9 +30,8 @@ #include "girepository.h" #include "gmetadata.h" -gboolean raw = FALSE; -gchar **input = NULL; -gchar *output = NULL; +/* FIXME: Avoid global */ +static gchar *output = NULL; static void write_type_name (const gchar *namespace, @@ -1104,14 +1103,6 @@ write_repository (GIRepository *repository, g_strfreev (namespaces); } -static GOptionEntry options[] = -{ - { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "handle raw metadata", NULL }, - { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, - { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, - { NULL, } -}; - static const guchar * load_metadata (const gchar *filename, GModule **dlhandle, @@ -1152,11 +1143,20 @@ load_metadata (const gchar *filename, int main (int argc, char *argv[]) { + gboolean raw = FALSE; + gchar **input = NULL; GOptionContext *context; GError *error = NULL; gboolean needs_prefix; gint i; GMetadata *data; + GOptionEntry options[] = + { + { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "handle raw metadata", NULL }, + { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, + { NULL, } + }; g_type_init (); -- GitLab From 64d32c97b58fa16af34b83a29ed199c546e8d817 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Tue, 22 Apr 2008 22:48:16 +0000 Subject: [PATCH 20/99] Revert revisions 157,149-148,136-129 and 120. Move back to using 2008-04-22 Johan Dahlin * girepository/ginfo.c (g_info_from_entry), (g_type_info_new), (g_type_info_is_pointer), (g_type_info_get_tag), (g_type_info_get_param_type), (g_type_info_get_interface), (g_type_info_get_array_length), (g_type_info_is_zero_terminated), (g_type_info_get_n_error_domains), (g_type_info_get_error_domain), (g_error_domain_info_get_codes), (g_enum_info_get_value), (g_object_info_get_interface), (g_object_info_get_field), (g_interface_info_get_prerequisite), (g_signal_info_get_class_closure), (g_constant_info_get_value): * girepository/ginvoke.c (get_ffi_type): * girepository/girepository.h: * girepository/gmetadata.c (g_metadata_get_dir_entry), (g_metadata_check_sanity), (validate_header), (validate_array_type_blob), (validate_iface_type_blob), (validate_param_type_blob), (validate_error_type_blob), (validate_type_blob), (validate_constant_blob), (validate_struct_blob), (validate_enum_blob): * girepository/gmetadata.h: * tests/Makefile.am: * tests/invoke/Makefile.am: * tests/invoke/invoke.c (main): * tests/roundtrips.sh: * tools/Makefile.am: * tools/compiler.c (format_output), (write_out_metadata), (main): * tools/generate.c (write_type_name), (write_type_info), (write_constant_value), (write_enum_info), (load_metadata), (main): * tools/gidlcompilercontext.c: * tools/gidlcompilercontext.h: * tools/gidlcompilerentrynode.c: * tools/gidlcompilerentrynode.h: * tools/gidlcompilertypenode.c: * tools/gidlcompilertypenode.h: * tools/gidlmodule.c (g_idl_module_build_metadata): * tools/gidlmodule.h: * tools/gidlnode.c (init_stats), (dump_stats), (g_idl_node_get_size), (g_idl_node_get_full_size), (g_idl_node_cmp), (g_idl_node_can_have_member), (g_idl_node_add_member), (g_idl_node_param_direction_string), (parse_int_value), (parse_uint_value), (parse_float_value), (parse_boolean_value), (find_entry_node), (find_entry), (serialize_type), (g_idl_node_build_metadata), (write_string): * tools/gidlnode.h: * tools/gidlparser.c (parse_type_internal): * tools/quote-file.sh: Revert revisions 157,149-148,136-129 and 120. Move back to using g-idl-generate to generate the metadata and avoids dependency on a c compiler. svn path=/trunk/; revision=214 --- girepository/tools/generate.c | 55 +++++++++++++---------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index f55731ee37..8c5c3b3b12 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -38,8 +38,7 @@ write_type_name (const gchar *namespace, GIBaseInfo *info, FILE *file) { - if (g_base_info_get_namespace (info) != 0 && - strcmp (namespace, g_base_info_get_namespace (info)) != 0) + if (strcmp (namespace, g_base_info_get_namespace (info)) != 0) g_fprintf (file, "%s.", g_base_info_get_namespace (info)); g_fprintf (file, "%s", g_base_info_get_name (info)); @@ -79,11 +78,11 @@ write_type_info (const gchar *namespace, tag = g_type_info_get_tag (info); - if (tag < TYPE_TAG_UTF8) + if (tag < 18) g_fprintf (file, "%s%s", basic[tag], g_type_info_is_pointer (info) ? "*" : ""); - else if (tag <= TYPE_TAG_FILENAME) + else if (tag < 20) g_fprintf (file, "%s", basic[tag]); - else if (tag == TYPE_TAG_ARRAY) + else if (tag == 20) { gint length; @@ -102,7 +101,7 @@ write_type_info (const gchar *namespace, g_fprintf (file, "]"); g_base_info_unref ((GIBaseInfo *)type); } - else if (tag == TYPE_TAG_SYMBOL) + else if (tag == 21) { GIBaseInfo *iface = g_type_info_get_interface (info); write_type_name (namespace, iface, file); @@ -110,7 +109,7 @@ write_type_info (const gchar *namespace, g_fprintf (file, "*"); g_base_info_unref (iface); } - else if (tag == TYPE_TAG_LIST) + else if (tag == 22) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GList"); @@ -123,7 +122,7 @@ write_type_info (const gchar *namespace, } g_fprintf (file, "*"); } - else if (tag == TYPE_TAG_SLIST) + else if (tag == 23) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GSList"); @@ -136,7 +135,7 @@ write_type_info (const gchar *namespace, } g_fprintf (file, "*"); } - else if (tag == TYPE_TAG_HASH) + else if (tag == 24) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GHashTable"); @@ -153,7 +152,7 @@ write_type_info (const gchar *namespace, } g_fprintf (file, "*"); } - else if (tag == TYPE_TAG_ERROR) + else if (tag == 25) { gint n; @@ -532,11 +531,8 @@ write_constant_value (const gchar *namespace, case GI_TYPE_TAG_FILENAME: g_fprintf (file, "%s", value->v_string); break; - case GI_TYPE_TAG_SYMBOL: - g_fprintf (file, "%s", value->v_string); - break; default: - g_warning ("Could not get type tag for constant"); + g_assert_not_reached (); } } @@ -574,22 +570,16 @@ write_enum_info (const gchar *namespace, FILE *file) { const gchar *name; - const gchar *type_name = NULL; - const gchar *type_init = NULL; + const gchar *type_name; + const gchar *type_init; gboolean deprecated; gint i; name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - /* Make sure this is a registered enum before filling out the - * GType information - */ - if (g_enum_info_is_registered ((GIEnumInfo *)info)) - { - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - } + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) g_fprintf (file, " Date: Sun, 8 Jun 2008 14:37:30 +0000 Subject: [PATCH 21/99] tools/gidlnode.c 2008-06-08 Philip Van Hoof * girepository/girepository.c: * girepository/gtypelib.c: * girepository/ginfo.c: * girepository/ginvoke.c: * girepository/girepository.h: * girepository/gtypelib.h: * girepository/gmetadata.c: * girepository/Makefile.am: * girepository/gmetadata.h: * tools/compiler.c: * tools/gidlmodule.c: * tools/gidlnode.c * tools/generate.c: * tools/gidlmodule.h: * tools/gidlparser.c: Renamed GMetadata to GTypelib svn path=/trunk/; revision=288 --- girepository/tools/generate.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 8c5c3b3b12..3e057ef155 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -28,7 +28,7 @@ #include #include "girepository.h" -#include "gmetadata.h" +#include "gtypelib.h" /* FIXME: Avoid global */ static gchar *output = NULL; @@ -1103,14 +1103,14 @@ load_metadata (const gchar *filename, GModule *handle; handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); - if (!g_module_symbol (handle, "_G_METADATA", (gpointer *) &metadata)) + if (!g_module_symbol (handle, "_G_TYPELIB", (gpointer *) &metadata)) { g_printerr ("Could not load metadata from '%s': %s\n", filename, g_module_error ()); return NULL; } - if (!g_module_symbol (handle, "_G_METADATA_SIZE", (gpointer *) &metadata_size)) + if (!g_module_symbol (handle, "_G_TYPELIB_SIZE", (gpointer *) &metadata_size)) { g_printerr ("Could not load metadata from '%s': %s\n", filename, g_module_error ()); @@ -1134,7 +1134,7 @@ main (int argc, char *argv[]) GError *error = NULL; gboolean needs_prefix; gint i; - GMetadata *data; + GTypelib *data; GOptionEntry options[] = { { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "handle raw metadata", NULL }, @@ -1145,7 +1145,7 @@ main (int argc, char *argv[]) g_type_init (); - g_metadata_check_sanity (); + g_typelib_check_sanity (); context = g_option_context_new (""); g_option_context_add_main_entries (context, options, NULL); @@ -1190,10 +1190,10 @@ main (int argc, char *argv[]) else needs_prefix = FALSE; - data = g_metadata_new_from_const_memory (metadata, len); + data = g_typelib_new_from_const_memory (metadata, len); { GError *error = NULL; - if (!g_metadata_validate (data, &error)) { + if (!g_typelib_validate (data, &error)) { g_printerr ("metadata not valid: %s\n", error->message); g_clear_error (&error); } @@ -1201,7 +1201,7 @@ main (int argc, char *argv[]) g_irepository_register (g_irepository_get_default (), data); write_repository (g_irepository_get_default (), needs_prefix); g_irepository_unregister (g_irepository_get_default (), - g_metadata_get_namespace (data)); + g_typelib_get_namespace (data)); if (dlhandle) { -- GitLab From dcd26fddc7d06854f9384f01e3976c3fed495552 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 8 Aug 2008 19:09:17 +0000 Subject: [PATCH 22/99] Merge in the gir-compiler branch. Thanks to Philip and Colin for their 2008-08-08 Johan Dahlin * girepository/gtypelib.c (validate_header): * girepository/gtypelib.h: * giscanner/ast.py: * giscanner/girwriter.py: * giscanner/sourcescanner.c (gi_source_symbol_ref), (gi_source_symbol_unref): * tests/array.test: * tests/boxed.test: * tests/constant.test: * tests/enum.test: * tests/errors.test: * tests/function.test: * tests/gobject.test: * tests/interface.test: * tests/invoke/Makefile.am: * tests/invoke/testfns.xml: * tests/object.test: * tests/parser/Makefile.am: * tests/roundtrips.sh: * tests/struct.test: * tests/types.test: * tests/union.test: * tests/xref1.test: * tests/xref2.test: * tools/Makefile.am: * tools/compiler.c (main): * tools/generate.c (write_callable_info), (write_function_info), (write_repository): * tools/gidlmodule.c: * tools/gidlmodule.h: * tools/gidlnode.c: * tools/gidlnode.h: * tools/gidlparser.c: * tools/gidlparser.h: * tools/gidlwriter.c: * tools/gidlwriter.h: * tools/scanner.c (create_node_from_gtype), (create_node_from_ctype), (g_igenerator_process_properties), (g_igenerator_process_signals), (g_igenerator_create_object), (g_igenerator_create_interface), (g_igenerator_create_boxed), (g_igenerator_create_enum), (g_igenerator_create_flags), (g_igenerator_process_function_symbol), (g_igenerator_process_unregistered_struct_typedef), (g_igenerator_process_struct_typedef), (g_igenerator_process_union_typedef), (g_igenerator_process_enum_typedef), (g_igenerator_process_function_typedef), (g_igenerator_process_constant), (g_igenerator_process_symbols), (g_igenerator_add_module), (g_igenerator_add_include_idl): Merge in the gir-compiler branch. Thanks to Philip and Colin for their help. svn path=/trunk/; revision=325 --- girepository/tools/generate.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 3e057ef155..70085c93ec 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -237,7 +237,7 @@ write_callable_info (const gchar *namespace, GITypeInfo *type; gint i; - g_fprintf (file, "%*s \n"); - g_fprintf (file, "\n"); + g_fprintf (file, "\n"); for (i = 0; namespaces[i]; i++) { @@ -1085,7 +1088,7 @@ write_repository (GIRepository *repository, g_fprintf (file, " \n"); } - g_fprintf (file, "\n"); + g_fprintf (file, "\n"); if (output != NULL) fclose (file); -- GitLab From c2bbd6ecbab16f49dd3556987fed95a14f80c068 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Sat, 9 Aug 2008 12:55:32 +0000 Subject: [PATCH 23/99] Rename metadata to typelib in variable names, comments and apis. 2008-08-09 Johan Dahlin * *.[ch]: Rename metadata to typelib in variable names, comments and apis. svn path=/trunk/; revision=339 --- girepository/tools/generate.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 70085c93ec..f3acc9ce7b 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1097,35 +1097,35 @@ write_repository (GIRepository *repository, } static const guchar * -load_metadata (const gchar *filename, +load_typelib (const gchar *filename, GModule **dlhandle, gsize *len) { - guchar *metadata; - gsize *metadata_size; + guchar *typelib; + gsize *typelib_size; GModule *handle; handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); - if (!g_module_symbol (handle, "_G_TYPELIB", (gpointer *) &metadata)) + if (!g_module_symbol (handle, "_G_TYPELIB", (gpointer *) &typelib)) { - g_printerr ("Could not load metadata from '%s': %s\n", + g_printerr ("Could not load typelib from '%s': %s\n", filename, g_module_error ()); return NULL; } - if (!g_module_symbol (handle, "_G_TYPELIB_SIZE", (gpointer *) &metadata_size)) + if (!g_module_symbol (handle, "_G_TYPELIB_SIZE", (gpointer *) &typelib_size)) { - g_printerr ("Could not load metadata from '%s': %s\n", + g_printerr ("Could not load typelib from '%s': %s\n", filename, g_module_error ()); return NULL; } - *len = *metadata_size; + *len = *typelib_size; if (dlhandle) *dlhandle = handle; - return metadata; + return typelib; } int @@ -1140,7 +1140,7 @@ main (int argc, char *argv[]) GTypelib *data; GOptionEntry options[] = { - { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "handle raw metadata", NULL }, + { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "handle raw typelib", NULL }, { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, { NULL, } @@ -1164,12 +1164,12 @@ main (int argc, char *argv[]) for (i = 0; input[i]; i++) { GModule *dlhandle = NULL; - const guchar *metadata; + const guchar *typelib; gsize len; if (raw) { - if (!g_file_get_contents (input[i], (gchar **)&metadata, &len, &error)) + if (!g_file_get_contents (input[i], (gchar **)&typelib, &len, &error)) { g_fprintf (stderr, "failed to read '%s': %s\n", input[i], error->message); @@ -1179,10 +1179,10 @@ main (int argc, char *argv[]) } else { - metadata = load_metadata (input[i], &dlhandle, &len); - if (!metadata) + typelib = load_typelib (input[i], &dlhandle, &len); + if (!typelib) { - g_fprintf (stderr, "failed to load metadata from '%s'\n", + g_fprintf (stderr, "failed to load typelib from '%s'\n", input[i]); continue; } @@ -1193,11 +1193,11 @@ main (int argc, char *argv[]) else needs_prefix = FALSE; - data = g_typelib_new_from_const_memory (metadata, len); + data = g_typelib_new_from_const_memory (typelib, len); { GError *error = NULL; if (!g_typelib_validate (data, &error)) { - g_printerr ("metadata not valid: %s\n", error->message); + g_printerr ("typelib not valid: %s\n", error->message); g_clear_error (&error); } } -- GitLab From 8ed19c3d86001a5fed8f117e8ac03636f80d2b67 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Thu, 14 Aug 2008 19:07:34 +0000 Subject: [PATCH 24/99] Don't require c:type. Test boxed.gir Update, remove parts we don't support 2008-08-14 Johan Dahlin * girepository/girparser.c (start_type): Don't require c:type. * tests/Makefile.am: Test boxed.gir * tests/boxed.gir: Update, remove parts we don't support yet * tests/roundtrips.sh: Remove * tools/generate.c (write_type_info), (write_field_info), (write_callable_info), (write_struct_info): Make it emit proper gir. svn path=/trunk/; revision=376 --- girepository/tools/generate.c | 197 ++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 92 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index f3acc9ce7b..1292c3d70e 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -54,24 +54,24 @@ write_type_info (const gchar *namespace, GITypeInfo *type; const gchar* basic[] = { - "void", - "gboolean", - "gint8", - "guint8", - "gint16", - "guint16", - "gint32", - "guint32", - "gint64", - "guint64", - "gint", - "guint", - "glong", - "gulong", - "gssize", - "gsize", - "gfloat", - "gdouble", + "none", + "boolean", + "int8", + "uint8", + "int16", + "uint16", + "int32", + "uint32", + "int64", + "uint64", + "int", + "uint", + "long", + "ulong", + "ssize", + "size", + "float", + "double", "utf8", "filename" }; @@ -200,21 +200,16 @@ write_field_info (const gchar *namespace, offset = g_field_info_get_offset (info); g_fprintf (file, - " \n"); + g_fprintf (file,">\n"); + + g_fprintf (file, " \n"); + + g_fprintf (file, " \n"); + } static void @@ -237,12 +242,9 @@ write_callable_info (const gchar *namespace, GITypeInfo *type; gint i; - g_fprintf (file, "%*s \n", indent, ""); type = g_callable_info_get_return_type (info); - write_type_info (namespace, type, file); - - g_fprintf (file, "\""); if (g_type_info_is_pointer (type)) { @@ -265,75 +267,86 @@ write_callable_info (const gchar *namespace, if (g_callable_info_may_return_null (info)) g_fprintf (file, " null-ok=\"1\""); - g_fprintf (file, " />\n"); + g_fprintf (file, "%*s \n"); + + g_fprintf (file, "%*s \n", indent, ""); - if (g_callable_info_get_n_args (info) > 0) + if (g_callable_info_get_n_args (info) <= 0) + return; + + g_fprintf (file, "%*s \n", indent, ""); + for (i = 0; i < g_callable_info_get_n_args (info); i++) { - g_fprintf (file, "%*s \n", indent, ""); - for (i = 0; i < g_callable_info_get_n_args (info); i++) + GIArgInfo *arg = g_callable_info_get_arg (info, i); + + g_fprintf (file, "%*s \n"); - - g_base_info_unref ((GIBaseInfo *)arg); + } + g_base_info_unref ((GIBaseInfo *)type); + + g_fprintf (file, " direction=\""); + switch (g_arg_info_get_direction (arg)) + { + case GI_DIRECTION_IN: + g_fprintf (file, "in"); + break; + case GI_DIRECTION_OUT: + g_fprintf (file, "out"); + break; + case GI_DIRECTION_INOUT: + g_fprintf (file, "inout"); + break; } - - g_fprintf (file, "%*s \n", indent, ""); + g_fprintf (file, "\""); + + if (g_arg_info_may_be_null (arg)) + g_fprintf (file, " null-ok=\"1\""); + + if (g_arg_info_is_dipper (arg)) + g_fprintf (file, " dipper=\"1\""); + + if (g_arg_info_is_return_value (arg)) + g_fprintf (file, " retval=\"1\""); + + if (g_arg_info_is_optional (arg)) + g_fprintf (file, " optional=\"1\""); + + g_fprintf (file, ">\n"); + + g_fprintf (file, "%*s \n"); + + g_fprintf (file, "%*s \n", indent, ""); + + g_base_info_unref ((GIBaseInfo *)arg); } + + g_fprintf (file, "%*s \n", indent, ""); } static void @@ -417,7 +430,7 @@ write_struct_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - g_fprintf (file, " \n"); + g_fprintf (file, " \n"); else g_fprintf (file, " \n"); } -- GitLab From f49fa21c3194a40f4212657c12ab31f5318cd75f Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Thu, 14 Aug 2008 19:32:26 +0000 Subject: [PATCH 25/99] Clear up constant parsing 2008-08-14 Johan Dahlin * girepository/girparser.c (start_field), (start_constant), (start_type), (end_element_handler): Clear up constant parsing * tests/object.gir: Update * tools/generate.c (write_callable_info), (write_function_info), (write_callback_info), (write_constant_info), (write_signal_info), (write_vfunc_info), (write_property_info), (write_object_info), (write_interface_info): Constants/Signals are handled now. svn path=/trunk/; revision=377 --- girepository/tools/generate.c | 53 ++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 1292c3d70e..226f1ac1de 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -242,8 +242,6 @@ write_callable_info (const gchar *namespace, GITypeInfo *type; gint i; - g_fprintf (file, "%*s \n", indent, ""); - type = g_callable_info_get_return_type (info); if (g_type_info_is_pointer (type)) @@ -263,6 +261,11 @@ write_callable_info (const gchar *namespace, g_assert_not_reached (); } } + + g_fprintf (file, ">\n"); + + g_fprintf (file, "%*s \n", indent, ""); + g_base_info_unref ((GIBaseInfo *)type); if (g_callable_info_may_return_null (info)) g_fprintf (file, " null-ok=\"1\""); @@ -384,7 +387,6 @@ write_function_info (const gchar *namespace, if (deprecated) g_fprintf (file, " deprecated=\"1\""); - g_fprintf (file, ">\n"); write_callable_info (namespace, (GICallableInfo*)info, file, indent); g_fprintf (file, "%*s\n", indent, "", tag); } @@ -406,7 +408,6 @@ write_callback_info (const gchar *namespace, if (deprecated) g_fprintf (file, " deprecated=\"1\""); - g_fprintf (file, ">\n"); write_callable_info (namespace, (GICallableInfo*)info, file, indent); g_fprintf (file, "%*s\n", indent, ""); } @@ -563,15 +564,22 @@ write_constant_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, "%*s\n"); + g_fprintf (file, "\">\n"); + + g_fprintf (file, "%*s\n"); + + g_fprintf (file, "%*s\n", indent, ""); g_base_info_unref ((GIBaseInfo *)type); } @@ -634,7 +642,7 @@ write_signal_info (const gchar *namespace, flags = g_signal_info_get_flags (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, " \n"); - write_callable_info (namespace, (GICallableInfo*)info, file, 6); - g_fprintf (file, " \n"); + + g_fprintf (file, " \n"); } static void @@ -693,9 +700,9 @@ write_vfunc_info (const gchar *namespace, g_fprintf (file, " override=\"never\""); g_fprintf (file, " offset=\"%d\"", offset); - g_fprintf (file, ">\n"); write_callable_info (namespace, (GICallableInfo*)info, file, 6); + g_fprintf (file, " \n"); } @@ -735,11 +742,17 @@ write_property_info (const gchar *namespace, g_fprintf (file, " construct-only=\"1\""); type = g_property_info_get_type (info); - g_fprintf (file, " type=\""); + + g_fprintf (file, ">\n"); + + g_fprintf (file, " \n"); + g_fprintf (file, "\"/>\n"); + + g_fprintf (file, " \n"); + } static void @@ -759,7 +772,7 @@ write_object_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - g_fprintf (file, " \n"); + g_fprintf (file, " \n"); } static void @@ -852,7 +865,7 @@ write_interface_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - g_fprintf (file, " Date: Thu, 14 Aug 2008 19:35:36 +0000 Subject: [PATCH 26/99] Fix generation of enum/bitfields 2008-08-14 Johan Dahlin * tests/Makefile.am: * tests/enum.gir: * tools/generate.c (write_enum_info): Fix generation of enum/bitfields svn path=/trunk/; revision=378 --- girepository/tools/generate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 226f1ac1de..4cbf23ec32 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -603,13 +603,13 @@ write_enum_info (const gchar *namespace, type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) - g_fprintf (file, " \n"); + g_fprintf (file, " \n"); else - g_fprintf (file, " \n"); + g_fprintf (file, " \n"); } static void -- GitLab From 2f803f62e63b4e456329aaec32eecf4fe01c603c Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Thu, 14 Aug 2008 19:45:37 +0000 Subject: [PATCH 27/99] Fix generator for constant/gobject/struct 2008-08-14 Johan Dahlin * tests/Makefile.am: * tests/constant.gir: * tests/gobject.gir: * tests/struct.gir: * tools/generate.c (write_struct_info): Fix generator for constant/gobject/struct svn path=/trunk/; revision=379 --- girepository/tools/generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 4cbf23ec32..3e6a8f82ba 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -434,7 +434,7 @@ write_struct_info (const gchar *namespace, g_fprintf (file, " \n"); else - g_fprintf (file, " \n"); + g_fprintf (file, " \n"); } static void -- GitLab From d922fdb5fcca5f2dba151613e11668567252efa8 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 22 Aug 2008 14:43:41 +0000 Subject: [PATCH 28/99] Add g-ir-generate. Support $(DEBUG) Do immediate close tags if no 2008-08-22 Colin Walters * gobject-introspection-1.0.pc.in: Add g-ir-generate. * tests/Makefile.am: Support $(DEBUG) * tools/generate.c: Do immediate close tags if no sub-elements. svn path=/trunk/; revision=448 --- girepository/tools/generate.c | 43 +++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 3e6a8f82ba..1f331570a1 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -422,6 +422,7 @@ write_struct_info (const gchar *namespace, const gchar *type_init; gboolean deprecated; gint i; + int n_elts; name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); @@ -439,26 +440,34 @@ write_struct_info (const gchar *namespace, if (deprecated) g_fprintf (file, " deprecated=\"1\""); - g_fprintf (file, ">\n"); - - for (i = 0; i < g_struct_info_get_n_fields (info); i++) + n_elts = g_struct_info_get_n_fields (info) + g_struct_info_get_n_methods (info); + if (n_elts > 0) { - GIFieldInfo *field = g_struct_info_get_field (info, i); - write_field_info (namespace, field, NULL, file); - g_base_info_unref ((GIBaseInfo *)field); - } - - for (i = 0; i < g_struct_info_get_n_methods (info); i++) + g_fprintf (file, ">\n"); + + for (i = 0; i < g_struct_info_get_n_fields (info); i++) + { + GIFieldInfo *field = g_struct_info_get_field (info, i); + write_field_info (namespace, field, NULL, file); + g_base_info_unref ((GIBaseInfo *)field); + } + + for (i = 0; i < g_struct_info_get_n_methods (info); i++) + { + GIFunctionInfo *function = g_struct_info_get_method (info, i); + write_function_info (namespace, function, file, 6); + g_base_info_unref ((GIBaseInfo *)function); + } + + if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) + g_fprintf (file, " \n"); + else + g_fprintf (file, " \n"); + } + else { - GIFunctionInfo *function = g_struct_info_get_method (info, i); - write_function_info (namespace, function, file, 6); - g_base_info_unref ((GIBaseInfo *)function); + g_fprintf (file, "/>\n"); } - - if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) - g_fprintf (file, " \n"); - else - g_fprintf (file, " \n"); } static void -- GitLab From e1cd6689507199b2f88342af021b23f1842844f0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 22 Aug 2008 17:34:29 +0000 Subject: [PATCH 29/99] Fix unref sequence. 2008-08-22 Colin Walters * tools/generate.c (write_callable_info): Fix unref sequence. svn path=/trunk/; revision=449 --- girepository/tools/generate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 1f331570a1..8ff90b9bca 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -266,7 +266,6 @@ write_callable_info (const gchar *namespace, g_fprintf (file, "%*s \n", indent, ""); - g_base_info_unref ((GIBaseInfo *)type); if (g_callable_info_may_return_null (info)) g_fprintf (file, " null-ok=\"1\""); @@ -306,7 +305,6 @@ write_callable_info (const gchar *namespace, g_assert_not_reached (); } } - g_base_info_unref ((GIBaseInfo *)type); g_fprintf (file, " direction=\""); switch (g_arg_info_get_direction (arg)) @@ -350,6 +348,7 @@ write_callable_info (const gchar *namespace, } g_fprintf (file, "%*s \n", indent, ""); + g_base_info_unref ((GIBaseInfo *)type); } static void -- GitLab From ab1e9433db313af4bac60338c890df13ef5a6875 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 22 Aug 2008 19:09:11 +0000 Subject: [PATCH 30/99] Don't put * in types, suppress transfer="none" svn path=/trunk/; revision=453 --- girepository/tools/generate.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 8ff90b9bca..b419cf51bd 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -78,9 +78,7 @@ write_type_info (const gchar *namespace, tag = g_type_info_get_tag (info); - if (tag < 18) - g_fprintf (file, "%s%s", basic[tag], g_type_info_is_pointer (info) ? "*" : ""); - else if (tag < 20) + if (tag < 20) g_fprintf (file, "%s", basic[tag]); else if (tag == 20) { @@ -105,8 +103,6 @@ write_type_info (const gchar *namespace, { GIBaseInfo *iface = g_type_info_get_interface (info); write_type_name (namespace, iface, file); - if (g_type_info_is_pointer (info)) - g_fprintf (file, "*"); g_base_info_unref (iface); } else if (tag == 22) @@ -120,7 +116,6 @@ write_type_info (const gchar *namespace, g_fprintf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } - g_fprintf (file, "*"); } else if (tag == 23) { @@ -133,7 +128,6 @@ write_type_info (const gchar *namespace, g_fprintf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } - g_fprintf (file, "*"); } else if (tag == 24) { @@ -150,7 +144,6 @@ write_type_info (const gchar *namespace, g_fprintf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } - g_fprintf (file, "*"); } else if (tag == 25) { @@ -171,7 +164,6 @@ write_type_info (const gchar *namespace, } g_fprintf (file, ">"); } - g_fprintf (file, "*"); } } @@ -249,7 +241,6 @@ write_callable_info (const gchar *namespace, switch (g_callable_info_get_caller_owns (info)) { case GI_TRANSFER_NOTHING: - g_fprintf (file, " transfer=\"none\""); break; case GI_TRANSFER_CONTAINER: g_fprintf (file, " transfer=\"shallow\""); @@ -293,7 +284,6 @@ write_callable_info (const gchar *namespace, switch (g_arg_info_get_ownership_transfer (arg)) { case GI_TRANSFER_NOTHING: - g_fprintf (file, " transfer=\"none\""); break; case GI_TRANSFER_CONTAINER: g_fprintf (file, " transfer=\"shallow\""); -- GitLab From cf73901c6b7deac8966bbd5832e11d990a65583c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 22 Aug 2008 20:05:23 +0000 Subject: [PATCH 31/99] Pass through recursive types. Avoid overwriting errors. Always write the 2008-08-22 Colin Walters * 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 --- girepository/tools/generate.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index b419cf51bd..44346ce191 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -279,22 +279,19 @@ write_callable_info (const gchar *namespace, g_fprintf (file, "%*s Date: Fri, 22 Aug 2008 21:08:06 +0000 Subject: [PATCH 32/99] Install config.py, better error handling if we forget --raw svn path=/trunk/; revision=461 --- girepository/tools/generate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 44346ce191..05c1a076bd 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1127,6 +1127,13 @@ load_typelib (const gchar *filename, GModule *handle; handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); + if (handle == NULL) + { + g_printerr ("Could not load typelib from '%s': %s\n", + filename, g_module_error ()); + return NULL; + } + if (!g_module_symbol (handle, "_G_TYPELIB", (gpointer *) &typelib)) { g_printerr ("Could not load typelib from '%s': %s\n", -- GitLab From fc4cffc61d23f368f111303db8b2bc24404aedc4 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 22 Aug 2008 21:14:31 +0000 Subject: [PATCH 33/99] Default to --raw. Update. 2008-08-22 Colin Walters * tools/generate.c, tools/compiler.c: Default to --raw. * all Makefile.am: Update. svn path=/trunk/; revision=462 --- girepository/tools/generate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 05c1a076bd..52e1c8436e 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1159,7 +1159,7 @@ load_typelib (const gchar *filename, int main (int argc, char *argv[]) { - gboolean raw = FALSE; + gboolean shlib = FALSE; gchar **input = NULL; GOptionContext *context; GError *error = NULL; @@ -1168,7 +1168,7 @@ main (int argc, char *argv[]) GTypelib *data; GOptionEntry options[] = { - { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "handle raw typelib", NULL }, + { "shlib", 0, 0, G_OPTION_ARG_NONE, &shlib, "handle typelib embedded in shlib", NULL }, { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, { NULL, } @@ -1195,7 +1195,7 @@ main (int argc, char *argv[]) const guchar *typelib; gsize len; - if (raw) + if (!shlib) { if (!g_file_get_contents (input[i], (gchar **)&typelib, &len, &error)) { -- GitLab From c306fea286a4f6b5b101ae201266cb3a4678e521 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 25 Aug 2008 15:22:39 +0000 Subject: [PATCH 34/99] Parse new implements syntax, drop gapi one. Update. Generate new syntax. 2008-08-25 Colin Walters * girepository/girparser.c: Parse new implements syntax, drop gapi one. * tests/object.gir: Update. * tools/generate.c: Generate new syntax. svn path=/trunk/; revision=492 --- girepository/tools/generate.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 52e1c8436e..53bebd2260 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -787,16 +787,14 @@ write_object_info (const gchar *namespace, if (g_object_info_get_n_interfaces (info) > 0) { - g_fprintf (file, " \n"); for (i = 0; i < g_object_info_get_n_interfaces (info); i++) { GIInterfaceInfo *imp = g_object_info_get_interface (info, i); - g_fprintf (file, " \n"); g_base_info_unref ((GIBaseInfo*)imp); } - g_fprintf (file, " \n"); } for (i = 0; i < g_object_info_get_n_fields (info); i++) -- GitLab From 97e04b2b5dec4e6b3cf4db3bf9588cbe1a5f1b4c Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 27 Aug 2008 13:33:21 +0000 Subject: [PATCH 35/99] Make g-ir-scanner work on Windows. Still problems with the typelib code. 2008-08-27 Tor Lillqvist Make g-ir-scanner work on Windows. Still problems with the typelib code. Changes okayed by jdahlin. * configure.ac: Check for Windows, set Automake conditional OS_WIN32. Change backslashes to forward slashes in pyexecdir to avoid shell quoting issues * girepository/Makefile.am: Use -no-undefined so that libtool agrees to build a shared library on Windows. * girepository/girparser.c (backtrace_stderr): No backtrace() on Windows. Empty implementation on Windows so far. * girepository/gtypelib.c (g_typelib_check_sanity): Give more informative error message for the assertion failures. Tell also what the expected size of the struct is. Check all sizes first and fail afterwards if at least one size was different from expected. * tools/Makefile.am: Reorder libraries into proper logical dependency order. * tools/generate.c: Don't include , not used. * giscanner/Makefile.am: On Windows, link with the Python library, and install the module DLL as _giscanner.pyd. Remove the unnecessary import library and libtool library that libtool has installed. * giscanner/scannerlexer.l: Recognize the gcc __attribute__ syntax and just skip it. Recognize also two "l" suffixes for long long constants. Recognize also __inline__. * giscanner/grealpath.h (g_realpath): Implement on Windows, using GetFullPathName(). As such, GetFullPathName() does more than the UNIX realpath(). It also changes relative paths into absolute paths. But for our purposes that shouldn't matter. * giscanner/giscannermodule.c (pygi_source_scanner_parse_file): On Windows the file descriptor passed to us is from Python. Python Python2.5 uses the msvcr71.dll C library, while mingw-built code uses msvcrt.dll. On Windows, file descriptors are specific to which C library is used. So we must find out what underlying OS handle corresponds to the file descriptor Python passes us, and then make that into a file descriptor valid for the C library this code uses. * giscanner/sourcescanner.py (_parse): Don't need to bypass __attribute__ as the lexer now handles it. The definition as empty was ineffective for mingw anyway, as mingw's _mingw.h undefines __attribute__. Close the temp file before unlinking it. * giscanner/cgobject.py: Use correct library name for the gobject DLL on Windows. * gir/Makefile.am: Must pass the full basename of the DLLs on Windows to g-ir-scanner. It's a bit ugly that we have to "know" that the names of the GLib DLLs are like libglib-2.0-0.dll, but in reality they won't change, until there is a GLib 3, and then also the Unix code here needs changing. Must pass CPPFLAGS to g-ir-scanner when building GLib.gir so that libintl.h is found. svn path=/trunk/; revision=503 --- girepository/tools/generate.c | 1 - 1 file changed, 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 53bebd2260..02152df3c3 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -20,7 +20,6 @@ */ #include -#include #include #include -- GitLab From 56428ae349e0dfaa87925242ccd33806969a47dd Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 29 Aug 2008 18:19:26 +0000 Subject: [PATCH 36/99] Correctly handle GLib.List, GLib.Error etc * girepository/girparser.c: Accept both List (for compiling GLib) and GLib.List (what the scanner generates). * tests/ - Update. * tools/generate.c: Generate canonical form. svn path=/trunk/; revision=522 --- girepository/tools/generate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 02152df3c3..40c497b2a3 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -107,7 +107,7 @@ write_type_info (const gchar *namespace, else if (tag == 22) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GList"); + g_fprintf (file, "GLib.List"); if (type) { g_fprintf (file, "<"); @@ -119,7 +119,7 @@ write_type_info (const gchar *namespace, else if (tag == 23) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GSList"); + g_fprintf (file, "GLib.SList"); if (type) { g_fprintf (file, "<"); @@ -131,7 +131,7 @@ write_type_info (const gchar *namespace, else if (tag == 24) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GHashTable"); + g_fprintf (file, "GLib.HashTable"); if (type) { g_fprintf (file, "<"); @@ -148,7 +148,7 @@ write_type_info (const gchar *namespace, { gint n; - g_fprintf (file, "GError"); + g_fprintf (file, "GLib.Error"); n = g_type_info_get_n_error_domains (info); if (n > 0) { -- GitLab From 030b17bc9fcd56b3abd07e46ed27baf58e0e6316 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 30 Aug 2008 20:31:07 +0000 Subject: [PATCH 37/99] Put dependencies in typelibs, resolve them when loading * gir/Makefile.am: Dep on Makefile * girepository/ginfo.c: Print out a nicer error message if we failed to load something. * girepository/girepository.c: Clean up default typelib handling; remove global default_typelib variable. Ensure we handle NULL repository in more places. Support dependency resolution. * tests/Makefile.am: Kill off gobject.gir, it conflicts with the real one. * tests/Object.gir: Depend on GObject. * tools/generate.c: Take --includedir argument to say which directories to search for typelibs. Print out dependencies. svn path=/trunk/; revision=541 --- girepository/tools/generate.c | 51 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 40c497b2a3..26ac847860 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -31,6 +31,7 @@ /* FIXME: Avoid global */ static gchar *output = NULL; +gchar **includedirs = NULL; static void write_type_name (const gchar *namespace, @@ -371,7 +372,7 @@ write_function_info (const gchar *namespace, if (deprecated) g_fprintf (file, " deprecated=\"1\""); - + write_callable_info (namespace, (GICallableInfo*)info, file, indent); g_fprintf (file, "%*s\n", indent, "", tag); } @@ -1002,15 +1003,16 @@ write_union_info (const gchar *namespace, } static void -write_repository (GIRepository *repository, +write_repository (const char *namespace, gboolean needs_prefix) { FILE *file; - gchar **namespaces; gchar *ns; gint i, j; + char **dependencies; + GIRepository *repository; - namespaces = g_irepository_get_namespaces (repository); + repository = g_irepository_get_default (); if (output == NULL) file = stdout; @@ -1019,7 +1021,7 @@ write_repository (GIRepository *repository, gchar *filename; if (needs_prefix) - filename = g_strdup_printf ("%s-%s", namespaces[0], output); + filename = g_strdup_printf ("%s-%s", namespace, output); else filename = g_strdup (output); file = g_fopen (filename, "w"); @@ -1042,10 +1044,21 @@ write_repository (GIRepository *repository, " xmlns:c=\"http://www.gtk.org/introspection/c/1.0\"\n" " xmlns:glib=\"http://www.gtk.org/introspection/glib/1.0\">\n"); - for (i = 0; namespaces[i]; i++) + dependencies = g_irepository_get_dependencies (repository, + namespace); + if (dependencies != NULL) + { + for (i = 0; dependencies[i]; i++) + { + g_fprintf (file, " \n", dependencies[i]); + } + } + + if (TRUE) { const gchar *shared_library; - ns = namespaces[i]; + const char *ns = namespace; + shared_library = g_irepository_get_shared_library (repository, ns); if (shared_library) g_fprintf (file, " \n", @@ -1110,8 +1123,6 @@ write_repository (GIRepository *repository, if (output != NULL) fclose (file); - - g_strfreev (namespaces); } static const guchar * @@ -1167,10 +1178,13 @@ main (int argc, char *argv[]) { { "shlib", 0, 0, G_OPTION_ARG_NONE, &shlib, "handle typelib embedded in shlib", NULL }, { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, + { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, { NULL, } }; + g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); + g_type_init (); g_typelib_check_sanity (); @@ -1186,11 +1200,16 @@ main (int argc, char *argv[]) return 1; } + if (includedirs != NULL) + for (i = 0; includedirs[i]; i++) + g_irepository_prepend_search_path (includedirs[i]); + for (i = 0; input[i]; i++) { GModule *dlhandle = NULL; const guchar *typelib; gsize len; + const char *namespace; if (!shlib) { @@ -1224,12 +1243,18 @@ main (int argc, char *argv[]) if (!g_typelib_validate (data, &error)) { g_printerr ("typelib not valid: %s\n", error->message); g_clear_error (&error); + return 1; } } - g_irepository_register (g_irepository_get_default (), data); - write_repository (g_irepository_get_default (), needs_prefix); - g_irepository_unregister (g_irepository_get_default (), - g_typelib_get_namespace (data)); + namespace = g_irepository_load_typelib (g_irepository_get_default (), data, + &error); + if (namespace == NULL) + { + g_printerr ("failed to load typelib: %s\n", error->message); + return 1; + } + + write_repository (namespace, needs_prefix); if (dlhandle) { -- GitLab From 886b9c66c57f534d9bea7c8396b16384a9001092 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 30 Aug 2008 20:31:12 +0000 Subject: [PATCH 38/99] Remove g_irepository_unregister, add GIRepositoryLoadFlags svn path=/trunk/; revision=543 --- girepository/tools/generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 26ac847860..2f6f512ebc 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1246,7 +1246,7 @@ main (int argc, char *argv[]) return 1; } } - namespace = g_irepository_load_typelib (g_irepository_get_default (), data, + namespace = g_irepository_load_typelib (g_irepository_get_default (), data, 0, &error); if (namespace == NULL) { -- GitLab From 77683a327f9f570b247cd3500a2fba9e32c4709c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 6 Sep 2008 20:33:51 +0000 Subject: [PATCH 39/99] Allow both union and struct to be boxed or not * girepository/girnode.c: Allow gtype_name and gtype_init in struct and union. * girepository/girparser.c: Parse glib: boxed bits for both structure and union. * girepository/gtypelib.c: Don't barf if structure is boxed. * giscanner/girparser.py: Parse new XML format. * giscanner/girwriter.py: Write out new XML format. * giscanner/glibast.py: Define new classes which are both Boxed and Struct/Union, as well as an "Other" for everything else. * giscanner/glibtransformer.py: Handle boxed types specially; we try to merge them with a struct/union if one exists, otherwise fall back to generic boxed. * tests/*: Update. * tools/generate.c: Write out new format. svn path=/trunk/; revision=575 --- girepository/tools/generate.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 2f6f512ebc..efa4e7a74c 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -413,15 +413,18 @@ write_struct_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); + type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); + if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) { - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - - g_fprintf (file, " Date: Tue, 16 Sep 2008 19:44:26 +0000 Subject: [PATCH 40/99] Print out "any" for VOID+pointer, not "none" * tools/generate.c: Print out "any" for VOID+pointer, not "none" svn path=/trunk/; revision=610 --- girepository/tools/generate.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index efa4e7a74c..c63acdccb4 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -52,6 +52,7 @@ write_type_info (const gchar *namespace, gint tag; gint i; GITypeInfo *type; + gboolean is_pointer; const gchar* basic[] = { "none", @@ -77,8 +78,14 @@ write_type_info (const gchar *namespace, }; tag = g_type_info_get_tag (info); - - if (tag < 20) + is_pointer = g_type_info_is_pointer (info); + + if (tag == GI_TYPE_TAG_VOID) { + if (is_pointer) + g_fprintf (file, "%s", "any"); + else + g_fprintf (file, "%s", "none"); + } else if (tag < 20) g_fprintf (file, "%s", basic[tag]); else if (tag == 20) { -- GitLab From 4ae9d0f2fa85f041a98ca7ffc25b9a6f3caf5185 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 19 Sep 2008 16:16:18 +0000 Subject: [PATCH 41/99] Add check to make sure we're not hitting out unresolved types svn path=/trunk/; revision=616 --- girepository/tools/generate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index c63acdccb4..01f47767c8 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -33,6 +33,16 @@ static gchar *output = NULL; gchar **includedirs = NULL; +static void +check_unresolved (GIBaseInfo *info) +{ + if (g_base_info_get_type (info) != GI_INFO_TYPE_UNRESOLVED) + return; + + g_critical ("Found unresolved type '%s' '%s'\n", + g_base_info_get_name (info), g_base_info_get_namespace (info)); +} + static void write_type_name (const gchar *namespace, GIBaseInfo *info, @@ -77,6 +87,8 @@ write_type_info (const gchar *namespace, "filename" }; + check_unresolved ((GIBaseInfo*)info); + tag = g_type_info_get_tag (info); is_pointer = g_type_info_is_pointer (info); -- GitLab From ff45096d9635db46a728a7db9156f7af720c595c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 19 Sep 2008 18:54:50 +0000 Subject: [PATCH 42/99] Fix indentation svn path=/trunk/; revision=618 --- girepository/tools/generate.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 01f47767c8..8fb8aea84b 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -92,12 +92,14 @@ write_type_info (const gchar *namespace, tag = g_type_info_get_tag (info); is_pointer = g_type_info_is_pointer (info); - if (tag == GI_TYPE_TAG_VOID) { - if (is_pointer) - g_fprintf (file, "%s", "any"); - else - g_fprintf (file, "%s", "none"); - } else if (tag < 20) + if (tag == GI_TYPE_TAG_VOID) + { + if (is_pointer) + g_fprintf (file, "%s", "any"); + else + g_fprintf (file, "%s", "none"); + } + else if (tag < 20) g_fprintf (file, "%s", basic[tag]); else if (tag == 20) { -- GitLab From 78c7abb34fd99b8b6be795c73a2e28f963858eb3 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 19 Sep 2008 23:43:33 +0000 Subject: [PATCH 43/99] Explode immediately if we don't recognize a type svn path=/trunk/; revision=619 --- girepository/tools/generate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 8fb8aea84b..ada48cccf4 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -186,6 +186,8 @@ write_type_info (const gchar *namespace, g_fprintf (file, ">"); } } + else + g_assert_not_reached (); } static void -- GitLab From 68fb7868d3e592d5554fefa075cb9b2c936ae128 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 23 Sep 2008 18:20:25 +0000 Subject: [PATCH 44/99] Merge branch 'bug552566-timet/wip' svn path=/trunk/; revision=624 --- girepository/tools/generate.c | 1 + 1 file changed, 1 insertion(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index ada48cccf4..f10bdf9159 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -83,6 +83,7 @@ write_type_info (const gchar *namespace, "size", "float", "double", + "time_t", "utf8", "filename" }; -- GitLab From 11a41321a39100f5fdd61e1f8a1a8b00b901f325 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 23 Sep 2008 22:18:06 +0000 Subject: [PATCH 45/99] Use symbolic names for type tags instead of hardcoded integers svn path=/trunk/; revision=626 --- girepository/tools/generate.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index f10bdf9159..dca2cdac07 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -100,9 +100,9 @@ write_type_info (const gchar *namespace, else g_fprintf (file, "%s", "none"); } - else if (tag < 20) + else if (tag < GI_TYPE_TAG_ARRAY) g_fprintf (file, "%s", basic[tag]); - else if (tag == 20) + else if (tag == GI_TYPE_TAG_ARRAY) { gint length; @@ -121,13 +121,13 @@ write_type_info (const gchar *namespace, g_fprintf (file, "]"); g_base_info_unref ((GIBaseInfo *)type); } - else if (tag == 21) + else if (tag == GI_TYPE_TAG_INTERFACE) { GIBaseInfo *iface = g_type_info_get_interface (info); write_type_name (namespace, iface, file); g_base_info_unref (iface); } - else if (tag == 22) + else if (tag == GI_TYPE_TAG_GLIST) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GLib.List"); @@ -139,7 +139,7 @@ write_type_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)type); } } - else if (tag == 23) + else if (tag == GI_TYPE_TAG_GSLIST) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GLib.SList"); @@ -151,7 +151,7 @@ write_type_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)type); } } - else if (tag == 24) + else if (tag == GI_TYPE_TAG_GHASH) { type = g_type_info_get_param_type (info, 0); g_fprintf (file, "GLib.HashTable"); @@ -167,7 +167,7 @@ write_type_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)type); } } - else if (tag == 25) + else if (tag == GI_TYPE_TAG_ERROR) { gint n; @@ -188,7 +188,10 @@ write_type_info (const gchar *namespace, } } else - g_assert_not_reached (); + { + g_printerr ("Unhandled type tag %d\n", tag); + g_assert_not_reached (); + } } static void -- GitLab From c0114d88115c6c816e87a3a4b96c13181cc11936 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 2 Oct 2008 13:25:46 +0000 Subject: [PATCH 46/99] Bug 554632: Create type tag for GType svn path=/trunk/; revision=641 --- girepository/tools/generate.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index dca2cdac07..5f10d27caf 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -64,30 +64,6 @@ write_type_info (const gchar *namespace, GITypeInfo *type; gboolean is_pointer; - const gchar* basic[] = { - "none", - "boolean", - "int8", - "uint8", - "int16", - "uint16", - "int32", - "uint32", - "int64", - "uint64", - "int", - "uint", - "long", - "ulong", - "ssize", - "size", - "float", - "double", - "time_t", - "utf8", - "filename" - }; - check_unresolved ((GIBaseInfo*)info); tag = g_type_info_get_tag (info); @@ -100,8 +76,8 @@ write_type_info (const gchar *namespace, else g_fprintf (file, "%s", "none"); } - else if (tag < GI_TYPE_TAG_ARRAY) - g_fprintf (file, "%s", basic[tag]); + else if (G_TYPE_TAG_IS_BASIC (tag)) + g_fprintf (file, "%s", g_type_tag_to_string (tag)); else if (tag == GI_TYPE_TAG_ARRAY) { gint length; -- GitLab From 12f6efcf38e7210f832fe9c607515503ec09a316 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 12 Oct 2008 04:51:48 +0000 Subject: [PATCH 47/99] Bug 552858: versioning This is a big patch. You should probably remove your installation tree to be cleaner. * docs/typelib-format.txt: Add nsversion entry which holds version of namespace. * girepository/girepository.h: Add 'version' parameter to g_irepository_require. This may be NULL. Normally bindings should pass an explicit version though. * girepository/girepository.c: Lots of infrastructure to support versioning. Add some more documentation. Disallow some usage of NULL namespaces. * girepository/girmodule.c: Add version parameter. * girepository/gtypelib.c: Update header size. * giscanner/ast.py: Add version to Namespace. * giscanner/girparser.py: Parse version attribute from XML, pass to Namespace. * giscanner/girwriter.py: Write out version parameter. * giscanner/transformer.py: Clean up include registration. * tests/*: Add version attribute. * tests/invoke/invoke.c: Don't try looking up test before it's loaded in repository. * tools/generate.c: Output version parameter. * gir/Makefile.am: Add 2.0 version to .gir files. svn path=/trunk/; revision=677 --- girepository/tools/generate.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 5f10d27caf..7e8d5a2864 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1064,13 +1064,16 @@ write_repository (const char *namespace, { const gchar *shared_library; const char *ns = namespace; + const char *version; + + version = g_irepository_get_version (repository, ns); shared_library = g_irepository_get_shared_library (repository, ns); if (shared_library) - g_fprintf (file, " \n", - ns, shared_library); + g_fprintf (file, " \n", + ns, version, shared_library); else - g_fprintf (file, " \n", ns); + g_fprintf (file, " \n", ns, version); for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) { -- GitLab From 04b52f98743e85cecb889149542199af24e7d941 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Sun, 12 Oct 2008 21:07:28 +0000 Subject: [PATCH 48/99] use "container" for container/shallow ownership transfer (not "shallow") 2008-10-12 Tommi Komulainen * girepository/girparser.c (parse_param_transfer): * tools/generate.c (write_callable_info): use "container" for container/shallow ownership transfer (not "shallow") svn path=/trunk/; revision=689 --- girepository/tools/generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 7e8d5a2864..8e25d33dcf 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -246,7 +246,7 @@ write_callable_info (const gchar *namespace, case GI_TRANSFER_NOTHING: break; case GI_TRANSFER_CONTAINER: - g_fprintf (file, " transfer=\"shallow\""); + g_fprintf (file, " transfer=\"container\""); break; case GI_TRANSFER_EVERYTHING: g_fprintf (file, " transfer=\"full\""); @@ -287,7 +287,7 @@ write_callable_info (const gchar *namespace, case GI_TRANSFER_NOTHING: break; case GI_TRANSFER_CONTAINER: - g_fprintf (file, " transfer=\"shallow\""); + g_fprintf (file, " transfer=\"container\""); break; case GI_TRANSFER_EVERYTHING: g_fprintf (file, " transfer=\"full\""); -- GitLab From 781262a266b26179806a20f51c8b25e198591b2a Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Sun, 12 Oct 2008 21:07:39 +0000 Subject: [PATCH 49/99] move "transfer" and "null-ok" attributes from to 2008-10-12 Tommi Komulainen * tools/generate.c (write_callable_info): move "transfer" and "null-ok" attributes from to element svn path=/trunk/; revision=691 --- girepository/tools/generate.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 8e25d33dcf..04cb87c4fb 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -239,6 +239,10 @@ write_callable_info (const gchar *namespace, type = g_callable_info_get_return_type (info); + g_fprintf (file, ">\n"); + + g_fprintf (file, "%*s \n"); - - g_fprintf (file, "%*s \n", indent, ""); if (g_callable_info_may_return_null (info)) g_fprintf (file, " null-ok=\"1\""); + g_fprintf (file, ">\n"); + g_fprintf (file, "%*s Date: Sun, 12 Oct 2008 21:07:44 +0000 Subject: [PATCH 50/99] use "transfer-ownership" attribute for return values 2008-10-12 Tommi Komulainen * tools/generate.c (write_callable_info): use "transfer-ownership" attribute for return values svn path=/trunk/; revision=692 --- girepository/tools/generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 04cb87c4fb..224d2b40f3 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -250,10 +250,10 @@ write_callable_info (const gchar *namespace, case GI_TRANSFER_NOTHING: break; case GI_TRANSFER_CONTAINER: - g_fprintf (file, " transfer=\"container\""); + g_fprintf (file, " transfer-ownership=\"container\""); break; case GI_TRANSFER_EVERYTHING: - g_fprintf (file, " transfer=\"full\""); + g_fprintf (file, " transfer-ownership=\"full\""); break; default: g_assert_not_reached (); -- GitLab From e4b12d60c22988d358821babf0d7da5f5c1a3baf Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 15 Oct 2008 22:06:37 +0000 Subject: [PATCH 51/99] wrap all FILE access to go through simple xmlwriter 2008-10-15 Tommi Komulainen * tools/generate.c (xml_printf, xml_open, xml_close, xml_free): (write_type_name, write_type_info, write_field_info, write_callable_info, write_function_info, write_callback_info, write_struct_info, write_value_info, write_constant_value, write_constant_info, write_enum_info, write_signal_info, write_vfunc_info, write_property_info, write_object_info, write_interface_info, write_error_domain_info, write_union_info, write_repository): wrap all FILE access to go through simple xmlwriter svn path=/trunk/; revision=712 --- girepository/tools/generate.c | 471 +++++++++++++++++++--------------- 1 file changed, 259 insertions(+), 212 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 224d2b40f3..6991ba3032 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -33,6 +33,51 @@ static gchar *output = NULL; gchar **includedirs = NULL; +typedef struct { + FILE *file; +} Xml; + +static void +xml_printf (Xml *xml, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + vfprintf (xml->file, fmt, ap); + va_end (ap); +} + +static Xml * +xml_open (FILE *file) +{ + Xml *xml; + + xml = g_new (Xml, 1); + xml->file = file; + + return xml; +} + +static void +xml_close (Xml *xml) +{ + if (xml->file != NULL) + { + fflush (xml->file); + if (xml->file != stdout) + fclose (xml->file); + xml->file = NULL; + } +} + +static void +xml_free (Xml *xml) +{ + xml_close (xml); + g_free (xml); +} + + static void check_unresolved (GIBaseInfo *info) { @@ -46,18 +91,18 @@ check_unresolved (GIBaseInfo *info) static void write_type_name (const gchar *namespace, GIBaseInfo *info, - FILE *file) + Xml *file) { if (strcmp (namespace, g_base_info_get_namespace (info)) != 0) - g_fprintf (file, "%s.", g_base_info_get_namespace (info)); + xml_printf (file, "%s.", g_base_info_get_namespace (info)); - g_fprintf (file, "%s", g_base_info_get_name (info)); + xml_printf (file, "%s", g_base_info_get_name (info)); } static void write_type_info (const gchar *namespace, GITypeInfo *info, - FILE *file) + Xml *file) { gint tag; gint i; @@ -72,29 +117,29 @@ write_type_info (const gchar *namespace, if (tag == GI_TYPE_TAG_VOID) { if (is_pointer) - g_fprintf (file, "%s", "any"); + xml_printf (file, "%s", "any"); else - g_fprintf (file, "%s", "none"); + xml_printf (file, "%s", "none"); } else if (G_TYPE_TAG_IS_BASIC (tag)) - g_fprintf (file, "%s", g_type_tag_to_string (tag)); + xml_printf (file, "%s", g_type_tag_to_string (tag)); else if (tag == GI_TYPE_TAG_ARRAY) { gint length; type = g_type_info_get_param_type (info, 0); write_type_info (namespace, type, file); - g_fprintf (file, "["); + xml_printf (file, "["); length = g_type_info_get_array_length (info); if (length >= 0) - g_fprintf (file, "length=%d", length); + xml_printf (file, "length=%d", length); if (g_type_info_is_zero_terminated (info)) - g_fprintf (file, "%szero-terminated=1", length >= 0 ? "," : ""); + xml_printf (file, "%szero-terminated=1", length >= 0 ? "," : ""); - g_fprintf (file, "]"); + xml_printf (file, "]"); g_base_info_unref ((GIBaseInfo *)type); } else if (tag == GI_TYPE_TAG_INTERFACE) @@ -106,40 +151,40 @@ write_type_info (const gchar *namespace, else if (tag == GI_TYPE_TAG_GLIST) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GLib.List"); + xml_printf (file, "GLib.List"); if (type) { - g_fprintf (file, "<"); + xml_printf (file, "<"); write_type_info (namespace, type, file); - g_fprintf (file, ">"); + xml_printf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } } else if (tag == GI_TYPE_TAG_GSLIST) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GLib.SList"); + xml_printf (file, "GLib.SList"); if (type) { - g_fprintf (file, "<"); + xml_printf (file, "<"); write_type_info (namespace, type, file); - g_fprintf (file, ">"); + xml_printf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } } else if (tag == GI_TYPE_TAG_GHASH) { type = g_type_info_get_param_type (info, 0); - g_fprintf (file, "GLib.HashTable"); + xml_printf (file, "GLib.HashTable"); if (type) { - g_fprintf (file, "<"); + xml_printf (file, "<"); write_type_info (namespace, type, file); g_base_info_unref ((GIBaseInfo *)type); type = g_type_info_get_param_type (info, 1); - g_fprintf (file, ","); + xml_printf (file, ","); write_type_info (namespace, type, file); - g_fprintf (file, ">"); + xml_printf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } } @@ -147,20 +192,20 @@ write_type_info (const gchar *namespace, { gint n; - g_fprintf (file, "GLib.Error"); + xml_printf (file, "GLib.Error"); n = g_type_info_get_n_error_domains (info); if (n > 0) { - g_fprintf (file, "<"); + xml_printf (file, "<"); for (i = 0; i < n; i++) { GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); if (i > 0) - g_fprintf (file, ","); + xml_printf (file, ","); write_type_name (namespace, (GIBaseInfo *)ed, file); g_base_info_unref ((GIBaseInfo *)ed); } - g_fprintf (file, ">"); + xml_printf (file, ">"); } } else @@ -174,13 +219,13 @@ static void write_constant_value (const gchar *namespace, GITypeInfo *info, GArgument *argument, - FILE *file); + Xml *file); static void write_field_info (const gchar *namespace, GIFieldInfo *info, GIConstantInfo *branch, - FILE *file) + Xml *file) { const gchar *name; GIFieldInfoFlags flags; @@ -194,44 +239,44 @@ write_field_info (const gchar *namespace, size = g_field_info_get_size (info); offset = g_field_info_get_offset (info); - g_fprintf (file, + xml_printf (file, " \n"); + xml_printf (file,">\n"); - g_fprintf (file, " \n"); + xml_printf (file, "\"/>\n"); - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_callable_info (const gchar *namespace, GICallableInfo *info, - FILE *file, + Xml *file, gint indent) { GITypeInfo *type; @@ -239,9 +284,9 @@ write_callable_info (const gchar *namespace, type = g_callable_info_get_return_type (info); - g_fprintf (file, ">\n"); + xml_printf (file, ">\n"); - g_fprintf (file, "%*s \n"); + xml_printf (file, ">\n"); - g_fprintf (file, "%*s \n"); + xml_printf (file, "\"/>\n"); - g_fprintf (file, "%*s \n", indent, ""); + xml_printf (file, "%*s \n", indent, ""); if (g_callable_info_get_n_args (info) <= 0) return; - g_fprintf (file, "%*s \n", indent, ""); + xml_printf (file, "%*s \n", indent, ""); for (i = 0; i < g_callable_info_get_n_args (info); i++) { GIArgInfo *arg = g_callable_info_get_arg (info, i); - g_fprintf (file, "%*s \n"); + xml_printf (file, ">\n"); - g_fprintf (file, "%*s \n"); + xml_printf (file, "\"/>\n"); - g_fprintf (file, "%*s \n", indent, ""); + xml_printf (file, "%*s \n", indent, ""); g_base_info_unref ((GIBaseInfo *)arg); } - g_fprintf (file, "%*s \n", indent, ""); + xml_printf (file, "%*s \n", indent, ""); g_base_info_unref ((GIBaseInfo *)type); } static void write_function_info (const gchar *namespace, GIFunctionInfo *info, - FILE *file, + Xml *file, gint indent) { GIFunctionInfoFlags flags; @@ -367,25 +412,25 @@ write_function_info (const gchar *namespace, else tag = "function"; - g_fprintf (file, "%*s<%s name=\"%s\" c:identifier=\"%s\"", - indent, "", tag, name, symbol); + xml_printf (file, "%*s<%s name=\"%s\" c:identifier=\"%s\"", + indent, "", tag, name, symbol); if (flags & GI_FUNCTION_IS_SETTER) - g_fprintf (file, " type=\"setter\""); + xml_printf (file, " type=\"setter\""); else if (flags & GI_FUNCTION_IS_GETTER) - g_fprintf (file, " type=\"getter\""); + xml_printf (file, " type=\"getter\""); if (deprecated) - g_fprintf (file, " deprecated=\"1\""); + xml_printf (file, " deprecated=\"1\""); write_callable_info (namespace, (GICallableInfo*)info, file, indent); - g_fprintf (file, "%*s\n", indent, "", tag); + xml_printf (file, "%*s\n", indent, "", tag); } static void write_callback_info (const gchar *namespace, GICallbackInfo *info, - FILE *file, + Xml *file, gint indent) { const gchar *name; @@ -394,19 +439,19 @@ write_callback_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, "%*s\n", indent, ""); + xml_printf (file, "%*s\n", indent, ""); } static void write_struct_info (const gchar *namespace, GIStructInfo *info, - FILE *file) + Xml *file) { const gchar *name; const gchar *type_name; @@ -423,21 +468,21 @@ write_struct_info (const gchar *namespace, if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) { - g_fprintf (file, " 0) { - g_fprintf (file, ">\n"); + xml_printf (file, ">\n"); for (i = 0; i < g_struct_info_get_n_fields (info); i++) { @@ -454,20 +499,20 @@ write_struct_info (const gchar *namespace, } if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) - g_fprintf (file, " \n"); + xml_printf (file, " \n"); else - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } else { - g_fprintf (file, "/>\n"); + xml_printf (file, "/>\n"); } } static void write_value_info (const gchar *namespace, GIValueInfo *info, - FILE *file) + Xml *file) { const gchar *name; glong value; @@ -477,76 +522,76 @@ write_value_info (const gchar *namespace, value = g_value_info_get_value (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, " \n"); + xml_printf (file, " />\n"); } static void write_constant_value (const gchar *namespace, GITypeInfo *type, GArgument *value, - FILE *file) + Xml *file) { switch (g_type_info_get_tag (type)) { case GI_TYPE_TAG_BOOLEAN: - g_fprintf (file, "%d", value->v_boolean); + xml_printf (file, "%d", value->v_boolean); break; case GI_TYPE_TAG_INT8: - g_fprintf (file, "%d", value->v_int8); + xml_printf (file, "%d", value->v_int8); break; case GI_TYPE_TAG_UINT8: - g_fprintf (file, "%d", value->v_uint8); + xml_printf (file, "%d", value->v_uint8); break; case GI_TYPE_TAG_INT16: - g_fprintf (file, "%" G_GINT16_FORMAT, value->v_int16); + xml_printf (file, "%" G_GINT16_FORMAT, value->v_int16); break; case GI_TYPE_TAG_UINT16: - g_fprintf (file, "%" G_GUINT16_FORMAT, value->v_uint16); + xml_printf (file, "%" G_GUINT16_FORMAT, value->v_uint16); break; case GI_TYPE_TAG_INT32: - g_fprintf (file, "%" G_GINT32_FORMAT, value->v_int32); + xml_printf (file, "%" G_GINT32_FORMAT, value->v_int32); break; case GI_TYPE_TAG_UINT32: - g_fprintf (file, "%" G_GUINT32_FORMAT, value->v_uint32); + xml_printf (file, "%" G_GUINT32_FORMAT, value->v_uint32); break; case GI_TYPE_TAG_INT64: - g_fprintf (file, "%" G_GINT64_FORMAT, value->v_int64); + xml_printf (file, "%" G_GINT64_FORMAT, value->v_int64); break; case GI_TYPE_TAG_UINT64: - g_fprintf (file, "%" G_GUINT64_FORMAT, value->v_uint64); + xml_printf (file, "%" G_GUINT64_FORMAT, value->v_uint64); break; case GI_TYPE_TAG_INT: - g_fprintf (file, "%d", value->v_int); + xml_printf (file, "%d", value->v_int); break; case GI_TYPE_TAG_UINT: - g_fprintf (file, "%d", value->v_uint); + xml_printf (file, "%d", value->v_uint); break; case GI_TYPE_TAG_LONG: - g_fprintf (file, "%ld", value->v_long); + xml_printf (file, "%ld", value->v_long); break; case GI_TYPE_TAG_ULONG: - g_fprintf (file, "%ld", value->v_ulong); + xml_printf (file, "%ld", value->v_ulong); break; case GI_TYPE_TAG_SSIZE: - g_fprintf (file, "%zd", value->v_ssize); + xml_printf (file, "%zd", value->v_ssize); break; case GI_TYPE_TAG_SIZE: - g_fprintf (file, "%zd", value->v_size); + xml_printf (file, "%zd", value->v_size); break; case GI_TYPE_TAG_FLOAT: - g_fprintf (file, "%f", value->v_float); + xml_printf (file, "%f", value->v_float); break; case GI_TYPE_TAG_DOUBLE: - g_fprintf (file, "%f", value->v_double); + xml_printf (file, "%f", value->v_double); break; case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: - g_fprintf (file, "%s", value->v_string); + xml_printf (file, "%s", value->v_string); break; default: g_assert_not_reached (); @@ -556,7 +601,7 @@ write_constant_value (const gchar *namespace, static void write_constant_info (const gchar *namespace, GIConstantInfo *info, - FILE *file, + Xml *file, gint indent) { GITypeInfo *type; @@ -567,22 +612,22 @@ write_constant_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, "%*s\n"); + xml_printf (file, "\">\n"); - g_fprintf (file, "%*s\n"); + xml_printf (file, "\"/>\n"); - g_fprintf (file, "%*s\n", indent, ""); + xml_printf (file, "%*s\n", indent, ""); g_base_info_unref ((GIBaseInfo *)type); } @@ -591,7 +636,7 @@ write_constant_info (const gchar *namespace, static void write_enum_info (const gchar *namespace, GIEnumInfo *info, - FILE *file) + Xml *file) { const gchar *name; const gchar *type_name; @@ -606,18 +651,18 @@ write_enum_info (const gchar *namespace, type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) - g_fprintf (file, " \n"); + xml_printf (file, ">\n"); for (i = 0; i < g_enum_info_get_n_values (info); i++) { @@ -627,15 +672,15 @@ write_enum_info (const gchar *namespace, } if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) - g_fprintf (file, " \n"); + xml_printf (file, " \n"); else - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_signal_info (const gchar *namespace, GISignalInfo *info, - FILE *file) + Xml *file) { GSignalFlags flags; const gchar *name; @@ -645,39 +690,39 @@ write_signal_info (const gchar *namespace, flags = g_signal_info_get_flags (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_vfunc_info (const gchar *namespace, GIVFuncInfo *info, - FILE *file) + Xml *file) { GIVFuncInfoFlags flags; const gchar *name; @@ -689,30 +734,30 @@ write_vfunc_info (const gchar *namespace, deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); offset = g_vfunc_info_get_offset (info); - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_property_info (const gchar *namespace, GIPropertyInfo *info, - FILE *file) + Xml *file) { GParamFlags flags; const gchar *name; @@ -723,45 +768,45 @@ write_property_info (const gchar *namespace, flags = g_property_info_get_flags (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - g_fprintf (file, " \n"); + xml_printf (file, ">\n"); - g_fprintf (file, " \n"); + xml_printf (file, "\"/>\n"); - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_object_info (const gchar *namespace, GIObjectInfo *info, - FILE *file) + Xml *file) { const gchar *name; const gchar *type_name; @@ -775,32 +820,32 @@ write_object_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - g_fprintf (file, " \n"); + xml_printf (file, ">\n"); if (g_object_info_get_n_interfaces (info) > 0) { for (i = 0; i < g_object_info_get_n_interfaces (info); i++) { GIInterfaceInfo *imp = g_object_info_get_interface (info, i); - g_fprintf (file, " \n"); + xml_printf (file,"\" />\n"); g_base_info_unref ((GIBaseInfo*)imp); } } @@ -847,13 +892,13 @@ write_object_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)constant); } - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_interface_info (const gchar *namespace, GIInterfaceInfo *info, - FILE *file) + Xml *file) { const gchar *name; const gchar *type_name; @@ -866,30 +911,30 @@ write_interface_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - g_fprintf (file, " \n"); + xml_printf (file, ">\n"); if (g_interface_info_get_n_prerequisites (info) > 0) { - g_fprintf (file, " \n"); + xml_printf (file, " \n"); for (i = 0; i < g_interface_info_get_n_prerequisites (info); i++) { GIBaseInfo *req = g_interface_info_get_prerequisite (info, i); if (g_base_info_get_type (req) == GI_INFO_TYPE_INTERFACE) - g_fprintf (file, " \n"); + xml_printf (file, "\" />\n"); g_base_info_unref (req); } - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } for (i = 0; i < g_interface_info_get_n_methods (info); i++) @@ -927,13 +972,13 @@ write_interface_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)constant); } - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_error_domain_info (const gchar *namespace, GIErrorDomainInfo *info, - FILE *file) + Xml *file) { GIBaseInfo *enum_; const gchar *name, *quark; @@ -941,18 +986,18 @@ write_error_domain_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); quark = g_error_domain_info_get_quark (info); enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info); - g_fprintf (file, + xml_printf (file, " \n"); + xml_printf (file, "\" />\n"); g_base_info_unref (enum_); } static void write_union_info (const gchar *namespace, GIUnionInfo *info, - FILE *file) + Xml *file) { const gchar *name; const gchar *type_name; @@ -966,15 +1011,15 @@ write_union_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - g_fprintf (file, " \n"); + xml_printf (file, ">\n"); if (g_union_info_is_discriminated (info)) { @@ -984,9 +1029,9 @@ write_union_info (const gchar *namespace, offset = g_union_info_get_discriminator_offset (info); type = g_union_info_get_discriminator_type (info); - g_fprintf (file, " \n"); + xml_printf (file, "\" />\n"); g_base_info_unref ((GIBaseInfo *)type); } @@ -1007,23 +1052,24 @@ write_union_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)function); } - g_fprintf (file, " \n"); + xml_printf (file, " \n"); } static void write_repository (const char *namespace, gboolean needs_prefix) { - FILE *file; + FILE *ofile; gchar *ns; gint i, j; char **dependencies; GIRepository *repository; + Xml *xml; repository = g_irepository_get_default (); if (output == NULL) - file = stdout; + ofile = stdout; else { gchar *filename; @@ -1032,9 +1078,9 @@ write_repository (const char *namespace, filename = g_strdup_printf ("%s-%s", namespace, output); else filename = g_strdup (output); - file = g_fopen (filename, "w"); + ofile = g_fopen (filename, "w"); - if (file == NULL) + if (ofile == NULL) { g_fprintf (stderr, "failed to open '%s': %s\n", filename, g_strerror (errno)); @@ -1045,12 +1091,14 @@ write_repository (const char *namespace, g_free (filename); } + + xml = xml_open (ofile); - g_fprintf (file, "\n"); - g_fprintf (file, "\n"); + xml_printf (xml, "\n"); + xml_printf (xml, "\n"); dependencies = g_irepository_get_dependencies (repository, namespace); @@ -1058,7 +1106,7 @@ write_repository (const char *namespace, { for (i = 0; dependencies[i]; i++) { - g_fprintf (file, " \n", dependencies[i]); + xml_printf (xml, " \n", dependencies[i]); } } @@ -1072,10 +1120,10 @@ write_repository (const char *namespace, shared_library = g_irepository_get_shared_library (repository, ns); if (shared_library) - g_fprintf (file, " \n", - ns, version, shared_library); + xml_printf (xml, " \n", + ns, version, shared_library); else - g_fprintf (file, " \n", ns, version); + xml_printf (xml, " \n", ns, version); for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) { @@ -1083,41 +1131,41 @@ write_repository (const char *namespace, switch (g_base_info_get_type (info)) { case GI_INFO_TYPE_FUNCTION: - write_function_info (ns, (GIFunctionInfo *)info, file, 4); + write_function_info (ns, (GIFunctionInfo *)info, xml, 4); break; case GI_INFO_TYPE_CALLBACK: - write_callback_info (ns, (GICallbackInfo *)info, file, 4); + write_callback_info (ns, (GICallbackInfo *)info, xml, 4); break; case GI_INFO_TYPE_STRUCT: case GI_INFO_TYPE_BOXED: - write_struct_info (ns, (GIStructInfo *)info, file); + write_struct_info (ns, (GIStructInfo *)info, xml); break; case GI_INFO_TYPE_UNION: - write_union_info (ns, (GIUnionInfo *)info, file); + write_union_info (ns, (GIUnionInfo *)info, xml); break; case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: - write_enum_info (ns, (GIEnumInfo *)info, file); + write_enum_info (ns, (GIEnumInfo *)info, xml); break; case GI_INFO_TYPE_CONSTANT: - write_constant_info (ns, (GIConstantInfo *)info, file, 4); + write_constant_info (ns, (GIConstantInfo *)info, xml, 4); break; case GI_INFO_TYPE_OBJECT: - write_object_info (ns, (GIObjectInfo *)info, file); + write_object_info (ns, (GIObjectInfo *)info, xml); break; case GI_INFO_TYPE_INTERFACE: - write_interface_info (ns, (GIInterfaceInfo *)info, file); + write_interface_info (ns, (GIInterfaceInfo *)info, xml); break; case GI_INFO_TYPE_ERROR_DOMAIN: - write_error_domain_info (ns, (GIErrorDomainInfo *)info, file); + write_error_domain_info (ns, (GIErrorDomainInfo *)info, xml); break; default: @@ -1127,13 +1175,12 @@ write_repository (const char *namespace, g_base_info_unref (info); } - g_fprintf (file, " \n"); + xml_printf (xml, " \n"); } - g_fprintf (file, "\n"); + xml_printf (xml, "\n"); - if (output != NULL) - fclose (file); + xml_free (xml); } static const guchar * -- GitLab From efaa5894ad2c58d76d7b3452f27a463ce201eca8 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 15 Oct 2008 22:06:52 +0000 Subject: [PATCH 52/99] Keep track of generated XML tree and handle indentation and closing tags 2008-10-15 Tommi Komulainen * tools/generate.c (xml_element_new, xml_element_free, xml_start_element, xml_end_element, xml_end_element_unchecked, xml_open, xml_close): Keep track of generated XML tree and handle indentation and closing tags properly. (write_field_info, write_callable_info, write_function_info, write_callback_info, write_struct_info, write_value_info, write_constant_info, write_enum_info, write_signal_info, write_vfunc_info, write_property_info, write_object_info, write_interface_info, write_error_domain_info, write_union_info, write_repository): Use xml_start_element and xml_end_element to open/close tags. svn path=/trunk/; revision=713 --- girepository/tools/generate.c | 273 ++++++++++++++++++++++------------ 1 file changed, 179 insertions(+), 94 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 6991ba3032..a31a164b0e 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -35,8 +35,32 @@ gchar **includedirs = NULL; typedef struct { FILE *file; + GSList *stack; } Xml; +typedef struct { + char *name; + guint has_children : 1; +} XmlElement; + +static XmlElement * +xml_element_new (const char *name) +{ + XmlElement *elem; + + elem = g_new (XmlElement, 1); + elem->name = g_strdup (name); + elem->has_children = FALSE; + return elem; +} + +static void +xml_element_free (XmlElement *elem) +{ + g_free (elem->name); + g_free (elem); +} + static void xml_printf (Xml *xml, const char *fmt, ...) { @@ -47,6 +71,53 @@ xml_printf (Xml *xml, const char *fmt, ...) va_end (ap); } +static void +xml_start_element (Xml *xml, const char *element_name) +{ + XmlElement *parent = NULL; + + if (xml->stack) + { + parent = xml->stack->data; + + if (!parent->has_children) + xml_printf (xml, ">\n"); + + parent->has_children = TRUE; + } + + xml_printf (xml, "%*s<%s", g_slist_length(xml->stack)*2, "", element_name); + + xml->stack = g_slist_prepend (xml->stack, xml_element_new (element_name)); +} + +static void +xml_end_element (Xml *xml, const char *name) +{ + XmlElement *elem; + + g_assert (xml->stack != NULL); + + elem = xml->stack->data; + xml->stack = g_slist_delete_link (xml->stack, xml->stack); + + if (name != NULL) + g_assert_cmpstr (name, ==, elem->name); + + if (elem->has_children) + xml_printf (xml, "%*s\n", g_slist_length (xml->stack)*2, "", elem->name); + else + xml_printf (xml, "/>\n"); + + xml_element_free (elem); +} + +static void +xml_end_element_unchecked (Xml *xml) +{ + xml_end_element (xml, NULL); +} + static Xml * xml_open (FILE *file) { @@ -54,6 +125,7 @@ xml_open (FILE *file) xml = g_new (Xml, 1); xml->file = file; + xml->stack = NULL; return xml; } @@ -61,6 +133,7 @@ xml_open (FILE *file) static void xml_close (Xml *xml) { + g_assert (xml->stack == NULL); if (xml->file != NULL) { fflush (xml->file); @@ -239,8 +312,8 @@ write_field_info (const gchar *namespace, size = g_field_info_get_size (info); offset = g_field_info_get_offset (info); - xml_printf (file, - " \n"); + xml_start_element (file, "type"); - xml_printf (file, " \n"); + xml_printf (file, "\""); - xml_printf (file, " \n"); + xml_end_element (file, "type"); + xml_end_element (file, "field"); } static void @@ -284,9 +358,7 @@ write_callable_info (const gchar *namespace, type = g_callable_info_get_return_type (info); - xml_printf (file, ">\n"); - - xml_printf (file, "%*s \n"); + xml_start_element (file, "type"); - xml_printf (file, "%*s \n"); + xml_printf (file, "\""); - xml_printf (file, "%*s \n", indent, ""); + xml_end_element (file, "type"); + + xml_end_element (file, "return-value"); if (g_callable_info_get_n_args (info) <= 0) return; - xml_printf (file, "%*s \n", indent, ""); + xml_start_element (file, "parameters"); for (i = 0; i < g_callable_info_get_n_args (info); i++) { GIArgInfo *arg = g_callable_info_get_arg (info, i); - xml_printf (file, "%*s \n"); + xml_start_element (file, "type"); - xml_printf (file, "%*s \n"); - - xml_printf (file, "%*s \n", indent, ""); + xml_printf (file, "\""); + + xml_end_element (file, "type"); + + xml_end_element (file, "parameter"); g_base_info_unref ((GIBaseInfo *)arg); } - xml_printf (file, "%*s \n", indent, ""); + xml_end_element (file, "parameters"); g_base_info_unref ((GIBaseInfo *)type); } @@ -412,8 +489,9 @@ write_function_info (const gchar *namespace, else tag = "function"; - xml_printf (file, "%*s<%s name=\"%s\" c:identifier=\"%s\"", - indent, "", tag, name, symbol); + xml_start_element (file, tag); + xml_printf (file, " name=\"%s\" c:identifier=\"%s\"", + name, symbol); if (flags & GI_FUNCTION_IS_SETTER) xml_printf (file, " type=\"setter\""); @@ -424,7 +502,7 @@ write_function_info (const gchar *namespace, xml_printf (file, " deprecated=\"1\""); write_callable_info (namespace, (GICallableInfo*)info, file, indent); - xml_printf (file, "%*s\n", indent, "", tag); + xml_end_element (file, tag); } static void @@ -439,13 +517,14 @@ write_callback_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - xml_printf (file, "%*s\n", indent, ""); + xml_end_element (file, "callback"); } static void @@ -468,10 +547,14 @@ write_struct_info (const gchar *namespace, if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) { - xml_printf (file, " 0) { - xml_printf (file, ">\n"); - for (i = 0; i < g_struct_info_get_n_fields (info); i++) { GIFieldInfo *field = g_struct_info_get_field (info, i); @@ -498,15 +579,9 @@ write_struct_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)function); } - if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) - xml_printf (file, " \n"); - else - xml_printf (file, " \n"); } - else - { - xml_printf (file, "/>\n"); - } + + xml_end_element_unchecked (file); } static void @@ -522,12 +597,13 @@ write_value_info (const gchar *namespace, value = g_value_info_get_value (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - xml_printf (file, " \n"); + xml_end_element (file, "member"); } static void @@ -612,22 +688,25 @@ write_constant_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - xml_printf (file, "%*s\n"); + xml_printf (file, "\""); - xml_printf (file, "%*s\n"); + xml_end_element (file, "type"); - xml_printf (file, "%*s\n", indent, ""); + xml_end_element (file, "constant"); g_base_info_unref ((GIBaseInfo *)type); } @@ -651,10 +730,10 @@ write_enum_info (const gchar *namespace, type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) - xml_printf (file, " \n"); for (i = 0; i < g_enum_info_get_n_values (info); i++) { @@ -671,10 +749,7 @@ write_enum_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)value); } - if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) - xml_printf (file, " \n"); - else - xml_printf (file, " \n"); + xml_end_element_unchecked (file); } static void @@ -690,7 +765,8 @@ write_signal_info (const gchar *namespace, flags = g_signal_info_get_flags (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - xml_printf (file, " \n"); + xml_end_element (file, "glib:signal"); } static void @@ -734,7 +810,8 @@ write_vfunc_info (const gchar *namespace, deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); offset = g_vfunc_info_get_offset (info); - xml_printf (file, " \n"); + xml_end_element (file, "vfunc"); } static void @@ -768,7 +845,8 @@ write_property_info (const gchar *namespace, flags = g_property_info_get_flags (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - xml_printf (file, " \n"); + xml_start_element (file, "type"); - xml_printf (file, " \n"); + xml_printf (file, "\""); - xml_printf (file, " \n"); + xml_end_element (file, "type"); + xml_end_element (file, "property"); } static void @@ -820,7 +899,8 @@ write_object_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - xml_printf (file, " \n"); if (g_object_info_get_n_interfaces (info) > 0) { for (i = 0; i < g_object_info_get_n_interfaces (info); i++) { GIInterfaceInfo *imp = g_object_info_get_interface (info, i); - xml_printf (file, " \n"); + xml_printf (file,"\""); + xml_end_element (file, "implements"); g_base_info_unref ((GIBaseInfo*)imp); } } @@ -892,7 +973,7 @@ write_object_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)constant); } - xml_printf (file, " \n"); + xml_end_element (file, "class"); } static void @@ -911,30 +992,31 @@ write_interface_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - xml_printf (file, " \n"); if (g_interface_info_get_n_prerequisites (info) > 0) { - xml_printf (file, " \n"); + xml_start_element (file, "requires"); for (i = 0; i < g_interface_info_get_n_prerequisites (info); i++) { GIBaseInfo *req = g_interface_info_get_prerequisite (info, i); if (g_base_info_get_type (req) == GI_INFO_TYPE_INTERFACE) - xml_printf (file, " \n"); + xml_end_element_unchecked (file); g_base_info_unref (req); } - xml_printf (file, " \n"); + xml_end_element (file, "requires"); } for (i = 0; i < g_interface_info_get_n_methods (info); i++) @@ -972,7 +1054,7 @@ write_interface_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)constant); } - xml_printf (file, " \n"); + xml_end_element (file, "interface"); } static void @@ -986,11 +1068,11 @@ write_error_domain_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); quark = g_error_domain_info_get_quark (info); enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info); - xml_printf (file, - " \n"); + xml_end_element (file, "errordomain"); g_base_info_unref (enum_); } @@ -1011,7 +1093,8 @@ write_union_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - xml_printf (file, " \n"); if (g_union_info_is_discriminated (info)) { @@ -1029,9 +1111,10 @@ write_union_info (const gchar *namespace, offset = g_union_info_get_discriminator_offset (info); type = g_union_info_get_discriminator_type (info); - xml_printf (file, " \n"); + xml_end_element (file, "discriminator"); g_base_info_unref ((GIBaseInfo *)type); } @@ -1052,7 +1135,7 @@ write_union_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)function); } - xml_printf (file, " \n"); + xml_end_element (file, "union"); } static void @@ -1095,10 +1178,11 @@ write_repository (const char *namespace, xml = xml_open (ofile); xml_printf (xml, "\n"); - xml_printf (xml, "\n"); + " xmlns:glib=\"http://www.gtk.org/introspection/glib/1.0\""); dependencies = g_irepository_get_dependencies (repository, namespace); @@ -1106,7 +1190,9 @@ write_repository (const char *namespace, { for (i = 0; dependencies[i]; i++) { - xml_printf (xml, " \n", dependencies[i]); + xml_start_element (xml, "include"); + xml_printf (xml, " name=\"%s\"", dependencies[i]); + xml_end_element (xml, "include"); } } @@ -1119,11 +1205,10 @@ write_repository (const char *namespace, version = g_irepository_get_version (repository, ns); shared_library = g_irepository_get_shared_library (repository, ns); + xml_start_element (xml, "namespace"); + xml_printf (xml, " name=\"%s\" version=\"%s\"", ns, version); if (shared_library) - xml_printf (xml, " \n", - ns, version, shared_library); - else - xml_printf (xml, " \n", ns, version); + xml_printf (xml, " shared-library=\"%s\"", shared_library); for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) { @@ -1175,10 +1260,10 @@ write_repository (const char *namespace, g_base_info_unref (info); } - xml_printf (xml, " \n"); + xml_end_element (xml, "namespace"); } - xml_printf (xml, "\n"); + xml_end_element (xml, "repository"); xml_free (xml); } -- GitLab From 8da9bc265b132f2d6c5d135606faa1ad4483c2bc Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 15 Oct 2008 22:07:33 +0000 Subject: [PATCH 53/99] remove unused indent parameters, xmlwriter keeps track of necessary 2008-10-15 Tommi Komulainen * tools/generate.c (write_field_info, write_callable_info, write_function_info, write_callback_info, write_struct_info, write_constant_value, write_signal_info, write_vfunc_info, write_object_info, write_interface_info, write_union_info, write_repository): remove unused indent parameters, xmlwriter keeps track of necessary indentation svn path=/trunk/; revision=714 --- girepository/tools/generate.c | 38 ++++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index a31a164b0e..e280dedd6d 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -350,8 +350,7 @@ write_field_info (const gchar *namespace, static void write_callable_info (const gchar *namespace, GICallableInfo *info, - Xml *file, - gint indent) + Xml *file) { GITypeInfo *type; gint i; @@ -468,8 +467,7 @@ write_callable_info (const gchar *namespace, static void write_function_info (const gchar *namespace, GIFunctionInfo *info, - Xml *file, - gint indent) + Xml *file) { GIFunctionInfoFlags flags; const gchar *tag; @@ -501,15 +499,14 @@ write_function_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - write_callable_info (namespace, (GICallableInfo*)info, file, indent); + write_callable_info (namespace, (GICallableInfo*)info, file); xml_end_element (file, tag); } static void write_callback_info (const gchar *namespace, GICallbackInfo *info, - Xml *file, - gint indent) + Xml *file) { const gchar *name; gboolean deprecated; @@ -523,7 +520,7 @@ write_callback_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - write_callable_info (namespace, (GICallableInfo*)info, file, indent); + write_callable_info (namespace, (GICallableInfo*)info, file); xml_end_element (file, "callback"); } @@ -575,7 +572,7 @@ write_struct_info (const gchar *namespace, for (i = 0; i < g_struct_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_struct_info_get_method (info, i); - write_function_info (namespace, function, file, 6); + write_function_info (namespace, function, file); g_base_info_unref ((GIBaseInfo *)function); } @@ -677,8 +674,7 @@ write_constant_value (const gchar *namespace, static void write_constant_info (const gchar *namespace, GIConstantInfo *info, - Xml *file, - gint indent) + Xml *file) { GITypeInfo *type; const gchar *name; @@ -790,7 +786,7 @@ write_signal_info (const gchar *namespace, if (flags & G_SIGNAL_NO_HOOKS) xml_printf (file, " no-hooks=\"1\""); - write_callable_info (namespace, (GICallableInfo*)info, file, 6); + write_callable_info (namespace, (GICallableInfo*)info, file); xml_end_element (file, "glib:signal"); } @@ -826,7 +822,7 @@ write_vfunc_info (const gchar *namespace, xml_printf (file, " offset=\"%d\"", offset); - write_callable_info (namespace, (GICallableInfo*)info, file, 6); + write_callable_info (namespace, (GICallableInfo*)info, file); xml_end_element (file, "vfunc"); } @@ -941,7 +937,7 @@ write_object_info (const gchar *namespace, for (i = 0; i < g_object_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_object_info_get_method (info, i); - write_function_info (namespace, function, file, 6); + write_function_info (namespace, function, file); g_base_info_unref ((GIBaseInfo *)function); } @@ -969,7 +965,7 @@ write_object_info (const gchar *namespace, for (i = 0; i < g_object_info_get_n_constants (info); i++) { GIConstantInfo *constant = g_object_info_get_constant (info, i); - write_constant_info (namespace, constant, file, 6); + write_constant_info (namespace, constant, file); g_base_info_unref ((GIBaseInfo *)constant); } @@ -1022,7 +1018,7 @@ write_interface_info (const gchar *namespace, for (i = 0; i < g_interface_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_interface_info_get_method (info, i); - write_function_info (namespace, function, file, 6); + write_function_info (namespace, function, file); g_base_info_unref ((GIBaseInfo *)function); } @@ -1050,7 +1046,7 @@ write_interface_info (const gchar *namespace, for (i = 0; i < g_interface_info_get_n_constants (info); i++) { GIConstantInfo *constant = g_interface_info_get_constant (info, i); - write_constant_info (namespace, constant, file, 6); + write_constant_info (namespace, constant, file); g_base_info_unref ((GIBaseInfo *)constant); } @@ -1131,7 +1127,7 @@ write_union_info (const gchar *namespace, for (i = 0; i < g_union_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_union_info_get_method (info, i); - write_function_info (namespace, function, file, 6); + write_function_info (namespace, function, file); g_base_info_unref ((GIBaseInfo *)function); } @@ -1216,11 +1212,11 @@ write_repository (const char *namespace, switch (g_base_info_get_type (info)) { case GI_INFO_TYPE_FUNCTION: - write_function_info (ns, (GIFunctionInfo *)info, xml, 4); + write_function_info (ns, (GIFunctionInfo *)info, xml); break; case GI_INFO_TYPE_CALLBACK: - write_callback_info (ns, (GICallbackInfo *)info, xml, 4); + write_callback_info (ns, (GICallbackInfo *)info, xml); break; case GI_INFO_TYPE_STRUCT: @@ -1238,7 +1234,7 @@ write_repository (const char *namespace, break; case GI_INFO_TYPE_CONSTANT: - write_constant_info (ns, (GIConstantInfo *)info, xml, 4); + write_constant_info (ns, (GIConstantInfo *)info, xml); break; case GI_INFO_TYPE_OBJECT: -- GitLab From b870ad079db257c0cc68d2b99ba6d8a67eb5fc29 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 15 Oct 2008 22:07:57 +0000 Subject: [PATCH 54/99] quote printf arguments so that we don't generate invalid XML by writing 2008-10-15 Tommi Komulainen * tools/generate.c (xml_printf): quote printf arguments so that we don't generate invalid XML by writing unescaped double quotes and such in attributes svn path=/trunk/; revision=715 --- girepository/tools/generate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index e280dedd6d..d4eb4e8eb3 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -65,9 +65,12 @@ static void xml_printf (Xml *xml, const char *fmt, ...) { va_list ap; + char *s; va_start (ap, fmt); - vfprintf (xml->file, fmt, ap); + s = g_markup_vprintf_escaped (fmt, ap); + fputs (s, xml->file); + g_free (s); va_end (ap); } -- GitLab From 65a653d3a9ef01065352e411bb447db53c625e20 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 15 Oct 2008 22:08:26 +0000 Subject: [PATCH 55/99] =?UTF-8?q?Bug=20556174=20=E2=80=93=20parse=20types?= =?UTF-8?q?=20for=20lists=20etc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-15 Tommi Komulainen Bug 556174 – parse types for lists etc. * girepository/girparser.c (end_type_recurse): * tests/boxed.gir: * tools/generate.c (write_type_info, write_field_info, write_callable_info, write_callable_info, write_constant_info, write_property_info): use nested s for lists and hashes svn path=/trunk/; revision=717 --- girepository/tools/generate.c | 105 +++++++++++++--------------------- 1 file changed, 41 insertions(+), 64 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index d4eb4e8eb3..fb80138db8 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -192,97 +192,112 @@ write_type_info (const gchar *namespace, if (tag == GI_TYPE_TAG_VOID) { - if (is_pointer) - xml_printf (file, "%s", "any"); - else - xml_printf (file, "%s", "none"); + xml_start_element (file, "type"); + + xml_printf (file, " name=\"%s\"", is_pointer ? "any" : "none"); + + xml_end_element (file, "type"); } else if (G_TYPE_TAG_IS_BASIC (tag)) - xml_printf (file, "%s", g_type_tag_to_string (tag)); + { + xml_start_element (file, "type"); + xml_printf (file, " name=\"%s\"", g_type_tag_to_string (tag)); + xml_end_element (file, "type"); + } else if (tag == GI_TYPE_TAG_ARRAY) { gint length; + xml_start_element (file, "array"); + type = g_type_info_get_param_type (info, 0); - write_type_info (namespace, type, file); - xml_printf (file, "["); length = g_type_info_get_array_length (info); if (length >= 0) - xml_printf (file, "length=%d", length); + xml_printf (file, " length=\"%d\"", length); if (g_type_info_is_zero_terminated (info)) - xml_printf (file, "%szero-terminated=1", length >= 0 ? "," : ""); - - xml_printf (file, "]"); + xml_printf (file, " zero-terminated=\"1\""); + + write_type_info (namespace, type, file); + g_base_info_unref ((GIBaseInfo *)type); + + xml_end_element (file, "array"); } else if (tag == GI_TYPE_TAG_INTERFACE) { GIBaseInfo *iface = g_type_info_get_interface (info); + xml_start_element (file, "type"); + xml_printf (file, " name=\""); write_type_name (namespace, iface, file); + xml_printf (file, "\""); + xml_end_element (file, "type"); g_base_info_unref (iface); } else if (tag == GI_TYPE_TAG_GLIST) { + xml_start_element (file, "type"); + xml_printf (file, " name=\"GLib.List\""); type = g_type_info_get_param_type (info, 0); - xml_printf (file, "GLib.List"); if (type) { - xml_printf (file, "<"); write_type_info (namespace, type, file); - xml_printf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } + xml_end_element (file, "type"); } else if (tag == GI_TYPE_TAG_GSLIST) { + xml_start_element (file, "type"); + xml_printf (file, " name=\"GLib.SList\""); type = g_type_info_get_param_type (info, 0); - xml_printf (file, "GLib.SList"); if (type) { - xml_printf (file, "<"); write_type_info (namespace, type, file); - xml_printf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } + xml_end_element (file, "type"); } else if (tag == GI_TYPE_TAG_GHASH) { + xml_start_element (file, "type"); + xml_printf (file, " name=\"GLib.HashTable\""); type = g_type_info_get_param_type (info, 0); - xml_printf (file, "GLib.HashTable"); if (type) { - xml_printf (file, "<"); write_type_info (namespace, type, file); g_base_info_unref ((GIBaseInfo *)type); type = g_type_info_get_param_type (info, 1); - xml_printf (file, ","); write_type_info (namespace, type, file); - xml_printf (file, ">"); g_base_info_unref ((GIBaseInfo *)type); } + xml_end_element (file, "type"); } else if (tag == GI_TYPE_TAG_ERROR) { gint n; - xml_printf (file, "GLib.Error"); + xml_start_element (file, "type"); + xml_printf (file, " name=\"GLib.Error\""); + n = g_type_info_get_n_error_domains (info); if (n > 0) { - xml_printf (file, "<"); for (i = 0; i < n; i++) { GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); - if (i > 0) - xml_printf (file, ","); + xml_start_element (file, "type"); + xml_printf (file, " name=\""); write_type_name (namespace, (GIBaseInfo *)ed, file); + xml_printf (file, "\""); + xml_end_element (file, "type"); g_base_info_unref ((GIBaseInfo *)ed); } - xml_printf (file, ">"); } + + xml_end_element (file, "type"); } else { @@ -336,17 +351,9 @@ write_field_info (const gchar *namespace, xml_printf (file, "\""); } - xml_start_element (file, "type"); - - xml_printf (file, " name=\""); - write_type_info (namespace, type, file); g_base_info_unref ((GIBaseInfo *)type); - xml_printf (file, "\""); - - xml_end_element (file, "type"); - xml_end_element (file, "field"); } @@ -382,16 +389,8 @@ write_callable_info (const gchar *namespace, if (g_callable_info_may_return_null (info)) xml_printf (file, " null-ok=\"1\""); - xml_start_element (file, "type"); - - xml_printf (file, " name=\""); - write_type_info (namespace, type, file); - xml_printf (file, "\""); - - xml_end_element (file, "type"); - xml_end_element (file, "return-value"); if (g_callable_info_get_n_args (info) <= 0) @@ -447,17 +446,9 @@ write_callable_info (const gchar *namespace, if (g_arg_info_is_optional (arg)) xml_printf (file, " optional=\"1\""); - xml_start_element (file, "type"); - - xml_printf (file, " name=\""); - type = g_arg_info_get_type (arg); write_type_info (namespace, type, file); - xml_printf (file, "\""); - - xml_end_element (file, "type"); - xml_end_element (file, "parameter"); g_base_info_unref ((GIBaseInfo *)arg); @@ -697,13 +688,7 @@ write_constant_info (const gchar *namespace, write_constant_value (namespace, type, &value, file); xml_printf (file, "\""); - xml_start_element (file, "type"); - xml_printf (file, " name=\""); - write_type_info (namespace, type, file); - xml_printf (file, "\""); - - xml_end_element (file, "type"); xml_end_element (file, "constant"); @@ -868,16 +853,8 @@ write_property_info (const gchar *namespace, type = g_property_info_get_type (info); - xml_start_element (file, "type"); - - xml_printf (file, " name=\""); - write_type_info (namespace, type, file); - xml_printf (file, "\""); - - xml_end_element (file, "type"); - xml_end_element (file, "property"); } -- GitLab From deba627f8f12cc320fccc502eec435a35bf3971d Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 15 Oct 2008 22:08:40 +0000 Subject: [PATCH 56/99] reduce code duplication 2008-10-15 Tommi Komulainen * tools/generate.c (write_type_name, write_type_info, write_type_info, write_object_info, write_object_info, write_interface_info, write_error_domain_info): reduce code duplication svn path=/trunk/; revision=718 --- girepository/tools/generate.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index fb80138db8..7493f657fa 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -175,6 +175,17 @@ write_type_name (const gchar *namespace, xml_printf (file, "%s", g_base_info_get_name (info)); } +static void +write_type_name_attribute (const gchar *namespace, + GIBaseInfo *info, + const char *attr_name, + Xml *file) +{ + xml_printf (file, " %s=\"", attr_name); + write_type_name (namespace, info, file); + xml_printf (file, "\""); +} + static void write_type_info (const gchar *namespace, GITypeInfo *info, @@ -230,9 +241,7 @@ write_type_info (const gchar *namespace, { GIBaseInfo *iface = g_type_info_get_interface (info); xml_start_element (file, "type"); - xml_printf (file, " name=\""); - write_type_name (namespace, iface, file); - xml_printf (file, "\""); + write_type_name_attribute (namespace, iface, "name", file); xml_end_element (file, "type"); g_base_info_unref (iface); } @@ -289,9 +298,7 @@ write_type_info (const gchar *namespace, { GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); xml_start_element (file, "type"); - xml_printf (file, " name=\""); - write_type_name (namespace, (GIBaseInfo *)ed, file); - xml_printf (file, "\""); + write_type_name_attribute (namespace, (GIBaseInfo *)ed, "name", file); xml_end_element (file, "type"); g_base_info_unref ((GIBaseInfo *)ed); } @@ -881,9 +888,7 @@ write_object_info (const gchar *namespace, pnode = g_object_info_get_parent (info); if (pnode) { - xml_printf (file, " parent=\""); - write_type_name (namespace, (GIBaseInfo *)pnode, file); - xml_printf (file, "\"" ); + write_type_name_attribute (namespace, (GIBaseInfo *)pnode, "parent", file); g_base_info_unref ((GIBaseInfo *)pnode); } @@ -899,9 +904,7 @@ write_object_info (const gchar *namespace, { GIInterfaceInfo *imp = g_object_info_get_interface (info, i); xml_start_element (file, "implements"); - xml_printf (file, " name=\""); - write_type_name (namespace, (GIBaseInfo*)imp, file); - xml_printf (file,"\""); + write_type_name_attribute (namespace, (GIBaseInfo *)imp, "name", file); xml_end_element (file, "implements"); g_base_info_unref ((GIBaseInfo*)imp); } @@ -987,8 +990,7 @@ write_interface_info (const gchar *namespace, xml_start_element (file, "interface"); else xml_start_element (file, "object"); - xml_printf (file, " name=\""); - write_type_name (namespace, req, file); + write_type_name_attribute (namespace, req, "name", file); xml_end_element_unchecked (file); g_base_info_unref (req); } @@ -1045,9 +1047,9 @@ write_error_domain_info (const gchar *namespace, quark = g_error_domain_info_get_quark (info); enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info); xml_start_element (file, "errordomain"); - xml_printf (file, " name=\"%s\" get-quark=\"%s\" codes=\"", + xml_printf (file, " name=\"%s\" get-quark=\"%s\"", name, quark); - write_type_name (namespace, enum_, file); + write_type_name_attribute (namespace, enum_, "codes", file); xml_end_element (file, "errordomain"); g_base_info_unref (enum_); } -- GitLab From c874b58562138267a2940be682c1bcef69391a30 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 16 Oct 2008 13:16:30 +0000 Subject: [PATCH 57/99] Fix up g-ir-generate for new include= syntax svn path=/trunk/; revision=726 --- girepository/tools/generate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 7493f657fa..74dd41a0e9 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1168,9 +1168,11 @@ write_repository (const char *namespace, { for (i = 0; dependencies[i]; i++) { + char **parts = g_strsplit (dependencies[i], "-", 2); xml_start_element (xml, "include"); - xml_printf (xml, " name=\"%s\"", dependencies[i]); + xml_printf (xml, " name=\"%s\" version=\"%s\"", parts[0], parts[1]); xml_end_element (xml, "include"); + g_strfreev (parts); } } -- GitLab From 477412eeca7998a5b66e51f6fab2b376985ff59e Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Thu, 16 Oct 2008 17:07:05 +0000 Subject: [PATCH 58/99] =?UTF-8?q?Bug=20556543=20=E2=80=93=20reduce=20compi?= =?UTF-8?q?ler=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-16 Tommi Komulainen Bug 556543 – reduce compiler warnings * girepository/ginfo.c: * girepository/girepository.c (register_internal, count_interfaces, find_interface, find_namespace_version, parse_version, g_irepository_require): * girepository/girmodule.c (g_ir_module_build_typelib): * girepository/girnode.c (init_stats, dump_stats, _g_irnode_init_stats, _g_irnode_dump_stats, g_ir_node_can_have_member): * girepository/girparser.c (firstpass_end_element_handler, locate_gir, parse_basic, parse_type_internal, resolve_aliases, start_alias, start_type, end_type_top, parse_include, cleanup, post_filter): * girepository/gtypelib.c (validate_function_blob, validate_enum_blob): * giscanner/giscannermodule.c (directive_get_options, type_get_child_list): * giscanner/scannerlexer.l (parse_gtkdoc): * giscanner/scannerparser.y (ctype_free): * giscanner/sourcescanner.c: * giscanner/sourcescanner.h (gi_source_scanner_parse_macros): * tests/types/gitesttypes.c: * tools/compiler.c (main): * tools/generate.c (write_repository): Remove unused variables and code, add missing includes, declarations and case statements. svn path=/trunk/; revision=730 --- girepository/tools/generate.c | 1 - 1 file changed, 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 74dd41a0e9..0e286fb9a4 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1121,7 +1121,6 @@ write_repository (const char *namespace, gboolean needs_prefix) { FILE *ofile; - gchar *ns; gint i, j; char **dependencies; GIRepository *repository; -- GitLab From 80429426af17f23670f54e0f52a71887451b2a28 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Fri, 17 Oct 2008 14:57:38 +0000 Subject: [PATCH 59/99] =?UTF-8?q?Bug=20556732=20=E2=80=93=20generate=20gir?= =?UTF-8?q?=20files=20consistently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-17 Tommi Komulainen Bug 556732 – generate gir files consistently * giscanner/girwriter.py (_write_property): write properties 'construct' attribute if set * tools/generate.c (write_property_info): write properties 'readable' and 'writable' attributes only if non-default * tests/object.gir: add writable="0" * tests/scanner/foo-1.0-expected.gir: add construct="1" svn path=/trunk/; revision=742 --- girepository/tools/generate.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 0e286fb9a4..729583f30f 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -841,16 +841,12 @@ write_property_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - - if (flags & G_PARAM_READABLE) - xml_printf (file, " readable=\"1\""); - else - xml_printf (file, " readable=\"0\""); + /* Properties are assumed to be read-only (see also girwriter.py) */ + if (!(flags & G_PARAM_READABLE)) + xml_printf (file, " readable=\"0\""); if (flags & G_PARAM_WRITABLE) xml_printf (file, " writable=\"1\""); - else - xml_printf (file, " writable=\"0\""); if (flags & G_PARAM_CONSTRUCT) xml_printf (file, " construct=\"1\""); -- GitLab From 3bddeae0fa4cb2af3afa84b2c9d1ae71547e6706 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Fri, 17 Oct 2008 14:58:37 +0000 Subject: [PATCH 60/99] =?UTF-8?q?Bug=20556732=20=E2=80=93=20generate=20gir?= =?UTF-8?q?=20files=20consistently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-17 Tommi Komulainen Bug 556732 – generate gir files consistently * giscanner/ast.py (Field): add readable and writable properties * giscanner/girparser.py (_parse_field): copy 'readable' and 'writable' attributes * giscanner/transformer.py (_create_member): create fields as read-write * giscanner/glibtransformer.py (_introspect_object, _pair_class_struct): make object instance and class fields read-only * giscanner/girwriter.py (_write_field): * tools/generate.c (write_field_info): write field 'readable' and 'writable' attributes only if non-default (read-only) * girepository/girparser.c (start_field): in the absence of attributes assume fields are read-only * tests/boxed.gir: * tests/struct.gir: remove redundant readable="1" from fields * tests/scanner/foo-1.0-expected.gir: * tests/scanner/utility-1.0-expected.gir: add writable="1" to all record and union fields svn path=/trunk/; revision=743 --- girepository/tools/generate.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 729583f30f..fa7dd46b97 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -338,10 +338,16 @@ write_field_info (const gchar *namespace, offset = g_field_info_get_offset (info); xml_start_element (file, "field"); - xml_printf (file, " name=\"%s\" readable=\"%s\" writable=\"%s\"", - name, - flags & GI_FIELD_IS_READABLE ? "1" : "0", - flags & GI_FIELD_IS_WRITABLE ? "1" : "0"); + xml_printf (file, " name=\"%s\"", name); + + /* Fields are assumed to be read-only + * (see also girwriter.py and girparser.c) + */ + if (!(flags & GI_FIELD_IS_READABLE)) + xml_printf (file, " readable=\"0\""); + if (flags & GI_FIELD_IS_WRITABLE) + xml_printf (file, " writable=\"1\""); + if (size) xml_printf (file, " bits=\"%d\"", size); -- GitLab From 66a5209b6c6e225e516576d8d467f335dd67f510 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Fri, 17 Oct 2008 14:59:07 +0000 Subject: [PATCH 61/99] =?UTF-8?q?Bug=20556732=20=E2=80=93=20generate=20gir?= =?UTF-8?q?=20files=20consistently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-17 Tommi Komulainen Bug 556732 – generate gir files consistently * tools/generate.c (write_callable_info): write 'direction' attribute only if other than 'in' to be consistent with girwriter.py * tests/boxed.gir: * tests/object.gir: remove direction="in" which is the default svn path=/trunk/; revision=744 --- girepository/tools/generate.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index fa7dd46b97..52c706424e 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -432,20 +432,17 @@ write_callable_info (const gchar *namespace, g_assert_not_reached (); } - xml_printf (file, " direction=\""); switch (g_arg_info_get_direction (arg)) { case GI_DIRECTION_IN: - xml_printf (file, "in"); break; case GI_DIRECTION_OUT: - xml_printf (file, "out"); + xml_printf (file, " direction=\"out\""); break; case GI_DIRECTION_INOUT: - xml_printf (file, "inout"); + xml_printf (file, " direction=\"inout\""); break; } - xml_printf (file, "\""); if (g_arg_info_may_be_null (arg)) xml_printf (file, " null-ok=\"1\""); -- GitLab From d3e2ead0dbaa4b1a9ac755698a3c028e8404fd20 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Fri, 17 Oct 2008 14:59:23 +0000 Subject: [PATCH 62/99] =?UTF-8?q?Bug=20556732=20=E2=80=93=20generate=20gir?= =?UTF-8?q?=20files=20consistently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-17 Tommi Komulainen Bug 556732 – generate gir files consistently * girepository/girparser.c (start_parameter): * tests/boxed.gir: * tests/invoke/testfns-1.0.gir: * tools/generate.c (write_callable_info): write 'transfer-ownership' attribute consistently with both return-value and parameter elements svn path=/trunk/; revision=745 --- girepository/tools/generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 52c706424e..7294506f3d 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -423,10 +423,10 @@ write_callable_info (const gchar *namespace, case GI_TRANSFER_NOTHING: break; case GI_TRANSFER_CONTAINER: - xml_printf (file, " transfer=\"container\""); + xml_printf (file, " transfer-ownership=\"container\""); break; case GI_TRANSFER_EVERYTHING: - xml_printf (file, " transfer=\"full\""); + xml_printf (file, " transfer-ownership=\"full\""); break; default: g_assert_not_reached (); -- GitLab From cb720c675e1590e34744a6e8c6d435681e49e9c0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 21 Oct 2008 18:20:25 +0000 Subject: [PATCH 63/99] Write out throws attribute svn path=/trunk/; revision=776 --- girepository/tools/generate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 7294506f3d..42ce9e4356 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -478,11 +478,13 @@ write_function_info (const gchar *namespace, const gchar *name; const gchar *symbol; gboolean deprecated; + gboolean throws; flags = g_function_info_get_flags (info); name = g_base_info_get_name ((GIBaseInfo *)info); symbol = g_function_info_get_symbol (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + throws = flags & GI_FUNCTION_THROWS; if (flags & GI_FUNCTION_IS_CONSTRUCTOR) tag = "constructor"; @@ -503,6 +505,9 @@ write_function_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); + if (throws) + xml_printf (file, " throws=\"1\""); + write_callable_info (namespace, (GICallableInfo*)info, file); xml_end_element (file, tag); } -- GitLab From 659a300f875b676cddb98232c5456106bf964ed7 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 22 Oct 2008 14:02:02 +0000 Subject: [PATCH 64/99] =?UTF-8?q?Bug=20557405=20=E2=80=93=20Use=20'allow-n?= =?UTF-8?q?one'=20consistently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-22 Tommi Komulainen * docs/typelib-format.txt: * girepository/ginfo.c (g_arg_info_may_be_null): * girepository/girnode.c (g_ir_node_build_typelib): * girepository/girnode.h (struct _GIrNodeParam): * girepository/girparser.c (start_parameter): * girepository/girwriter.c (function_generate): * girepository/gtypelib.h (ArgBlob): * tests/errors.gir: * tests/function.gir: * tools/generate.c (write_callable_info): Use 'allow-none' consistently throughout svn path=/trunk/; revision=782 --- girepository/tools/generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 42ce9e4356..b6e6fc8646 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -400,7 +400,7 @@ write_callable_info (const gchar *namespace, } if (g_callable_info_may_return_null (info)) - xml_printf (file, " null-ok=\"1\""); + xml_printf (file, " allow-none=\"1\""); write_type_info (namespace, type, file); @@ -445,7 +445,7 @@ write_callable_info (const gchar *namespace, } if (g_arg_info_may_be_null (arg)) - xml_printf (file, " null-ok=\"1\""); + xml_printf (file, " allow-none=\"1\""); if (g_arg_info_is_dipper (arg)) xml_printf (file, " dipper=\"1\""); -- GitLab From e4542c021c8a229396727e582df50a9cc1fe4be6 Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Wed, 22 Oct 2008 16:46:19 +0000 Subject: [PATCH 65/99] =?UTF-8?q?Bug=20557379=20=E2=80=93=20g-ir-generate?= =?UTF-8?q?=20not=20writing=20the=20'abstract'=20attribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-22 Tommi Komulainen * tests/scanner/drawable-1.0-expected.tgir: * tests/scanner/drawable-injected-1.0-expected.tgir: * tests/scanner/foo-1.0-expected.tgir: * tools/generate.c (write_object_info): write 'abstract' attribute for classes svn path=/trunk/; revision=785 --- girepository/tools/generate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index b6e6fc8646..8a3b1d865d 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -878,11 +878,13 @@ write_object_info (const gchar *namespace, const gchar *type_name; const gchar *type_init; gboolean deprecated; + gboolean is_abstract; GIObjectInfo *pnode; gint i; name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); + is_abstract = g_object_info_get_abstract (info); type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); @@ -896,6 +898,9 @@ write_object_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)pnode); } + if (is_abstract) + xml_printf (file, " abstract=\"1\""); + xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init); if (deprecated) -- GitLab From d9ab34b17c7f201133d661217305ce25471a0a0a Mon Sep 17 00:00:00 2001 From: Tommi Komulainen Date: Thu, 23 Oct 2008 17:42:25 +0000 Subject: [PATCH 66/99] =?UTF-8?q?Bug=20556739=20=E2=80=93=20transfer-owner?= =?UTF-8?q?ship=20attribute=20should=20be=20mandatory=20in=20.gir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-10-23 Tommi Komulainen * girepository/girparser.c (parse_param_transfer): * giscanner/transformer.py (_create_parameter, _create_return): * giscanner/girwriter.py (_write_return, _write_parameter): * tools/generate.c (write_callable_info): always write and require "transfer-ownership" for return-values and parameters * tests/boxed.gir: * tests/invoke/testfns-1.0.gir: * tests/object.gir: * tests/scanner/DrawableAdditions.xml: * tests/scanner/GtkFrob-1.0-expected.tgir: * tests/scanner/annotation-1.0-expected.tgir: * tests/scanner/drawable-1.0-expected.tgir: * tests/scanner/drawable-injected-1.0-expected.gir: * tests/scanner/drawable-injected-1.0-expected.tgir: * tests/scanner/foo-1.0-expected.tgir: Updated svn path=/trunk/; revision=797 --- girepository/tools/generate.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 8a3b1d865d..fad680f5d2 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -382,21 +382,19 @@ write_callable_info (const gchar *namespace, xml_start_element (file, "return-value"); - if (g_type_info_is_pointer (type)) + switch (g_callable_info_get_caller_owns (info)) { - switch (g_callable_info_get_caller_owns (info)) - { - case GI_TRANSFER_NOTHING: - break; - case GI_TRANSFER_CONTAINER: - xml_printf (file, " transfer-ownership=\"container\""); - break; - case GI_TRANSFER_EVERYTHING: - xml_printf (file, " transfer-ownership=\"full\""); - break; - default: - g_assert_not_reached (); - } + case GI_TRANSFER_NOTHING: + xml_printf (file, " transfer-ownership=\"none\""); + break; + case GI_TRANSFER_CONTAINER: + xml_printf (file, " transfer-ownership=\"container\""); + break; + case GI_TRANSFER_EVERYTHING: + xml_printf (file, " transfer-ownership=\"full\""); + break; + default: + g_assert_not_reached (); } if (g_callable_info_may_return_null (info)) @@ -421,6 +419,7 @@ write_callable_info (const gchar *namespace, switch (g_arg_info_get_ownership_transfer (arg)) { case GI_TRANSFER_NOTHING: + xml_printf (file, " transfer-ownership=\"none\""); break; case GI_TRANSFER_CONTAINER: xml_printf (file, " transfer-ownership=\"container\""); -- GitLab From 2d1e6e2c5ccdd7e682e3f7b065dbb71e76719e88 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 25 Oct 2008 15:20:54 +0000 Subject: [PATCH 67/99] Bug 557786 - support fixed size arrays svn path=/trunk/; revision=814 --- girepository/tools/generate.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index fad680f5d2..c9b2f8a1b6 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -217,16 +217,19 @@ write_type_info (const gchar *namespace, } else if (tag == GI_TYPE_TAG_ARRAY) { - gint length; - + gint length, size; + xml_start_element (file, "array"); type = g_type_info_get_param_type (info, 0); length = g_type_info_get_array_length (info); - if (length >= 0) - xml_printf (file, " length=\"%d\"", length); + xml_printf (file, " length=\"%d\"", length); + + size = g_type_info_get_array_fixed_size (info); + if (size >= 0) + xml_printf (file, " fixed-size=\"%d\"", size); if (g_type_info_is_zero_terminated (info)) xml_printf (file, " zero-terminated=\"1\""); -- GitLab From 1892f7dcfd95b2a190aca1064398f4ca3994f693 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Tue, 11 Nov 2008 05:10:47 +0000 Subject: [PATCH 68/99] Remove field offsets from g-ir-generate output and test inputs Field offsets are a) architecture dependent so they shouldn't be part of the architecture-independent gir format which is installed in datadir. b) Are architecture-dependent so they shouldn't be in test expected output. Remove field offsets from girs. (Virtual function and discriminator offsets are not removed, as they aren't fully hooked up to the field-offset computation machinery yet.) svn path=/trunk/; revision=877 --- girepository/tools/generate.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index c9b2f8a1b6..840de7ca53 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -354,8 +354,6 @@ write_field_info (const gchar *namespace, if (size) xml_printf (file, " bits=\"%d\"", size); - xml_printf (file, " offset=\"%d\"", offset); - type = g_field_info_get_type (info); if (branch) -- GitLab From fcdfe8dbd97dfacffdffd817ccaebd4fc5bf1960 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 17 Nov 2008 00:27:39 +0000 Subject: [PATCH 69/99] Also generate new syntax svn path=/trunk/; revision=933 --- girepository/tools/generate.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 840de7ca53..7c849bcda1 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -986,24 +986,19 @@ write_interface_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - if (g_interface_info_get_n_prerequisites (info) > 0) { - xml_start_element (file, "requires"); for (i = 0; i < g_interface_info_get_n_prerequisites (info); i++) { GIBaseInfo *req = g_interface_info_get_prerequisite (info, i); - - if (g_base_info_get_type (req) == GI_INFO_TYPE_INTERFACE) - xml_start_element (file, "interface"); - else - xml_start_element (file, "object"); + + xml_start_element (file, "prerequisite"); write_type_name_attribute (namespace, req, "name", file); + xml_end_element_unchecked (file); g_base_info_unref (req); } - xml_end_element (file, "requires"); } for (i = 0; i < g_interface_info_get_n_methods (info); i++) -- GitLab From 981e55ef57971dcdd47b660f70cc28b541b12555 Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Sat, 3 Jan 2009 13:44:42 +0000 Subject: [PATCH 70/99] =?UTF-8?q?Bug=20556489=20=E2=80=93=20callback=20ann?= =?UTF-8?q?otations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-01-03 Andreas Rottmann Bug 556489 – callback annotations * giscanner/transformer.py * tools/generate.c (write_callable_info): Write out the new scope, closure and destroy attributes. * giscanner/transformer.py (Transformer._type_is_callback): New method, checking if a given type is a callback. (Transformer._augment_callback_params): New method; adds information (closure, destroy) to callback parameters. (Transformer._handle_closure, Transformer._handle_destroy): New methods, auxiliary to _augment_callback_params. (Transformer._create_function): Call _augment_callback_params(). (Transformer._create_parameter): Handle scope option. (Transformer._create_typedef_callback): New method, creates a callback, and registers it in the typedef namespace (Transformer._create_typedef): Use _create_typedef_callback() instead of the plain _create_callback(). * giscanner/ast.py (Parameter): Added callback-related fields. * giscanner/girwriter.py: Write out new Parameter fields. * girepository/girnode.h (GIrNodeParam): Added fields scope, closure and destroy. * girepository/gtypelib.h (ArgBlob): Ditto. * girepository/girparser.c (start_parameter): Handle new fields. * girepository/girmodule.c (g_ir_module_build_typelib): Adjust arg_blob_size, bump major version due to this change. * girepository/girnode.c (g_ir_node_get_full_size_internal) (g_ir_node_build_typelib) * girepository/gtypelib.c (g_typelib_check_sanity): ArgBlob size adjustments. (g_ir_node_build_typelib): Fill in new ArgBlob flags from param. * girepository/girepository.h (GIScope): New enumeration, listing the different possible scopes for callbacks. * girepository/ginfo.c (g_arg_info_get_scope) (g_arg_info_get_closure, g_arg_info_get_destroy): Accessors for callback-related argument indices (callback scope, closure for a callback, destroy notification for a callback). * tests/scanner/: Added testcases for new features. svn path=/trunk/; revision=998 --- girepository/tools/generate.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 7c849bcda1..dcc36faf9a 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -455,6 +455,30 @@ write_callable_info (const gchar *namespace, if (g_arg_info_is_optional (arg)) xml_printf (file, " optional=\"1\""); + + switch (g_arg_info_get_scope (arg)) + { + case GI_SCOPE_TYPE_INVALID: + break; + case GI_SCOPE_TYPE_CALL: + xml_printf (file, " scope=\"call\""); + break; + case GI_SCOPE_TYPE_OBJECT: + xml_printf (file, " scope=\"object\""); + break; + case GI_SCOPE_TYPE_ASYNC: + xml_printf (file, " scope=\"async\""); + break; + case GI_SCOPE_TYPE_NOTIFIED: + xml_printf (file, " scope=\"notified\""); + break; + } + + if (g_arg_info_get_closure (arg) >= 0) + xml_printf (file, " closure=\"%d\"", g_arg_info_get_closure (arg)); + + if (g_arg_info_get_destroy (arg) >= 0) + xml_printf (file, " destroy=\"%d\"", g_arg_info_get_destroy (arg)); type = g_arg_info_get_type (arg); write_type_info (namespace, type, file); -- GitLab From d90d14cf672fb02f2bc52ee27ce3954224426cc4 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 6 Feb 2009 18:37:13 +0000 Subject: [PATCH 71/99] Bug 551738 - Associate classes with their structs Inside glibtransformer, we now look at structures ending in "Class" and see if they have an associated GlibObject (i.e. a structure of the same name without the "Class" suffix). If found, pair them up. The .gir file for gains an attribute denoting its associated class struct. Any many now have a glib:is-class-struct-for annotation which tells which (if any) for which it defines the layout. In the .typelib, we record the association between the class and its structure. Generic structures however just have a boolean saying whether they're a class struct. (Going from a generic class struct to its class should not be necessary). Finally, we expose GIRepository APIs to access both bits of information from the .typelib. svn path=/trunk/; revision=1088 --- girepository/tools/generate.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index dcc36faf9a..8b4185fcec 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -566,6 +566,7 @@ write_struct_info (const gchar *namespace, const gchar *type_name; const gchar *type_init; gboolean deprecated; + gboolean is_class_struct; gint i; int n_elts; @@ -591,6 +592,10 @@ write_struct_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); + + is_class_struct = g_struct_info_is_class_struct (info); + if (is_class_struct) + xml_printf (file, " glib:is-class-struct=\"1\""); n_elts = g_struct_info_get_n_fields (info) + g_struct_info_get_n_methods (info); if (n_elts > 0) @@ -904,6 +909,7 @@ write_object_info (const gchar *namespace, gboolean deprecated; gboolean is_abstract; GIObjectInfo *pnode; + GIStructInfo *class_struct; gint i; name = g_base_info_get_name ((GIBaseInfo *)info); @@ -921,6 +927,13 @@ write_object_info (const gchar *namespace, write_type_name_attribute (namespace, (GIBaseInfo *)pnode, "parent", file); g_base_info_unref ((GIBaseInfo *)pnode); } + + class_struct = g_object_info_get_class_struct (info); + if (class_struct) + { + write_type_name_attribute (namespace, (GIBaseInfo*) class_struct, "glib:class-struct", file); + g_base_info_unref ((GIBaseInfo*)class_struct); + } if (is_abstract) xml_printf (file, " abstract=\"1\""); -- GitLab From cd2dcdf1f4f9f401dc69f3a063f98830bc428947 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 20 Feb 2009 17:34:20 -0500 Subject: [PATCH 72/99] Bug 572434 - Associate interfaces with their C structures Similar to GObject class structs, we pair up GInterfaces with their C structures. Also, move some GLib-specific things into glibast.py, and make the naming more generic. --- girepository/tools/generate.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 8b4185fcec..80c3980775 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -566,7 +566,7 @@ write_struct_info (const gchar *namespace, const gchar *type_name; const gchar *type_init; gboolean deprecated; - gboolean is_class_struct; + gboolean is_gtype_struct; gint i; int n_elts; @@ -593,9 +593,9 @@ write_struct_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - is_class_struct = g_struct_info_is_class_struct (info); - if (is_class_struct) - xml_printf (file, " glib:is-class-struct=\"1\""); + is_gtype_struct = g_struct_info_is_gtype_struct (info); + if (is_gtype_struct) + xml_printf (file, " glib:is-gtype-struct=\"1\""); n_elts = g_struct_info_get_n_fields (info) + g_struct_info_get_n_methods (info); if (n_elts > 0) @@ -931,7 +931,7 @@ write_object_info (const gchar *namespace, class_struct = g_object_info_get_class_struct (info); if (class_struct) { - write_type_name_attribute (namespace, (GIBaseInfo*) class_struct, "glib:class-struct", file); + write_type_name_attribute (namespace, (GIBaseInfo*) class_struct, "glib:type-struct", file); g_base_info_unref ((GIBaseInfo*)class_struct); } @@ -1009,6 +1009,7 @@ write_interface_info (const gchar *namespace, const gchar *name; const gchar *type_name; const gchar *type_init; + GIStructInfo *class_struct; gboolean deprecated; gint i; @@ -1021,6 +1022,13 @@ write_interface_info (const gchar *namespace, xml_printf (file, " name=\"%s\" glib:type-name=\"%s\" glib:get-type=\"%s\"", name, type_name, type_init); + class_struct = g_interface_info_get_iface_struct (info); + if (class_struct) + { + write_type_name_attribute (namespace, (GIBaseInfo*) class_struct, "glib:type-struct", file); + g_base_info_unref ((GIBaseInfo*)class_struct); + } + if (deprecated) xml_printf (file, " deprecated=\"1\""); -- GitLab From ae73e2e4e6327a9c998af33d4fdd6d8e0cfa14b3 Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Fri, 27 Feb 2009 00:17:16 +0100 Subject: [PATCH 73/99] Add --all option to g-ir-generate Add --all option, which is intended to show some information not usually included in the GIR. Currently, it shows the size of structs and unions. Signed-off-by: Andreas Rottmann --- girepository/tools/generate.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 80c3980775..b95e05221a 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -32,6 +32,7 @@ /* FIXME: Avoid global */ static gchar *output = NULL; gchar **includedirs = NULL; +static gboolean show_all = FALSE; typedef struct { FILE *file; @@ -365,6 +366,12 @@ write_field_info (const gchar *namespace, xml_printf (file, "\""); } + if (show_all) + { + if (offset >= 0) + xml_printf (file, "offset=\"%d\"", offset); + } + write_type_info (namespace, type, file); g_base_info_unref ((GIBaseInfo *)type); @@ -568,6 +575,7 @@ write_struct_info (const gchar *namespace, gboolean deprecated; gboolean is_gtype_struct; gint i; + gint size; int n_elts; name = g_base_info_get_name ((GIBaseInfo *)info); @@ -597,6 +605,10 @@ write_struct_info (const gchar *namespace, if (is_gtype_struct) xml_printf (file, " glib:is-gtype-struct=\"1\""); + size = g_struct_info_get_size (info); + if (show_all && size >= 0) + xml_printf (file, " size=\"%d\"", size); + n_elts = g_struct_info_get_n_fields (info) + g_struct_info_get_n_methods (info); if (n_elts > 0) { @@ -1113,6 +1125,7 @@ write_union_info (const gchar *namespace, const gchar *type_init; gboolean deprecated; gint i; + gint size; name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); @@ -1129,6 +1142,9 @@ write_union_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); + size = g_union_info_get_size (info); + if (show_all && size >= 0) + xml_printf (file, " size=\"%d\"", size); if (g_union_info_is_discriminated (info)) { @@ -1349,7 +1365,8 @@ main (int argc, char *argv[]) { { "shlib", 0, 0, G_OPTION_ARG_NONE, &shlib, "handle typelib embedded in shlib", NULL }, { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, - { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL }, + { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL }, + { "all", 0, 0, G_OPTION_ARG_NONE, &show_all, "show all available information", NULL, }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, { NULL, } }; -- GitLab From 43c682703cb91f23fb72a0bbffe338d50be78c69 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 19 Feb 2009 21:48:51 -0500 Subject: [PATCH 74/99] Bug 571548 - Generic attributes We now support an extensible mechanism where arbitrary key-value pairs may be associated with almost all items, including objects, methods, and properties. These attributes appear in both the .gir and the .typelib. --- girepository/tools/generate.c | 42 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index b95e05221a..c4d7291244 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -2,6 +2,7 @@ /* GObject introspection: IDL generator * * Copyright (C) 2005 Matthias Clasen + * Copyright (C) 2008,2009 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -317,6 +318,21 @@ write_type_info (const gchar *namespace, } } +static void +write_attributes (Xml *file, + GIBaseInfo *info) +{ + GIAttributeIter iter = { 0, }; + char *name, *value; + + while (g_base_info_iterate_attributes (info, &iter, &name, &value)) + { + xml_start_element (file, "attribute"); + xml_printf (file, " name=\"%s\" value=\"%s\"", name, value); + xml_end_element (file, "attribute"); + } +} + static void write_constant_value (const gchar *namespace, GITypeInfo *info, @@ -355,6 +371,8 @@ write_field_info (const gchar *namespace, if (size) xml_printf (file, " bits=\"%d\"", size); + write_attributes (file, (GIBaseInfo*) info); + type = g_field_info_get_type (info); if (branch) @@ -386,6 +404,8 @@ write_callable_info (const gchar *namespace, GITypeInfo *type; gint i; + write_attributes (file, (GIBaseInfo*) info); + type = g_callable_info_get_return_type (info); xml_start_element (file, "return-value"); @@ -604,6 +624,8 @@ write_struct_info (const gchar *namespace, is_gtype_struct = g_struct_info_is_gtype_struct (info); if (is_gtype_struct) xml_printf (file, " glib:is-gtype-struct=\"1\""); + + write_attributes (file, (GIBaseInfo*) info); size = g_struct_info_get_size (info); if (show_all && size >= 0) @@ -650,6 +672,8 @@ write_value_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); + write_attributes (file, (GIBaseInfo*) info); + xml_end_element (file, "member"); } @@ -746,6 +770,8 @@ write_constant_info (const gchar *namespace, write_type_info (namespace, type, file); + write_attributes (file, (GIBaseInfo*) info); + xml_end_element (file, "constant"); g_base_info_unref ((GIBaseInfo *)type); @@ -780,7 +806,8 @@ write_enum_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - + + write_attributes (file, (GIBaseInfo*) info); for (i = 0; i < g_enum_info_get_n_values (info); i++) { @@ -902,7 +929,9 @@ write_property_info (const gchar *namespace, if (flags & G_PARAM_CONSTRUCT_ONLY) xml_printf (file, " construct-only=\"1\""); - + + write_attributes (file, (GIBaseInfo*) info); + type = g_property_info_get_type (info); write_type_info (namespace, type, file); @@ -954,7 +983,8 @@ write_object_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - + + write_attributes (file, (GIBaseInfo*) info); if (g_object_info_get_n_interfaces (info) > 0) { @@ -1044,6 +1074,8 @@ write_interface_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); + write_attributes (file, (GIBaseInfo*) info); + if (g_interface_info_get_n_prerequisites (info) > 0) { for (i = 0; i < g_interface_info_get_n_prerequisites (info); i++) @@ -1141,11 +1173,13 @@ write_union_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - + size = g_union_info_get_size (info); if (show_all && size >= 0) xml_printf (file, " size=\"%d\"", size); + write_attributes (file, (GIBaseInfo*) info); + if (g_union_info_is_discriminated (info)) { gint offset; -- GitLab From 02bb4f8d6a5f489cde17e84f45e0703bdead6303 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 27 Feb 2009 19:02:48 -0500 Subject: [PATCH 75/99] Bug 557383 - Virtual method support Broadly speaking, this change adds the concept of to the .gir. The typelib already had most of the infrastructure for virtual functions, though there is one API addition. The scanner assumes that any class callback slot that doesn't match a signal name is a virtual. In the .gir, we write out *both* the wrapper and a . If we can determine an association between them (based on the names matching, or a new Virtual: annotation), then we notate that in the .gir. The typelib gains an association from the vfunc to the function, if it exists. This will be useful for bindings since they already know how to consume FunctionInfo. --- girepository/tools/generate.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index c4d7291244..48d7dfb628 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -869,6 +869,7 @@ write_vfunc_info (const gchar *namespace, { GIVFuncInfoFlags flags; const gchar *name; + GIFunctionInfo *invoker; gboolean deprecated; gint offset; @@ -876,8 +877,9 @@ write_vfunc_info (const gchar *namespace, flags = g_vfunc_info_get_flags (info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); offset = g_vfunc_info_get_offset (info); + invoker = g_vfunc_info_get_invoker (info); - xml_start_element (file, "vfunc"); + xml_start_element (file, "virtual-method"); xml_printf (file, " name=\"%s\"", name); if (deprecated) @@ -893,9 +895,12 @@ write_vfunc_info (const gchar *namespace, xml_printf (file, " offset=\"%d\"", offset); + if (invoker) + xml_printf (file, " invoker=\"%s\"", g_base_info_get_name ((GIBaseInfo*)invoker)); + write_callable_info (namespace, (GICallableInfo*)info, file); - xml_end_element (file, "vfunc"); + xml_end_element (file, "virtual-method"); } static void -- GitLab From f979d003ce072fca8e119c794df840c819b54b45 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 12 Feb 2009 18:42:47 -0500 Subject: [PATCH 76/99] Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype Parse the c:prefix from the .gir, include it in the header. Armed with this information, we can now optimize lookups of GTypes because we have the requirement that GTypes must start with the c:prefix. We do fall back though if a lookup fails. --- girepository/tools/generate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 48d7dfb628..f876721841 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1282,16 +1282,20 @@ write_repository (const char *namespace, if (TRUE) { const gchar *shared_library; + const gchar *c_prefix; const char *ns = namespace; const char *version; version = g_irepository_get_version (repository, ns); shared_library = g_irepository_get_shared_library (repository, ns); + c_prefix = g_irepository_get_c_prefix (repository, ns); xml_start_element (xml, "namespace"); xml_printf (xml, " name=\"%s\" version=\"%s\"", ns, version); if (shared_library) xml_printf (xml, " shared-library=\"%s\"", shared_library); + if (c_prefix) + xml_printf (xml, " c:prefix=\"%s\"", c_prefix); for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) { -- GitLab From 7a6056cbebfa014b7a90b4ff2c563d6e18a591a7 Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Fri, 27 Mar 2009 19:31:55 +0100 Subject: [PATCH 77/99] Bug 576605 - Get rid of GI_SCOPE_TYPE_OBJECT Remove support for (scope object) as it lacks a real use case. --- girepository/tools/generate.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index f876721841..a71f3654cf 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -490,9 +490,6 @@ write_callable_info (const gchar *namespace, case GI_SCOPE_TYPE_CALL: xml_printf (file, " scope=\"call\""); break; - case GI_SCOPE_TYPE_OBJECT: - xml_printf (file, " scope=\"object\""); - break; case GI_SCOPE_TYPE_ASYNC: xml_printf (file, " scope=\"async\""); break; -- GitLab From 90c166144ca73b9199738a73637b0792b6b63bb1 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Mon, 9 Nov 2009 19:17:23 +0100 Subject: [PATCH 78/99] Implement callbacks as part of struct fields. Fixes #557383 gir: embed inside typelib: if a field contains a callback, store it just after the FieldBlob girepository API: no additions --- girepository/tools/generate.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index a71f3654cf..fcff5b62cf 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -339,6 +339,11 @@ write_constant_value (const gchar *namespace, GArgument *argument, Xml *file); +static void +write_callback_info (const gchar *namespace, + GICallbackInfo *info, + Xml *file); + static void write_field_info (const gchar *namespace, GIFieldInfo *info, @@ -350,6 +355,7 @@ write_field_info (const gchar *namespace, gint size; gint offset; GITypeInfo *type; + GIBaseInfo *interface; GArgument value; name = g_base_info_get_name ((GIBaseInfo *)info); @@ -389,8 +395,16 @@ write_field_info (const gchar *namespace, if (offset >= 0) xml_printf (file, "offset=\"%d\"", offset); } - - write_type_info (namespace, type, file); + + interface = g_type_info_get_interface (type); + if (interface && g_base_info_get_type(interface) == GI_INFO_TYPE_CALLBACK) + write_callback_info (namespace, (GICallbackInfo *)interface, file); + else + write_type_info (namespace, type, file); + + if (interface) + g_base_info_unref (interface); + g_base_info_unref ((GIBaseInfo *)type); xml_end_element (file, "field"); -- GitLab From 567a6d2195ac0f37413a090bd66ceb792a5654ff Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Thu, 25 Mar 2010 09:17:03 -0300 Subject: [PATCH 79/99] Remove trailing whitespace --- girepository/tools/generate.c | 179 +++++++++++++++++----------------- 1 file changed, 90 insertions(+), 89 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index fcff5b62cf..2292de01fe 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1,3 +1,4 @@ + /* -*- Mode: C; c-file-style: "gnu"; -*- */ /* GObject introspection: IDL generator * @@ -156,17 +157,17 @@ xml_free (Xml *xml) } -static void +static void check_unresolved (GIBaseInfo *info) { if (g_base_info_get_type (info) != GI_INFO_TYPE_UNRESOLVED) return; - g_critical ("Found unresolved type '%s' '%s'\n", + g_critical ("Found unresolved type '%s' '%s'\n", g_base_info_get_name (info), g_base_info_get_namespace (info)); } -static void +static void write_type_name (const gchar *namespace, GIBaseInfo *info, Xml *file) @@ -190,27 +191,27 @@ write_type_name_attribute (const gchar *namespace, static void write_type_info (const gchar *namespace, - GITypeInfo *info, + GITypeInfo *info, Xml *file) { gint tag; gint i; GITypeInfo *type; gboolean is_pointer; - + check_unresolved ((GIBaseInfo*)info); tag = g_type_info_get_tag (info); is_pointer = g_type_info_is_pointer (info); - if (tag == GI_TYPE_TAG_VOID) + if (tag == GI_TYPE_TAG_VOID) { xml_start_element (file, "type"); xml_printf (file, " name=\"%s\"", is_pointer ? "any" : "none"); xml_end_element (file, "type"); - } + } else if (G_TYPE_TAG_IS_BASIC (tag)) { xml_start_element (file, "type"); @@ -220,7 +221,7 @@ write_type_info (const gchar *namespace, else if (tag == GI_TYPE_TAG_ARRAY) { gint length, size; - + xml_start_element (file, "array"); type = g_type_info_get_param_type (info, 0); @@ -232,7 +233,7 @@ write_type_info (const gchar *namespace, size = g_type_info_get_array_fixed_size (info); if (size >= 0) xml_printf (file, " fixed-size=\"%d\"", size); - + if (g_type_info_is_zero_terminated (info)) xml_printf (file, " zero-terminated=\"1\""); @@ -289,7 +290,7 @@ write_type_info (const gchar *namespace, } xml_end_element (file, "type"); } - else if (tag == GI_TYPE_TAG_ERROR) + else if (tag == GI_TYPE_TAG_ERROR) { gint n; @@ -334,7 +335,7 @@ write_attributes (Xml *file, } static void -write_constant_value (const gchar *namespace, +write_constant_value (const gchar *namespace, GITypeInfo *info, GArgument *argument, Xml *file); @@ -356,7 +357,7 @@ write_field_info (const gchar *namespace, gint offset; GITypeInfo *type; GIBaseInfo *interface; - GArgument value; + GArgument value; name = g_base_info_get_name ((GIBaseInfo *)info); flags = g_field_info_get_flags (info); @@ -410,7 +411,7 @@ write_field_info (const gchar *namespace, xml_end_element (file, "field"); } -static void +static void write_callable_info (const gchar *namespace, GICallableInfo *info, Xml *file) @@ -438,14 +439,14 @@ write_callable_info (const gchar *namespace, default: g_assert_not_reached (); } - + if (g_callable_info_may_return_null (info)) xml_printf (file, " allow-none=\"1\""); write_type_info (namespace, type, file); xml_end_element (file, "return-value"); - + if (g_callable_info_get_n_args (info) <= 0) return; @@ -453,11 +454,11 @@ write_callable_info (const gchar *namespace, for (i = 0; i < g_callable_info_get_n_args (info); i++) { GIArgInfo *arg = g_callable_info_get_arg (info, i); - + xml_start_element (file, "parameter"); xml_printf (file, " name=\"%s\"", g_base_info_get_name ((GIBaseInfo *) arg)); - + switch (g_arg_info_get_ownership_transfer (arg)) { case GI_TRANSFER_NOTHING: @@ -472,7 +473,7 @@ write_callable_info (const gchar *namespace, default: g_assert_not_reached (); } - + switch (g_arg_info_get_direction (arg)) { case GI_DIRECTION_IN: @@ -484,16 +485,16 @@ write_callable_info (const gchar *namespace, xml_printf (file, " direction=\"inout\""); break; } - + if (g_arg_info_may_be_null (arg)) xml_printf (file, " allow-none=\"1\""); - + if (g_arg_info_is_dipper (arg)) xml_printf (file, " dipper=\"1\""); - + if (g_arg_info_is_return_value (arg)) xml_printf (file, " retval=\"1\""); - + if (g_arg_info_is_optional (arg)) xml_printf (file, " optional=\"1\""); @@ -511,13 +512,13 @@ write_callable_info (const gchar *namespace, xml_printf (file, " scope=\"notified\""); break; } - + if (g_arg_info_get_closure (arg) >= 0) xml_printf (file, " closure=\"%d\"", g_arg_info_get_closure (arg)); - + if (g_arg_info_get_destroy (arg) >= 0) xml_printf (file, " destroy=\"%d\"", g_arg_info_get_destroy (arg)); - + type = g_arg_info_get_type (arg); write_type_info (namespace, type, file); @@ -525,7 +526,7 @@ write_callable_info (const gchar *namespace, g_base_info_unref ((GIBaseInfo *)arg); } - + xml_end_element (file, "parameters"); g_base_info_unref ((GIBaseInfo *)type); } @@ -554,16 +555,16 @@ write_function_info (const gchar *namespace, tag = "method"; else tag = "function"; - + xml_start_element (file, tag); xml_printf (file, " name=\"%s\" c:identifier=\"%s\"", name, symbol); - + if (flags & GI_FUNCTION_IS_SETTER) xml_printf (file, " type=\"setter\""); else if (flags & GI_FUNCTION_IS_GETTER) xml_printf (file, " type=\"getter\""); - + if (deprecated) xml_printf (file, " deprecated=\"1\""); @@ -587,10 +588,10 @@ write_callback_info (const gchar *namespace, xml_start_element (file, "callback"); xml_printf (file, " name=\"%s\"", name); - + if (deprecated) xml_printf (file, " deprecated=\"1\""); - + write_callable_info (namespace, (GICallableInfo*)info, file); xml_end_element (file, "callback"); } @@ -614,7 +615,7 @@ write_struct_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - + if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) { xml_start_element (file, "glib:boxed"); @@ -625,19 +626,19 @@ write_struct_info (const gchar *namespace, xml_start_element (file, "record"); xml_printf (file, " name=\"%s\"", name); } - + if (type_name != NULL) xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init); - + if (deprecated) xml_printf (file, " deprecated=\"1\""); - + is_gtype_struct = g_struct_info_is_gtype_struct (info); if (is_gtype_struct) xml_printf (file, " glib:is-gtype-struct=\"1\""); write_attributes (file, (GIBaseInfo*) info); - + size = g_struct_info_get_size (info); if (show_all && size >= 0) xml_printf (file, " size=\"%d\"", size); @@ -651,15 +652,15 @@ write_struct_info (const gchar *namespace, write_field_info (namespace, field, NULL, file); g_base_info_unref ((GIBaseInfo *)field); } - + for (i = 0; i < g_struct_info_get_n_methods (info); i++) { GIFunctionInfo *function = g_struct_info_get_method (info, i); write_function_info (namespace, function, file); g_base_info_unref ((GIBaseInfo *)function); } - - } + + } xml_end_element_unchecked (file); } @@ -682,14 +683,14 @@ write_value_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - + write_attributes (file, (GIBaseInfo*) info); xml_end_element (file, "member"); } static void -write_constant_value (const gchar *namespace, +write_constant_value (const gchar *namespace, GITypeInfo *type, GArgument *value, Xml *file) @@ -784,7 +785,7 @@ write_constant_info (const gchar *namespace, write_attributes (file, (GIBaseInfo*) info); xml_end_element (file, "constant"); - + g_base_info_unref ((GIBaseInfo *)type); } @@ -814,7 +815,7 @@ write_enum_info (const gchar *namespace, if (type_init) xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init); - + if (deprecated) xml_printf (file, " deprecated=\"1\""); @@ -848,7 +849,7 @@ write_signal_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - + if (flags & G_SIGNAL_RUN_FIRST) xml_printf (file, " when=\"FIRST\""); else if (flags & G_SIGNAL_RUN_LAST) @@ -874,7 +875,7 @@ write_signal_info (const gchar *namespace, } static void -write_vfunc_info (const gchar *namespace, +write_vfunc_info (const gchar *namespace, GIVFuncInfo *info, Xml *file) { @@ -895,7 +896,7 @@ write_vfunc_info (const gchar *namespace, if (deprecated) xml_printf (file, " deprecated=\"1\""); - + if (flags & GI_VFUNC_MUST_CHAIN_UP) xml_printf (file, " must-chain-up=\"1\""); @@ -903,7 +904,7 @@ write_vfunc_info (const gchar *namespace, xml_printf (file, " override=\"always\""); else if (flags & GI_VFUNC_MUST_NOT_OVERRIDE) xml_printf (file, " override=\"never\""); - + xml_printf (file, " offset=\"%d\"", offset); if (invoker) @@ -956,7 +957,7 @@ write_property_info (const gchar *namespace, } static void -write_object_info (const gchar *namespace, +write_object_info (const gchar *namespace, GIObjectInfo *info, Xml *file) { @@ -972,7 +973,7 @@ write_object_info (const gchar *namespace, name = g_base_info_get_name ((GIBaseInfo *)info); deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); is_abstract = g_object_info_get_abstract (info); - + type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); xml_start_element (file, "class"); @@ -984,7 +985,7 @@ write_object_info (const gchar *namespace, write_type_name_attribute (namespace, (GIBaseInfo *)pnode, "parent", file); g_base_info_unref ((GIBaseInfo *)pnode); } - + class_struct = g_object_info_get_class_struct (info); if (class_struct) { @@ -1041,7 +1042,7 @@ write_object_info (const gchar *namespace, write_signal_info (namespace, signal, file); g_base_info_unref ((GIBaseInfo *)signal); } - + for (i = 0; i < g_object_info_get_n_vfuncs (info); i++) { GIVFuncInfo *vfunc = g_object_info_get_vfunc (info, i); @@ -1055,7 +1056,7 @@ write_object_info (const gchar *namespace, write_constant_info (namespace, constant, file); g_base_info_unref ((GIBaseInfo *)constant); } - + xml_end_element (file, "class"); } @@ -1126,7 +1127,7 @@ write_interface_info (const gchar *namespace, write_signal_info (namespace, signal, file); g_base_info_unref ((GIBaseInfo *)signal); } - + for (i = 0; i < g_interface_info_get_n_vfuncs (info); i++) { GIVFuncInfo *vfunc = g_interface_info_get_vfunc (info, i); @@ -1140,7 +1141,7 @@ write_interface_info (const gchar *namespace, write_constant_info (namespace, constant, file); g_base_info_unref ((GIBaseInfo *)constant); } - + xml_end_element (file, "interface"); } @@ -1151,7 +1152,7 @@ write_error_domain_info (const gchar *namespace, { GIBaseInfo *enum_; const gchar *name, *quark; - + name = g_base_info_get_name ((GIBaseInfo *)info); quark = g_error_domain_info_get_quark (info); enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info); @@ -1164,8 +1165,8 @@ write_error_domain_info (const gchar *namespace, } static void -write_union_info (const gchar *namespace, - GIUnionInfo *info, +write_union_info (const gchar *namespace, + GIUnionInfo *info, Xml *file) { const gchar *name; @@ -1180,13 +1181,13 @@ write_union_info (const gchar *namespace, type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - + xml_start_element (file, "union"); xml_printf (file, " name=\"%s\"", name); - + if (type_name) xml_printf (file, " type-name=\"%s\" get-type=\"%s\"", type_name, type_init); - + if (deprecated) xml_printf (file, " deprecated=\"1\""); @@ -1203,7 +1204,7 @@ write_union_info (const gchar *namespace, offset = g_union_info_get_discriminator_offset (info); type = g_union_info_get_discriminator_type (info); - + xml_start_element (file, "discriminator"); xml_printf (file, " offset=\"%d\" type=\"", offset); write_type_info (namespace, type, file); @@ -1248,27 +1249,27 @@ write_repository (const char *namespace, else { gchar *filename; - + if (needs_prefix) - filename = g_strdup_printf ("%s-%s", namespace, output); + filename = g_strdup_printf ("%s-%s", namespace, output); else filename = g_strdup (output); ofile = g_fopen (filename, "w"); - + if (ofile == NULL) { g_fprintf (stderr, "failed to open '%s': %s\n", filename, g_strerror (errno)); g_free (filename); - + return; } - + g_free (filename); } xml = xml_open (ofile); - + xml_printf (xml, "\n"); xml_start_element (xml, "repository"); xml_printf (xml, " version=\"1.0\"\n" @@ -1307,7 +1308,7 @@ write_repository (const char *namespace, xml_printf (xml, " shared-library=\"%s\"", shared_library); if (c_prefix) xml_printf (xml, " c:prefix=\"%s\"", c_prefix); - + for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) { GIBaseInfo *info = g_irepository_get_info (repository, ns, j); @@ -1316,7 +1317,7 @@ write_repository (const char *namespace, case GI_INFO_TYPE_FUNCTION: write_function_info (ns, (GIFunctionInfo *)info, xml); break; - + case GI_INFO_TYPE_CALLBACK: write_callback_info (ns, (GICallbackInfo *)info, xml); break; @@ -1334,7 +1335,7 @@ write_repository (const char *namespace, case GI_INFO_TYPE_FLAGS: write_enum_info (ns, (GIEnumInfo *)info, xml); break; - + case GI_INFO_TYPE_CONSTANT: write_constant_info (ns, (GIConstantInfo *)info, xml); break; @@ -1362,7 +1363,7 @@ write_repository (const char *namespace, } xml_end_element (xml, "repository"); - + xml_free (xml); } @@ -1373,41 +1374,41 @@ load_typelib (const gchar *filename, { guchar *typelib; gsize *typelib_size; - GModule *handle; + GModule *handle; handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); if (handle == NULL) { - g_printerr ("Could not load typelib from '%s': %s\n", + g_printerr ("Could not load typelib from '%s': %s\n", filename, g_module_error ()); return NULL; } if (!g_module_symbol (handle, "_G_TYPELIB", (gpointer *) &typelib)) { - g_printerr ("Could not load typelib from '%s': %s\n", + g_printerr ("Could not load typelib from '%s': %s\n", filename, g_module_error ()); return NULL; } - + if (!g_module_symbol (handle, "_G_TYPELIB_SIZE", (gpointer *) &typelib_size)) { - g_printerr ("Could not load typelib from '%s': %s\n", + g_printerr ("Could not load typelib from '%s': %s\n", filename, g_module_error ()); return NULL; } *len = *typelib_size; - + if (dlhandle) *dlhandle = handle; return typelib; } -int +int main (int argc, char *argv[]) -{ +{ gboolean shlib = FALSE; gchar **input = NULL; GOptionContext *context; @@ -1415,10 +1416,10 @@ main (int argc, char *argv[]) gboolean needs_prefix; gint i; GTypelib *data; - GOptionEntry options[] = + GOptionEntry options[] = { { "shlib", 0, 0, G_OPTION_ARG_NONE, &shlib, "handle typelib embedded in shlib", NULL }, - { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, + { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL }, { "all", 0, 0, G_OPTION_ARG_NONE, &show_all, "show all available information", NULL, }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, @@ -1435,10 +1436,10 @@ main (int argc, char *argv[]) g_option_context_add_main_entries (context, options, NULL); g_option_context_parse (context, &argc, &argv, &error); - if (!input) - { - g_fprintf (stderr, "no input files\n"); - + if (!input) + { + g_fprintf (stderr, "no input files\n"); + return 1; } @@ -1457,7 +1458,7 @@ main (int argc, char *argv[]) { if (!g_file_get_contents (input[i], (gchar **)&typelib, &len, &error)) { - g_fprintf (stderr, "failed to read '%s': %s\n", + g_fprintf (stderr, "failed to read '%s': %s\n", input[i], error->message); g_clear_error (&error); continue; @@ -1468,7 +1469,7 @@ main (int argc, char *argv[]) typelib = load_typelib (input[i], &dlhandle, &len); if (!typelib) { - g_fprintf (stderr, "failed to load typelib from '%s'\n", + g_fprintf (stderr, "failed to load typelib from '%s'\n", input[i]); continue; } @@ -1495,7 +1496,7 @@ main (int argc, char *argv[]) g_printerr ("failed to load typelib: %s\n", error->message); return 1; } - + write_repository (namespace, needs_prefix); if (dlhandle) @@ -1513,6 +1514,6 @@ main (int argc, char *argv[]) break; } } - + return 0; } -- GitLab From 320dd66c62cb8865549dc82ebd3942adafeaf1a9 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Thu, 25 Mar 2010 23:12:12 -0300 Subject: [PATCH 80/99] Add support for foreign structs Foreign structs are special in the sense that there might be native bindings (for instance PyCairo for PyGI) that provides the same functionallity as the introspected variant. https://bugzilla.gnome.org/show_bug.cgi?id=610357 --- girepository/tools/generate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 2292de01fe..b813b12625 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -606,6 +606,7 @@ write_struct_info (const gchar *namespace, const gchar *type_init; gboolean deprecated; gboolean is_gtype_struct; + gboolean foreign; gint i; gint size; int n_elts; @@ -643,6 +644,10 @@ write_struct_info (const gchar *namespace, if (show_all && size >= 0) xml_printf (file, " size=\"%d\"", size); + foreign = g_struct_info_is_foreign (info); + if (foreign) + xml_printf (file, " foreign=\"1\""); + n_elts = g_struct_info_get_n_fields (info) + g_struct_info_get_n_methods (info); if (n_elts > 0) { -- GitLab From ecd9c2f3e7c64304570ed154346bfa2b8fe5f168 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 16 Dec 2009 11:47:19 -0500 Subject: [PATCH 81/99] Support (out caller-allocates) People have wanted support for marking (out) on functions of the form: /** * clutter_color_from_pixel: * @pixel: A pixel * @color: (out): Color to initialize with value of @pixel */ void clutter_color_from_pixel (guint32 pixel, ClutterColor *color); Where the caller is supposed to have allocated the argument; the C function just initializes it. This patch adds support for this argument passing style to introspection. In this case, we see the (out), and notice that there's only a single indirection (*) on the argument, and assume that this means (out caller-allocates). https://bugzilla.gnome.org/show_bug.cgi?id=604749 --- girepository/tools/generate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index b813b12625..42772da140 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -479,7 +479,8 @@ write_callable_info (const gchar *namespace, case GI_DIRECTION_IN: break; case GI_DIRECTION_OUT: - xml_printf (file, " direction=\"out\""); + xml_printf (file, " direction=\"out\" caller-allocates=\"%s\"", + g_arg_info_is_caller_allocates (arg) ? "1" : "0"); break; case GI_DIRECTION_INOUT: xml_printf (file, " direction=\"inout\""); @@ -489,9 +490,6 @@ write_callable_info (const gchar *namespace, if (g_arg_info_may_be_null (arg)) xml_printf (file, " allow-none=\"1\""); - if (g_arg_info_is_dipper (arg)) - xml_printf (file, " dipper=\"1\""); - if (g_arg_info_is_return_value (arg)) xml_printf (file, " retval=\"1\""); -- GitLab From a9a3352d8aeccb341246da8812ad074345019f1d Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Thu, 27 May 2010 00:17:56 -0300 Subject: [PATCH 82/99] [g-ir-generate] Write out array type For GLib arrays, write out the array type to the tgir --- girepository/tools/generate.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 42772da140..39235962cb 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -221,9 +221,29 @@ write_type_info (const gchar *namespace, else if (tag == GI_TYPE_TAG_ARRAY) { gint length, size; + char *name = NULL; xml_start_element (file, "array"); + switch (g_type_info_get_array_type (info)) { + case GI_ARRAY_TYPE_C: + break; + case GI_ARRAY_TYPE_ARRAY: + name = "GLib.Array"; + break; + case GI_ARRAY_TYPE_PTR_ARRAY: + name = "GLib.PtrArray"; + break; + case GI_ARRAY_TYPE_BYTE_ARRAY: + name = "GLib.ByteArray"; + break; + default: + break; + } + + if (name) + xml_printf (file, " name=\"%s\"", name); + type = g_type_info_get_param_type (info, 0); length = g_type_info_get_array_length (info); -- GitLab From ccdceb1e093ef6aad79e6b244102ee9362cadcdd Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 31 May 2010 17:44:46 -0300 Subject: [PATCH 83/99] [gtypelib.ch] Rename to gitypelib.ch Rename gtypelib.h -> gitypelib-internal.h and rename gtypelib.c to gitypelib.c --- girepository/tools/generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 39235962cb..3cc3c6486f 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -29,7 +29,7 @@ #include #include "girepository.h" -#include "gtypelib.h" +#include "gitypelib-internal.h" /* FIXME: Avoid global */ static gchar *output = NULL; -- GitLab From af10e6bd6e68f53275578ee9e39f9e18c9dd431e Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 7 Jun 2010 10:41:00 -0300 Subject: [PATCH 84/99] [generate] Get rid of globals Get rid of all globals in gir generator, in preparation for moving all code into libgirepository --- girepository/tools/generate.c | 39 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 3cc3c6486f..3937f40ae0 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -31,14 +31,10 @@ #include "girepository.h" #include "gitypelib-internal.h" -/* FIXME: Avoid global */ -static gchar *output = NULL; -gchar **includedirs = NULL; -static gboolean show_all = FALSE; - typedef struct { FILE *file; GSList *stack; + gboolean show_all; } Xml; typedef struct { @@ -411,7 +407,7 @@ write_field_info (const gchar *namespace, xml_printf (file, "\""); } - if (show_all) + if (file->show_all) { if (offset >= 0) xml_printf (file, "offset=\"%d\"", offset); @@ -659,7 +655,7 @@ write_struct_info (const gchar *namespace, write_attributes (file, (GIBaseInfo*) info); size = g_struct_info_get_size (info); - if (show_all && size >= 0) + if (file->show_all && size >= 0) xml_printf (file, " size=\"%d\"", size); foreign = g_struct_info_is_foreign (info); @@ -1215,7 +1211,7 @@ write_union_info (const gchar *namespace, xml_printf (file, " deprecated=\"1\""); size = g_union_info_get_size (info); - if (show_all && size >= 0) + if (file->show_all && size >= 0) xml_printf (file, " size=\"%d\"", size); write_attributes (file, (GIBaseInfo*) info); @@ -1256,8 +1252,10 @@ write_union_info (const gchar *namespace, } static void -write_repository (const char *namespace, - gboolean needs_prefix) +write_repository (const char *filename, + const char *namespace, + gboolean needs_prefix, + gboolean show_all) { FILE *ofile; gint i, j; @@ -1267,32 +1265,32 @@ write_repository (const char *namespace, repository = g_irepository_get_default (); - if (output == NULL) + if (filename == NULL) ofile = stdout; else { - gchar *filename; + gchar *full_filename; if (needs_prefix) - filename = g_strdup_printf ("%s-%s", namespace, output); + full_filename = g_strdup_printf ("%s-%s", namespace, filename); else - filename = g_strdup (output); + full_filename = g_strdup (filename); ofile = g_fopen (filename, "w"); if (ofile == NULL) { g_fprintf (stderr, "failed to open '%s': %s\n", - filename, g_strerror (errno)); - g_free (filename); + full_filename, g_strerror (errno)); + g_free (full_filename); return; } - g_free (filename); + g_free (full_filename); } xml = xml_open (ofile); - + xml->show_all = show_all; xml_printf (xml, "\n"); xml_start_element (xml, "repository"); xml_printf (xml, " version=\"1.0\"\n" @@ -1433,6 +1431,9 @@ int main (int argc, char *argv[]) { gboolean shlib = FALSE; + gchar *output = NULL; + gchar **includedirs = NULL; + gboolean show_all = FALSE; gchar **input = NULL; GOptionContext *context; GError *error = NULL; @@ -1520,7 +1521,7 @@ main (int argc, char *argv[]) return 1; } - write_repository (namespace, needs_prefix); + write_repository (output, namespace, needs_prefix, show_all); if (dlhandle) { -- GitLab From a01e97f46f273d18ff2ee689b51ac7bd711b5d8a Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 7 Jun 2010 10:52:43 -0300 Subject: [PATCH 85/99] [girwriter] Refactor out of generate.c Move out the girwriter out of generate.c. Still a private API, but that will probably change in the future. --- girepository/tools/generate.c | 1369 +-------------------------------- 1 file changed, 5 insertions(+), 1364 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 3937f40ae0..cd1fedc331 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -21,1377 +21,18 @@ * Boston, MA 02111-1307, USA. */ -#include -#include - #include -#include #include +#include +#include "girwriter.h" #include "girepository.h" #include "gitypelib-internal.h" -typedef struct { - FILE *file; - GSList *stack; - gboolean show_all; -} Xml; - -typedef struct { - char *name; - guint has_children : 1; -} XmlElement; - -static XmlElement * -xml_element_new (const char *name) -{ - XmlElement *elem; - - elem = g_new (XmlElement, 1); - elem->name = g_strdup (name); - elem->has_children = FALSE; - return elem; -} - -static void -xml_element_free (XmlElement *elem) -{ - g_free (elem->name); - g_free (elem); -} - -static void -xml_printf (Xml *xml, const char *fmt, ...) -{ - va_list ap; - char *s; - - va_start (ap, fmt); - s = g_markup_vprintf_escaped (fmt, ap); - fputs (s, xml->file); - g_free (s); - va_end (ap); -} - -static void -xml_start_element (Xml *xml, const char *element_name) -{ - XmlElement *parent = NULL; - - if (xml->stack) - { - parent = xml->stack->data; - - if (!parent->has_children) - xml_printf (xml, ">\n"); - - parent->has_children = TRUE; - } - - xml_printf (xml, "%*s<%s", g_slist_length(xml->stack)*2, "", element_name); - - xml->stack = g_slist_prepend (xml->stack, xml_element_new (element_name)); -} - -static void -xml_end_element (Xml *xml, const char *name) -{ - XmlElement *elem; - - g_assert (xml->stack != NULL); - - elem = xml->stack->data; - xml->stack = g_slist_delete_link (xml->stack, xml->stack); - - if (name != NULL) - g_assert_cmpstr (name, ==, elem->name); - - if (elem->has_children) - xml_printf (xml, "%*s\n", g_slist_length (xml->stack)*2, "", elem->name); - else - xml_printf (xml, "/>\n"); - - xml_element_free (elem); -} - -static void -xml_end_element_unchecked (Xml *xml) -{ - xml_end_element (xml, NULL); -} - -static Xml * -xml_open (FILE *file) -{ - Xml *xml; - - xml = g_new (Xml, 1); - xml->file = file; - xml->stack = NULL; - - return xml; -} - -static void -xml_close (Xml *xml) -{ - g_assert (xml->stack == NULL); - if (xml->file != NULL) - { - fflush (xml->file); - if (xml->file != stdout) - fclose (xml->file); - xml->file = NULL; - } -} - -static void -xml_free (Xml *xml) -{ - xml_close (xml); - g_free (xml); -} - - -static void -check_unresolved (GIBaseInfo *info) -{ - if (g_base_info_get_type (info) != GI_INFO_TYPE_UNRESOLVED) - return; - - g_critical ("Found unresolved type '%s' '%s'\n", - g_base_info_get_name (info), g_base_info_get_namespace (info)); -} - -static void -write_type_name (const gchar *namespace, - GIBaseInfo *info, - Xml *file) -{ - if (strcmp (namespace, g_base_info_get_namespace (info)) != 0) - xml_printf (file, "%s.", g_base_info_get_namespace (info)); - - xml_printf (file, "%s", g_base_info_get_name (info)); -} - -static void -write_type_name_attribute (const gchar *namespace, - GIBaseInfo *info, - const char *attr_name, - Xml *file) -{ - xml_printf (file, " %s=\"", attr_name); - write_type_name (namespace, info, file); - xml_printf (file, "\""); -} - -static void -write_type_info (const gchar *namespace, - GITypeInfo *info, - Xml *file) -{ - gint tag; - gint i; - GITypeInfo *type; - gboolean is_pointer; - - check_unresolved ((GIBaseInfo*)info); - - tag = g_type_info_get_tag (info); - is_pointer = g_type_info_is_pointer (info); - - if (tag == GI_TYPE_TAG_VOID) - { - xml_start_element (file, "type"); - - xml_printf (file, " name=\"%s\"", is_pointer ? "any" : "none"); - - xml_end_element (file, "type"); - } - else if (G_TYPE_TAG_IS_BASIC (tag)) - { - xml_start_element (file, "type"); - xml_printf (file, " name=\"%s\"", g_type_tag_to_string (tag)); - xml_end_element (file, "type"); - } - else if (tag == GI_TYPE_TAG_ARRAY) - { - gint length, size; - char *name = NULL; - - xml_start_element (file, "array"); - - switch (g_type_info_get_array_type (info)) { - case GI_ARRAY_TYPE_C: - break; - case GI_ARRAY_TYPE_ARRAY: - name = "GLib.Array"; - break; - case GI_ARRAY_TYPE_PTR_ARRAY: - name = "GLib.PtrArray"; - break; - case GI_ARRAY_TYPE_BYTE_ARRAY: - name = "GLib.ByteArray"; - break; - default: - break; - } - - if (name) - xml_printf (file, " name=\"%s\"", name); - - type = g_type_info_get_param_type (info, 0); - - length = g_type_info_get_array_length (info); - if (length >= 0) - xml_printf (file, " length=\"%d\"", length); - - size = g_type_info_get_array_fixed_size (info); - if (size >= 0) - xml_printf (file, " fixed-size=\"%d\"", size); - - if (g_type_info_is_zero_terminated (info)) - xml_printf (file, " zero-terminated=\"1\""); - - write_type_info (namespace, type, file); - - g_base_info_unref ((GIBaseInfo *)type); - - xml_end_element (file, "array"); - } - else if (tag == GI_TYPE_TAG_INTERFACE) - { - GIBaseInfo *iface = g_type_info_get_interface (info); - xml_start_element (file, "type"); - write_type_name_attribute (namespace, iface, "name", file); - xml_end_element (file, "type"); - g_base_info_unref (iface); - } - else if (tag == GI_TYPE_TAG_GLIST) - { - xml_start_element (file, "type"); - xml_printf (file, " name=\"GLib.List\""); - type = g_type_info_get_param_type (info, 0); - if (type) - { - write_type_info (namespace, type, file); - g_base_info_unref ((GIBaseInfo *)type); - } - xml_end_element (file, "type"); - } - else if (tag == GI_TYPE_TAG_GSLIST) - { - xml_start_element (file, "type"); - xml_printf (file, " name=\"GLib.SList\""); - type = g_type_info_get_param_type (info, 0); - if (type) - { - write_type_info (namespace, type, file); - g_base_info_unref ((GIBaseInfo *)type); - } - xml_end_element (file, "type"); - } - else if (tag == GI_TYPE_TAG_GHASH) - { - xml_start_element (file, "type"); - xml_printf (file, " name=\"GLib.HashTable\""); - type = g_type_info_get_param_type (info, 0); - if (type) - { - write_type_info (namespace, type, file); - g_base_info_unref ((GIBaseInfo *)type); - type = g_type_info_get_param_type (info, 1); - write_type_info (namespace, type, file); - g_base_info_unref ((GIBaseInfo *)type); - } - xml_end_element (file, "type"); - } - else if (tag == GI_TYPE_TAG_ERROR) - { - gint n; - - xml_start_element (file, "type"); - xml_printf (file, " name=\"GLib.Error\""); - - n = g_type_info_get_n_error_domains (info); - if (n > 0) - { - for (i = 0; i < n; i++) - { - GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i); - xml_start_element (file, "type"); - write_type_name_attribute (namespace, (GIBaseInfo *)ed, "name", file); - xml_end_element (file, "type"); - g_base_info_unref ((GIBaseInfo *)ed); - } - } - - xml_end_element (file, "type"); - } - else - { - g_printerr ("Unhandled type tag %d\n", tag); - g_assert_not_reached (); - } -} - -static void -write_attributes (Xml *file, - GIBaseInfo *info) -{ - GIAttributeIter iter = { 0, }; - char *name, *value; - - while (g_base_info_iterate_attributes (info, &iter, &name, &value)) - { - xml_start_element (file, "attribute"); - xml_printf (file, " name=\"%s\" value=\"%s\"", name, value); - xml_end_element (file, "attribute"); - } -} - -static void -write_constant_value (const gchar *namespace, - GITypeInfo *info, - GArgument *argument, - Xml *file); - -static void -write_callback_info (const gchar *namespace, - GICallbackInfo *info, - Xml *file); - -static void -write_field_info (const gchar *namespace, - GIFieldInfo *info, - GIConstantInfo *branch, - Xml *file) -{ - const gchar *name; - GIFieldInfoFlags flags; - gint size; - gint offset; - GITypeInfo *type; - GIBaseInfo *interface; - GArgument value; - - name = g_base_info_get_name ((GIBaseInfo *)info); - flags = g_field_info_get_flags (info); - size = g_field_info_get_size (info); - offset = g_field_info_get_offset (info); - - xml_start_element (file, "field"); - xml_printf (file, " name=\"%s\"", name); - - /* Fields are assumed to be read-only - * (see also girwriter.py and girparser.c) - */ - if (!(flags & GI_FIELD_IS_READABLE)) - xml_printf (file, " readable=\"0\""); - if (flags & GI_FIELD_IS_WRITABLE) - xml_printf (file, " writable=\"1\""); - - if (size) - xml_printf (file, " bits=\"%d\"", size); - - write_attributes (file, (GIBaseInfo*) info); - - type = g_field_info_get_type (info); - - if (branch) - { - xml_printf (file, " branch=\""); - type = g_constant_info_get_type (branch); - g_constant_info_get_value (branch, &value); - write_constant_value (namespace, type, &value, file); - xml_printf (file, "\""); - } - - if (file->show_all) - { - if (offset >= 0) - xml_printf (file, "offset=\"%d\"", offset); - } - - interface = g_type_info_get_interface (type); - if (interface && g_base_info_get_type(interface) == GI_INFO_TYPE_CALLBACK) - write_callback_info (namespace, (GICallbackInfo *)interface, file); - else - write_type_info (namespace, type, file); - - if (interface) - g_base_info_unref (interface); - - g_base_info_unref ((GIBaseInfo *)type); - - xml_end_element (file, "field"); -} - -static void -write_callable_info (const gchar *namespace, - GICallableInfo *info, - Xml *file) -{ - GITypeInfo *type; - gint i; - - write_attributes (file, (GIBaseInfo*) info); - - type = g_callable_info_get_return_type (info); - - xml_start_element (file, "return-value"); - - switch (g_callable_info_get_caller_owns (info)) - { - case GI_TRANSFER_NOTHING: - xml_printf (file, " transfer-ownership=\"none\""); - break; - case GI_TRANSFER_CONTAINER: - xml_printf (file, " transfer-ownership=\"container\""); - break; - case GI_TRANSFER_EVERYTHING: - xml_printf (file, " transfer-ownership=\"full\""); - break; - default: - g_assert_not_reached (); - } - - if (g_callable_info_may_return_null (info)) - xml_printf (file, " allow-none=\"1\""); - - write_type_info (namespace, type, file); - - xml_end_element (file, "return-value"); - - if (g_callable_info_get_n_args (info) <= 0) - return; - - xml_start_element (file, "parameters"); - for (i = 0; i < g_callable_info_get_n_args (info); i++) - { - GIArgInfo *arg = g_callable_info_get_arg (info, i); - - xml_start_element (file, "parameter"); - xml_printf (file, " name=\"%s\"", - g_base_info_get_name ((GIBaseInfo *) arg)); - - switch (g_arg_info_get_ownership_transfer (arg)) - { - case GI_TRANSFER_NOTHING: - xml_printf (file, " transfer-ownership=\"none\""); - break; - case GI_TRANSFER_CONTAINER: - xml_printf (file, " transfer-ownership=\"container\""); - break; - case GI_TRANSFER_EVERYTHING: - xml_printf (file, " transfer-ownership=\"full\""); - break; - default: - g_assert_not_reached (); - } - - switch (g_arg_info_get_direction (arg)) - { - case GI_DIRECTION_IN: - break; - case GI_DIRECTION_OUT: - xml_printf (file, " direction=\"out\" caller-allocates=\"%s\"", - g_arg_info_is_caller_allocates (arg) ? "1" : "0"); - break; - case GI_DIRECTION_INOUT: - xml_printf (file, " direction=\"inout\""); - break; - } - - if (g_arg_info_may_be_null (arg)) - xml_printf (file, " allow-none=\"1\""); - - if (g_arg_info_is_return_value (arg)) - xml_printf (file, " retval=\"1\""); - - if (g_arg_info_is_optional (arg)) - xml_printf (file, " optional=\"1\""); - - switch (g_arg_info_get_scope (arg)) - { - case GI_SCOPE_TYPE_INVALID: - break; - case GI_SCOPE_TYPE_CALL: - xml_printf (file, " scope=\"call\""); - break; - case GI_SCOPE_TYPE_ASYNC: - xml_printf (file, " scope=\"async\""); - break; - case GI_SCOPE_TYPE_NOTIFIED: - xml_printf (file, " scope=\"notified\""); - break; - } - - if (g_arg_info_get_closure (arg) >= 0) - xml_printf (file, " closure=\"%d\"", g_arg_info_get_closure (arg)); - - if (g_arg_info_get_destroy (arg) >= 0) - xml_printf (file, " destroy=\"%d\"", g_arg_info_get_destroy (arg)); - - type = g_arg_info_get_type (arg); - write_type_info (namespace, type, file); - - xml_end_element (file, "parameter"); - - g_base_info_unref ((GIBaseInfo *)arg); - } - - xml_end_element (file, "parameters"); - g_base_info_unref ((GIBaseInfo *)type); -} - -static void -write_function_info (const gchar *namespace, - GIFunctionInfo *info, - Xml *file) -{ - GIFunctionInfoFlags flags; - const gchar *tag; - const gchar *name; - const gchar *symbol; - gboolean deprecated; - gboolean throws; - - flags = g_function_info_get_flags (info); - name = g_base_info_get_name ((GIBaseInfo *)info); - symbol = g_function_info_get_symbol (info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - throws = flags & GI_FUNCTION_THROWS; - - if (flags & GI_FUNCTION_IS_CONSTRUCTOR) - tag = "constructor"; - else if (flags & GI_FUNCTION_IS_METHOD) - tag = "method"; - else - tag = "function"; - - xml_start_element (file, tag); - xml_printf (file, " name=\"%s\" c:identifier=\"%s\"", - name, symbol); - - if (flags & GI_FUNCTION_IS_SETTER) - xml_printf (file, " type=\"setter\""); - else if (flags & GI_FUNCTION_IS_GETTER) - xml_printf (file, " type=\"getter\""); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - if (throws) - xml_printf (file, " throws=\"1\""); - - write_callable_info (namespace, (GICallableInfo*)info, file); - xml_end_element (file, tag); -} - -static void -write_callback_info (const gchar *namespace, - GICallbackInfo *info, - Xml *file) -{ - const gchar *name; - gboolean deprecated; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - xml_start_element (file, "callback"); - xml_printf (file, " name=\"%s\"", name); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - write_callable_info (namespace, (GICallableInfo*)info, file); - xml_end_element (file, "callback"); -} - -static void -write_struct_info (const gchar *namespace, - GIStructInfo *info, - Xml *file) -{ - const gchar *name; - const gchar *type_name; - const gchar *type_init; - gboolean deprecated; - gboolean is_gtype_struct; - gboolean foreign; - gint i; - gint size; - int n_elts; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - - if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_BOXED) - { - xml_start_element (file, "glib:boxed"); - xml_printf (file, " glib:name=\"%s\"", name); - } - else - { - xml_start_element (file, "record"); - xml_printf (file, " name=\"%s\"", name); - } - - if (type_name != NULL) - xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - is_gtype_struct = g_struct_info_is_gtype_struct (info); - if (is_gtype_struct) - xml_printf (file, " glib:is-gtype-struct=\"1\""); - - write_attributes (file, (GIBaseInfo*) info); - - size = g_struct_info_get_size (info); - if (file->show_all && size >= 0) - xml_printf (file, " size=\"%d\"", size); - - foreign = g_struct_info_is_foreign (info); - if (foreign) - xml_printf (file, " foreign=\"1\""); - - n_elts = g_struct_info_get_n_fields (info) + g_struct_info_get_n_methods (info); - if (n_elts > 0) - { - for (i = 0; i < g_struct_info_get_n_fields (info); i++) - { - GIFieldInfo *field = g_struct_info_get_field (info, i); - write_field_info (namespace, field, NULL, file); - g_base_info_unref ((GIBaseInfo *)field); - } - - for (i = 0; i < g_struct_info_get_n_methods (info); i++) - { - GIFunctionInfo *function = g_struct_info_get_method (info, i); - write_function_info (namespace, function, file); - g_base_info_unref ((GIBaseInfo *)function); - } - - } - - xml_end_element_unchecked (file); -} - -static void -write_value_info (const gchar *namespace, - GIValueInfo *info, - Xml *file) -{ - const gchar *name; - glong value; - gboolean deprecated; - - name = g_base_info_get_name ((GIBaseInfo *)info); - value = g_value_info_get_value (info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - xml_start_element (file, "member"); - xml_printf (file, " name=\"%s\" value=\"%ld\"", name, value); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - write_attributes (file, (GIBaseInfo*) info); - - xml_end_element (file, "member"); -} - -static void -write_constant_value (const gchar *namespace, - GITypeInfo *type, - GArgument *value, - Xml *file) -{ - switch (g_type_info_get_tag (type)) - { - case GI_TYPE_TAG_BOOLEAN: - xml_printf (file, "%d", value->v_boolean); - break; - case GI_TYPE_TAG_INT8: - xml_printf (file, "%d", value->v_int8); - break; - case GI_TYPE_TAG_UINT8: - xml_printf (file, "%d", value->v_uint8); - break; - case GI_TYPE_TAG_INT16: - xml_printf (file, "%" G_GINT16_FORMAT, value->v_int16); - break; - case GI_TYPE_TAG_UINT16: - xml_printf (file, "%" G_GUINT16_FORMAT, value->v_uint16); - break; - case GI_TYPE_TAG_INT32: - xml_printf (file, "%" G_GINT32_FORMAT, value->v_int32); - break; - case GI_TYPE_TAG_UINT32: - xml_printf (file, "%" G_GUINT32_FORMAT, value->v_uint32); - break; - case GI_TYPE_TAG_INT64: - xml_printf (file, "%" G_GINT64_FORMAT, value->v_int64); - break; - case GI_TYPE_TAG_UINT64: - xml_printf (file, "%" G_GUINT64_FORMAT, value->v_uint64); - break; - case GI_TYPE_TAG_INT: - xml_printf (file, "%d", value->v_int); - break; - case GI_TYPE_TAG_UINT: - xml_printf (file, "%d", value->v_uint); - break; - case GI_TYPE_TAG_LONG: - xml_printf (file, "%ld", value->v_long); - break; - case GI_TYPE_TAG_ULONG: - xml_printf (file, "%ld", value->v_ulong); - break; - case GI_TYPE_TAG_SSIZE: - xml_printf (file, "%zd", value->v_ssize); - break; - case GI_TYPE_TAG_SIZE: - xml_printf (file, "%zd", value->v_size); - break; - case GI_TYPE_TAG_FLOAT: - xml_printf (file, "%f", value->v_float); - break; - case GI_TYPE_TAG_DOUBLE: - xml_printf (file, "%f", value->v_double); - break; - case GI_TYPE_TAG_UTF8: - case GI_TYPE_TAG_FILENAME: - xml_printf (file, "%s", value->v_string); - break; - default: - g_assert_not_reached (); - } -} - -static void -write_constant_info (const gchar *namespace, - GIConstantInfo *info, - Xml *file) -{ - GITypeInfo *type; - const gchar *name; - gboolean deprecated; - GArgument value; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - xml_start_element (file, "constant"); - xml_printf (file, " name=\"%s\"", name); - - type = g_constant_info_get_type (info); - xml_printf (file, " value=\""); - - g_constant_info_get_value (info, &value); - write_constant_value (namespace, type, &value, file); - xml_printf (file, "\""); - - write_type_info (namespace, type, file); - - write_attributes (file, (GIBaseInfo*) info); - - xml_end_element (file, "constant"); - - g_base_info_unref ((GIBaseInfo *)type); -} - - -static void -write_enum_info (const gchar *namespace, - GIEnumInfo *info, - Xml *file) -{ - const gchar *name; - const gchar *type_name; - const gchar *type_init; - gboolean deprecated; - gint i; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - - if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM) - xml_start_element (file, "enumeration"); - else - xml_start_element (file, "bitfield"); - xml_printf (file, " name=\"%s\"", name); - - if (type_init) - xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - write_attributes (file, (GIBaseInfo*) info); - - for (i = 0; i < g_enum_info_get_n_values (info); i++) - { - GIValueInfo *value = g_enum_info_get_value (info, i); - write_value_info (namespace, value, file); - g_base_info_unref ((GIBaseInfo *)value); - } - - xml_end_element_unchecked (file); -} - -static void -write_signal_info (const gchar *namespace, - GISignalInfo *info, - Xml *file) -{ - GSignalFlags flags; - const gchar *name; - gboolean deprecated; - - name = g_base_info_get_name ((GIBaseInfo *)info); - flags = g_signal_info_get_flags (info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - xml_start_element (file, "glib:signal"); - xml_printf (file, " name=\"%s\"", name); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - if (flags & G_SIGNAL_RUN_FIRST) - xml_printf (file, " when=\"FIRST\""); - else if (flags & G_SIGNAL_RUN_LAST) - xml_printf (file, " when=\"LAST\""); - else if (flags & G_SIGNAL_RUN_CLEANUP) - xml_printf (file, " when=\"CLEANUP\""); - - if (flags & G_SIGNAL_NO_RECURSE) - xml_printf (file, " no-recurse=\"1\""); - - if (flags & G_SIGNAL_DETAILED) - xml_printf (file, " detailed=\"1\""); - - if (flags & G_SIGNAL_ACTION) - xml_printf (file, " action=\"1\""); - - if (flags & G_SIGNAL_NO_HOOKS) - xml_printf (file, " no-hooks=\"1\""); - - write_callable_info (namespace, (GICallableInfo*)info, file); - - xml_end_element (file, "glib:signal"); -} - -static void -write_vfunc_info (const gchar *namespace, - GIVFuncInfo *info, - Xml *file) -{ - GIVFuncInfoFlags flags; - const gchar *name; - GIFunctionInfo *invoker; - gboolean deprecated; - gint offset; - - name = g_base_info_get_name ((GIBaseInfo *)info); - flags = g_vfunc_info_get_flags (info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - offset = g_vfunc_info_get_offset (info); - invoker = g_vfunc_info_get_invoker (info); - - xml_start_element (file, "virtual-method"); - xml_printf (file, " name=\"%s\"", name); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - if (flags & GI_VFUNC_MUST_CHAIN_UP) - xml_printf (file, " must-chain-up=\"1\""); - - if (flags & GI_VFUNC_MUST_OVERRIDE) - xml_printf (file, " override=\"always\""); - else if (flags & GI_VFUNC_MUST_NOT_OVERRIDE) - xml_printf (file, " override=\"never\""); - - xml_printf (file, " offset=\"%d\"", offset); - - if (invoker) - xml_printf (file, " invoker=\"%s\"", g_base_info_get_name ((GIBaseInfo*)invoker)); - - write_callable_info (namespace, (GICallableInfo*)info, file); - - xml_end_element (file, "virtual-method"); -} - -static void -write_property_info (const gchar *namespace, - GIPropertyInfo *info, - Xml *file) -{ - GParamFlags flags; - const gchar *name; - gboolean deprecated; - GITypeInfo *type; - - name = g_base_info_get_name ((GIBaseInfo *)info); - flags = g_property_info_get_flags (info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - xml_start_element (file, "property"); - xml_printf (file, " name=\"%s\"", name); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - /* Properties are assumed to be read-only (see also girwriter.py) */ - if (!(flags & G_PARAM_READABLE)) - xml_printf (file, " readable=\"0\""); - if (flags & G_PARAM_WRITABLE) - xml_printf (file, " writable=\"1\""); - - if (flags & G_PARAM_CONSTRUCT) - xml_printf (file, " construct=\"1\""); - - if (flags & G_PARAM_CONSTRUCT_ONLY) - xml_printf (file, " construct-only=\"1\""); - - write_attributes (file, (GIBaseInfo*) info); - - type = g_property_info_get_type (info); - - write_type_info (namespace, type, file); - - xml_end_element (file, "property"); -} - -static void -write_object_info (const gchar *namespace, - GIObjectInfo *info, - Xml *file) -{ - const gchar *name; - const gchar *type_name; - const gchar *type_init; - gboolean deprecated; - gboolean is_abstract; - GIObjectInfo *pnode; - GIStructInfo *class_struct; - gint i; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - is_abstract = g_object_info_get_abstract (info); - - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - xml_start_element (file, "class"); - xml_printf (file, " name=\"%s\"", name); - - pnode = g_object_info_get_parent (info); - if (pnode) - { - write_type_name_attribute (namespace, (GIBaseInfo *)pnode, "parent", file); - g_base_info_unref ((GIBaseInfo *)pnode); - } - - class_struct = g_object_info_get_class_struct (info); - if (class_struct) - { - write_type_name_attribute (namespace, (GIBaseInfo*) class_struct, "glib:type-struct", file); - g_base_info_unref ((GIBaseInfo*)class_struct); - } - - if (is_abstract) - xml_printf (file, " abstract=\"1\""); - - xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - write_attributes (file, (GIBaseInfo*) info); - - if (g_object_info_get_n_interfaces (info) > 0) - { - for (i = 0; i < g_object_info_get_n_interfaces (info); i++) - { - GIInterfaceInfo *imp = g_object_info_get_interface (info, i); - xml_start_element (file, "implements"); - write_type_name_attribute (namespace, (GIBaseInfo *)imp, "name", file); - xml_end_element (file, "implements"); - g_base_info_unref ((GIBaseInfo*)imp); - } - } - - for (i = 0; i < g_object_info_get_n_fields (info); i++) - { - GIFieldInfo *field = g_object_info_get_field (info, i); - write_field_info (namespace, field, NULL, file); - g_base_info_unref ((GIBaseInfo *)field); - } - - for (i = 0; i < g_object_info_get_n_methods (info); i++) - { - GIFunctionInfo *function = g_object_info_get_method (info, i); - write_function_info (namespace, function, file); - g_base_info_unref ((GIBaseInfo *)function); - } - - for (i = 0; i < g_object_info_get_n_properties (info); i++) - { - GIPropertyInfo *prop = g_object_info_get_property (info, i); - write_property_info (namespace, prop, file); - g_base_info_unref ((GIBaseInfo *)prop); - } - - for (i = 0; i < g_object_info_get_n_signals (info); i++) - { - GISignalInfo *signal = g_object_info_get_signal (info, i); - write_signal_info (namespace, signal, file); - g_base_info_unref ((GIBaseInfo *)signal); - } - - for (i = 0; i < g_object_info_get_n_vfuncs (info); i++) - { - GIVFuncInfo *vfunc = g_object_info_get_vfunc (info, i); - write_vfunc_info (namespace, vfunc, file); - g_base_info_unref ((GIBaseInfo *)vfunc); - } - - for (i = 0; i < g_object_info_get_n_constants (info); i++) - { - GIConstantInfo *constant = g_object_info_get_constant (info, i); - write_constant_info (namespace, constant, file); - g_base_info_unref ((GIBaseInfo *)constant); - } - - xml_end_element (file, "class"); -} - -static void -write_interface_info (const gchar *namespace, - GIInterfaceInfo *info, - Xml *file) -{ - const gchar *name; - const gchar *type_name; - const gchar *type_init; - GIStructInfo *class_struct; - gboolean deprecated; - gint i; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - xml_start_element (file, "interface"); - xml_printf (file, " name=\"%s\" glib:type-name=\"%s\" glib:get-type=\"%s\"", - name, type_name, type_init); - - class_struct = g_interface_info_get_iface_struct (info); - if (class_struct) - { - write_type_name_attribute (namespace, (GIBaseInfo*) class_struct, "glib:type-struct", file); - g_base_info_unref ((GIBaseInfo*)class_struct); - } - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - write_attributes (file, (GIBaseInfo*) info); - - if (g_interface_info_get_n_prerequisites (info) > 0) - { - for (i = 0; i < g_interface_info_get_n_prerequisites (info); i++) - { - GIBaseInfo *req = g_interface_info_get_prerequisite (info, i); - - xml_start_element (file, "prerequisite"); - write_type_name_attribute (namespace, req, "name", file); - - xml_end_element_unchecked (file); - g_base_info_unref (req); - } - } - - for (i = 0; i < g_interface_info_get_n_methods (info); i++) - { - GIFunctionInfo *function = g_interface_info_get_method (info, i); - write_function_info (namespace, function, file); - g_base_info_unref ((GIBaseInfo *)function); - } - - for (i = 0; i < g_interface_info_get_n_properties (info); i++) - { - GIPropertyInfo *prop = g_interface_info_get_property (info, i); - write_property_info (namespace, prop, file); - g_base_info_unref ((GIBaseInfo *)prop); - } - - for (i = 0; i < g_interface_info_get_n_signals (info); i++) - { - GISignalInfo *signal = g_interface_info_get_signal (info, i); - write_signal_info (namespace, signal, file); - g_base_info_unref ((GIBaseInfo *)signal); - } - - for (i = 0; i < g_interface_info_get_n_vfuncs (info); i++) - { - GIVFuncInfo *vfunc = g_interface_info_get_vfunc (info, i); - write_vfunc_info (namespace, vfunc, file); - g_base_info_unref ((GIBaseInfo *)vfunc); - } - - for (i = 0; i < g_interface_info_get_n_constants (info); i++) - { - GIConstantInfo *constant = g_interface_info_get_constant (info, i); - write_constant_info (namespace, constant, file); - g_base_info_unref ((GIBaseInfo *)constant); - } - - xml_end_element (file, "interface"); -} - -static void -write_error_domain_info (const gchar *namespace, - GIErrorDomainInfo *info, - Xml *file) -{ - GIBaseInfo *enum_; - const gchar *name, *quark; - - name = g_base_info_get_name ((GIBaseInfo *)info); - quark = g_error_domain_info_get_quark (info); - enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info); - xml_start_element (file, "errordomain"); - xml_printf (file, " name=\"%s\" get-quark=\"%s\"", - name, quark); - write_type_name_attribute (namespace, enum_, "codes", file); - xml_end_element (file, "errordomain"); - g_base_info_unref (enum_); -} - -static void -write_union_info (const gchar *namespace, - GIUnionInfo *info, - Xml *file) -{ - const gchar *name; - const gchar *type_name; - const gchar *type_init; - gboolean deprecated; - gint i; - gint size; - - name = g_base_info_get_name ((GIBaseInfo *)info); - deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info); - - type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info); - type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info); - - xml_start_element (file, "union"); - xml_printf (file, " name=\"%s\"", name); - - if (type_name) - xml_printf (file, " type-name=\"%s\" get-type=\"%s\"", type_name, type_init); - - if (deprecated) - xml_printf (file, " deprecated=\"1\""); - - size = g_union_info_get_size (info); - if (file->show_all && size >= 0) - xml_printf (file, " size=\"%d\"", size); - - write_attributes (file, (GIBaseInfo*) info); - - if (g_union_info_is_discriminated (info)) - { - gint offset; - GITypeInfo *type; - - offset = g_union_info_get_discriminator_offset (info); - type = g_union_info_get_discriminator_type (info); - - xml_start_element (file, "discriminator"); - xml_printf (file, " offset=\"%d\" type=\"", offset); - write_type_info (namespace, type, file); - xml_end_element (file, "discriminator"); - g_base_info_unref ((GIBaseInfo *)type); - } - - for (i = 0; i < g_union_info_get_n_fields (info); i++) - { - GIFieldInfo *field = g_union_info_get_field (info, i); - GIConstantInfo *constant = g_union_info_get_discriminator (info, i); - write_field_info (namespace, field, constant, file); - g_base_info_unref ((GIBaseInfo *)field); - if (constant) - g_base_info_unref ((GIBaseInfo *)constant); - } - - for (i = 0; i < g_union_info_get_n_methods (info); i++) - { - GIFunctionInfo *function = g_union_info_get_method (info, i); - write_function_info (namespace, function, file); - g_base_info_unref ((GIBaseInfo *)function); - } - - xml_end_element (file, "union"); -} - -static void -write_repository (const char *filename, - const char *namespace, - gboolean needs_prefix, - gboolean show_all) -{ - FILE *ofile; - gint i, j; - char **dependencies; - GIRepository *repository; - Xml *xml; - - repository = g_irepository_get_default (); - - if (filename == NULL) - ofile = stdout; - else - { - gchar *full_filename; - - if (needs_prefix) - full_filename = g_strdup_printf ("%s-%s", namespace, filename); - else - full_filename = g_strdup (filename); - ofile = g_fopen (filename, "w"); - - if (ofile == NULL) - { - g_fprintf (stderr, "failed to open '%s': %s\n", - full_filename, g_strerror (errno)); - g_free (full_filename); - - return; - } - - g_free (full_filename); - } - - xml = xml_open (ofile); - xml->show_all = show_all; - xml_printf (xml, "\n"); - xml_start_element (xml, "repository"); - xml_printf (xml, " version=\"1.0\"\n" - " xmlns=\"http://www.gtk.org/introspection/core/1.0\"\n" - " xmlns:c=\"http://www.gtk.org/introspection/c/1.0\"\n" - " xmlns:glib=\"http://www.gtk.org/introspection/glib/1.0\""); - - dependencies = g_irepository_get_dependencies (repository, - namespace); - if (dependencies != NULL) - { - for (i = 0; dependencies[i]; i++) - { - char **parts = g_strsplit (dependencies[i], "-", 2); - xml_start_element (xml, "include"); - xml_printf (xml, " name=\"%s\" version=\"%s\"", parts[0], parts[1]); - xml_end_element (xml, "include"); - g_strfreev (parts); - } - } - - if (TRUE) - { - const gchar *shared_library; - const gchar *c_prefix; - const char *ns = namespace; - const char *version; - - version = g_irepository_get_version (repository, ns); - - shared_library = g_irepository_get_shared_library (repository, ns); - c_prefix = g_irepository_get_c_prefix (repository, ns); - xml_start_element (xml, "namespace"); - xml_printf (xml, " name=\"%s\" version=\"%s\"", ns, version); - if (shared_library) - xml_printf (xml, " shared-library=\"%s\"", shared_library); - if (c_prefix) - xml_printf (xml, " c:prefix=\"%s\"", c_prefix); - - for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) - { - GIBaseInfo *info = g_irepository_get_info (repository, ns, j); - switch (g_base_info_get_type (info)) - { - case GI_INFO_TYPE_FUNCTION: - write_function_info (ns, (GIFunctionInfo *)info, xml); - break; - - case GI_INFO_TYPE_CALLBACK: - write_callback_info (ns, (GICallbackInfo *)info, xml); - break; - - case GI_INFO_TYPE_STRUCT: - case GI_INFO_TYPE_BOXED: - write_struct_info (ns, (GIStructInfo *)info, xml); - break; - - case GI_INFO_TYPE_UNION: - write_union_info (ns, (GIUnionInfo *)info, xml); - break; - - case GI_INFO_TYPE_ENUM: - case GI_INFO_TYPE_FLAGS: - write_enum_info (ns, (GIEnumInfo *)info, xml); - break; - - case GI_INFO_TYPE_CONSTANT: - write_constant_info (ns, (GIConstantInfo *)info, xml); - break; - - case GI_INFO_TYPE_OBJECT: - write_object_info (ns, (GIObjectInfo *)info, xml); - break; - - case GI_INFO_TYPE_INTERFACE: - write_interface_info (ns, (GIInterfaceInfo *)info, xml); - break; - - case GI_INFO_TYPE_ERROR_DOMAIN: - write_error_domain_info (ns, (GIErrorDomainInfo *)info, xml); - break; - - default: - g_error ("unknown info type %d\n", g_base_info_get_type (info)); - } - - g_base_info_unref (info); - } - - xml_end_element (xml, "namespace"); - } - - xml_end_element (xml, "repository"); - - xml_free (xml); -} - static const guchar * load_typelib (const gchar *filename, - GModule **dlhandle, - gsize *len) + GModule **dlhandle, + gsize *len) { guchar *typelib; gsize *typelib_size; @@ -1521,7 +162,7 @@ main (int argc, char *argv[]) return 1; } - write_repository (output, namespace, needs_prefix, show_all); + gir_writer_write (output, namespace, needs_prefix, show_all); if (dlhandle) { -- GitLab From 4bf5ef6bd711d35622d12fac120bff0f80530fa6 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 14 Jul 2010 11:59:11 -0400 Subject: [PATCH 86/99] [girepository] Actually verify header of loaded typelibs in g_irepository_require Take a GError * for typelib loading code, validate the header. This fixes bizarre errors from gjs where g_irepository_require would happily load old typelibs. --- girepository/tools/generate.c | 96 +++++------------------------------ 1 file changed, 13 insertions(+), 83 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index cd1fedc331..b456901995 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -29,45 +29,6 @@ #include "girepository.h" #include "gitypelib-internal.h" -static const guchar * -load_typelib (const gchar *filename, - GModule **dlhandle, - gsize *len) -{ - guchar *typelib; - gsize *typelib_size; - GModule *handle; - - handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY); - if (handle == NULL) - { - g_printerr ("Could not load typelib from '%s': %s\n", - filename, g_module_error ()); - return NULL; - } - - if (!g_module_symbol (handle, "_G_TYPELIB", (gpointer *) &typelib)) - { - g_printerr ("Could not load typelib from '%s': %s\n", - filename, g_module_error ()); - return NULL; - } - - if (!g_module_symbol (handle, "_G_TYPELIB_SIZE", (gpointer *) &typelib_size)) - { - g_printerr ("Could not load typelib from '%s': %s\n", - filename, g_module_error ()); - return NULL; - } - - *len = *typelib_size; - - if (dlhandle) - *dlhandle = handle; - - return typelib; -} - int main (int argc, char *argv[]) { @@ -114,62 +75,31 @@ main (int argc, char *argv[]) for (i = 0; input[i]; i++) { - GModule *dlhandle = NULL; - const guchar *typelib; - gsize len; + GError *error = NULL; const char *namespace; + GMappedFile *mfile; + GTypelib *typelib; - if (!shlib) - { - if (!g_file_get_contents (input[i], (gchar **)&typelib, &len, &error)) - { - g_fprintf (stderr, "failed to read '%s': %s\n", - input[i], error->message); - g_clear_error (&error); - continue; - } - } - else - { - typelib = load_typelib (input[i], &dlhandle, &len); - if (!typelib) - { - g_fprintf (stderr, "failed to load typelib from '%s'\n", - input[i]); - continue; - } - } + mfile = g_mapped_file_new (input[i], FALSE, &error); + if (!mfile) + g_error ("failed to read '%s': %s", input[i], error->message); if (input[i + 1] && output) needs_prefix = TRUE; else needs_prefix = FALSE; - data = g_typelib_new_from_const_memory (typelib, len); - { - GError *error = NULL; - if (!g_typelib_validate (data, &error)) { - g_printerr ("typelib not valid: %s\n", error->message); - g_clear_error (&error); - return 1; - } - } - namespace = g_irepository_load_typelib (g_irepository_get_default (), data, 0, + typelib = g_typelib_new_from_mapped_file (mfile, &error); + if (!typelib) + g_error ("failed to create typelib '%s': %s", input[i], error->message); + + namespace = g_irepository_load_typelib (g_irepository_get_default (), typelib, 0, &error); if (namespace == NULL) - { - g_printerr ("failed to load typelib: %s\n", error->message); - return 1; - } - + g_error ("failed to load typelib: %s", error->message); + gir_writer_write (output, namespace, needs_prefix, show_all); - if (dlhandle) - { - g_module_close (dlhandle); - dlhandle = NULL; - } - /* when writing to stdout, stop after the first module */ if (input[i + 1] && !output) { -- GitLab From a52046e847ba4d722b4904b7e0c2db54cee88be3 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 19 Jul 2010 17:48:17 -0400 Subject: [PATCH 87/99] Fix two compilation warnings --- girepository/tools/generate.c | 1 - 1 file changed, 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index b456901995..395caff6a7 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -41,7 +41,6 @@ main (int argc, char *argv[]) GError *error = NULL; gboolean needs_prefix; gint i; - GTypelib *data; GOptionEntry options[] = { { "shlib", 0, 0, G_OPTION_ARG_NONE, &shlib, "handle typelib embedded in shlib", NULL }, -- GitLab From dac19120aa0d2b54f6316dfed6e45fd9571b56cc Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Tue, 31 Aug 2010 17:36:06 -0300 Subject: [PATCH 88/99] [GIRepository] Rename GTypelib to GITypelib Keep a typedef for backwards compatibility, until the major bindings has moved over. --- girepository/tools/generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 395caff6a7..7fe1afb0a4 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -77,7 +77,7 @@ main (int argc, char *argv[]) GError *error = NULL; const char *namespace; GMappedFile *mfile; - GTypelib *typelib; + GITypelib *typelib; mfile = g_mapped_file_new (input[i], FALSE, &error); if (!mfile) -- GitLab From 4dc7b03bce79055f1e56581ccde92b75b610045d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 3 Feb 2012 13:42:56 -0500 Subject: [PATCH 89/99] Add Emacs mode lines to C sources --- girepository/tools/generate.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 7fe1afb0a4..0426512f9f 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -1,6 +1,5 @@ - -/* -*- Mode: C; c-file-style: "gnu"; -*- */ -/* GObject introspection: IDL generator +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * GObject introspection: IDL generator * * Copyright (C) 2005 Matthias Clasen * Copyright (C) 2008,2009 Red Hat, Inc. -- GitLab From 42654f09793da33e0aa9eab682101aa391703185 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 16 Oct 2012 10:58:08 -0400 Subject: [PATCH 90/99] Drop calls to g_type_init() And bump our GLib requirement. --- girepository/tools/generate.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 0426512f9f..3e31097807 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -52,8 +52,6 @@ main (int argc, char *argv[]) g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); - g_type_init (); - g_typelib_check_sanity (); context = g_option_context_new (""); -- GitLab From 77e08288a5e126934587308c00e3c39caec1b492 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Thu, 28 Apr 2016 23:53:43 +0200 Subject: [PATCH 91/99] g-ir-inspect: Inspect GI typelibs Various distributions (mainly RPM based so far) make use of automatic dependencies extracted from typelib files (they can require other typelibs and also shared libraries) Current features * Print used shared libraries * Print used typelib dependencies Based-on-patch-by: Dominique Leuenberger Reference: https://bugzilla.gnome.org/show_bug.cgi?id=665672 Reviewed-by: Colin Walters Signed-off-by: Dominique Leuenberger Signed-off-by: Igor Gnatenko --- girepository/tools/g-ir-inspect.c | 133 ++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 girepository/tools/g-ir-inspect.c diff --git a/girepository/tools/g-ir-inspect.c b/girepository/tools/g-ir-inspect.c new file mode 100644 index 0000000000..7223af1f3c --- /dev/null +++ b/girepository/tools/g-ir-inspect.c @@ -0,0 +1,133 @@ +/* GObject introspection: typelib inspector + * + * Copyright (C) 2011-2016 Dominique Leuenberger + * Copyright © 2016 Igor Gnatenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include + +static void +print_shlibs (const gchar *namespace) +{ + guint i = 0; + + /* Finding the shared library we depend on (if any) */ + const gchar *shlibs = g_irepository_get_shared_library (NULL, namespace); + if (shlibs && shlibs[0] != '\0') + { + /* shlibs is a comma-separated list of libraries */ + GStrv libs = g_strsplit (shlibs, ",", -1); + for (i = 0; libs[i]; i++) + g_print ("shlib: %s\n", libs[i]); + g_strfreev (libs); + } +} + +static void +print_typelibs (const gchar *namespace) +{ + guint i = 0; + + /* Finding all the typelib-based Requires */ + GStrv deps = g_irepository_get_dependencies (NULL, namespace); + if (deps) + { + for (i = 0; deps[i]; i++) + g_print ("typelib: %s\n", deps[i]); + g_strfreev (deps); + } +} + +gint +main (gint argc, + gchar *argv[]) +{ + gint status = EXIT_SUCCESS; + + GError *error = NULL; + GITypelib *typelib = NULL; + + gchar *version = NULL; + gboolean opt_shlibs = FALSE; + gboolean opt_typelibs = FALSE; + GStrv namespaces = NULL; + const gchar *namespace = NULL; + const GOptionEntry options[] = { + { "version", 0, 0, G_OPTION_ARG_STRING, &version, "Version", "VERSION" }, + { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires" }, + { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires" }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" }, + { NULL }, + }; + + g_autoptr(GOptionContext) context = g_option_context_new ("- Inspect GI typelib"); + g_option_context_add_main_entries (context, options, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + status = EXIT_FAILURE; + g_printerr ("Failed to parse command line options: %s\n", error->message); + goto out; + } + + if (!namespaces) + { + status = EXIT_FAILURE; + g_printerr ("Please specify at least one namespace\n"); + goto out; + } + + if (g_strv_length (namespaces) > 1) + { + status = EXIT_FAILURE; + g_printerr ("Please specify only one namespace\n"); + goto out; + } + namespace = namespaces[0]; + + if (!opt_shlibs && !opt_typelibs) + { + status = EXIT_FAILURE; + g_printerr ("Please specify --print-shlibs, --print-typelibs or both.\n"); + goto out; + } + + typelib = g_irepository_require (NULL, namespace, version, 0, &error); + if (!typelib) + { + status = EXIT_FAILURE; + g_printerr ("Failed to load typelib: %s\n", error->message); + goto out; + } + + if (opt_shlibs) + print_shlibs (namespace); + if (opt_typelibs) + print_typelibs (namespace); + +out: + if (error) + g_error_free (error); + if (typelib) + g_typelib_free (typelib); + g_strfreev (namespaces); + g_free (version); + + return status; +} -- GitLab From 68162605ba7a8bcf476a36b1ee0ee1b31d238a2b Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Sun, 7 Aug 2016 09:58:57 +0200 Subject: [PATCH 92/99] g-ir-inspect: remove last usage of g_autoptr() Signed-off-by: Igor Gnatenko https://bugzilla.gnome.org/show_bug.cgi?id=769600 --- girepository/tools/g-ir-inspect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/girepository/tools/g-ir-inspect.c b/girepository/tools/g-ir-inspect.c index 7223af1f3c..2e68824b45 100644 --- a/girepository/tools/g-ir-inspect.c +++ b/girepository/tools/g-ir-inspect.c @@ -77,7 +77,7 @@ main (gint argc, { NULL }, }; - g_autoptr(GOptionContext) context = g_option_context_new ("- Inspect GI typelib"); + GOptionContext *context = g_option_context_new ("- Inspect GI typelib"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { @@ -122,6 +122,7 @@ main (gint argc, print_typelibs (namespace); out: + g_option_context_free (context); if (error) g_error_free (error); if (typelib) -- GitLab From 43d2206bcf27527da05b352d866456c98cb93095 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Wed, 17 Aug 2016 16:32:22 +0200 Subject: [PATCH 93/99] g-ir-inspect: make description for --version a bit better Reported-and-tested-by: Dominique Leuenberger Signed-off-by: Igor Gnatenko Reviewed-by: Colin Walters --- girepository/tools/g-ir-inspect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/tools/g-ir-inspect.c b/girepository/tools/g-ir-inspect.c index 2e68824b45..6152f9af6a 100644 --- a/girepository/tools/g-ir-inspect.c +++ b/girepository/tools/g-ir-inspect.c @@ -70,7 +70,7 @@ main (gint argc, GStrv namespaces = NULL; const gchar *namespace = NULL; const GOptionEntry options[] = { - { "version", 0, 0, G_OPTION_ARG_STRING, &version, "Version", "VERSION" }, + { "version", 0, 0, G_OPTION_ARG_STRING, &version, "Typelib version to inspect", "VERSION" }, { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires" }, { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires" }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" }, -- GitLab From 55bca7b445e34792a90e7d664d6b0521351e5fff Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Mon, 11 Jan 2016 13:35:34 +0800 Subject: [PATCH 94/99] g-ir-{compiler,generate,inspect}: Call setlocale in main function It is required to correctly show translated messages on some locales. https://bugzilla.gnome.org/show_bug.cgi?id=760419 --- girepository/tools/g-ir-inspect.c | 3 +++ girepository/tools/generate.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/girepository/tools/g-ir-inspect.c b/girepository/tools/g-ir-inspect.c index 6152f9af6a..2dfe61c295 100644 --- a/girepository/tools/g-ir-inspect.c +++ b/girepository/tools/g-ir-inspect.c @@ -22,6 +22,7 @@ #include #include #include +#include static void print_shlibs (const gchar *namespace) @@ -77,6 +78,8 @@ main (gint argc, { NULL }, }; + setlocale (LC_ALL, ""); + GOptionContext *context = g_option_context_new ("- Inspect GI typelib"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 3e31097807..926ffcac5e 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -20,6 +20,8 @@ * Boston, MA 02111-1307, USA. */ +#include + #include #include #include @@ -54,6 +56,8 @@ main (int argc, char *argv[]) g_typelib_check_sanity (); + setlocale (LC_ALL, ""); + context = g_option_context_new (""); g_option_context_add_main_entries (context, options, NULL); g_option_context_parse (context, &argc, &argv, &error); -- GitLab From ea917797bb90ed1a614031a64b108bdb9f8f7718 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 18 May 2017 20:42:28 -0700 Subject: [PATCH 95/99] g-ir-inspect: Ensure variables are at the top of block We did not yet advertise C99 requirements for G-I yet, so let's not assume this yet. --- girepository/tools/g-ir-inspect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/girepository/tools/g-ir-inspect.c b/girepository/tools/g-ir-inspect.c index 2dfe61c295..5699e93d35 100644 --- a/girepository/tools/g-ir-inspect.c +++ b/girepository/tools/g-ir-inspect.c @@ -77,10 +77,11 @@ main (gint argc, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" }, { NULL }, }; + GOptionContext *context = NULL; setlocale (LC_ALL, ""); - GOptionContext *context = g_option_context_new ("- Inspect GI typelib"); + context = g_option_context_new ("- Inspect GI typelib"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { -- GitLab From d70551e6241807b277908d4ed1cabf8d02800d2b Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 29 Jul 2018 15:40:31 +0200 Subject: [PATCH 96/99] g-ir-generate: fix missing error handling for command line parsing The error arg was used but the result never checked. --- girepository/tools/generate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 926ffcac5e..f35893c3b2 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -60,7 +60,12 @@ main (int argc, char *argv[]) context = g_option_context_new (""); g_option_context_add_main_entries (context, options, NULL); - g_option_context_parse (context, &argc, &argv, &error); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_fprintf (stderr, "failed to parse: %s\n", error->message); + g_error_free (error); + return 1; + } if (!input) { -- GitLab From 4c150f199ee745918c4e187aef3ccdcb7b010750 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 29 Jul 2018 15:56:35 +0200 Subject: [PATCH 97/99] build: enable -Wshadow --- girepository/tools/generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index f35893c3b2..36e1d05adc 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -80,11 +80,11 @@ main (int argc, char *argv[]) for (i = 0; input[i]; i++) { - GError *error = NULL; const char *namespace; GMappedFile *mfile; GITypelib *typelib; + error = NULL; mfile = g_mapped_file_new (input[i], FALSE, &error); if (!mfile) g_error ("failed to read '%s': %s", input[i], error->message); -- GitLab From c24a174437144ad5a5a01932d10067ac5b8719fe Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 16 Dec 2018 13:42:27 +0100 Subject: [PATCH 98/99] Add a --version option to g-ir-compiler and g-ir-generate. Fixes #55 --- girepository/tools/generate.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 36e1d05adc..143f01fd7c 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -41,6 +41,7 @@ main (int argc, char *argv[]) GOptionContext *context; GError *error = NULL; gboolean needs_prefix; + gboolean show_version = FALSE; gint i; GOptionEntry options[] = { @@ -48,6 +49,7 @@ main (int argc, char *argv[]) { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL }, { "all", 0, 0, G_OPTION_ARG_NONE, &show_all, "show all available information", NULL, }, + { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "show program's version number and exit", NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, { NULL, } }; @@ -67,6 +69,13 @@ main (int argc, char *argv[]) return 1; } + if (show_version) + { + g_printf ("g-ir-generate %u.%u.%u\n", + GI_MAJOR_VERSION, GI_MINOR_VERSION, GI_MICRO_VERSION); + return 0; + } + if (!input) { g_fprintf (stderr, "no input files\n"); -- GitLab From 931931d8f1e1e9c61ed214408cdaf16a01c72baf Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 8 Feb 2024 14:01:57 +0000 Subject: [PATCH 99/99] girepository: Add SPDX lines to newly imported tools Signed-off-by: Philip Withnall --- girepository/tools/g-ir-inspect.c | 2 ++ girepository/tools/generate.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/girepository/tools/g-ir-inspect.c b/girepository/tools/g-ir-inspect.c index 5699e93d35..efcfa979b3 100644 --- a/girepository/tools/g-ir-inspect.c +++ b/girepository/tools/g-ir-inspect.c @@ -3,6 +3,8 @@ * Copyright (C) 2011-2016 Dominique Leuenberger * Copyright © 2016 Igor Gnatenko * + * SPDX-License-Identifier: LGPL-2.1-or-later + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either diff --git a/girepository/tools/generate.c b/girepository/tools/generate.c index 143f01fd7c..8172682bc1 100644 --- a/girepository/tools/generate.c +++ b/girepository/tools/generate.c @@ -4,6 +4,8 @@ * Copyright (C) 2005 Matthias Clasen * Copyright (C) 2008,2009 Red Hat, Inc. * + * SPDX-License-Identifier: LGPL-2.1-or-later + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either -- GitLab