[pygobject] Fix various potential compiler warnings



commit f939a71167bd94c9e7777312af444183f7b20441
Author: Christoph Reiter <creiter src gnome org>
Date:   Tue Jan 24 18:13:56 2017 +0100

    Fix various potential compiler warnings
    
    This is useful for a the next commit which switches away from
    gnome-common and uses AX_COMPILER_FLAGS adding some new compiler
    warning flags.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777713

 gi/gimodule.c            |    7 ++++---
 gi/gobjectmodule.c       |   22 +++++++++++-----------
 gi/pygenum.c             |    2 +-
 gi/pygflags.c            |    8 ++++----
 gi/pygi-argument.c       |    2 ++
 gi/pygi-array.c          |   16 ++++++++--------
 gi/pygi-cache.c          |    2 ++
 gi/pygi-closure.c        |    2 +-
 gi/pygi-foreign.c        |    2 +-
 gi/pygi-info.c           |   13 ++++++++++---
 gi/pygi-invoke.c         |    3 +++
 gi/pygi-property.c       |    2 +-
 gi/pygi-signal-closure.c |    3 ++-
 gi/pygi-value.c          |   11 +++++++----
 gi/pygobject-object.c    |   20 ++++++++++----------
 15 files changed, 67 insertions(+), 48 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index d60a6a5..50a3e05 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -23,6 +23,7 @@
 
 #include <glib-object.h>
 
+#include "config.h"
 #include "pyglib.h"
 #include "pyginterface.h"
 #include "pygi-repository.h"
@@ -567,7 +568,7 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
     iochannel = pyg_boxed_get (py_iochannel, GIOChannel);
 
     while (status == G_IO_STATUS_NORMAL
-          && (max_count == -1 || total_read < max_count)) {
+          && (max_count == -1 || total_read < (gsize)max_count)) {
        gsize single_read;
        char* buf;
        gsize buf_size;
@@ -585,7 +586,7 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
            if (ret_obj == NULL)
                goto failure;
        }
-       else if (buf_size + total_read > PYGLIB_PyBytes_Size(ret_obj)) {
+       else if (buf_size + total_read > (gsize)PYGLIB_PyBytes_Size(ret_obj)) {
            if (PYGLIB_PyBytes_Resize(&ret_obj, buf_size + total_read) == -1)
                goto failure;
        }
@@ -602,7 +603,7 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
        total_read += single_read;
     }
        
