summaryrefslogtreecommitdiff
path: root/girepository/girparser.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-07-07 14:07:17 -0400
committerColin Walters <walters@verbum.org>2010-07-09 14:15:52 -0400
commit5cb925b20739c04e18e94a03a3e4e68041894b03 (patch)
tree246f895c0a92ab1afd341170e45908104964ece3 /girepository/girparser.c
parent07a36b499a7db6c65132511dc43f6acd281100ec (diff)
downloadgobject-introspection-5cb925b20739c04e18e94a03a3e4e68041894b03.tar.gz
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
Diffstat (limited to 'girepository/girparser.c')
-rw-r--r--girepository/girparser.c69
1 files changed, 56 insertions, 13 deletions
diff --git a/girepository/girparser.c b/girepository/girparser.c
index 488d77b9..8af0396d 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -328,17 +328,36 @@ static GIrNodeType * parse_type_internal (const gchar *str, gchar **next, gboole
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;
}