From: Douglas Bagnall Date: Tue, 10 Jan 2017 23:18:15 +0000 (+1300) Subject: pyldb: p3k readiness: allow single unicode string in msg element X-Git-Tag: tdb-1.3.13~593 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb4ad8dffea3c6e462f1055bd51fceed80a84952;p=thirdparty%2Fsamba.git pyldb: p3k readiness: allow single unicode string in msg element Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- 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;