diff options
author | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2006-10-03 13:46:03 +0000 |
---|---|---|
committer | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2006-10-03 13:46:03 +0000 |
commit | ced58c3849be22f3577ccf7c7d3f6b66362f0626 (patch) | |
tree | 958558e1944b1c9a8743e40f9dd82d1d6336e49f | |
parent | 63c68ca46895952ee589d5e476eefc173c4f0e9b (diff) | |
download | pygobject-ced58c3849be22f3577ccf7c7d3f6b66362f0626.tar.gz pygobject-ced58c3849be22f3577ccf7c7d3f6b66362f0626.tar.xz pygobject-ced58c3849be22f3577ccf7c7d3f6b66362f0626.zip |
Python 2.5, int vs ssize_t
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | gobject/Makefile.am | 2 | ||||
-rw-r--r-- | gobject/gobjectmodule.c | 26 | ||||
-rw-r--r-- | gobject/pygenum.c | 2 | ||||
-rw-r--r-- | gobject/pygiochannel.c | 4 | ||||
-rw-r--r-- | gobject/pygobject-private.h | 7 | ||||
-rw-r--r-- | gobject/pygobject.c | 69 | ||||
-rw-r--r-- | gobject/pygoptioncontext.c | 10 | ||||
-rw-r--r-- | gobject/pygtype.c | 2 |
9 files changed, 96 insertions, 50 deletions
@@ -1,3 +1,27 @@ +2006-10-03 Gustavo J. A. M. Carneiro <gjc@gnome.org> + + * gobject/Makefile.am: + * gobject/gobjectmodule.c: (add_signals), (add_properties), + (pyg_signal_new), (pyg_object_new), (get_handler_priority), + (pyg_io_add_watch), (pyg_spawn_async), (pyg_add_emission_hook), + (pyg_remove_emission_hook), (pyg_filename_from_utf8), + (_pyg_strv_to_gvalue): + * gobject/pygiochannel.c: (py_io_channel_write_chars), + (py_io_channel_write_lines): + * gobject/pygobject-private.h: + * gobject/pygobject.c: (PyGProps_length), (pygobject_init), + (pygobject_connect), (pygobject_connect_after), + (pygobject_connect_object), (pygobject_connect_object_after), + (pygobject_disconnect), (pygobject_handler_is_connected), + (pygobject_handler_block), (pygobject_handler_unblock), + (pygobject_emit), (pygobject_chain_from_overridden): + * gobject/pygoptioncontext.c: (pyg_option_context_parse): + * gobject/pygtype.c: (pyg_value_from_pyobject): + + Python 2.5 and 64 bits fixes (Py_ssize_t), closes bug #338487. + + * gobject/pygenum.c (pyg_enum_repr): Const warning fix. + 2006-09-29 Johan Dahlin <jdahlin@async.com.br> * pygtk.py: LGPL, not GPL header diff --git a/gobject/Makefile.am b/gobject/Makefile.am index 451fecb..eba8e6c 100644 --- a/gobject/Makefile.am +++ b/gobject/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = 1.7 PLATFORM_VERSION = 2.0 -INCLUDES = $(PYTHON_INCLUDES) $(GLIB_CFLAGS) +INCLUDES = $(PYTHON_INCLUDES) $(GLIB_CFLAGS) -DPY_SSIZE_T_CLEAN pkgincludedir = $(includedir)/pygtk-$(PLATFORM_VERSION) pkginclude_HEADERS = pygobject.h diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 3cecc98..df3f8b7 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -631,7 +631,7 @@ add_signals (GType instance_type, PyObject *signals) { gboolean ret = TRUE; GObjectClass *oclass; - int pos = 0; + Py_ssize_t pos = 0; PyObject *key, *value, *overridden_signals = NULL; overridden_signals = PyDict_New(); @@ -947,7 +947,7 @@ add_properties (GType instance_type, PyObject *properties) { gboolean ret = TRUE; GObjectClass *oclass; - int pos = 0; + Py_ssize_t pos = 0; PyObject *key, *value; oclass = g_type_class_ref(instance_type); @@ -1442,7 +1442,7 @@ pyg_signal_new(PyObject *self, PyObject *args) PyObject *py_return_type, *py_param_types; GType instance_type = 0; - guint n_params, i; + Py_ssize_t n_params, i; GType *param_types; guint signal_id; @@ -1830,7 +1830,7 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs) } if (kwargs) { - int pos = 0; + Py_ssize_t pos = 0; PyObject *key; PyObject *value; @@ -1886,7 +1886,7 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs) static gint get_handler_priority(gint *priority, PyObject *kwargs) { - gint len, pos; + Py_ssize_t len, pos; PyObject *key, *val; /* no keyword args? leave as default */ @@ -2073,7 +2073,8 @@ static PyObject * pyg_io_add_watch(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject *first, *pyfd, *callback, *cbargs = NULL, *data; - gint fd, priority = G_PRIORITY_DEFAULT, condition, len; + gint fd, priority = G_PRIORITY_DEFAULT, condition; + Py_ssize_t len; GIOChannel *iochannel; guint handler_id; @@ -2375,7 +2376,7 @@ pyg_spawn_async(PyObject *unused, PyObject *args, PyObject *kwargs) struct _PyGChildSetupData *callback_data = NULL; GError *error = NULL; GPid child_pid = -1; - int len, i; + Py_ssize_t len, i; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OsiOOOOO:gobject.spawn_async", kwlist, @@ -2603,7 +2604,8 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args) PyObject *first, *callback, *extra_args, *data; gchar *name; gulong hook_id; - guint sigid, len; + guint sigid; + Py_ssize_t len; GQuark detail = 0; GType gtype; PyObject *pygtype; @@ -2649,7 +2651,7 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args) data, (GDestroyNotify)pyg_destroy_notify); - return PyInt_FromLong(hook_id); + return PyLong_FromUnsignedLong(hook_id); } static PyObject * @@ -2661,7 +2663,7 @@ pyg_remove_emission_hook(PyGObject *self, PyObject *args) gulong hook_id; GType gtype; - if (!PyArg_ParseTuple(args, "Osi:gobject.remove_emission_hook", + if (!PyArg_ParseTuple(args, "Osk:gobject.remove_emission_hook", &pygtype, &name, &hook_id)) return NULL; @@ -2730,7 +2732,7 @@ static PyObject * pyg_filename_from_utf8(PyGObject *self, PyObject *args) { char *filename, *utf8string; - int utf8string_len; + Py_ssize_t utf8string_len; gsize bytes_written; GError *error = NULL; PyObject *py_filename; @@ -2995,7 +2997,7 @@ _pyg_strv_from_gvalue(const GValue *value) static int _pyg_strv_to_gvalue(GValue *value, PyObject *obj) { - int argc, i; + Py_ssize_t argc, i; gchar **argv; if (!(PyTuple_Check(obj) || PyList_Check(obj))) diff --git a/gobject/pygenum.c b/gobject/pygenum.c index 305dd68..543bc49 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -47,7 +47,7 @@ static PyObject * pyg_enum_repr(PyGEnum *self) { GEnumClass *enum_class; - char *value; + const char *value; guint index; static char tmp[256]; diff --git a/gobject/pygiochannel.c b/gobject/pygiochannel.c index aaf3840..a7f3629 100644 --- a/gobject/pygiochannel.c +++ b/gobject/pygiochannel.c @@ -255,7 +255,7 @@ py_io_channel_write_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "buf", NULL }; const char* buf; - int buf_len; + Py_ssize_t buf_len; gsize count; GError* error = NULL; GIOStatus status; @@ -278,7 +278,7 @@ py_io_channel_write_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "lines", NULL }; char *buf; - int buf_len; + Py_ssize_t buf_len; gsize count; GError* error = NULL; GIOStatus status; diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h index ed1cd05..4ea38fa 100644 --- a/gobject/pygobject-private.h +++ b/gobject/pygobject-private.h @@ -20,6 +20,13 @@ } while (0) #endif +#if PY_VERSION_HEX < 0x02050000 +typedef int Py_ssize_t; +#define PY_SSIZE_T_MAX INT_MAX +#define PY_SSIZE_T_MIN INT_MIN +#endif + + /* from gobjectmodule.c */ extern struct _PyGObject_Functions pygobject_api_functions; #define pyg_block_threads() G_STMT_START { \ diff --git a/gobject/pygobject.c b/gobject/pygobject.c index 5660296..4cfe9e9 100644 --- a/gobject/pygobject.c +++ b/gobject/pygobject.c @@ -338,7 +338,7 @@ pygobject_props_get_iter(PyGProps *self) return (PyObject *) iter; } -static int +static Py_ssize_t PyGProps_length(PyGProps *self) { GObjectClass *class; @@ -348,17 +348,17 @@ PyGProps_length(PyGProps *self) g_object_class_list_properties(class, &n_props); g_type_class_unref(class); - return (int)n_props; + return (Py_ssize_t)n_props; } static PySequenceMethods _PyGProps_as_sequence = { - (inquiry)PyGProps_length, - (binaryfunc)0, - (intargfunc)0, - (intargfunc)0, - (intintargfunc)0, - (intobjargproc)0, - (intintobjargproc)0 + (lenfunc) PyGProps_length, + 0, + 0, + 0, + 0, + 0, + 0 }; PyTypeObject PyGProps_Type = { @@ -1010,7 +1010,7 @@ pygobject_init(PyGObject *self, PyObject *args, PyObject *kwargs) } if (kwargs) { - int pos = 0; + Py_ssize_t pos = 0; PyObject *key; PyObject *value; @@ -1215,7 +1215,8 @@ pygobject_connect(PyGObject *self, PyObject *args) { PyObject *first, *callback, *extra_args; gchar *name; - guint handlerid, sigid, len; + guint sigid, len; + gulong handlerid; GQuark detail = 0; GClosure *closure; @@ -1253,7 +1254,7 @@ pygobject_connect(PyGObject *self, PyObject *args) handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail, closure, FALSE); Py_DECREF(extra_args); - return PyInt_FromLong(handlerid); + return PyLong_FromUnsignedLong(handlerid); } static PyObject * @@ -1261,7 +1262,9 @@ pygobject_connect_after(PyGObject *self, PyObject *args) { PyObject *first, *callback, *extra_args; gchar *name; - guint handlerid, sigid, len; + guint sigid; + gulong handlerid; + Py_ssize_t len; GQuark detail; GClosure *closure; @@ -1300,7 +1303,7 @@ pygobject_connect_after(PyGObject *self, PyObject *args) handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail, closure, TRUE); Py_DECREF(extra_args); - return PyInt_FromLong(handlerid); + return PyLong_FromUnsignedLong(handlerid); } static PyObject * @@ -1308,7 +1311,9 @@ pygobject_connect_object(PyGObject *self, PyObject *args) { PyObject *first, *callback, *extra_args, *object; gchar *name; - guint handlerid, sigid, len; + guint sigid; + gulong handlerid; + Py_ssize_t len; GQuark detail; GClosure *closure; @@ -1347,7 +1352,7 @@ pygobject_connect_object(PyGObject *self, PyObject *args) handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail, closure, FALSE); Py_DECREF(extra_args); - return PyInt_FromLong(handlerid); + return PyLong_FromUnsignedLong(handlerid); } static PyObject * @@ -1355,7 +1360,9 @@ pygobject_connect_object_after(PyGObject *self, PyObject *args) { PyObject *first, *callback, *extra_args, *object; gchar *name; - guint handlerid, sigid, len; + guint sigid; + gulong handlerid; + Py_ssize_t len; GQuark detail; GClosure *closure; @@ -1394,15 +1401,15 @@ pygobject_connect_object_after(PyGObject *self, PyObject *args) handlerid = g_signal_connect_closure_by_id(self->obj, sigid, detail, closure, TRUE); Py_DECREF(extra_args); - return PyInt_FromLong(handlerid); + return PyLong_FromUnsignedLong(handlerid); } static PyObject * pygobject_disconnect(PyGObject *self, PyObject *args) { - guint handler_id; + gulong handler_id; - if (!PyArg_ParseTuple(args, "i:GObject.disconnect", &handler_id)) + if (!PyArg_ParseTuple(args, "k:GObject.disconnect", &handler_id)) return NULL; CHECK_GOBJECT(self); @@ -1415,9 +1422,9 @@ pygobject_disconnect(PyGObject *self, PyObject *args) static PyObject * pygobject_handler_is_connected(PyGObject *self, PyObject *args) { - guint handler_id; + gulong handler_id; - if (!PyArg_ParseTuple(args, "i:GObject.handler_is_connected", &handler_id)) + if (!PyArg_ParseTuple(args, "k:GObject.handler_is_connected", &handler_id)) return NULL; @@ -1429,9 +1436,9 @@ pygobject_handler_is_connected(PyGObject *self, PyObject *args) static PyObject * pygobject_handler_block(PyGObject *self, PyObject *args) { - guint handler_id; + gulong handler_id; - if (!PyArg_ParseTuple(args, "i:GObject.handler_block", &handler_id)) + if (!PyArg_ParseTuple(args, "k:GObject.handler_block", &handler_id)) return NULL; CHECK_GOBJECT(self); @@ -1444,9 +1451,9 @@ pygobject_handler_block(PyGObject *self, PyObject *args) static PyObject * pygobject_handler_unblock(PyGObject *self, PyObject *args) { - guint handler_id; + gulong handler_id; - if (!PyArg_ParseTuple(args, "i:GObject.handler_unblock", &handler_id)) + if (!PyArg_ParseTuple(args, "k:GObject.handler_unblock", &handler_id)) return NULL; g_signal_handler_unblock(self->obj, handler_id); Py_INCREF(Py_None); @@ -1456,7 +1463,8 @@ pygobject_handler_unblock(PyGObject *self, PyObject *args) static PyObject * pygobject_emit(PyGObject *self, PyObject *args) { - guint signal_id, i, len; + guint signal_id, i; + Py_ssize_t len; GQuark detail; PyObject *first, *py_ret; gchar *name; @@ -1489,7 +1497,7 @@ pygobject_emit(PyGObject *self, PyObject *args) gchar buf[128]; g_snprintf(buf, sizeof(buf), - "%d parameters needed for signal %s; %d given", + "%d parameters needed for signal %s; %ld given", query.n_params, name, len - 1); PyErr_SetString(PyExc_TypeError, buf); return NULL; @@ -1569,7 +1577,8 @@ static PyObject * pygobject_chain_from_overridden(PyGObject *self, PyObject *args) { GSignalInvocationHint *ihint; - guint signal_id, i, len; + guint signal_id, i; + Py_ssize_t len; PyObject *py_ret; const gchar *name; GSignalQuery query; @@ -1597,7 +1606,7 @@ pygobject_chain_from_overridden(PyGObject *self, PyObject *args) gchar buf[128]; g_snprintf(buf, sizeof(buf), - "%d parameters needed for signal %s; %d given", + "%d parameters needed for signal %s; %ld given", query.n_params, name, len); PyErr_SetString(PyExc_TypeError, buf); return NULL; diff --git a/gobject/pygoptioncontext.c b/gobject/pygoptioncontext.c index 7996fb6..177b171 100644 --- a/gobject/pygoptioncontext.c +++ b/gobject/pygoptioncontext.c @@ -63,7 +63,8 @@ pyg_option_context_parse(PyGOptionContext *self, static char *kwlist[] = { "argv", NULL }; PyObject *arg; PyObject *new_argv, *argv; - gssize argv_length, pos; + Py_ssize_t argv_length, pos; + gint argv_length_int; char **argv_content, **original; GError *error = NULL; gboolean result; @@ -100,11 +101,14 @@ pyg_option_context_parse(PyGOptionContext *self, } } original = g_strdupv(argv_content); - + + g_assert(argv_length <= G_MAXINT); + argv_length_int = argv_length; pyg_begin_allow_threads; - result = g_option_context_parse(self->context, &argv_length, &argv_content, + result = g_option_context_parse(self->context, &argv_length_int, &argv_content, &error); pyg_end_allow_threads; + argv_length = argv_length_int; if (!result) { diff --git a/gobject/pygtype.c b/gobject/pygtype.c index efbabb7..2146978 100644 --- a/gobject/pygtype.c +++ b/gobject/pygtype.c @@ -859,7 +859,7 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj) G_VALUE_HOLDS(value, G_TYPE_GSTRING)) { GString *string; char *buffer; - int len; + Py_ssize_t len; if (PyString_AsStringAndSize(obj, &buffer, &len)) return -1; string = g_string_new_len(buffer, len); |