girepository: Use size_t for size-related arguments and return types

We used to use unsigned values, while they should be big enough to old
the data we're handling here, it's cleaner and clearer if we use size_t
as type for such values, as it makes straight forward to understand what
a value should contain. It also makes these values more future proof.
This commit is contained in:
Marco Trevisan (Treviño) 2024-01-16 01:00:07 +01:00
parent de8ac339fb
commit 157f93d2ee
11 changed files with 49 additions and 51 deletions

View File

@ -357,7 +357,7 @@ GIBaseInfo *
gi_info_new (GIInfoType type,
GIBaseInfo *container,
GITypelib *typelib,
uint32_t offset)
size_t offset)
{
return gi_info_new_full (type, ((GIRealInfo*)container)->repository, container, typelib, offset);
}

View File

@ -96,6 +96,6 @@ GI_AVAILABLE_IN_ALL
GIBaseInfo * gi_info_new (GIInfoType type,
GIBaseInfo *container,
GITypelib *typelib,
uint32_t offset);
size_t offset);
G_END_DECLS

View File

@ -114,7 +114,7 @@ gi_enum_info_get_value (GIEnumInfo *info,
{
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
int offset;
size_t offset;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_ENUM_INFO (info), NULL);
@ -164,7 +164,7 @@ GIFunctionInfo *
gi_enum_info_get_method (GIEnumInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
EnumBlob *blob;

View File

@ -135,7 +135,7 @@ GIPropertyInfo *
gi_interface_info_get_property (GIInterfaceInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
InterfaceBlob *blob;
@ -192,7 +192,7 @@ GIFunctionInfo *
gi_interface_info_get_method (GIInterfaceInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
InterfaceBlob *blob;
@ -230,7 +230,7 @@ GIFunctionInfo *
gi_interface_info_find_method (GIInterfaceInfo *info,
const char *name)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header = (Header *)rinfo->typelib->data;
InterfaceBlob *blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
@ -280,7 +280,7 @@ GISignalInfo *
gi_interface_info_get_signal (GIInterfaceInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
InterfaceBlob *blob;
@ -375,7 +375,7 @@ GIVFuncInfo *
gi_interface_info_get_vfunc (GIInterfaceInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
InterfaceBlob *blob;
@ -416,7 +416,7 @@ GIVFuncInfo *
gi_interface_info_find_vfunc (GIInterfaceInfo *info,
const char *name)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
InterfaceBlob *blob;
@ -474,7 +474,7 @@ GIConstantInfo *
gi_interface_info_get_constant (GIInterfaceInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
InterfaceBlob *blob;

View File

@ -59,9 +59,9 @@
* Returns: field offset, in bytes
* Since: 2.80
*/
static uint32_t
static size_t
gi_object_info_get_field_offset (GIObjectInfo *info,
unsigned int n)
size_t n)
{
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header = (Header *)rinfo->typelib->data;
@ -320,7 +320,7 @@ GIFieldInfo *
gi_object_info_get_field (GIObjectInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
g_return_val_if_fail (info != NULL, NULL);
@ -368,7 +368,7 @@ GIPropertyInfo *
gi_object_info_get_property (GIObjectInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
ObjectBlob *blob;
@ -427,7 +427,7 @@ GIFunctionInfo *
gi_object_info_get_method (GIObjectInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
ObjectBlob *blob;
@ -468,7 +468,7 @@ GIFunctionInfo *
gi_object_info_find_method (GIObjectInfo *info,
const char *name)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
ObjectBlob *blob;
@ -588,7 +588,7 @@ GISignalInfo *
gi_object_info_get_signal (GIObjectInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
ObjectBlob *blob;
@ -629,10 +629,10 @@ GISignalInfo *
gi_object_info_find_signal (GIObjectInfo *info,
const char *name)
{
unsigned int n_signals;
size_t n_signals;
n_signals = gi_object_info_get_n_signals (info);
for (unsigned int i = 0; i < n_signals; i++)
for (size_t i = 0; i < n_signals; i++)
{
GISignalInfo *siginfo = gi_object_info_get_signal (info, i);
@ -686,7 +686,7 @@ GIVFuncInfo *
gi_object_info_get_vfunc (GIObjectInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
ObjectBlob *blob;
@ -734,7 +734,7 @@ GIVFuncInfo *
gi_object_info_find_vfunc (GIObjectInfo *info,
const char *name)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
ObjectBlob *blob;
@ -861,7 +861,7 @@ GIConstantInfo *
gi_object_info_get_constant (GIObjectInfo *info,
unsigned int n)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header;
ObjectBlob *blob;

View File

@ -397,8 +397,8 @@ write_field_info (const char *ns,
{
const char *name;
GIFieldInfoFlags flags;
int size;
int offset;
size_t size;
size_t offset;
GITypeInfo *type;
GIBaseInfo *interface;
GIArgument value;
@ -420,7 +420,7 @@ write_field_info (const char *ns,
xml_printf (file, " writable=\"1\"");
if (size)
xml_printf (file, " bits=\"%d\"", size);
xml_printf (file, " bits=\"%zu\"", size);
write_attributes (file, (GIBaseInfo*) info);
@ -438,8 +438,7 @@ write_field_info (const char *ns,
if (file->show_all)
{
if (offset >= 0)
xml_printf (file, "offset=\"%d\"", offset);
xml_printf (file, "offset=\"%zu\"", offset);
}
interface = gi_type_info_get_interface (type);
@ -653,7 +652,7 @@ write_struct_info (const char *ns,
gboolean deprecated;
gboolean is_gtype_struct;
gboolean foreign;
int size;
size_t size;
unsigned int n_elts;
name = gi_base_info_get_name ((GIBaseInfo *)info);
@ -694,8 +693,8 @@ write_struct_info (const char *ns,
write_attributes (file, (GIBaseInfo*) info);
size = gi_struct_info_get_size (info);
if (file->show_all && size >= 0)
xml_printf (file, " size=\"%d\"", size);
if (file->show_all)
xml_printf (file, " size=\"%zu\"", size);
foreign = gi_struct_info_is_foreign (info);
if (foreign)
@ -927,7 +926,7 @@ write_vfunc_info (const char *ns,
const char *name;
GIFunctionInfo *invoker;
gboolean deprecated;
int offset;
size_t offset;
name = gi_base_info_get_name ((GIBaseInfo *)info);
flags = gi_vfunc_info_get_flags (info);
@ -949,7 +948,7 @@ write_vfunc_info (const char *ns,
else if (flags & GI_VFUNC_MUST_NOT_OVERRIDE)
xml_printf (file, " override=\"never\"");
xml_printf (file, " offset=\"%d\"", offset);
xml_printf (file, " offset=\"%zu\"", offset);
if (invoker)
{
@ -1284,14 +1283,14 @@ write_union_info (const char *ns,
if (gi_union_info_is_discriminated (info))
{
unsigned int offset;
size_t offset;
GITypeInfo *type;
offset = gi_union_info_get_discriminator_offset (info);
type = gi_union_info_get_discriminator_type (info);
xml_start_element (file, "discriminator");
xml_printf (file, " offset=\"%d\" type=\"", offset);
xml_printf (file, " offset=\"%zu\" type=\"", offset);
write_type_info (ns, type, file);
xml_end_element (file, "discriminator");
gi_base_info_unref ((GIBaseInfo *)type);
@ -1337,7 +1336,7 @@ gi_ir_writer_write (const char *filename,
gboolean show_all)
{
FILE *ofile;
int i, j;
size_t i, j;
char **dependencies;
GIRepository *repository;
Xml *xml;
@ -1396,7 +1395,7 @@ gi_ir_writer_write (const char *filename,
const char *c_prefix;
const char *cur_ns = ns;
const char *cur_version;
int n_infos;
unsigned int n_infos;
cur_version = gi_repository_get_version (repository, cur_ns);

View File

@ -132,10 +132,9 @@ gi_struct_info_find_field (GIStructInfo *info,
GIRealInfo *rinfo = (GIRealInfo *)info;
StructBlob *blob = (StructBlob *)&rinfo->typelib->data[rinfo->offset];
Header *header = (Header *)rinfo->typelib->data;
uint32_t offset = rinfo->offset + header->struct_blob_size;
int i;
size_t offset = rinfo->offset + header->struct_blob_size;
for (i = 0; i < blob->n_fields; i++)
for (size_t i = 0; i < blob->n_fields; i++)
{
FieldBlob *field_blob = (FieldBlob *)&rinfo->typelib->data[offset];
const char *fname = (const char *)&rinfo->typelib->data[field_blob->name];
@ -192,7 +191,7 @@ gi_struct_info_get_method (GIStructInfo *info,
GIRealInfo *rinfo = (GIRealInfo *)info;
StructBlob *blob = (StructBlob *)&rinfo->typelib->data[rinfo->offset];
Header *header = (Header *)rinfo->typelib->data;
int offset;
size_t offset;
offset = gi_struct_get_field_offset (info, blob->n_fields) + n * header->function_blob_size;
return (GIFunctionInfo *) gi_info_new (GI_INFO_TYPE_FUNCTION, (GIBaseInfo*)info,
@ -215,7 +214,7 @@ GIFunctionInfo *
gi_struct_info_find_method (GIStructInfo *info,
const char *name)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
StructBlob *blob = (StructBlob *)&rinfo->typelib->data[rinfo->offset];

View File

@ -121,7 +121,7 @@ gi_union_info_get_method (GIUnionInfo *info,
GIRealInfo *rinfo = (GIRealInfo *)info;
UnionBlob *blob = (UnionBlob *)&rinfo->typelib->data[rinfo->offset];
Header *header = (Header *)rinfo->typelib->data;
int offset;
size_t offset;
offset = rinfo->offset + header->union_blob_size
+ blob->n_fields * header->field_blob_size
@ -157,7 +157,7 @@ gi_union_info_is_discriminated (GIUnionInfo *info)
* Returns: offset, in bytes, of the discriminator
* Since: 2.80
*/
unsigned int
size_t
gi_union_info_get_discriminator_offset (GIUnionInfo *info)
{
GIRealInfo *rinfo = (GIRealInfo *)info;
@ -202,7 +202,7 @@ gi_union_info_get_discriminator_type (GIUnionInfo *info)
*/
GIConstantInfo *
gi_union_info_get_discriminator (GIUnionInfo *info,
unsigned int n)
size_t n)
{
GIRealInfo *rinfo = (GIRealInfo *)info;
UnionBlob *blob = (UnionBlob *)&rinfo->typelib->data[rinfo->offset];
@ -210,7 +210,7 @@ gi_union_info_get_discriminator (GIUnionInfo *info,
if (blob->discriminated)
{
Header *header = (Header *)rinfo->typelib->data;
int offset;
size_t offset;
offset = rinfo->offset + header->union_blob_size
+ blob->n_fields * header->field_blob_size
@ -240,7 +240,7 @@ GIFunctionInfo *
gi_union_info_find_method (GIUnionInfo *info,
const char *name)
{
int offset;
size_t offset;
GIRealInfo *rinfo = (GIRealInfo *)info;
Header *header = (Header *)rinfo->typelib->data;
UnionBlob *blob = (UnionBlob *)&rinfo->typelib->data[rinfo->offset];

View File

@ -61,14 +61,14 @@ GI_AVAILABLE_IN_ALL
gboolean gi_union_info_is_discriminated (GIUnionInfo *info);
GI_AVAILABLE_IN_ALL
unsigned int gi_union_info_get_discriminator_offset (GIUnionInfo *info);
size_t gi_union_info_get_discriminator_offset (GIUnionInfo *info);
GI_AVAILABLE_IN_ALL
GITypeInfo * gi_union_info_get_discriminator_type (GIUnionInfo *info);
GI_AVAILABLE_IN_ALL
GIConstantInfo * gi_union_info_get_discriminator (GIUnionInfo *info,
unsigned int n);
size_t n);
GI_AVAILABLE_IN_ALL
GIFunctionInfo * gi_union_info_find_method (GIUnionInfo *info,

View File

@ -121,7 +121,7 @@ gi_vfunc_info_get_flags (GIVFuncInfo *info)
* Returns: the struct offset or `0xFFFF` if its unknown
* Since: 2.80
*/
unsigned int
size_t
gi_vfunc_info_get_offset (GIVFuncInfo *info)
{
GIRealInfo *rinfo = (GIRealInfo *)info;

View File

@ -47,7 +47,7 @@ GI_AVAILABLE_IN_ALL
GIVFuncInfoFlags gi_vfunc_info_get_flags (GIVFuncInfo *info);
GI_AVAILABLE_IN_ALL
unsigned int gi_vfunc_info_get_offset (GIVFuncInfo *info);
size_t gi_vfunc_info_get_offset (GIVFuncInfo *info);
GI_AVAILABLE_IN_ALL
GISignalInfo * gi_vfunc_info_get_signal (GIVFuncInfo *info);