summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-01-11 15:02:40 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-01-11 15:03:08 +0000
commit50fa5eb54992c28d63b0532533f755ff39f082e2 (patch)
tree7cd4c93e490187bd0da34d9475f93e8aa88deec5
parent4f043cf34a8001c071644eb8c89dc7d43e86b62a (diff)
downloaddbus-python-50fa5eb54992c28d63b0532533f755ff39f082e2.tar.gz
Add INTORLONG_CHECK macro so we don't have to conditionalize PyInt_Check
-rw-r--r--_dbus_bindings/bus.c7
-rw-r--r--_dbus_bindings/bytes.c8
-rw-r--r--_dbus_bindings/dbus_bindings-internal.h2
-rw-r--r--_dbus_bindings/message-append.c8
-rw-r--r--_dbus_bindings/unixfd.c7
5 files changed, 11 insertions, 21 deletions
diff --git a/_dbus_bindings/bus.c b/_dbus_bindings/bus.c
index 99d98c2..2294b30 100644
--- a/_dbus_bindings/bus.c
+++ b/_dbus_bindings/bus.c
@@ -69,11 +69,7 @@ DBusPyConnection_NewForBus(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
return (PyObject *)self;
}
- else if (!first || PyLong_Check(first)
-#ifndef PY3
- || PyInt_Check(first)
-#endif
- )
+ else if (!first || INTORLONG_CHECK(first))
{
long type;
PyObject *libdbusconn;
@@ -85,6 +81,7 @@ DBusPyConnection_NewForBus(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
DBUS_BUS_SESSION. */
if (first) {
+ /* on Python 2 this accepts either int or long */
type = PyLong_AsLong(first);
if (type == -1 && PyErr_Occurred())
return NULL;
diff --git a/_dbus_bindings/bytes.c b/_dbus_bindings/bytes.c
index 9914319..fc490d9 100644
--- a/_dbus_bindings/bytes.c
+++ b/_dbus_bindings/bytes.c
@@ -96,12 +96,8 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
if (!obj)
goto bad_arg;
}
- else if (PyLong_Check(obj)
-#ifndef PY3
- || PyInt_Check(obj)
-#endif
- )
- {
+ else if (INTORLONG_CHECK(obj)) {
+ /* on Python 2 this accepts either int or long */
long i = PyLong_AsLong(obj);
long my_variant_level;
diff --git a/_dbus_bindings/dbus_bindings-internal.h b/_dbus_bindings/dbus_bindings-internal.h
index 8069666..4b831e8 100644
--- a/_dbus_bindings/dbus_bindings-internal.h
+++ b/_dbus_bindings/dbus_bindings-internal.h
@@ -80,6 +80,7 @@ static inline int type##_CheckExact (PyObject *o) \
#define NATIVEINT_TYPE (PyLong_Type)
#define NATIVEINT_FROMLONG(x) (PyLong_FromLong(x))
#define NATIVEINT_ASLONG(x) (PyLong_AsLong(x))
+#define INTORLONG_CHECK(obj) (PyLong_Check(obj))
#define NATIVESTR_TYPE (PyUnicode_Type)
#define NATIVESTR_CHECK(obj) (PyUnicode_Check(obj))
#define NATIVESTR_FROMSTR(obj) (PyUnicode_FromString(obj))
@@ -87,6 +88,7 @@ static inline int type##_CheckExact (PyObject *o) \
#define NATIVEINT_TYPE (PyInt_Type)
#define NATIVEINT_FROMLONG(x) (PyInt_FromLong(x))
#define NATIVEINT_ASLONG(x) (PyInt_AsLong(x))
+#define INTORLONG_CHECK(obj) (PyLong_Check(obj) || PyInt_Check(obj))
#define NATIVESTR_TYPE (PyBytes_Type)
#define NATIVESTR_CHECK(obj) (PyBytes_Check(obj))
#define NATIVESTR_FROMSTR(obj) (PyBytes_FromString(obj))
diff --git a/_dbus_bindings/message-append.c b/_dbus_bindings/message-append.c
index bbf1286..6dab214 100644
--- a/_dbus_bindings/message-append.c
+++ b/_dbus_bindings/message-append.c
@@ -595,6 +595,7 @@ _message_iter_append_byte(DBusMessageIter *appender, PyObject *obj)
y = *(unsigned char *)PyBytes_AS_STRING(obj);
}
else {
+ /* on Python 2 this accepts either int or long */
long i = PyLong_AsLong(obj);
if (i == -1 && PyErr_Occurred()) return -1;
@@ -633,12 +634,9 @@ _message_iter_append_unixfd(DBusMessageIter *appender, PyObject *obj)
int fd;
long original_fd;
- if (PyLong_Check(obj)
-#ifndef PY3
- || PyInt_Check(obj)
-#endif
- )
+ if (INTORLONG_CHECK(obj))
{
+ /* on Python 2 this accepts either int or long */
original_fd = PyLong_AsLong(obj);
if (original_fd == -1 && PyErr_Occurred())
return -1;
diff --git a/_dbus_bindings/unixfd.c b/_dbus_bindings/unixfd.c
index 98504e3..0cfc394 100644
--- a/_dbus_bindings/unixfd.c
+++ b/_dbus_bindings/unixfd.c
@@ -71,12 +71,9 @@ make_fd(PyObject *arg, int *fd)
{
long fd_arg;
- if (PyLong_Check(arg)
-#ifndef PY3
- || PyInt_Check(arg)
-#endif
- )
+ if (INTORLONG_CHECK(arg))
{
+ /* on Python 2 this accepts either int or long */
fd_arg = PyLong_AsLong(arg);
if (fd_arg == -1 && PyErr_Occurred()) {
return -1;