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 /_dbus_bindings/server.c | |
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
Diffstat (limited to '_dbus_bindings/server.c')
-rw-r--r-- | _dbus_bindings/server.c | 30 |
1 files changed, 20 insertions, 10 deletions
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 |