Don't include machine-dependent integral types in the typelib

Previously we had both e.g. GI_TYPE_TAG_LONG and GI_TYPE_TAG_INT64,
but in fact the typelib is already machine-specific, so it makes sense
to just encode this as a fixed type.  The .gir remains abstract.

We also remove size_t from the typelib; one would never want to treat
it differently than an integer.

time_t is removed as well; while bindings like gjs had special handling
to turn it into e.g. a JS Date object, I don't think we should encourage
people to use these POSIX types in their API.  Use GTimeVal or the like
instead.

Because the typelib is now really machine-specific, we need to remove
the -expected.tgirs from git.  (We could potentially add a check
which wasn't just a literal diff later)

https://bugzilla.gnome.org/show_bug.cgi?id=623774
This commit is contained in:
Colin Walters 2010-07-07 14:07:17 -04:00
parent cf2b0074ad
commit 3a310fd242
9 changed files with 79 additions and 224 deletions

View File

@ -129,27 +129,6 @@ g_constant_info_get_value (GIConstantInfo *info,
case GI_TYPE_TAG_DOUBLE:
value->v_double = *(gdouble*)&rinfo->typelib->data[blob->offset];
break;
case GI_TYPE_TAG_TIME_T:
value->v_long = *(long*)&rinfo->typelib->data[blob->offset];
break;
case GI_TYPE_TAG_SHORT:
value->v_short = *(gshort*)&rinfo->typelib->data[blob->offset];
break;
case GI_TYPE_TAG_USHORT:
value->v_ushort = *(gushort*)&rinfo->typelib->data[blob->offset];
break;
case GI_TYPE_TAG_INT:
value->v_int = *(gint*)&rinfo->typelib->data[blob->offset];
break;
case GI_TYPE_TAG_UINT:
value->v_uint = *(guint*)&rinfo->typelib->data[blob->offset];
break;
case GI_TYPE_TAG_LONG:
value->v_long = *(glong*)&rinfo->typelib->data[blob->offset];
break;
case GI_TYPE_TAG_ULONG:
value->v_ulong = *(gulong*)&rinfo->typelib->data[blob->offset];
break;
}
}
}

View File

