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.
This commit is contained in:
Colin Walters 2009-02-20 17:34:20 -05:00
parent f13354f9ea
commit 9dbb0bf80f
7 changed files with 64 additions and 33 deletions

40
ginfo.c
View File

@ -1182,22 +1182,22 @@ g_struct_info_get_alignment (GIStructInfo *info)
}
/**
* g_struct_info_is_class_struct:
* g_struct_info_is_gtype_struct:
* @info: GIStructInfo
*
* Return true if this structure represents the "class structure" for some
* GObject. This function is mainly useful to hide this kind of structure
* from public APIs.
* #GObject or #GInterface. This function is mainly useful to hide this kind of structure
* from generated public APIs.
*
* Returns: TRUE if it's a class struct, otherwise FALSE
* Returns: %TRUE if this is a class struct, %FALSE otherwise
*/
gboolean
g_struct_info_is_class_struct (GIStructInfo *info)
g_struct_info_is_gtype_struct (GIStructInfo *info)
{
GIBaseInfo *base = (GIBaseInfo *)info;
StructBlob *blob = (StructBlob *)&base->typelib->data[base->offset];
return blob->is_class_struct;
return blob->is_gtype_struct;
}
gint
@ -1495,10 +1495,10 @@ g_object_info_get_constant (GIObjectInfo *info,
* g_object_info_get_class_struct:
* @info: A #GIObjectInfo to query
*
* Every GObject has two structures; an instance structure and a class
* Every #GObject has two structures; an instance structure and a class
* structure. This function returns the metadata for the class structure.
*
* Returns: a GIStrucTInfo for the class struct or NULL if none found.
* Returns: a #GIStructInfo for the class struct or %NULL if none found.
*/
GIStructInfo *
g_object_info_get_class_struct (GIObjectInfo *info)
@ -1506,9 +1506,9 @@ g_object_info_get_class_struct (GIObjectInfo *info)
GIBaseInfo *base = (GIBaseInfo *)info;
ObjectBlob *blob = (ObjectBlob *)&base->typelib->data[base->offset];
if (blob->class_struct)
if (blob->gtype_struct)
return (GIStructInfo *) g_info_from_entry (base->repository,
base->typelib, blob->class_struct);
base->typelib, blob->gtype_struct);
else
return NULL;
}
@ -1691,8 +1691,26 @@ g_interface_info_get_constant (GIInterfaceInfo *info,
base->typelib, offset);
}
/**
* g_interface_info_get_iface_struct:
* @info: A #GIInterfaceInfo to query
*
* Returns the layout C structure associated with this #GInterface.
*
* Returns: A #GIStructInfo for the class struct or %NULL if none found.
*/
GIStructInfo *
g_interface_info_get_iface_struct (GIInterfaceInfo *info)
{
GIBaseInfo *base = (GIBaseInfo *)info;
InterfaceBlob *blob = (InterfaceBlob *)&base->typelib->data[base->offset];
if (blob->gtype_struct)
return (GIStructInfo *) g_info_from_entry (base->repository,
base->typelib, blob->gtype_struct);
else
return NULL;
}
/* GIPropertyInfo functions */
GParamFlags

View File

