[perl-Glib-Object-Introspection/ppc64-fixes] Fix a few integer conversion issues
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib-Object-Introspection/ppc64-fixes] Fix a few integer conversion issues
- Date: Thu, 18 Sep 2014 09:34:08 +0000 (UTC)
commit 91836eec57d08feb356a51a7472e508ad204a580
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date: Thu Sep 18 10:03:54 2014 +0200
Fix a few integer conversion issues
Most of these changes just hush compiler warnings, but some also assert
formerly implicit assumptions.
gperl-i11n-enums.c | 8 ++++----
gperl-i11n-field.c | 8 ++++----
gperl-i11n-invoke-c.c | 20 +++++++++++---------
gperl-i11n-invoke-perl.c | 7 ++++---
gperl-i11n-invoke.c | 7 +++++--
gperl-i11n-marshal-arg.c | 3 ++-
gperl-i11n-marshal-array.c | 7 ++++---
gperl-i11n-marshal-callback.c | 2 +-
8 files changed, 35 insertions(+), 27 deletions(-)
---
diff --git a/gperl-i11n-enums.c b/gperl-i11n-enums.c
index 69f3e67..a85a774 100644
--- a/gperl-i11n-enums.c
+++ b/gperl-i11n-enums.c
@@ -1,10 +1,10 @@
/* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8; -*- */
-#define FILL_VALUES(values) \
+#define FILL_VALUES(values, value_type) \
{ gint i; \
for (i = 0; i < n_values; i++) { \
GIValueInfo *value_info = g_enum_info_get_value (info, i); \
- (values)[i].value = g_value_info_get_value (value_info); \
+ (values)[i].value = (value_type) g_value_info_get_value (value_info); \
/* FIXME: Can we assume that the strings will stick around long enough? */ \
(values)[i].value_nick = g_base_info_get_name (value_info); \
(values)[i].value_name = g_base_info_get_attribute (value_info, "c:identifier"); \
@@ -37,10 +37,10 @@ register_unregistered_enum (GIEnumInfo *info)
n_values = g_enum_info_get_n_values (info);
if (info_type == GI_INFO_TYPE_ENUM) {
values = g_new0 (GEnumValue, n_values+1); /* zero-terminated */
- FILL_VALUES ((GEnumValue *) values);
+ FILL_VALUES ((GEnumValue *) values, gint);
} else {
values = g_new0 (GFlagsValue, n_values+1); /* zero-terminated */
- FILL_VALUES ((GFlagsValue *) values);
+ FILL_VALUES ((GFlagsValue *) values, guint);
}
if (info_type == GI_INFO_TYPE_ENUM) {
diff --git a/gperl-i11n-field.c b/gperl-i11n-field.c
index 0d27537..39de231 100644
--- a/gperl-i11n-field.c
+++ b/gperl-i11n-field.c
@@ -67,7 +67,7 @@ get_field (GIFieldInfo *field_info, gpointer mem, GITransfer transfer)
g_type_info_get_tag (field_type) == GI_TYPE_TAG_INTERFACE &&
g_base_info_get_type (interface_info) == GI_INFO_TYPE_STRUCT)
{
- gsize offset;
+ gint offset;
offset = g_field_info_get_offset (field_info);
value.v_pointer = mem + offset;
sv = arg_to_sv (&value,
@@ -114,9 +114,9 @@ set_field (GIFieldInfo *field_info, gpointer mem, GITransfer transfer, SV *sv)
/* FIXME: No GIArgInfo and no GPerlI11nInvocationInfo here.
* What if the struct contains an object pointer, or a callback
* field? */
- gsize offset = g_field_info_get_offset (field_info);
+ gint offset = g_field_info_get_offset (field_info);
if (!g_type_info_is_pointer (field_type)) { /* By value */
- gssize size;
+ gsize size;
/* Enforce GI_TRANSFER_NOTHING since we will copy into
* the memory that has already been allocated inside
* 'mem' */
@@ -162,7 +162,7 @@ set_field (GIFieldInfo *field_info, gpointer mem, GITransfer transfer, SV *sv)
else if (tag == GI_TYPE_TAG_VOID &&
g_type_info_is_pointer (field_type))
{
- gsize offset = g_field_info_get_offset (field_info);
+ gint offset = g_field_info_get_offset (field_info);
sv_to_arg (sv, &arg, NULL, field_type,
transfer, TRUE, NULL);
G_STRUCT_MEMBER (gpointer, mem, offset) = arg.v_pointer;
diff --git a/gperl-i11n-invoke-c.c b/gperl-i11n-invoke-c.c
index 38f7a3e..b8509d0 100644
--- a/gperl-i11n-invoke-c.c
+++ b/gperl-i11n-invoke-c.c
@@ -70,13 +70,14 @@ invoke_c_code (GICallableInfo *info,
#if GI_CHECK_VERSION (1, 29, 0)
is_skipped = g_arg_info_is_skip (arg_info);
#endif
- perl_stack_pos = i
- + iinfo.constructor_offset
- + iinfo.method_offset
- + iinfo.stack_offset
+ perl_stack_pos = (gint) i
+ + (gint) iinfo.constructor_offset
+ + (gint) iinfo.method_offset
+ + (gint) iinfo.stack_offset
+ iinfo.dynamic_stack_offset;
- ffi_stack_pos = i
- + iinfo.method_offset;
+ ffi_stack_pos = (gint) i
+ + (gint) iinfo.method_offset;
+ g_assert (perl_stack_pos >= 0 && ffi_stack_pos >= 0);
/* FIXME: Is this right? I'm confused about the relation of
* the numbers in g_callable_info_get_arg and
@@ -310,8 +311,9 @@ _prepare_c_invocation_info (GPerlI11nCInvocationInfo *iinfo,
iinfo->target_namespace = namespace;
iinfo->target_function = function;
- iinfo->stack_offset = internal_stack_offset;
- iinfo->n_given_args = items - iinfo->stack_offset;
+ iinfo->stack_offset = (guint) internal_stack_offset;
+ g_assert (items >= iinfo->stack_offset);
+ iinfo->n_given_args = ((guint) items) - iinfo->stack_offset;
iinfo->n_invoke_args = iinfo->base.n_args;
iinfo->is_constructor = FALSE;
@@ -356,7 +358,7 @@ _prepare_c_invocation_info (GPerlI11nCInvocationInfo *iinfo,
* we'll only use as much as we need. since function argument lists
* are typically small, this shouldn't be a big problem. */
if (iinfo->n_invoke_args) {
- gint n = iinfo->n_invoke_args;
+ guint n = iinfo->n_invoke_args;
iinfo->in_args = gperl_alloc_temp (sizeof (GIArgument) * n);
iinfo->out_args = gperl_alloc_temp (sizeof (GIArgument) * n);
iinfo->arg_types_ffi = gperl_alloc_temp (sizeof (ffi_type *) * n);
diff --git a/gperl-i11n-invoke-perl.c b/gperl-i11n-invoke-perl.c
index a266c7b..da11a59 100644
--- a/gperl-i11n-invoke-perl.c
+++ b/gperl-i11n-invoke-perl.c
@@ -13,7 +13,8 @@ invoke_perl_code (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata
GPerlI11nPerlInvocationInfo iinfo;
guint args_offset = 0, i;
guint in_inout;
- guint n_return_values, n_returned;
+ guint n_return_values;
+ I32 n_returned;
I32 context;
SV *first_sv = NULL, *last_sv = NULL;
dGPERL_CALLBACK_MARSHAL_SP;
@@ -165,9 +166,9 @@ invoke_perl_code (ffi_cif* cif, gpointer resp, gpointer* args, gpointer userdata
n_returned = info->sub_name
? call_method (info->sub_name, context)
: call_sv (info->code, context);
- if (n_return_values != 0 && n_returned != n_return_values) {
+ if (n_return_values != 0 && (n_returned < 0 || ((guint) n_returned) != n_return_values)) {
ccroak ("callback returned %d values "
- "but is supposed to return %d values",
+ "but is supposed to return %u values",
n_returned, n_return_values);
}
diff --git a/gperl-i11n-invoke.c b/gperl-i11n-invoke.c
index 2eb8ea3..ae50804 100644
--- a/gperl-i11n-invoke.c
+++ b/gperl-i11n-invoke.c
@@ -4,6 +4,7 @@ static void
prepare_invocation_info (GPerlI11nInvocationInfo *iinfo,
GICallableInfo *info)
{
+ gint orig_n_args;
guint i;
dwarn ("invoke: %s\n"
@@ -20,7 +21,9 @@ prepare_invocation_info (GPerlI11nInvocationInfo *iinfo,
dwarn (" is_function = %d, is_vfunc = %d, is_callback = %d\n",
iinfo->is_function, iinfo->is_vfunc, iinfo->is_callback);
- iinfo->n_args = g_callable_info_get_n_args (info);
+ orig_n_args = g_callable_info_get_n_args (info);
+ g_assert (orig_n_args >= 0);
+ iinfo->n_args = (guint) orig_n_args;
if (iinfo->n_args) {
iinfo->arg_infos = gperl_alloc_temp (sizeof (GITypeInfo*) * iinfo->n_args);
@@ -33,7 +36,7 @@ prepare_invocation_info (GPerlI11nInvocationInfo *iinfo,
}
for (i = 0 ; i < iinfo->n_args ; i++) {
- iinfo->arg_infos[i] = g_callable_info_get_arg (info, i);
+ iinfo->arg_infos[i] = g_callable_info_get_arg (info, (gint) i);
iinfo->arg_types[i] = g_arg_info_get_type (iinfo->arg_infos[i]);
}
diff --git a/gperl-i11n-marshal-arg.c b/gperl-i11n-marshal-arg.c
index 7e49b34..d14d2e5 100644
--- a/gperl-i11n-marshal-arg.c
+++ b/gperl-i11n-marshal-arg.c
@@ -215,7 +215,8 @@ arg_to_sv (GIArgument * arg,
SV *sv;
gchar buffer[6];
gint length = g_unichar_to_utf8 (arg->v_uint32, buffer);
- sv = newSVpv (buffer, length);
+ g_assert (length >= 0);
+ sv = newSVpv (buffer, (STRLEN) length);
SvUTF8_on (sv);
return sv;
}
diff --git a/gperl-i11n-marshal-array.c b/gperl-i11n-marshal-array.c
index d11d09c..a2ddfb1 100644
--- a/gperl-i11n-marshal-array.c
+++ b/gperl-i11n-marshal-array.c
@@ -71,7 +71,7 @@ array_to_sv (GITypeInfo *info,
for (i = 0; i < length; i++) {
GIArgument *arg;
SV *value;
- arg = pointer + i * item_size;
+ arg = pointer + ((gsize) i) * item_size;
value = arg_to_sv (arg, param_info, item_transfer, iinfo);
if (value)
av_push (av, value);
@@ -95,7 +95,8 @@ sv_to_array (GITransfer transfer,
GITransfer item_transfer;
GITypeInfo *param_info;
GITypeTag param_tag;
- gint i, length, length_pos;
+ gint length_pos;
+ gsize i, length;
GPerlI11nArrayInfo *array_info = NULL;
GArray *array;
gpointer raw_array;
@@ -137,7 +138,7 @@ sv_to_array (GITransfer transfer,
is_zero_terminated = g_type_info_is_zero_terminated (type_info);
item_size = size_of_type_info (param_info);
- length = av_len (av) + 1;
+ length = (gsize) (av_len (av) + 1); /* av_len always returns at least -1 */
array = g_array_sized_new (is_zero_terminated, FALSE, item_size, length);
/* Arrays containing non-basic types as non-pointers need to be treated
diff --git a/gperl-i11n-marshal-callback.c b/gperl-i11n-marshal-callback.c
index b313813..4dd5dc2 100644
--- a/gperl-i11n-marshal-callback.c
+++ b/gperl-i11n-marshal-callback.c
@@ -117,7 +117,7 @@ callback_to_sv (GICallableInfo *interface, gpointer func, GPerlI11nInvocationInf
}
arg_info = g_callable_info_get_arg (invocation_info->interface,
- invocation_info->current_pos);
+ (gint) invocation_info->current_pos);
dwarn (" C callback at %d (%s)\n",
invocation_info->current_pos,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]