git.samba.org
/
nivanova
/
samba-autobuild
/
.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
pyldb: p3k readiness: allow single unicode string in msg element
[nivanova/samba-autobuild/.git]
/
lib
/
ldb
/
pyldb.c
diff --git
a/lib/ldb/pyldb.c
b/lib/ldb/pyldb.c
index bea837f210e0bf04ca6d57c4dc1c1794bfde472d..b65e25525ad0aa6158b90ac1fa31b57d43715d3b 100644
(file)
--- 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 (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);
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;
}
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;
}
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;
el->values[0].data = talloc_memdup(el->values,
(const uint8_t *)msg, size + 1);
el->values[0].length = size;