Commit e9f0e44f authored by Dan Winship's avatar Dan Winship Committed by Johan Dahlin
Browse files

Deprecate ErrorDomain

The previous ErrorDomain blob was never actually scanned or used, and
it was kind of a lame API conceptually.

To keep some compatibility, rather than removing the enumeration
values, rename them to _INVALID, and don't bump the typelib version.
This should in theory allow a new libgirepository to read an old
typelib.

Based on a patch from Colin Walters

https://bugzilla.gnome.org/show_bug.cgi?id=602516
parent 290bcbd4
......@@ -5,7 +5,6 @@ girepo_HEADERS = \
girepository/gicallableinfo.h \
girepository/giconstantinfo.h \
girepository/gienuminfo.h \
girepository/gierrordomaininfo.h \
girepository/gifieldinfo.h \
girepository/gifunctioninfo.h \
girepository/giinterfaceinfo.h \
......@@ -51,7 +50,6 @@ libgirepository_1_0_la_SOURCES = \
girepository/gicallableinfo.c \
girepository/giconstantinfo.c \
girepository/gienuminfo.c \
girepository/gierrordomaininfo.c \
girepository/gifieldinfo.c \
girepository/gifunctioninfo.c \
girepository/ginvoke.c \
......
......@@ -202,7 +202,6 @@ _g_type_info_init (GIBaseInfo *info,
* +----<link linkend="gi-GIArgInfo">GIArgInfo</link>
* +----<link linkend="gi-GICallableInfo">GICallableInfo</link>
* +----<link linkend="gi-GIConstantInfo">GIConstantInfo</link>
* +----<link linkend="gi-GIErrorDomainInfo">GIErrorDomainInfo</link>
* +----<link linkend="gi-GIFieldInfo">GIFieldInfo</link>
* +----<link linkend="gi-GIPropertyInfo">GIPropertyInfo</link>
* +----<link linkend="gi-GIRegisteredTypeInfo">GIRegisteredTypeInfo</link>
......@@ -299,7 +298,7 @@ g_base_info_get_name (GIBaseInfo *info)
case GI_INFO_TYPE_OBJECT:
case GI_INFO_TYPE_INTERFACE:
case GI_INFO_TYPE_CONSTANT:
case GI_INFO_TYPE_ERROR_DOMAIN:
case GI_INFO_TYPE_INVALID_0:
case GI_INFO_TYPE_UNION:
{
CommonBlob *blob = (CommonBlob *)&rinfo->typelib->data[rinfo->offset];
......@@ -421,7 +420,7 @@ g_base_info_is_deprecated (GIBaseInfo *info)
case GI_INFO_TYPE_OBJECT:
case GI_INFO_TYPE_INTERFACE:
case GI_INFO_TYPE_CONSTANT:
case GI_INFO_TYPE_ERROR_DOMAIN:
case GI_INFO_TYPE_INVALID_0:
{
CommonBlob *blob = (CommonBlob *)&rinfo->typelib->data[rinfo->offset];
......
/* GObject introspection: ErrorDomain implementation
*
* 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
* 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 <glib.h>
#include <girepository.h>
#include "girepository-private.h"
#include "gitypelib-internal.h"
/**
* SECTION:gierrordomaininfo
* @Short_description: Struct representing an error domain
* @Title: GIErrorDomainInfo
*
* A GIErrorDomainInfo struct represents a domain of a #GError.
* An error domain is associated with a #GQuark and contains a pointer
* to an enum with all the error codes.
*
* <refsect1 id="gi-gierrordomaininfo.struct-hierarchy" role="struct_hierarchy">
* <title role="struct_hierarchy.title">Struct hierarchy</title>
* <synopsis>
* <link linkend="gi-GIBaseInfo">GIBaseInfo</link>
* +----GIErrorDomainInfo
* </synopsis>
* </refsect1>
*/
/**
* g_error_domain_info_get_quark:
* @info: a #GIErrorDomainInfo
*
* Obtain a string representing the quark for this error domain.
* %NULL will be returned if the type tag is wrong or if a quark is
* missing in the typelib.
*
* Returns: the quark represented as a string or %NULL
*/
const gchar *
g_error_domain_info_get_quark (GIErrorDomainInfo *info)
{
GIRealInfo *rinfo = (GIRealInfo *)info;
ErrorDomainBlob *blob;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_ERROR_DOMAIN_INFO (info), NULL);
blob = (ErrorDomainBlob *)&rinfo->typelib->data[rinfo->offset];
return g_typelib_get_string (rinfo->typelib, blob->get_quark);
}
/**
* g_error_domain_info_get_codes:
* @info: a #GIErrorDomainInfo
*
* Obtain the enum containing all the error codes for this error domain.
* The return value will have a #GIInfoType of %GI_INFO_TYPE_ERROR_DOMAIN
*
* Returns: (transfer full): the error domain or %NULL if type tag is wrong,
* free the struct with g_base_info_unref() when done.
*/
GIInterfaceInfo *
g_error_domain_info_get_codes (GIErrorDomainInfo *info)
{
GIRealInfo *rinfo = (GIRealInfo *)info;
ErrorDomainBlob *blob;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_ERROR_DOMAIN_INFO (info), NULL);
blob = (ErrorDomainBlob *)&rinfo->typelib->data[rinfo->offset];
return (GIInterfaceInfo *) _g_info_from_entry (rinfo->repository,
rinfo->typelib, blob->error_codes);
}
/* GObject introspection: Error Domain
*
* 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
* 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.
*/
#ifndef __GIERRORDOMAININFO_H__
#define __GIERRORDOMAININFO_H__
#if !defined (__GIREPOSITORY_H_INSIDE__) && !defined (GI_COMPILATION)
#error "Only <girepository.h> can be included directly."
#endif
#include <gitypes.h>
G_BEGIN_DECLS
#define GI_IS_ERROR_DOMAIN_INFO(info) \
(g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_ERROR_DOMAIN)
const gchar * g_error_domain_info_get_quark (GIErrorDomainInfo *info);
GIInterfaceInfo * g_error_domain_info_get_codes (GIErrorDomainInfo *info);
G_END_DECLS
#endif /* __GIERRORDOMAININFO_H__ */
......@@ -322,7 +322,7 @@ g_field_info_get_field (GIFieldInfo *field_info,
case GI_INFO_TYPE_INTERFACE:
case GI_INFO_TYPE_FUNCTION:
case GI_INFO_TYPE_CONSTANT:
case GI_INFO_TYPE_ERROR_DOMAIN:
case GI_INFO_TYPE_INVALID_0:
case GI_INFO_TYPE_VALUE:
case GI_INFO_TYPE_SIGNAL:
case GI_INFO_TYPE_PROPERTY:
......@@ -498,7 +498,7 @@ g_field_info_set_field (GIFieldInfo *field_info,
case GI_INFO_TYPE_INTERFACE:
case GI_INFO_TYPE_FUNCTION:
case GI_INFO_TYPE_CONSTANT:
case GI_INFO_TYPE_ERROR_DOMAIN:
case GI_INFO_TYPE_INVALID_0:
case GI_INFO_TYPE_VALUE:
case GI_INFO_TYPE_SIGNAL:
case GI_INFO_TYPE_PROPERTY:
......
......@@ -1466,8 +1466,6 @@ g_info_type_to_string (GIInfoType type)
return "interface";
case GI_INFO_TYPE_CONSTANT:
return "constant";
case GI_INFO_TYPE_ERROR_DOMAIN:
return "error domain";
case GI_INFO_TYPE_UNION:
return "union";
case GI_INFO_TYPE_VALUE:
......
......@@ -32,7 +32,6 @@
#include <gicallableinfo.h>
#include <giconstantinfo.h>
#include <gienuminfo.h>
#include <gierrordomaininfo.h>
#include <gifieldinfo.h>
#include <gifunctioninfo.h>
#include <giinterfaceinfo.h>
......
......@@ -415,7 +415,7 @@ _g_ir_module_build_typelib (GIrModule *module)
header->field_blob_size = sizeof (FieldBlob);
header->value_blob_size = sizeof (ValueBlob);
header->constant_blob_size = sizeof (ConstantBlob);
header->error_domain_blob_size = sizeof (ErrorDomainBlob);
header->error_domain_blob_size = 16; /* No longer used */
header->attribute_blob_size = sizeof (AttributeBlob);
header->signature_blob_size = sizeof (SignatureBlob);
header->enum_blob_size = sizeof (EnumBlob);
......
......@@ -101,8 +101,6 @@ _g_ir_node_type_to_string (GIrNodeTypeId type)
return "value";
case G_IR_NODE_CONSTANT:
return "constant";
case G_IR_NODE_ERROR_DOMAIN:
return "error-domain";
case G_IR_NODE_XREF:
return "xref";
case G_IR_NODE_UNION:
......@@ -175,10 +173,6 @@ _g_ir_node_new (GIrNodeTypeId type,
node = g_malloc0 (sizeof (GIrNodeConstant));
break;
case G_IR_NODE_ERROR_DOMAIN:
node = g_malloc0 (sizeof (GIrNodeErrorDomain));
break;
case G_IR_NODE_XREF:
node = g_malloc0 (sizeof (GIrNodeXRef));
break;
......@@ -379,16 +373,6 @@ _g_ir_node_free (GIrNode *node)
}
break;
case G_IR_NODE_ERROR_DOMAIN:
{
GIrNodeErrorDomain *domain = (GIrNodeErrorDomain *)node;
g_free (node->name);
g_free (domain->getquark);
g_free (domain->codes);
}
break;
case G_IR_NODE_XREF:
{
GIrNodeXRef *xref = (GIrNodeXRef *)node;
......@@ -535,10 +519,6 @@ _g_ir_node_get_size (GIrNode *node)
size = sizeof (ConstantBlob);
break;
case G_IR_NODE_ERROR_DOMAIN:
size = sizeof (ErrorDomainBlob);
break;
case G_IR_NODE_XREF:
size = 0;
break;
......@@ -665,16 +645,7 @@ _g_ir_node_get_full_size_internal (GIrNode *parent,
size += _g_ir_node_get_full_size_internal (node, (GIrNode *)type->parameter_type2);
break;
case GI_TYPE_TAG_ERROR:
{
gint n;
if (type->errors)
n = g_strv_length (type->errors);
else
n = 0;
size += sizeof (ErrorTypeBlob) + 2 * (n + n % 2);
}
size += sizeof (ErrorTypeBlob);
break;
default:
g_error ("Unknown type tag %d\n", type->tag);
......@@ -844,16 +815,6 @@ _g_ir_node_get_full_size_internal (GIrNode *parent,
}
break;
case G_IR_NODE_ERROR_DOMAIN:
{
GIrNodeErrorDomain *domain = (GIrNodeErrorDomain *)node;
size = sizeof (ErrorDomainBlob);
size += ALIGN_VALUE (strlen (node->name) + 1, 4);
size += ALIGN_VALUE (strlen (domain->getquark) + 1, 4);
}
break;
case G_IR_NODE_XREF:
{
GIrNodeXRef *xref = (GIrNodeXRef *)node;
......@@ -935,7 +896,7 @@ _g_ir_node_can_have_member (GIrNode *node)
case G_IR_NODE_ENUM:
case G_IR_NODE_FLAGS:
case G_IR_NODE_CONSTANT:
case G_IR_NODE_ERROR_DOMAIN:
case G_IR_NODE_INVALID_0:
case G_IR_NODE_PARAM:
case G_IR_NODE_TYPE:
case G_IR_NODE_PROPERTY:
......@@ -1559,21 +1520,14 @@ _g_ir_node_build_typelib (GIrNode *node,
case GI_TYPE_TAG_ERROR:
{
ErrorTypeBlob *blob = (ErrorTypeBlob *)&data[*offset2];
gint i;
blob->pointer = 1;
blob->reserved = 0;
blob->tag = type->tag;
blob->reserved2 = 0;
if (type->errors)
blob->n_domains = g_strv_length (type->errors);
else
blob->n_domains = 0;
*offset2 = ALIGN_VALUE (*offset2 + G_STRUCT_OFFSET (ErrorTypeBlob, domains)
+ 2 * blob->n_domains, 4);
for (i = 0; i < blob->n_domains; i++)
blob->domains[i] = find_entry (build, type->errors[i]);
blob->n_domains = 0;
*offset2 += sizeof (ErrorTypeBlob);
}
break;
......@@ -2234,22 +2188,6 @@ _g_ir_node_build_typelib (GIrNode *node,
}
break;
case G_IR_NODE_ERROR_DOMAIN:
{
GIrNodeErrorDomain *domain = (GIrNodeErrorDomain *)node;
ErrorDomainBlob *blob = (ErrorDomainBlob *)&data[*offset];
*offset += sizeof (ErrorDomainBlob);
blob->blob_type = BLOB_TYPE_ERROR_DOMAIN;
blob->deprecated = domain->deprecated;
blob->reserved = 0;
blob->name = _g_ir_write_string (node->name, strings, data, offset2);
blob->get_quark = _g_ir_write_string (domain->getquark, strings, data, offset2);
blob->error_codes = find_entry (build, domain->codes);
blob->reserved2 = 0;
}
break;
case G_IR_NODE_CONSTANT:
{
GIrNodeConstant *constant = (GIrNodeConstant *)node;
......
......@@ -41,7 +41,6 @@ typedef struct _GIrNodeEnum GIrNodeEnum;
typedef struct _GIrNodeBoxed GIrNodeBoxed;
typedef struct _GIrNodeStruct GIrNodeStruct;
typedef struct _GIrNodeConstant GIrNodeConstant;
typedef struct _GIrNodeErrorDomain GIrNodeErrorDomain;
typedef struct _GIrNodeXRef GIrNodeXRef;
typedef struct _GIrNodeUnion GIrNodeUnion;
......@@ -57,7 +56,7 @@ typedef enum
G_IR_NODE_OBJECT = 7,
G_IR_NODE_INTERFACE = 8,
G_IR_NODE_CONSTANT = 9,
G_IR_NODE_ERROR_DOMAIN = 10,
G_IR_NODE_INVALID_0 = 10, /* DELETED - used to be ERROR_DOMAIN */
G_IR_NODE_UNION = 11,
G_IR_NODE_PARAM = 12,
G_IR_NODE_TYPE = 13,
......@@ -343,18 +342,6 @@ struct _GIrNodeUnion
};
struct _GIrNodeErrorDomain
{
GIrNode node;
gboolean deprecated;
gchar *name;
gchar *getquark;
gchar *codes;
};
GIrNode * _g_ir_node_new (GIrNodeTypeId type,
GIrModule *module);
void _g_ir_node_free (GIrNode *node);
......
......@@ -68,13 +68,12 @@ typedef enum
STATE_BOXED_FIELD,
STATE_STRUCT,
STATE_STRUCT_FIELD,
STATE_ERRORDOMAIN, /* 25 */
STATE_UNION,
STATE_UNION, /* 25 */
STATE_UNION_FIELD,
STATE_NAMESPACE_CONSTANT,
STATE_CLASS_CONSTANT,
STATE_INTERFACE_CONSTANT, /* 30 */
STATE_ALIAS,
STATE_INTERFACE_CONSTANT,
STATE_ALIAS, /* 30 */
STATE_TYPE,
STATE_ATTRIBUTE,
STATE_DOC,
......@@ -1614,68 +1613,6 @@ start_constant (GMarkupParseContext *context,
return TRUE;
}
static gboolean
start_errordomain (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
ParseContext *ctx,
GError **error)
{
const gchar *name;
const gchar *getquark;
const gchar *codes;
const gchar *deprecated;
GIrNodeErrorDomain *domain;
if (!(strcmp (element_name, "errordomain") == 0 &&
ctx->state == STATE_NAMESPACE))
return FALSE;
if (!introspectable_prelude (context, attribute_names, attribute_values, ctx, STATE_ERRORDOMAIN))
return TRUE;
name = find_attribute ("name", attribute_names, attribute_values);
getquark = find_attribute ("get-quark", attribute_names, attribute_values);
codes = find_attribute ("codes", attribute_names, attribute_values);
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
if (name == NULL)
{
MISSING_ATTRIBUTE (context, error, element_name, "name");
return FALSE;
}
else if (getquark == NULL)
{
MISSING_ATTRIBUTE (context, error, element_name, "getquark");
return FALSE;
}
else if (codes == NULL)
{
MISSING_ATTRIBUTE (context, error, element_name, "codes");
return FALSE;
}
domain = (GIrNodeErrorDomain *) _g_ir_node_new (G_IR_NODE_ERROR_DOMAIN,
ctx->current_module);
((GIrNode *)domain)->name = g_strdup (name);
domain->getquark = g_strdup (getquark);
domain->codes = g_strdup (codes);
if (deprecated)
domain->deprecated = TRUE;
else
domain->deprecated = FALSE;
push_node (ctx, (GIrNode *) domain);
ctx->current_module->entries =
g_list_append (ctx->current_module->entries, domain);
return TRUE;
}
static gboolean
start_interface (GMarkupParseContext *context,
const gchar *element_name,
......@@ -2788,10 +2725,6 @@ start_element_handler (GMarkupParseContext *context,
attribute_names, attribute_values,
ctx, error))
goto out;
else if (start_errordomain (context, element_name,
attribute_names, attribute_values,
ctx, error))
goto out;
break;
case 'f':
......@@ -3290,14 +3223,6 @@ end_element_handler (GMarkupParseContext *context,
}
break;
case STATE_ERRORDOMAIN:
if (require_end_element (context, ctx, "errordomain", element_name, error))
{
pop_node (ctx);
state_switch (ctx, STATE_NAMESPACE);
}
break;
case STATE_INTERFACE_PROPERTY:
if (strcmp ("type", element_name) == 0)
break;
......
......@@ -212,7 +212,6 @@ write_type_info (const gchar *namespace,
Xml *file)
{
gint tag;
gint i;
GITypeInfo *type;
gboolean is_pointer;
......@@ -329,24 +328,8 @@ write_type_info (const gchar *namespace,
}
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
......@@ -1193,25 +1176,6 @@ write_interface_info (const gchar *namespace,
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,
......@@ -1411,10 +1375,6 @@ gir_writer_write (const char *filename,
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));
}
......
......@@ -340,72 +340,3 @@ g_type_info_get_array_type (GITypeInfo *info)
return -1;
}
/**
* g_type_info_get_n_error_domains:
* @info: a #GITypeInfo
*
* Obtain the number of error domains for this type. The type tag
* must be a #GI_TYPE_TAG_ERROR or -1 will be returned.
*
* Returns: number of error domains or -1
*/
gint
g_type_info_get_n_error_domains (GITypeInfo *info)
{
GIRealInfo *rinfo = (GIRealInfo *)info;
SimpleTypeBlob *type;
g_return_val_if_fail (info != NULL, 0);
g_return_val_if_fail (GI_IS_TYPE_INFO (info), 0);
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
{
ErrorTypeBlob *blob = (ErrorTypeBlob *)&rinfo->typelib->data[rinfo->offset];
if (blob->tag == GI_TYPE_TAG_ERROR)
return blob->n_domains;