g_message ("%lu types (%lu before sharing)", unique_types_count, types_count);
}
+#define DO_ALIGNED_COPY(dest_addr, value, type) \
+do { \
+ type tmp_var; \
+ tmp_var = value; \
+ memcpy(dest_addr, &tmp_var, sizeof(type)); \
+} while(0)
+
#define ALIGN_VALUE(this, boundary) \
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
GIrNodeVFunc *vfunc = (GIrNodeVFunc *)node;
g_free (node->name);
+ g_free (vfunc->invoker);
for (l = vfunc->parameters; l; l = l->next)
g_ir_node_free ((GIrNode *)l->data);
g_list_free (vfunc->parameters);
g_free (node->name);
g_ir_node_free ((GIrNode *)field->type);
+ g_ir_node_free ((GIrNode *)field->callback);
}
break;
break;
case G_IR_NODE_FIELD:
- size = sizeof (FieldBlob);
+ {
+ GIrNodeField *field = (GIrNodeField *)node;
+
+ size = sizeof (FieldBlob);
+ if (field->callback)
+ size += g_ir_node_get_size ((GIrNode *)field->callback);
+ }
break;
case G_IR_NODE_CONSTANT:
size = sizeof (FieldBlob);
size += ALIGN_VALUE (strlen (node->name) + 1, 4);
- size += g_ir_node_get_full_size_internal (node, (GIrNode *)field->type);
+ if (field->callback)
+ size += g_ir_node_get_full_size_internal (node, (GIrNode *)field->callback);
+ else
+ size += g_ir_node_get_full_size_internal (node, (GIrNode *)field->type);
}
break;
goto out;
}
- g_warning ("Entry '%s' not found", name);
+ g_ir_module_fatal (module, 0, "Type reference '%s' not found", name);
out:
return node != NULL;
}
+static int
+get_index_of_member_type (GIrNodeInterface *node,
+ GIrNodeTypeId type,
+ const char *name)
+{
+ guint index = -1;
+ GList *l;
+
+ for (l = node->members; l; l = l->next)
+ {
+ GIrNode *node = l->data;
+
+ if (node->type != type)
+ continue;
+
+ index++;
+
+ if (strcmp (node->name, name) == 0)
+ break;
+ }
+
+ return index;
+}
+
static void
serialize_type (GIrModule *module,
GList *modules,
"uint32",
"int64",
"uint64",
+ "short",
+ "ushort",
"int",
"uint",
"long",
"size",
"float",
"double",
+ "time_t",
+ "GType",
"utf8",
"filename",
- "string",
- "sequence",
- "any"
};
if (node->tag < GI_TYPE_TAG_ARRAY)
type->tag == GI_TYPE_TAG_UTF8 ||
type->tag == GI_TYPE_TAG_FILENAME)
{
- blob->reserved = 0;
- blob->reserved2 = 0;
- blob->pointer = type->is_pointer;
- blob->reserved3 = 0;
- blob->tag = type->tag;
+ blob->flags.reserved = 0;
+ blob->flags.reserved2 = 0;
+ blob->flags.pointer = type->is_pointer;
+ blob->flags.reserved3 = 0;
+ blob->flags.tag = type->tag;
}
else
{
array->has_size = type->has_size;
array->reserved2 = 0;
if (array->has_length)
- array->length = type->length;
+ array->dimensions.length = type->length;
else if (array->has_size)
- array->size = type->size;
+ array->dimensions.size = type->size;
else
- array->length = -1;
+ array->dimensions.length = -1;
pos = *offset2 + G_STRUCT_OFFSET (ArrayTypeBlob, type);
*offset2 += sizeof (ArrayTypeBlob);
FieldBlob *blob;
blob = (FieldBlob *)&data[*offset];
- /* We handle the size member specially below, so subtract it */
- *offset += sizeof (FieldBlob) - sizeof (SimpleTypeBlob);
blob->name = write_string (node->name, strings, data, offset2);
blob->readable = field->readable;
else
blob->struct_offset = 0xFFFF; /* mark as unknown */
- g_ir_node_build_typelib ((GIrNode *)field->type,
- node, build, offset, offset2);
+ if (field->callback)
+ {
+ blob->has_embedded_type = TRUE;
+ blob->type.offset = GI_INFO_TYPE_CALLBACK;
+ *offset += sizeof (FieldBlob);
+ g_ir_node_build_typelib ((GIrNode *)field->callback,
+ node, build, offset, offset2);
+ }
+ else
+ {
+ blob->has_embedded_type = FALSE;
+ /* We handle the size member specially below, so subtract it */
+ *offset += sizeof (FieldBlob) - sizeof (SimpleTypeBlob);
+ g_ir_node_build_typelib ((GIrNode *)field->type,
+ node, build, offset, offset2);
+ }
}
break;
blob->class_closure = 0; /* FIXME */
blob->reserved = 0;
+ if (vfunc->invoker)
+ {
+ int index = get_index_of_member_type ((GIrNodeInterface*)parent, G_IR_NODE_FUNCTION, vfunc->invoker);
+ if (index == -1)
+ {
+ g_error ("Unknown member function %s for vfunc %s", vfunc->invoker, node->name);
+ }
+ blob->invoker = (guint) index;
+ }
+ else
+ blob->invoker = 0x3ff; /* max of 10 bits */
+
blob->struct_offset = vfunc->offset;
blob->reserved2 = 0;
blob->signature = signature;
break;
case GI_TYPE_TAG_INT64:
blob->size = 8;
- *(gint64*)&data[blob->offset] = (gint64) parse_int_value (constant->value);
+ DO_ALIGNED_COPY(&data[blob->offset], parse_int_value (constant->value), gint64);
break;
case GI_TYPE_TAG_UINT64:
blob->size = 8;
- *(guint64*)&data[blob->offset] = (guint64) parse_uint_value (constant->value);
+ DO_ALIGNED_COPY(&data[blob->offset], parse_uint_value (constant->value), guint64);
+ break;
+ case GI_TYPE_TAG_SHORT:
+ blob->size = sizeof (gshort);
+ *(gshort*)&data[blob->offset] = (gshort) parse_int_value (constant->value);
+ break;
+ case GI_TYPE_TAG_USHORT:
+ blob->size = sizeof (gushort);
+ *(gushort*)&data[blob->offset] = (gushort) parse_uint_value (constant->value);
break;
case GI_TYPE_TAG_INT:
blob->size = sizeof (gint);
case GI_TYPE_TAG_SSIZE: /* FIXME */
case GI_TYPE_TAG_LONG:
blob->size = sizeof (glong);
- *(glong*)&data[blob->offset] = (glong) parse_int_value (constant->value);
+ DO_ALIGNED_COPY(&data[blob->offset], parse_int_value (constant->value), glong);
break;
case GI_TYPE_TAG_SIZE: /* FIXME */
case GI_TYPE_TAG_TIME_T:
case GI_TYPE_TAG_ULONG:
blob->size = sizeof (gulong);
- *(gulong*)&data[blob->offset] = (gulong) parse_uint_value (constant->value);
+ DO_ALIGNED_COPY(&data[blob->offset], parse_uint_value (constant->value), gulong);
break;
case GI_TYPE_TAG_FLOAT:
blob->size = sizeof (gfloat);
- *(gfloat*)&data[blob->offset] = (gfloat) parse_float_value (constant->value);
+ DO_ALIGNED_COPY(&data[blob->offset], parse_float_value (constant->value), gfloat);
break;
case GI_TYPE_TAG_DOUBLE:
blob->size = sizeof (gdouble);
- *(gdouble*)&data[blob->offset] = (gdouble) parse_float_value (constant->value);
+ DO_ALIGNED_COPY(&data[blob->offset], parse_float_value (constant->value), gdouble);
break;
case GI_TYPE_TAG_UTF8:
case GI_TYPE_TAG_FILENAME: