diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-07-04 19:35:43 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-07-04 19:35:43 +0100 |
commit | 5b79604a6d1eb11268293342d19da633e5eedaa4 (patch) | |
tree | 7bcde319702a52e92163bbd819c2d491534f3005 | |
parent | bdc48547078b8ba09856c81b7c4f148fb163c01b (diff) | |
download | dbus-python-5b79604a6d1eb11268293342d19da633e5eedaa4.tar.gz |
Avoid variable-length arrays, which MSVC *still* doesn't support
Based on patches from Christoph Höger.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=51725
-rw-r--r-- | _dbus_bindings/message-append.c | 16 | ||||
-rw-r--r-- | _dbus_bindings/server.c | 30 |
2 files changed, 33 insertions, 13 deletions
diff --git a/_dbus_bindings/message-append.c b/_dbus_bindings/message-append.c index e519ae2..27522bf 100644 --- a/_dbus_bindings/message-append.c +++ b/_dbus_bindings/message-append.c @@ -962,6 +962,7 @@ _message_iter_append_variant(DBusMessageIter *appender, PyObject *obj) int ret; long variant_level; dbus_bool_t dummy; + DBusMessageIter *variant_iters = NULL; /* Separate the object into the contained object, and the number of * variants it's wrapped in. */ @@ -987,10 +988,17 @@ _message_iter_append_variant(DBusMessageIter *appender, PyObject *obj) dbus_signature_iter_init(&obj_sig_iter, obj_sig_str); - { /* scope for variant_iters */ - DBusMessageIter variant_iters[variant_level]; + { long i; + variant_iters = calloc (variant_level, sizeof (DBusMessageIter)); + + if (!variant_iters) { + PyErr_NoMemory(); + ret = -1; + goto out; + } + for (i = 0; i < variant_level; i++) { DBusMessageIter *child = &variant_iters[i]; /* The first is a special case: its parent is the iter passed in @@ -1038,10 +1046,12 @@ _message_iter_append_variant(DBusMessageIter *appender, PyObject *obj) goto out; } } - } out: + if (variant_iters != NULL) + free (variant_iters); + Py_CLEAR(obj_sig); return ret; } diff --git a/_dbus_bindings/server.c b/_dbus_bindings/server.c index cb489f6..2d624a9 100644 --- a/_dbus_bindings/server.c +++ b/_dbus_bindings/server.c @@ -88,6 +88,9 @@ DBusPyServer_set_auth_mechanisms(Server *self, PyObject *fast_seq = NULL, *references = NULL; Py_ssize_t length; Py_ssize_t i; + /* a mutable array of constant strings */ + const char **list = NULL; + dbus_bool_t ret = FALSE; fast_seq = PySequence_Fast(auth_mechanisms, "Expecting sequence for auth_mechanisms parameter"); @@ -99,21 +102,27 @@ DBusPyServer_set_auth_mechanisms(Server *self, /* scope for list */ { - const char *list[length + 1]; + list = calloc (length + 1, sizeof (char *)); + + if (!list) { + PyErr_NoMemory(); + goto finally; + } if (!(references = PyTuple_New(length))) - goto error; + goto finally; for (i = 0; i < length; ++i) { PyObject *am, *am_as_bytes; am = PySequence_Fast_GET_ITEM(auth_mechanisms, i); - if (!am) goto error; + if (!am) + goto finally; if (PyUnicode_Check(am)) { am_as_bytes = PyUnicode_AsUTF8String(am); if (!am_as_bytes) - goto error; + goto finally; } else { am_as_bytes = am; @@ -121,7 +130,7 @@ DBusPyServer_set_auth_mechanisms(Server *self, } list[i] = PyBytes_AsString(am_as_bytes); if (!list[i]) - goto error; + goto finally; PyTuple_SET_ITEM(references, i, am_as_bytes); } @@ -133,13 +142,14 @@ DBusPyServer_set_auth_mechanisms(Server *self, Py_END_ALLOW_THREADS } + ret = TRUE; + +finally: + if (list) + free (list); Py_CLEAR(fast_seq); Py_CLEAR(references); - return TRUE; - error: - Py_CLEAR(fast_seq); - Py_CLEAR(references); - return FALSE; + return ret; } /* Return a new reference to a Python Server or subclass corresponding |