@ -417,7 +417,7 @@ GIFunctionInfo * g_struct_info_find_method (GIStructInfo *info,
const gchar *name);
gsize g_struct_info_get_size (GIStructInfo *info);
gsize g_struct_info_get_alignment (GIStructInfo *info);
gboolean g_struct_info_is_class_struct (GIStructInfo *info);
gboolean g_struct_info_is_gtype_struct (GIStructInfo *info);
/* GIRegisteredTypeInfo */
@ -487,6 +487,8 @@ gint g_interface_info_get_n_constants (GIInterfaceInfo *in
GIConstantInfo * g_interface_info_get_constant (GIInterfaceInfo *info,
gint n);
GIStructInfo * g_interface_info_get_iface_struct (GIInterfaceInfo *info);
/* GIPropertyInfo */

View File

@ -286,7 +286,8 @@ g_ir_node_free (GIrNode *node)
g_free (iface->gtype_name);
g_free (iface->gtype_init);
g_free (iface->class_struct);
g_free (iface->glib_type_struct);
g_free (iface->parent);
for (l = iface->interfaces; l; l = l->next)
@ -652,8 +653,8 @@ g_ir_node_get_full_size_internal (GIrNode *parent,
size = sizeof(ObjectBlob);
if (iface->parent)
size += ALIGN_VALUE (strlen (iface->parent) + 1, 4);
if (iface->class_struct)
size += ALIGN_VALUE (strlen (iface->class_struct) + 1, 4);
if (iface->glib_type_struct)
size += ALIGN_VALUE (strlen (iface->glib_type_struct) + 1, 4);
size += ALIGN_VALUE (strlen (node->name) + 1, 4);
size += ALIGN_VALUE (strlen (iface->gtype_name) + 1, 4);
if (iface->gtype_init)
@ -1781,7 +1782,7 @@ g_ir_node_build_typelib (GIrNode *node,
blob->blob_type = BLOB_TYPE_STRUCT;
blob->deprecated = struct_->deprecated;
blob->is_class_struct = struct_->is_gclass_struct;
blob->is_gtype_struct = struct_->is_gtype_struct;
blob->reserved = 0;
blob->name = write_string (node->name, strings, data, offset2);
blob->alignment = struct_->alignment;
@ -1984,10 +1985,10 @@ g_ir_node_build_typelib (GIrNode *node,
blob->parent = find_entry (module, modules, object->parent);
else
blob->parent = 0;
if (object->class_struct)
blob->class_struct = find_entry (module, modules, object->class_struct);
if (object->glib_type_struct)
blob->gtype_struct = find_entry (module, modules, object->glib_type_struct);
else
blob->class_struct = 0;
blob->gtype_struct = 0;
blob->n_interfaces = 0;
blob->n_fields = 0;
@ -2049,6 +2050,10 @@ g_ir_node_build_typelib (GIrNode *node,
blob->name = write_string (node->name, strings, data, offset2);
blob->gtype_name = write_string (iface->gtype_name, strings, data, offset2);
blob->gtype_init = write_string (iface->gtype_init, strings, data, offset2);
if (iface->glib_type_struct)
blob->gtype_struct = find_entry (module, modules, iface->glib_type_struct);
else
blob->gtype_struct = 0;
blob->n_prerequisites = 0;
blob->n_properties = 0;
blob->n_methods = 0;

View File

@ -237,7 +237,7 @@ struct _GIrNodeInterface
gchar *gtype_init;
gchar *parent;
gchar *class_struct; /* Only applies to classes */
gchar *glib_type_struct;
GList *interfaces;
GList *prerequisites;
@ -302,7 +302,7 @@ struct _GIrNodeStruct
gboolean deprecated;
gboolean disguised;
gboolean is_gclass_struct;
gboolean is_gtype_struct;
gchar *gtype_name;
gchar *gtype_init;

View File

@ -1482,10 +1482,12 @@ start_interface (GMarkupParseContext *context,
const gchar *typename;
const gchar *typeinit;
const gchar *deprecated;
const gchar *glib_type_struct;
name = find_attribute ("name", attribute_names, attribute_values);
typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
glib_type_struct = find_attribute ("glib:type-struct", attribute_names, attribute_values);
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
if (name == NULL)
@ -1502,6 +1504,7 @@ start_interface (GMarkupParseContext *context,
((GIrNode *)iface)->name = g_strdup (name);
iface->gtype_name = g_strdup (typename);
iface->gtype_init = g_strdup (typeinit);
iface->glib_type_struct = g_strdup (glib_type_struct);
if (deprecated)
iface->deprecated = TRUE;
else
@ -1533,7 +1536,7 @@ start_class (GMarkupParseContext *context,
{
const gchar *name;
const gchar *parent;
const gchar *class_struct;
const gchar *glib_type_struct;
const gchar *typename;
const gchar *typeinit;
const gchar *deprecated;
@ -1541,7 +1544,7 @@ start_class (GMarkupParseContext *context,
name = find_attribute ("name", attribute_names, attribute_values);
parent = find_attribute ("parent", attribute_names, attribute_values);
class_struct = find_attribute ("glib:class-struct", attribute_names, attribute_values);
glib_type_struct = find_attribute ("glib:type-struct", attribute_names, attribute_values);
typename = find_attribute ("glib:type-name", attribute_names, attribute_values);
typeinit = find_attribute ("glib:get-type", attribute_names, attribute_values);
deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
@ -1562,7 +1565,7 @@ start_class (GMarkupParseContext *context,
iface->gtype_name = g_strdup (typename);
iface->gtype_init = g_strdup (typeinit);
iface->parent = g_strdup (parent);
iface->class_struct = g_strdup (class_struct);
iface->glib_type_struct = g_strdup (glib_type_struct);
if (deprecated)
iface->deprecated = TRUE;
else
@ -2128,7 +2131,7 @@ start_struct (GMarkupParseContext *context,
const gchar *disguised;
const gchar *gtype_name;
const gchar *gtype_init;
const gchar *gclass_struct;
const gchar *gtype_struct;
GIrNodeStruct *struct_;
name = find_attribute ("name", attribute_names, attribute_values);
@ -2136,7 +2139,7 @@ start_struct (GMarkupParseContext *context,
disguised = find_attribute ("disguised", attribute_names, attribute_values);
gtype_name = find_attribute ("glib:type-name", attribute_names, attribute_values);
gtype_init = find_attribute ("glib:get-type", attribute_names, attribute_values);
gclass_struct = find_attribute ("glib:is-class-struct-for", attribute_names, attribute_values);
gtype_struct = find_attribute ("glib:is-gtype-struct-for", attribute_names, attribute_values);
if (name == NULL && ctx->node_stack == NULL)
{
@ -2165,7 +2168,7 @@ start_struct (GMarkupParseContext *context,
if (disguised && strcmp (disguised, "1") == 0)
struct_->disguised = TRUE;
struct_->is_gclass_struct = gclass_struct != NULL;
struct_->is_gtype_struct = gtype_struct != NULL;
struct_->gtype_name = g_strdup (gtype_name);
struct_->gtype_init = g_strdup (gtype_init);

View File

@ -183,7 +183,7 @@ g_typelib_check_sanity (void)
CHECK_SIZE (SignalBlob, 16);
CHECK_SIZE (VFuncBlob, 20);
CHECK_SIZE (ObjectBlob, 44);
CHECK_SIZE (InterfaceBlob, 36);
CHECK_SIZE (InterfaceBlob, 40);
CHECK_SIZE (ConstantBlob, 24);
CHECK_SIZE (AnnotationBlob, 12);
CHECK_SIZE (UnionBlob, 40);
@ -1458,11 +1458,11 @@ validate_object_blob (ValidateContext *ctx,
}
}
if (blob->class_struct != 0)
if (blob->gtype_struct != 0)
{
DirEntry *entry;
entry = get_dir_entry_checked (typelib, blob->class_struct, error);
entry = get_dir_entry_checked (typelib, blob->gtype_struct, error);
if (!entry)
return FALSE;
if (entry->blob_type != BLOB_TYPE_STRUCT && entry->local)

View File

@ -72,6 +72,7 @@ G_BEGIN_DECLS
TYPELIB HISTORY
-----
Version 1.0
- Rename class_struct to gtype_struct, add to interfaces
Changes since 0.9:
- Add padding to structures
@ -651,7 +652,7 @@ typedef struct {
* @deprecated: Whether this structure is deprecated
* @unregistered: If this is set, the type is not registered with GType.
* @alignment: The byte boundary that the struct is aligned to in memory
* @is_class_struct: Whether this structure is the "class structure" for a GObject
* @is_gtype_struct: Whether this structure is the class or interface layout for a GObject
* @size: The size of the struct in bytes.
* @gtype_name: String name of the associated #GType
* @gtype_init: String naming the symbol which gets the runtime #GType
@ -666,7 +667,7 @@ typedef struct {
guint16 deprecated : 1;
guint16 unregistered : 1;
guint16 is_class_struct : 1;
guint16 is_gtype_struct : 1;
guint16 alignment : 6;
guint16 reserved : 7;
@ -900,7 +901,7 @@ typedef struct {
guint32 gtype_init;
guint16 parent;
guint16 class_struct;
guint16 gtype_struct;
guint16 n_interfaces;
guint16 n_fields;
@ -929,6 +930,7 @@ typedef struct {
/**
* InterfaceBlob:
* @gtype_struct: Name of the interface "class" C structure
* @n_prerequisites: Number of prerequisites
* @n_properties: Number of properties
* @n_methods: Number of methods
@ -952,6 +954,7 @@ typedef struct {
guint32 gtype_name;
guint32 gtype_init;
guint16 gtype_struct;
guint16 n_prerequisites;
guint16 n_properties;