[patch] [python] Switch types from int to Py_ssize_t to be
compatible with Python 2.5 on 64-bit archs
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue Jan 16 10:06:26 PST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Something on this list seems to be breaking my PGP/MIME signatures :-(
so I'll try inline for this one...
All of these patches should also be available from:
http://people.freedesktop.org/~smcv/git/dbus-python/.git
- From b33efe312c8d89ecc6e2ba9f075d2d0a9e28c3e1 Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Tue, 16 Jan 2007 17:41:45 +0000
Subject: [PATCH] Switch types from int to Py_ssize_t to be compatible with Python 2.5 on 64-bit archs
- ---
_dbus_bindings/conn-methods.c | 2 +-
_dbus_bindings/dbus_bindings-internal.h | 10 ++++++++++
_dbus_bindings/message-append.c | 8 ++++----
_dbus_bindings/message-get-args.c | 7 +++++--
4 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/_dbus_bindings/conn-methods.c b/_dbus_bindings/conn-methods.c
index bf1fd59..f9c8554 100644
- --- a/_dbus_bindings/conn-methods.c
+++ b/_dbus_bindings/conn-methods.c
@@ -141,7 +141,7 @@ _filter_message(DBusConnection *conn, DBusMessage *message, void *user_data)
PyObject *callable = NULL;
PyObject *msg_obj;
#ifndef DBUS_PYTHON_DISABLE_CHECKS
- - int i, size;
+ Py_ssize_t i, size;
#endif
dbus_message_ref(message);
diff --git a/_dbus_bindings/dbus_bindings-internal.h b/_dbus_bindings/dbus_bindings-internal.h
index aedb343..d98a7ae 100644
- --- a/_dbus_bindings/dbus_bindings-internal.h
+++ b/_dbus_bindings/dbus_bindings-internal.h
@@ -25,7 +25,17 @@
#ifndef DBUS_BINDINGS_INTERNAL_H
#define DBUS_BINDINGS_INTERNAL_H
+#define PY_SSIZE_T_CLEAN 1
+
#include <Python.h>
+
+/* Python < 2.5 compat */
+#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
+typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+#endif
+
#define INSIDE_DBUS_PYTHON_BINDINGS
#include "dbus-python.h"
diff --git a/_dbus_bindings/message-append.c b/_dbus_bindings/message-append.c
index f629c57..5e4869c 100644
- --- a/_dbus_bindings/message-append.c
+++ b/_dbus_bindings/message-append.c
@@ -233,12 +233,12 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr)
return PyString_FromString(DBUS_TYPE_STRING_AS_STRING);
}
else if (PyTuple_Check(obj)) {
- - int len = PyTuple_GET_SIZE(obj);
+ Py_ssize_t len = PyTuple_GET_SIZE(obj);
PyObject *list = PyList_New(len + 2); /* new ref */
PyObject *item; /* temporary new ref */
PyObject *empty_str; /* temporary new ref */
PyObject *ret;
- - int i;
+ Py_ssize_t i;
if (!list) return NULL;
if (len == 0) {
@@ -314,7 +314,7 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr)
}
else if (PyDict_Check(obj)) {
PyObject *key, *value, *keysig, *valuesig;
- - int pos = 0;
+ Py_ssize_t pos = 0;
PyObject *ret = NULL;
if (DBusPyDict_Check(obj) && PyString_Check(((DBusPyDict *)obj)->signature)) {
@@ -708,7 +708,7 @@ _message_iter_append_string_as_byte_array(DBusMessageIter *appender,
PyObject *obj)
{
/* a bit of a faster path for byte arrays that are strings */
- - int len = PyString_GET_SIZE(obj);
+ Py_ssize_t len = PyString_GET_SIZE(obj);
const char *s;
DBusMessageIter sub;
int ret;
diff --git a/_dbus_bindings/message-get-args.c b/_dbus_bindings/message-get-args.c
index 7b981c5..41f3404 100644
- --- a/_dbus_bindings/message-get-args.c
+++ b/_dbus_bindings/message-get-args.c
@@ -23,6 +23,8 @@
*
*/
+#define PY_SIZE_T_CLEAN 1
+
#define DBG_IS_TOO_VERBOSE
#include "types-internal.h"
#include "message-internal.h"
@@ -119,7 +121,8 @@ _message_iter_get_dict(DBusMessageIter *iter,
int status;
sig = PyObject_CallFunction((PyObject *)&DBusPySignature_Type,
- - "(s#)", sig_str+2, strlen(sig_str)-3);
+ "(s#)", sig_str+2,
+ (Py_ssize_t)strlen(sig_str)-3);
status = PyDict_SetItem(kwargs, dbus_py_signature_const, sig);
Py_DECREF(sig);
if (status < 0) {
@@ -375,7 +378,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
dbus_message_iter_get_fixed_array(&sub,
(const unsigned char **)&u.s,
&n);
- - args = Py_BuildValue("(s#)", u.s, n);
+ args = Py_BuildValue("(s#)", u.s, (Py_ssize_t)n);
if (!args) break;
ret = PyObject_Call((PyObject *)&DBusPyByteArray_Type,
args, kwargs);
- --
1.4.4.4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net
iD8DBQFFrRQiWSc8zVUw7HYRAnlPAKDI4g6z18OmqeP0hw+MBaZ6feNxrACg27kB
4CxAeGsfm6+MxAfFn6BoZ3k=
=PVwr
-----END PGP SIGNATURE-----
More information about the dbus
mailing list