summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-11-15 16:07:57 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-24 11:07:42 +0000
commit1055343d746accc4048e5806f84a880143444c9f (patch)
treed5c86e7478a693a83910282539efa14f0e044c71
parent8e4836c318eb64ef720b497bebc247ac6a468b4b (diff)
downloaddbus-python-1055343d746accc4048e5806f84a880143444c9f.tar.gz
Use DBusBasicValue instead of reinventing it, if dbus is new enough
If we don't find it, continue to reinvent it, but move the reinvention to an internal header so it's at least the same in both files that want it.
-rw-r--r--_dbus_bindings/Makefile.am1
-rw-r--r--_dbus_bindings/compat-internal.h52
-rw-r--r--_dbus_bindings/message-append.c56
-rw-r--r--_dbus_bindings/message-get-args.c56
-rw-r--r--configure.ac5
5 files changed, 104 insertions, 66 deletions
diff --git a/_dbus_bindings/Makefile.am b/_dbus_bindings/Makefile.am
index 02d2ce0..2a5ec28 100644
--- a/_dbus_bindings/Makefile.am
+++ b/_dbus_bindings/Makefile.am
@@ -8,6 +8,7 @@ _dbus_bindings_la_SOURCES = \
abstract.c \
bus.c \
bytes.c \
+ compat-internal.h \
conn.c \
conn-internal.h \
conn-methods.c \
diff --git a/_dbus_bindings/compat-internal.h b/_dbus_bindings/compat-internal.h
new file mode 100644
index 0000000..143f23a
--- /dev/null
+++ b/_dbus_bindings/compat-internal.h
@@ -0,0 +1,52 @@
+/* Old D-Bus compatibility: implementation internals
+ *
+ * Copyright © 2006-2011 Collabora Ltd.
+ * Copyright © 2011 Nokia Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef DBUS_BINDINGS_COMPAT_INTERNAL_H
+#define DBUS_BINDINGS_COMPAT_INTERNAL_H
+
+#include "config.h"
+#include "dbus_bindings-internal.h"
+
+#ifndef HAVE_DBUSBASICVALUE
+typedef union {
+ dbus_bool_t bool_val;
+ double dbl;
+ dbus_uint16_t u16;
+ dbus_int16_t i16;
+ dbus_uint32_t u32;
+ dbus_int32_t i32;
+#if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG)
+ dbus_uint64_t u64;
+ dbus_int64_t i64;
+#endif
+ const char *str;
+ unsigned char byt;
+ float f;
+ int fd;
+} DBusBasicValue;
+#endif
+
+#endif
diff --git a/_dbus_bindings/message-append.c b/_dbus_bindings/message-append.c
index 6dab214..f4f843b 100644
--- a/_dbus_bindings/message-append.c
+++ b/_dbus_bindings/message-append.c
@@ -29,6 +29,7 @@
#include <assert.h>
#define DBG_IS_TOO_VERBOSE
+#include "compat-internal.h"
#include "types-internal.h"
#include "message-internal.h"
@@ -999,18 +1000,7 @@ _message_iter_append_pyobject(DBusMessageIter *appender,
dbus_bool_t *more)
{
int sig_type = dbus_signature_iter_get_current_type(sig_iter);
- union {
- dbus_bool_t b;
- double d;
- dbus_uint16_t uint16;
- dbus_int16_t int16;
- dbus_uint32_t uint32;
- dbus_int32_t int32;
-#if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG)
- dbus_uint64_t uint64;
- dbus_int64_t int64;
-#endif
- } u;
+ DBusBasicValue u;
int ret = -1;
#ifdef USING_DBG
@@ -1026,13 +1016,13 @@ _message_iter_append_pyobject(DBusMessageIter *appender,
case DBUS_TYPE_BOOLEAN:
if (PyObject_IsTrue(obj)) {
- u.b = 1;
+ u.bool_val = 1;
}
else {
- u.b = 0;
+ u.bool_val = 0;
}
- DBG("Performing actual append: bool(%ld)", (long)u.b);
- if (!dbus_message_iter_append_basic(appender, sig_type, &u.b)) {
+ DBG("Performing actual append: bool(%ld)", (long)u.bool_val);
+ if (!dbus_message_iter_append_basic(appender, sig_type, &u.bool_val)) {
PyErr_NoMemory();
ret = -1;
break;
@@ -1041,13 +1031,13 @@ _message_iter_append_pyobject(DBusMessageIter *appender,
break;
case DBUS_TYPE_DOUBLE:
- u.d = PyFloat_AsDouble(obj);
+ u.dbl = PyFloat_AsDouble(obj);
if (PyErr_Occurred()) {
ret = -1;
break;
}
- DBG("Performing actual append: double(%f)", u.d);
- if (!dbus_message_iter_append_basic(appender, sig_type, &u.d)) {
+ DBG("Performing actual append: double(%f)", u.dbl);
+ if (!dbus_message_iter_append_basic(appender, sig_type, &u.dbl)) {
PyErr_NoMemory();
ret = -1;
break;
@@ -1057,12 +1047,14 @@ _message_iter_append_pyobject(DBusMessageIter *appender,
#ifdef WITH_DBUS_FLOAT32
case DBUS_TYPE_FLOAT:
- u.d = PyFloat_AsDouble(obj);
+ u.dbl = PyFloat_AsDouble(obj);
if (PyErr_Occurred()) {
ret = -1;
break;
}
- u.f = (float)u.d;
+ /* FIXME: DBusBasicValue will need to grow a float member if
+ * float32 becomes supported */
+ u.f = (float)u.dbl;
DBG("Performing actual append: float(%f)", u.f);
if (!dbus_message_iter_append_basic(appender, sig_type, &u.f)) {
PyErr_NoMemory();
@@ -1075,14 +1067,14 @@ _message_iter_append_pyobject(DBusMessageIter *appender,
/* The integer types are all basically the same - we delegate to
intNN_range_check() */
-#define PROCESS_INTEGER(size) \
- u.size = dbus_py_##size##_range_check(obj);\
- if (u.size == (dbus_##size##_t)(-1) && PyErr_Occurred()) {\
+#define PROCESS_INTEGER(size, member) \
+ u.member = dbus_py_##size##_range_check(obj);\
+ if (u.member == (dbus_##size##_t)(-1) && PyErr_Occurred()) {\
ret = -1; \
break; \
}\
- DBG("Performing actual append: " #size "(%lld)", (long long)u.size); \
- if (!dbus_message_iter_append_basic(appender, sig_type, &u.size)) {\
+ DBG("Performing actual append: " #size "(%lld)", (long long)u.member); \
+ if (!dbus_message_iter_append_basic(appender, sig_type, &u.member)) {\
PyErr_NoMemory();\
ret = -1;\
break;\
@@ -1090,23 +1082,23 @@ _message_iter_append_pyobject(DBusMessageIter *appender,
ret = 0;
case DBUS_TYPE_INT16:
- PROCESS_INTEGER(int16)
+ PROCESS_INTEGER(int16, i16)
break;
case DBUS_TYPE_UINT16:
- PROCESS_INTEGER(uint16)
+ PROCESS_INTEGER(uint16, u16)
break;
case DBUS_TYPE_INT32:
- PROCESS_INTEGER(int32)
+ PROCESS_INTEGER(int32, i32)
break;
case DBUS_TYPE_UINT32:
- PROCESS_INTEGER(uint32)
+ PROCESS_INTEGER(uint32, u32)
break;
#if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG)
case DBUS_TYPE_INT64:
- PROCESS_INTEGER(int64)
+ PROCESS_INTEGER(int64, i64)
break;
case DBUS_TYPE_UINT64:
- PROCESS_INTEGER(uint64)
+ PROCESS_INTEGER(uint64, u64)
break;
#else
case DBUS_TYPE_INT64:
diff --git a/_dbus_bindings/message-get-args.c b/_dbus_bindings/message-get-args.c
index ceea3a4..44aa469 100644
--- a/_dbus_bindings/message-get-args.c
+++ b/_dbus_bindings/message-get-args.c
@@ -27,6 +27,7 @@
#define PY_SIZE_T_CLEAN 1
#define DBG_IS_TOO_VERBOSE
+#include "compat-internal.h"
#include "types-internal.h"
#include "message-internal.h"
@@ -190,22 +191,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
Message_get_args_options *opts,
long variant_level)
{
- union {
- const char *s;
- unsigned char y;
- dbus_bool_t b;
- double d;
- float f;
- dbus_uint16_t u16;
- dbus_int16_t i16;
- dbus_uint32_t u32;
- dbus_int32_t i32;
-#if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG)
- dbus_uint64_t u64;
- dbus_int64_t i64;
-#endif
- int fd;
- } u;
+ DBusBasicValue u;
int type = dbus_message_iter_get_arg_type(iter);
PyObject *args = NULL;
PyObject *kwargs = NULL;
@@ -243,17 +229,17 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
case DBUS_TYPE_STRING:
DBG("%s", "found a string");
- dbus_message_iter_get_basic(iter, &u.s);
+ dbus_message_iter_get_basic(iter, &u.str);
#ifndef PY3
if (opts->utf8_strings) {
- args = Py_BuildValue("(s)", u.s);
+ args = Py_BuildValue("(s)", u.str);
if (!args) break;
ret = PyObject_Call((PyObject *)&DBusPyUTF8String_Type,
args, kwargs);
}
else {
#endif
- unicode = PyUnicode_DecodeUTF8(u.s, strlen(u.s), NULL);
+ unicode = PyUnicode_DecodeUTF8(u.str, strlen(u.str), NULL);
if (!unicode) {
break;
}
@@ -270,24 +256,24 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
case DBUS_TYPE_SIGNATURE:
DBG("%s", "found a signature");
- dbus_message_iter_get_basic(iter, &u.s);
- args = Py_BuildValue("(s)", u.s);
+ dbus_message_iter_get_basic(iter, &u.str);
+ args = Py_BuildValue("(s)", u.str);
if (!args) break;
ret = PyObject_Call((PyObject *)&DBusPySignature_Type, args, kwargs);
break;
case DBUS_TYPE_OBJECT_PATH:
DBG("%s", "found an object path");
- dbus_message_iter_get_basic(iter, &u.s);
- args = Py_BuildValue("(s)", u.s);
+ dbus_message_iter_get_basic(iter, &u.str);
+ args = Py_BuildValue("(s)", u.str);
if (!args) break;
ret = PyObject_Call((PyObject *)&DBusPyObjectPath_Type, args, kwargs);
break;
case DBUS_TYPE_DOUBLE:
DBG("%s", "found a double");
- dbus_message_iter_get_basic(iter, &u.d);
- args = Py_BuildValue("(f)", u.d);
+ dbus_message_iter_get_basic(iter, &u.dbl);
+ args = Py_BuildValue("(f)", u.dbl);
if (!args) break;
ret = PyObject_Call((PyObject *)&DBusPyDouble_Type, args, kwargs);
break;
@@ -295,6 +281,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
#ifdef WITH_DBUS_FLOAT32
case DBUS_TYPE_FLOAT:
DBG("%s", "found a float");
+ /* FIXME: DBusBasicValue will need to grow a float member if
+ * float32 becomes supported */
dbus_message_iter_get_basic(iter, &u.f);
args = Py_BuildValue("(f)", (double)u.f);
if (!args) break;
@@ -376,8 +364,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
case DBUS_TYPE_BYTE:
DBG("%s", "found a byte");
- dbus_message_iter_get_basic(iter, &u.y);
- args = Py_BuildValue("(l)", (long)u.y);
+ dbus_message_iter_get_basic(iter, &u.byt);
+ args = Py_BuildValue("(l)", (long)u.byt);
if (!args)
break;
ret = PyObject_Call((PyObject *)&DBusPyByte_Type, args, kwargs);
@@ -385,8 +373,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
case DBUS_TYPE_BOOLEAN:
DBG("%s", "found a bool");
- dbus_message_iter_get_basic(iter, &u.b);
- args = Py_BuildValue("(l)", (long)u.b);
+ dbus_message_iter_get_basic(iter, &u.bool_val);
+ args = Py_BuildValue("(l)", (long)u.bool_val);
if (!args)
break;
ret = PyObject_Call((PyObject *)&DBusPyBoolean_Type, args, kwargs);
@@ -412,18 +400,18 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
DBG("%s", "actually, a byte array...");
dbus_message_iter_recurse(iter, &sub);
dbus_message_iter_get_fixed_array(&sub,
- (const unsigned char **)&u.s,
+ (const unsigned char **)&u.str,
&n);
- if (n == 0 && u.s == NULL) {
+ if (n == 0 && u.str == NULL) {
/* fd.o #21831: s# turns (NULL, 0) into None, but
* dbus_message_iter_get_fixed_array produces (NULL, 0)
* for an empty byte-blob... */
- u.s = "";
+ u.str = "";
}
#ifdef PY3
- args = Py_BuildValue("(y#)", u.s, (Py_ssize_t)n);
+ args = Py_BuildValue("(y#)", u.str, (Py_ssize_t)n);
#else
- args = Py_BuildValue("(s#)", u.s, (Py_ssize_t)n);
+ args = Py_BuildValue("(s#)", u.str, (Py_ssize_t)n);
#endif
if (!args) break;
ret = PyObject_Call((PyObject *)&DBusPyByteArray_Type,
diff --git a/configure.ac b/configure.ac
index 6e8e477..a1f9383 100644
--- a/configure.ac
+++ b/configure.ac
@@ -152,6 +152,11 @@ AM_CONDITIONAL([ENABLE_DOCS], [test "$enable_html_docs" != no])
PKG_CHECK_MODULES(DBUS, [dbus-1 >= 1.4])
PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-1 >= 0.70])
+dbuspy_save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS $DBUS_CFLAGS"
+AC_CHECK_TYPES([DBusBasicValue], [], [], [#include <dbus/dbus.h>])
+CFLAGS="$dbuspy_save_CFLAGS"
+
TP_COMPILER_WARNINGS([CFLAGS_WARNINGS], [test] dbus_python_released [= 0],
[all \
extra \