mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
girnode: Improve int types in GIIrNodeType
`GIIrNodeType` is built dynamically at runtime (rather than being mmapped from disk), so its types can accurately reflect their runtime semantics, rather than an on-disk format. As part of this, switch from `atoi()` to `g_ascii_string_to_unsigned()` for parsing the relevant fields from a GIR XML file. This means we now get error handling for invalid integers. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3155
This commit is contained in:
parent
543fea1df7
commit
e7f26b1440
@ -149,10 +149,10 @@ struct _GIIrNodeType
|
||||
|
||||
uint8_t zero_terminated : 1;
|
||||
uint8_t has_length : 1;
|
||||
int length;
|
||||
unsigned int length;
|
||||
uint8_t has_size : 1;
|
||||
int size;
|
||||
int array_type;
|
||||
size_t size;
|
||||
GIArrayType array_type;
|
||||
|
||||
GIIrNodeType *parameter_type1; /* (owned) */
|
||||
GIIrNodeType *parameter_type2; /* (owned) */
|
||||
|
@ -1243,7 +1243,7 @@ serialize_type (GIIrTypelibBuild *build,
|
||||
if (node->has_length)
|
||||
g_string_append_printf (str, "length=%d", node->length);
|
||||
else if (node->has_size)
|
||||
g_string_append_printf (str, "fixed-size=%d", node->size);
|
||||
g_string_append_printf (str, "fixed-size=%" G_GSIZE_FORMAT, node->size);
|
||||
|
||||
if (node->zero_terminated)
|
||||
g_string_append_printf (str, "%szero-terminated=1",
|
||||
|
@ -2100,15 +2100,33 @@ start_type (GMarkupParseContext *context,
|
||||
}
|
||||
|
||||
if (typenode->array_type == GI_ARRAY_TYPE_C) {
|
||||
guint64 parsed_uint;
|
||||
|
||||
zero = find_attribute ("zero-terminated", attribute_names, attribute_values);
|
||||
len = find_attribute ("length", attribute_names, attribute_values);
|
||||
size = find_attribute ("fixed-size", attribute_names, attribute_values);
|
||||
|
||||
typenode->has_length = len != NULL;
|
||||
typenode->length = typenode->has_length ? atoi (len) : -1;
|
||||
if (!typenode->has_length)
|
||||
typenode->length = -1;
|
||||
else if (g_ascii_string_to_unsigned (len, 10, 0, G_MAXUINT, &parsed_uint, error))
|
||||
typenode->length = parsed_uint;
|
||||
else
|
||||
{
|
||||
gi_ir_node_free ((GIIrNode *) typenode);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typenode->has_size = size != NULL;
|
||||
typenode->size = typenode->has_size ? atoi (size) : -1;
|
||||
if (!typenode->has_size)
|
||||
typenode->size = -1;
|
||||
else if (g_ascii_string_to_unsigned (size, 10, 0, G_MAXSIZE, &parsed_uint, error))
|
||||
typenode->size = parsed_uint;
|
||||
else
|
||||
{
|
||||
gi_ir_node_free ((GIIrNode *) typenode);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (zero)
|
||||
typenode->zero_terminated = strcmp(zero, "1") == 0;
|
||||
|
Loading…
Reference in New Issue
Block a user