-    if ( total_read != PYGLIB_PyBytes_Size(ret_obj) ) {
+    if ( total_read != (gsize)PYGLIB_PyBytes_Size(ret_obj) ) {
        if (PYGLIB_PyBytes_Resize(&ret_obj, total_read) == -1)
            goto failure;
     }
diff --git a/gi/gobjectmodule.c b/gi/gobjectmodule.c
index 0dc2670..1debcb6 100644
--- a/gi/gobjectmodule.c
+++ b/gi/gobjectmodule.c
@@ -783,19 +783,19 @@ add_properties (GObjectClass *klass, PyObject *properties)
        if (pspec) {
            g_object_class_install_property(klass, 1, pspec);
        } else {
-            PyObject *type, *value, *traceback;
+            PyObject *type, *pvalue, *traceback;
            ret = FALSE;
-            PyErr_Fetch(&type, &value, &traceback);
-            if (PYGLIB_PyUnicode_Check(value)) {
+            PyErr_Fetch(&type, &pvalue, &traceback);
+            if (PYGLIB_PyUnicode_Check(pvalue)) {
                 char msg[256];
                 g_snprintf(msg, 256,
                           "%s (while registering property '%s' for GType '%s')",
-               PYGLIB_PyUnicode_AsString(value),
+               PYGLIB_PyUnicode_AsString(pvalue),
                           prop_name, G_OBJECT_CLASS_NAME(klass));
-                Py_DECREF(value);
+                Py_DECREF(pvalue);
                 value = PYGLIB_PyUnicode_FromString(msg);
             }
-            PyErr_Restore(type, value, traceback);
+            PyErr_Restore(type, pvalue, traceback);
            break;
        }
     }
@@ -1616,7 +1616,7 @@ static PyMethodDef _gobject_functions[] = {
 const gchar *
 pyg_constant_strip_prefix(const gchar *name, const gchar *strip_prefix)
 {
-    gint prefix_len;
+    size_t prefix_len;
     guint i;
 
     prefix_len = strlen(strip_prefix);
@@ -1632,9 +1632,9 @@ pyg_constant_strip_prefix(const gchar *name, const gchar *strip_prefix)
 
     /* strip off prefix from value name, while keeping it a valid
      * identifier */
-    for (i = prefix_len; i >= 0; i--) {
-       if (g_ascii_isalpha(name[i]) || name[i] == '_') {
-           return &name[i];
+    for (i = prefix_len + 1; i > 0; i--) {
+       if (g_ascii_isalpha(name[i - 1]) || name[i - 1] == '_') {
+           return &name[i - 1];
        }
     }
     return name;
@@ -1757,7 +1757,7 @@ pyg_parse_constructor_args(GType        obj_type,
         params[param_i].name = prop_names[arg_i];
         g_value_init(&params[param_i].value, spec->value_type);
         if (pyg_value_from_pyobject(&params[param_i].value, py_args[arg_i]) == -1) {
-            int i;
+            guint i;
             PyErr_Format(PyExc_TypeError, "could not convert parameter '%s' of type '%s'",
                          arg_names[arg_i], g_type_name(spec->value_type));
             g_type_class_unref(oclass);
diff --git a/gi/pygenum.c b/gi/pygenum.c
index cea9c0f..53baaca 100644
--- a/gi/pygenum.c
+++ b/gi/pygenum.c
@@ -235,7 +235,7 @@ pyg_enum_add (PyObject *   module,
     PyGILState_STATE state;
     PyObject *instance_dict, *stub, *values, *o;
     GEnumClass *eclass;
-    int i;
+    guint i;
 
     g_return_val_if_fail(typename != NULL, NULL);
     if (!g_type_is_a (gtype, G_TYPE_ENUM)) {
diff --git a/gi/pygflags.c b/gi/pygflags.c
index 693fca0..a38e01c 100644
--- a/gi/pygflags.c
+++ b/gi/pygflags.c
@@ -74,7 +74,7 @@ generate_repr(GType gtype, guint value)
 {
     GFlagsClass *flags_class;
     char *retval = NULL, *tmp;
-    int i;
+    guint i;
 
     flags_class = g_type_class_ref(gtype);
     g_assert(G_IS_FLAGS_CLASS(flags_class));
@@ -256,7 +256,7 @@ pyg_flags_add (PyObject *   module,
     PyGILState_STATE state;
     PyObject *instance_dict, *stub, *values, *o;
     GFlagsClass *eclass;
-    int i;
+    guint i;
 
     g_return_val_if_fail(typename != NULL, NULL);
     if (!g_type_is_a(gtype, G_TYPE_FLAGS)) {
@@ -425,7 +425,7 @@ pyg_flags_get_value_names(PyGFlags *self, void *closure)
 {
   GFlagsClass *flags_class;
   PyObject *retval;
-  int i;
+  guint i;
 
   flags_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_FLAGS_CLASS(flags_class));
@@ -445,7 +445,7 @@ pyg_flags_get_value_nicks(PyGFlags *self, void *closure)
 {
   GFlagsClass *flags_class;
   PyObject *retval;
-  int i;
+  guint i;
 
   flags_class = g_type_class_ref(self->gtype);
   g_assert(G_IS_FLAGS_CLASS(flags_class));
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 0929038..a24318b 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1269,6 +1269,8 @@ _pygi_argument_release (GIArgument   *arg,
             g_slice_free (GError *, arg->v_pointer);
             break;
         }
+        default:
+            break;
     }
 }
 
diff --git a/gi/pygi-array.c b/gi/pygi-array.c
index 61d0617..6c8279d 100644
--- a/gi/pygi-array.c
+++ b/gi/pygi-array.c
@@ -185,7 +185,7 @@ _pygi_marshal_from_py_array (PyGIInvokeState   *state,
 {
     PyGIMarshalFromPyFunc from_py_marshaller;
     int i = 0;
-    int success_count = 0;
+    gsize success_count = 0;
     Py_ssize_t length;
     gssize item_size;
     gboolean is_ptr_array;
@@ -360,15 +360,15 @@ err:
             /* Only attempt per item cleanup on pointer items */
             if (sequence_cache->item_cache->is_pointer) {
                 for(j = 0; j < success_count; j++) {
-                    PyObject *py_item = PySequence_GetItem (py_arg, j);
+                    PyObject *py_seq_item = PySequence_GetItem (py_arg, j);
                     cleanup_func (state,
                                   sequence_cache->item_cache,
-                                  py_item,
+                                  py_seq_item,
                                   is_ptr_array ?
                                           g_ptr_array_index ((GPtrArray *)array_, j) :
                                           g_array_index (array_, gpointer, j),
                                   TRUE);
-                    Py_DECREF (py_item);
+                    Py_DECREF (py_seq_item);
                 }
             }
         }
@@ -532,10 +532,10 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
             }
         } else {
             GIArgument *len_arg = &state->args[array_cache->len_arg_index].arg_value;
-            PyGIArgCache *arg_cache = _pygi_callable_cache_get_arg (callable_cache,
+            PyGIArgCache *sub_cache = _pygi_callable_cache_get_arg (callable_cache,
                                                                     array_cache->len_arg_index);
 
-            if (!gi_argument_to_gsize (len_arg, &len, arg_cache->type_tag)) {
+            if (!gi_argument_to_gsize (len_arg, &len, sub_cache->type_tag)) {
                 return NULL;
             }
         }
@@ -570,7 +570,7 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
         if (arg->v_pointer == NULL) {
             py_obj = PyList_New (0);
         } else {
-            int i;
+            guint i;
 
             gsize item_size;
             PyGIMarshalToPyFunc item_to_py_marshaller;
@@ -656,7 +656,7 @@ err:
     } else {
         /* clean up unprocessed items */
         if (seq_cache->item_cache->to_py_cleanup != NULL) {
-            int j;
+            guint j;
             PyGIMarshalCleanupFunc cleanup_func = seq_cache->item_cache->to_py_cleanup;
             for (j = processed_items; j < array_->len; j++) {
                 cleanup_func (state,
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 170b242..29ea400 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -428,6 +428,8 @@ pygi_arg_cache_new (GITypeInfo *type_info,
                                                       transfer,
                                                       direction);
            break;
+       default:
+           break;
     }
 
     if (arg_cache != NULL) {
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index a75e358..21a0464 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -204,7 +204,7 @@ _pygi_closure_convert_ffi_arguments (PyGIInvokeArgState *state,
                                      PyGICallableCache *cache,
                                      void **args)
 {
-    gint i;
+    guint i;
 
     for (i = 0; i < _pygi_callable_cache_args_len (cache); i++) {
         PyGIArgCache *arg_cache = g_ptr_array_index (cache->args_cache, i);
diff --git a/gi/pygi-foreign.c b/gi/pygi-foreign.c
index f74b1e7..84af1ec 100644
--- a/gi/pygi-foreign.c
+++ b/gi/pygi-foreign.c
@@ -50,7 +50,7 @@ init_foreign_structs (void)
 static PyGIForeignStruct *
 do_lookup (const gchar *namespace, const gchar *name)
 {
-    gint i;
+    guint i;
     for (i = 0; i < foreign_structs->len; i++) {
         PyGIForeignStruct *foreign_struct = \
                 g_ptr_array_index (foreign_structs, i);
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index 09c513b..f2f7dce 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -1108,6 +1108,8 @@ _pygi_g_type_tag_size (GITypeTag type_tag)
                           "Unable to know the size (assuming %s is not a pointer)",
                           g_type_tag_to_string (type_tag));
             break;
+        default:
+            break;
     }
 
     return size;
@@ -1166,10 +1168,10 @@ _pygi_g_type_info_size (GITypeInfo *type_info)
                     if (g_type_info_is_pointer (type_info)) {
                         size = sizeof (gpointer);
                     } else {
-                        GITypeTag type_tag;
+                        GITypeTag enum_type_tag;
 
-                        type_tag = g_enum_info_get_storage_type ( (GIEnumInfo *) info);
-                        size = _pygi_g_type_tag_size (type_tag);
+                        enum_type_tag = g_enum_info_get_storage_type ( (GIEnumInfo *) info);
+                        size = _pygi_g_type_tag_size (enum_type_tag);
                     }
                     break;
                 case GI_INFO_TYPE_BOXED:
@@ -1207,6 +1209,8 @@ _pygi_g_type_info_size (GITypeInfo *type_info)
         case GI_TYPE_TAG_ERROR:
             size = sizeof (gpointer);
             break;
+        default:
+            break;
     }
 
     return size;
@@ -1429,6 +1433,9 @@ pygi_g_struct_info_is_simple (GIStructInfo *struct_info)
                 g_base_info_unref (info);
                 break;
             }
+            default:
+                g_assert_not_reached();
+                break;
         }
 
         g_base_info_unref ( (GIBaseInfo *) field_type_info);
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 619fe40..2c6a186 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -511,6 +511,9 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGIFunctionCache *function_cac
                 }
 
                 break;
+            default:
+                g_assert_not_reached();
+                break;
         }
 
         if (py_arg == _PyGIDefaultArgPlaceholder) {
diff --git a/gi/pygi-property.c b/gi/pygi-property.c
index 19cdb44..a2c3a17 100644
--- a/gi/pygi-property.c
+++ b/gi/pygi-property.c
@@ -348,7 +348,7 @@ pygi_set_property_value (PyGObject *instance,
              */
             GArray *arg_items = (GArray*) arg.v_pointer;
             gchar** strings;
-            int i;
+            guint i;
 
             if (arg_items == NULL)
                 goto out;
diff --git a/gi/pygi-signal-closure.c b/gi/pygi-signal-closure.c
index f2698d5..0cdc1e4 100644
--- a/gi/pygi-signal-closure.c
+++ b/gi/pygi-signal-closure.c
@@ -88,6 +88,7 @@ pygi_signal_closure_marshal(GClosure *closure,
 
     signal_info = ((PyGISignalClosure *)closure)->signal_info;
     n_sig_info_args = g_callable_info_get_n_args(signal_info);
+    g_assert_cmpint (n_sig_info_args, >=, 0);
     /* the first argument to a signal callback is instance,
        but instance is not counted in the introspection data */
     sig_info_highest_arg = n_sig_info_args + 1;
@@ -110,7 +111,7 @@ pygi_signal_closure_marshal(GClosure *closure,
             }
             PyTuple_SetItem(params, i, item);
 
-        } else if (i < sig_info_highest_arg) {
+        } else if (i < (guint)sig_info_highest_arg) {
             GIArgInfo arg_info;
             GITypeInfo type_info;
             GITypeTag type_tag;
diff --git a/gi/pygi-value.c b/gi/pygi-value.c
index 88faf63..6e3eb09 100644
--- a/gi/pygi-value.c
+++ b/gi/pygi-value.c
@@ -157,6 +157,8 @@ _pygi_argument_from_g_value(const GValue *value,
         case GI_TYPE_TAG_VOID:
             arg.v_pointer = g_value_get_pointer (value);
             break;
+        default:
+            break;
     }
 
     return arg;
@@ -173,15 +175,16 @@ pyg_value_array_from_pyobject(GValue *value,
                               PyObject *obj,
                               const GParamSpecValueArray *pspec)
 {
-    int len;
+    Py_ssize_t seq_len;
     GValueArray *value_array;
-    int i;
+    guint len, i;
 
-    len = PySequence_Length(obj);
-    if (len == -1) {
+    seq_len = PySequence_Length(obj);
+    if (seq_len == -1) {
         PyErr_Clear();
         return -1;
     }
+    len = (guint)seq_len;
 
     if (pspec && pspec->fixed_n_elements > 0 && len != pspec->fixed_n_elements)
         return -1;
diff --git a/gi/pygobject-object.c b/gi/pygobject-object.c
index b2fe471..9eed696 100644
--- a/gi/pygobject-object.c
+++ b/gi/pygobject-object.c
@@ -701,7 +701,7 @@ pyg_type_get_bases(GType gtype)
     guint n_interfaces;
     PyTypeObject *py_parent_type, *py_interface_type;
     PyObject *bases;
-    int i;
+    guint i;
     
     if (G_UNLIKELY(gtype == G_TYPE_OBJECT))
         return NULL;
@@ -847,7 +847,7 @@ pygobject_inherit_slots(PyTypeObject *type, PyObject *bases, gboolean check_for_
                                   offsetof(PyTypeObject, tp_repr),
                                   offsetof(PyTypeObject, tp_str),
                                   offsetof(PyTypeObject, tp_print) };
-    int i;
+    gsize i;
 
     /* Happens when registering gobject.GObject itself, at least. */
     if (!bases)
@@ -922,19 +922,19 @@ pygobject_lookup_class(GType gtype)
     PyTypeObject *py_type;
 
     if (gtype == G_TYPE_INTERFACE)
-       return &PyGInterface_Type;
+        return &PyGInterface_Type;
     
     py_type = g_type_get_qdata(gtype, pygobject_class_key);
     if (py_type == NULL) {
-       py_type = g_type_get_qdata(gtype, pyginterface_type_key);
+        py_type = g_type_get_qdata(gtype, pyginterface_type_key);
 
-    if (py_type == NULL)
-        py_type = (PyTypeObject *)pygi_type_import_by_g_type(gtype);
+        if (py_type == NULL)
+            py_type = (PyTypeObject *)pygi_type_import_by_g_type(gtype);
 
-       if (py_type == NULL) {
-           py_type = pygobject_new_with_interfaces(gtype);
-           g_type_set_qdata(gtype, pyginterface_type_key, py_type);
-       }
+        if (py_type == NULL) {
+            py_type = pygobject_new_with_interfaces(gtype);
+            g_type_set_qdata(gtype, pyginterface_type_key, py_type);
+        }
     }
     
     return py_type;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]