From bb4ad8dffea3c6e462f1055bd51fceed80a84952 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 11 Jan 2017 12:18:15 +1300 Subject: [PATCH] pyldb: p3k readiness: allow single unicode string in msg element Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- lib/ldb/pyldb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index bea837f210e..b65e25525ad 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -3047,7 +3047,7 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb if (py_elements != NULL) { Py_ssize_t i; - if (PyBytes_Check(py_elements)) { + if (PyBytes_Check(py_elements) || PyStr_Check(py_elements)) { char *_msg = NULL; el->num_values = 1; el->values = talloc_array(el, struct ldb_val, 1); @@ -3056,12 +3056,17 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb PyErr_NoMemory(); return NULL; } - result = PyBytes_AsStringAndSize(py_elements, &_msg, &size); + if (PyBytes_Check(py_elements)) { + result = PyBytes_AsStringAndSize(py_elements, &_msg, &size); + msg = _msg; + } else { + msg = PyStr_AsUTF8AndSize(py_elements, &size); + result = (msg == NULL) ? -1 : 0; + } if (result != 0) { talloc_free(mem_ctx); return NULL; } - msg = _msg; el->values[0].data = talloc_memdup(el->values, (const uint8_t *)msg, size + 1); el->values[0].length = size; -- 2.47.3