@ -215,15 +215,11 @@ g_field_info_get_field (GIFieldInfo *field_info,
break;
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_SHORT:
case GI_TYPE_TAG_USHORT:
value->v_uint16 = G_STRUCT_MEMBER (guint16, mem, offset);
result = TRUE;
break;
case GI_TYPE_TAG_INT32:
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_INT:
case GI_TYPE_TAG_UINT:
value->v_uint32 = G_STRUCT_MEMBER (guint32, mem, offset);
result = TRUE;
break;
@ -232,13 +228,6 @@ g_field_info_get_field (GIFieldInfo *field_info,
value->v_uint64 = G_STRUCT_MEMBER (guint64, mem, offset);
result = TRUE;
break;
case GI_TYPE_TAG_LONG:
case GI_TYPE_TAG_ULONG:
value->v_ulong = G_STRUCT_MEMBER (gulong, mem, offset);
result = TRUE;
break;
case GI_TYPE_TAG_SSIZE:
case GI_TYPE_TAG_SIZE:
case GI_TYPE_TAG_GTYPE:
value->v_size = G_STRUCT_MEMBER (gsize, mem, offset);
result = TRUE;
@ -251,16 +240,6 @@ g_field_info_get_field (GIFieldInfo *field_info,
value->v_double = G_STRUCT_MEMBER (gdouble, mem, offset);
result = TRUE;
break;
case GI_TYPE_TAG_TIME_T:
#if SIZEOF_TIME_T == 4
value->v_int32 = G_STRUCT_MEMBER (time_t, mem, offset);
#elif SIZEOF_TIME_T == 8
value->v_int64 = G_STRUCT_MEMBER (time_t, mem, offset);
#else
# error "Unexpected size for time_t: not 4 or 8"
#endif
result = TRUE;
break;
case GI_TYPE_TAG_UTF8:
case GI_TYPE_TAG_FILENAME:
case GI_TYPE_TAG_ARRAY:
@ -306,15 +285,11 @@ g_field_info_get_field (GIFieldInfo *field_info,
break;
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_SHORT:
case GI_TYPE_TAG_USHORT:
value->v_int = (gint)G_STRUCT_MEMBER (guint16, mem, offset);
result = TRUE;
break;
case GI_TYPE_TAG_INT32:
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_INT:
case GI_TYPE_TAG_UINT:
value->v_int = (gint)G_STRUCT_MEMBER (guint32, mem, offset);
result = TRUE;
break;
@ -323,11 +298,6 @@ g_field_info_get_field (GIFieldInfo *field_info,
value->v_int = (gint)G_STRUCT_MEMBER (guint64, mem, offset);
result = TRUE;
break;
case GI_TYPE_TAG_LONG:
case GI_TYPE_TAG_ULONG:
value->v_int = (gint)G_STRUCT_MEMBER (gulong, mem, offset);
result = TRUE;
break;
default:
g_warning("Field %s: Unexpected enum storage type %s",
g_base_info_get_name ((GIBaseInfo *)field_info),
@ -424,15 +394,11 @@ g_field_info_set_field (GIFieldInfo *field_info,
break;
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_SHORT:
case GI_TYPE_TAG_USHORT:
G_STRUCT_MEMBER (guint16, mem, offset) = value->v_uint16;
result = TRUE;
break;
case GI_TYPE_TAG_INT32:
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_INT:
case GI_TYPE_TAG_UINT:
G_STRUCT_MEMBER (guint32, mem, offset) = value->v_uint32;
result = TRUE;
break;
@ -441,13 +407,6 @@ g_field_info_set_field (GIFieldInfo *field_info,
G_STRUCT_MEMBER (guint64, mem, offset) = value->v_uint64;
result = TRUE;
break;
case GI_TYPE_TAG_LONG:
case GI_TYPE_TAG_ULONG:
G_STRUCT_MEMBER (gulong, mem, offset)= value->v_ulong;
result = TRUE;
break;
case GI_TYPE_TAG_SSIZE:
case GI_TYPE_TAG_SIZE:
case GI_TYPE_TAG_GTYPE:
G_STRUCT_MEMBER (gsize, mem, offset) = value->v_size;
result = TRUE;
@ -460,16 +419,6 @@ g_field_info_set_field (GIFieldInfo *field_info,
G_STRUCT_MEMBER (gdouble, mem, offset)= value->v_double;
result = TRUE;
break;
case GI_TYPE_TAG_TIME_T:
#if SIZEOF_TIME_T == 4
G_STRUCT_MEMBER (time_t, mem, offset) = value->v_int32;
#elif SIZEOF_TIME_T == 8
G_STRUCT_MEMBER (time_t, mem, offset) = value->v_int64;
#else
# error "Unexpected size for time_t: not 4 or 8"
#endif
result = TRUE;
break;
case GI_TYPE_TAG_UTF8:
case GI_TYPE_TAG_FILENAME:
case GI_TYPE_TAG_ARRAY:
@ -510,15 +459,11 @@ g_field_info_set_field (GIFieldInfo *field_info,
break;
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_SHORT:
case GI_TYPE_TAG_USHORT:
G_STRUCT_MEMBER (guint16, mem, offset) = (guint16)value->v_int;
result = TRUE;
break;
case GI_TYPE_TAG_INT32:
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_INT:
case GI_TYPE_TAG_UINT:
G_STRUCT_MEMBER (guint32, mem, offset) = (guint32)value->v_int;
result = TRUE;
break;
@ -527,11 +472,6 @@ g_field_info_set_field (GIFieldInfo *field_info,
G_STRUCT_MEMBER (guint64, mem, offset) = (guint64)value->v_int;
result = TRUE;
break;
case GI_TYPE_TAG_LONG:
case GI_TYPE_TAG_ULONG:
G_STRUCT_MEMBER (gulong, mem, offset) = (gulong)value->v_int;
result = TRUE;
break;
default:
g_warning("Field %s: Unexpected enum storage type %s",
g_base_info_get_name ((GIBaseInfo *)field_info),

View File

@ -1319,28 +1319,10 @@ g_type_tag_to_string (GITypeTag type)
return "int64";
case GI_TYPE_TAG_UINT64:
return "uint64";
case GI_TYPE_TAG_SHORT:
return "short";
case GI_TYPE_TAG_USHORT:
return "ushort";
case GI_TYPE_TAG_INT:
return "int";
case GI_TYPE_TAG_UINT:
return "uint";
case GI_TYPE_TAG_LONG:
return "long";
case GI_TYPE_TAG_ULONG:
return "ulong";
case GI_TYPE_TAG_SSIZE:
return "ssize";
case GI_TYPE_TAG_SIZE:
return "size";
case GI_TYPE_TAG_FLOAT:
return "float";
case GI_TYPE_TAG_DOUBLE:
return "double";
case GI_TYPE_TAG_TIME_T:
return "time_t";
case GI_TYPE_TAG_GTYPE:
return "GType";
case GI_TYPE_TAG_UTF8:

View File

@ -54,25 +54,6 @@ _gi_type_tag_get_ffi_type (GITypeTag tag,
return &ffi_type_sint64;
case GI_TYPE_TAG_UINT64:
return &ffi_type_uint64;
case GI_TYPE_TAG_SHORT:
return &ffi_type_sshort;
case GI_TYPE_TAG_USHORT:
return &ffi_type_ushort;
case GI_TYPE_TAG_INT:
return &ffi_type_sint;
case GI_TYPE_TAG_UINT:
return &ffi_type_uint;
case GI_TYPE_TAG_SSIZE:
#if GLIB_SIZEOF_SIZE_T == 4
return &ffi_type_sint32;
#elif GLIB_SIZEOF_SIZE_T == 8
return &ffi_type_sint64;
#else
# error "Unexpected size for size_t: not 4 or 8"
#endif
case GI_TYPE_TAG_LONG:
return &ffi_type_slong;
case GI_TYPE_TAG_SIZE:
case GI_TYPE_TAG_GTYPE:
#if GLIB_SIZEOF_SIZE_T == 4
return &ffi_type_uint32;
@ -81,16 +62,6 @@ _gi_type_tag_get_ffi_type (GITypeTag tag,
#else
# error "Unexpected size for size_t: not 4 or 8"
#endif
case GI_TYPE_TAG_TIME_T:
#if SIZEOF_TIME_T == 4
return &ffi_type_sint32;
#elif SIZEOF_TIME_T == 8
return &ffi_type_sint64;
#else
# error "Unexpected size for time_t: not 4 or 8"
#endif
case GI_TYPE_TAG_ULONG:
return &ffi_type_ulong;
case GI_TYPE_TAG_FLOAT:
return &ffi_type_float;
case GI_TYPE_TAG_DOUBLE:

View File

@ -2319,33 +2319,6 @@ g_ir_node_build_typelib (GIrNode *node,
blob->size = 8;
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);
*(gint*)&data[blob->offset] = (gint) parse_int_value (constant->value);
break;
case GI_TYPE_TAG_UINT:
blob->size = sizeof (guint);
*(gint*)&data[blob->offset] = (guint) parse_uint_value (constant->value);
break;
case GI_TYPE_TAG_SSIZE: /* FIXME */
case GI_TYPE_TAG_LONG:
blob->size = sizeof (glong);
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);
DO_ALIGNED_COPY(&data[blob->offset], parse_uint_value (constant->value), gulong);
break;
case GI_TYPE_TAG_FLOAT:
blob->size = sizeof (gfloat);
DO_ALIGNED_COPY(&data[blob->offset], parse_float_value (constant->value), gfloat);

View File

@ -326,19 +326,38 @@ push_node (ParseContext *ctx, GIrNode *node)
static GIrNodeType * parse_type_internal (const gchar *str, gchar **next, gboolean in_glib,
gboolean in_gobject);
typedef struct {
const gchar *str;
guint size;
guint is_signed : 1;
} IntegerAliasInfo;
static IntegerAliasInfo integer_aliases[] = {
{ "char", SIZEOF_CHAR, 0 },
{ "short", SIZEOF_SHORT, 1 },
{ "ushort", SIZEOF_SHORT, 0 },
{ "int", SIZEOF_INT, 1 },
{ "uint", SIZEOF_INT, 0 },
{ "long", SIZEOF_LONG, 1 },
{ "ulong", SIZEOF_LONG, 0 },
{ "gsize", GLIB_SIZEOF_SIZE_T, 0 },
{ "gssize", GLIB_SIZEOF_SIZE_T, 1 },
};
typedef struct {
const gchar *str;
gint tag;
gboolean pointer;
} BasicTypeInfo;
#define BASIC_TYPE_FIXED_OFFSET 3
static BasicTypeInfo basic_types[] = {
{ "none", GI_TYPE_TAG_VOID, 0 },
{ "any", GI_TYPE_TAG_VOID, 1 },
{ "bool", GI_TYPE_TAG_BOOLEAN, 0 },
{ "char", GI_TYPE_TAG_INT8, 0 },
{ "int8", GI_TYPE_TAG_INT8, 0 },
{ "int8", GI_TYPE_TAG_INT8, 0 }, /* Start of BASIC_TYPE_FIXED_OFFSET */
{ "uint8", GI_TYPE_TAG_UINT8, 0 },
{ "int16", GI_TYPE_TAG_INT16, 0 },
{ "uint16", GI_TYPE_TAG_UINT16, 0 },
@ -346,19 +365,8 @@ static BasicTypeInfo basic_types[] = {
{ "uint32", GI_TYPE_TAG_UINT32, 0 },
{ "int64", GI_TYPE_TAG_INT64, 0 },
{ "uint64", GI_TYPE_TAG_UINT64, 0 },
{ "short", GI_TYPE_TAG_SHORT, 0 },
{ "ushort", GI_TYPE_TAG_USHORT, 0 },
{ "int", GI_TYPE_TAG_INT, 0 },
{ "uint", GI_TYPE_TAG_UINT, 0 },
{ "long", GI_TYPE_TAG_LONG, 0 },
{ "ulong", GI_TYPE_TAG_ULONG, 0 },
{ "ssize_t", GI_TYPE_TAG_SSIZE, 0 },
{ "ssize", GI_TYPE_TAG_SSIZE, 0 },
{ "size_t", GI_TYPE_TAG_SIZE, 0 },
{ "size", GI_TYPE_TAG_SIZE, 0 },
{ "float", GI_TYPE_TAG_FLOAT, 0 },
{ "double", GI_TYPE_TAG_DOUBLE, 0 },
{ "time_t", GI_TYPE_TAG_TIME_T, 0 },
{ "GType", GI_TYPE_TAG_GTYPE, 0 },
{ "utf8", GI_TYPE_TAG_UTF8, 1 },
{ "filename", GI_TYPE_TAG_FILENAME,1 },
@ -375,6 +383,41 @@ parse_basic (const char *str)
if (g_str_has_prefix (str, basic_types[i].str))
return &(basic_types[i]);
}
for (i = 0; i < G_N_ELEMENTS (integer_aliases); i++)
{
if (g_str_has_prefix (str, integer_aliases[i].str))
{
switch (integer_aliases[i].size)
{
case sizeof(guint8):
if (integer_aliases[i].is_signed)
return &basic_types[BASIC_TYPE_FIXED_OFFSET];
else
return &basic_types[BASIC_TYPE_FIXED_OFFSET+1];
break;
case sizeof(guint16):
if (integer_aliases[i].is_signed)
return &basic_types[BASIC_TYPE_FIXED_OFFSET+2];
else
return &basic_types[BASIC_TYPE_FIXED_OFFSET+3];
break;
case sizeof(guint32):
if (integer_aliases[i].is_signed)
return &basic_types[BASIC_TYPE_FIXED_OFFSET+4];
else
return &basic_types[BASIC_TYPE_FIXED_OFFSET+5];
break;
case sizeof(guint64):
if (integer_aliases[i].is_signed)
return &basic_types[BASIC_TYPE_FIXED_OFFSET+6];
else
return &basic_types[BASIC_TYPE_FIXED_OFFSET+7];
break;
default:
g_assert_not_reached ();
}
}
}
return NULL;
}

View File

@ -757,24 +757,6 @@ write_constant_value (const gchar *namespace,
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;

View File

@ -909,17 +909,8 @@ validate_constant_blob (GTypelib *typelib,
4, /* UINT32 */
8, /* INT64 */
8, /* UINT64 */
sizeof (gshort),
sizeof (gushort),
sizeof (gint),
sizeof (guint),
sizeof (glong),
sizeof (gulong),
sizeof (gssize),
sizeof (gsize),
sizeof (gfloat),
sizeof (gdouble),
sizeof (time_t),
0, /* GTYPE */
0, /* UTF8 */
0, /* FILENAME */
@ -933,6 +924,8 @@ validate_constant_blob (GTypelib *typelib,
ConstantBlob *blob;
SimpleTypeBlob *type;
g_assert (G_N_ELEMENTS (value_size) == GI_TYPE_TAG_ERROR + 1);
if (typelib->len < offset + sizeof (ConstantBlob))
{
g_set_error (error,

View File

@ -319,17 +319,8 @@ typedef enum {
* @GI_TYPE_TAG_UINT32: 32-bit unsigned integer
* @GI_TYPE_TAG_INT64: 64-bit signed integer
* @GI_TYPE_TAG_UINT64: 64-bit unsigned integer
* @GI_TYPE_TAG_SHORT: signed short
* @GI_TYPE_TAG_USHORT: unsigned hosrt
* @GI_TYPE_TAG_INT: signed integer
* @GI_TYPE_TAG_UINT: unsigned integer
* @GI_TYPE_TAG_LONG: signed long
* @GI_TYPE_TAG_ULONG: unsigned long
* @GI_TYPE_TAG_SSIZE: ssize_t
* @GI_TYPE_TAG_SIZE: size_t
* @GI_TYPE_TAG_FLOAT: float
* @GI_TYPE_TAG_DOUBLE: double floating point
* @GI_TYPE_TAG_TIME_T: time_t
* @GI_TYPE_TAG_GTYPE: a #GType
* @GI_TYPE_TAG_UTF8: a UTF-8 encoded string
* @GI_TYPE_TAG_FILENAME: a filename, encoded in the same encoding
@ -355,31 +346,32 @@ typedef enum {
GI_TYPE_TAG_UINT32 = 7,
GI_TYPE_TAG_INT64 = 8,
GI_TYPE_TAG_UINT64 = 9,
GI_TYPE_TAG_SHORT = 10,
GI_TYPE_TAG_USHORT = 11,
GI_TYPE_TAG_INT = 12,
GI_TYPE_TAG_UINT = 13,
GI_TYPE_TAG_LONG = 14,
GI_TYPE_TAG_ULONG = 15,
GI_TYPE_TAG_SSIZE = 16,
GI_TYPE_TAG_SIZE = 17,
GI_TYPE_TAG_FLOAT = 18,
GI_TYPE_TAG_DOUBLE = 19,
GI_TYPE_TAG_TIME_T = 20,
GI_TYPE_TAG_GTYPE = 21,
GI_TYPE_TAG_UTF8 = 22,
GI_TYPE_TAG_FILENAME = 23,
GI_TYPE_TAG_FLOAT = 10,
GI_TYPE_TAG_DOUBLE = 11,
GI_TYPE_TAG_GTYPE = 12,
GI_TYPE_TAG_UTF8 = 13,
GI_TYPE_TAG_FILENAME = 14,
/* Non-basic types */
GI_TYPE_TAG_ARRAY = 24,
GI_TYPE_TAG_INTERFACE = 25,
GI_TYPE_TAG_GLIST = 26,
GI_TYPE_TAG_GSLIST = 27,
GI_TYPE_TAG_GHASH = 28,
GI_TYPE_TAG_ERROR = 29
GI_TYPE_TAG_ARRAY = 15,
GI_TYPE_TAG_INTERFACE = 16,
GI_TYPE_TAG_GLIST = 17,
GI_TYPE_TAG_GSLIST = 18,
GI_TYPE_TAG_GHASH = 19,
GI_TYPE_TAG_ERROR = 20
/* Note - there is only room currently for 32 tags.
* See docs/typelib-format.txt SimpleTypeBlob definition */
} GITypeTag;
#define GI_TYPE_TAG_N_TYPES (GI_TYPE_TAG_ERROR+1)
/* These were removed and no longer appear in the typelib;
* instead, the machine-specific versions like INT32 are
* always used.
*/
#define GI_TYPE_TAG_SHORT GI_TYPE_TAG_SHORT_WAS_REMOVED
#define GI_TYPE_TAG_INT GI_TYPE_TAG_INT_WAS_REMOVED
#define GI_TYPE_TAG_LONG GI_TYPE_TAG_LONG_WAS_REMOVED
/**
* GIArrayType:
* @GI_ARRAY_TYPE_C: a C array, char[] for instance