mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
pylibsmb: Simplify py_cli_create_contexts()
Py_BuildValue() can create tuples. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
fa7ad45486
commit
6d552b1e3e
@ -923,8 +923,6 @@ fail:
|
||||
static PyObject *py_cli_create_contexts(const struct smb2_create_blobs *blobs)
|
||||
{
|
||||
PyObject *py_blobs = NULL;
|
||||
PyObject *py_blob = NULL;
|
||||
PyObject *tmp = NULL;
|
||||
uint32_t i;
|
||||
|
||||
if (blobs == NULL) {
|
||||
@ -933,49 +931,32 @@ static PyObject *py_cli_create_contexts(const struct smb2_create_blobs *blobs)
|
||||
|
||||
py_blobs = PyList_New(blobs->num_blobs);
|
||||
if (py_blobs == NULL) {
|
||||
goto fail;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<blobs->num_blobs; i++) {
|
||||
struct smb2_create_blob *blob = &blobs->blobs[i];
|
||||
PyObject *py_blob = NULL;
|
||||
int ret;
|
||||
|
||||
py_blob = PyTuple_New(2);
|
||||
py_blob = Py_BuildValue(
|
||||
"(yy#)",
|
||||
blob->tag,
|
||||
blob->data.data,
|
||||
(int)blob->data.length);
|
||||
if (py_blob == NULL) {
|
||||
goto nomem;
|
||||
}
|
||||
|
||||
tmp = PyBytes_FromString(blob->tag);
|
||||
if (tmp == NULL) {
|
||||
goto nomem;
|
||||
}
|
||||
ret = PyTuple_SetItem(py_blob, 0, tmp);
|
||||
if (ret == -1) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
tmp = PyBytes_FromStringAndSize(
|
||||
(char *)blob->data.data, blob->data.length);
|
||||
if (tmp == NULL) {
|
||||
goto nomem;
|
||||
}
|
||||
ret = PyTuple_SetItem(py_blob, 1, tmp);
|
||||
if (ret == -1) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = PyList_SetItem(py_blobs, i, py_blob);
|
||||
if (ret == -1) {
|
||||
Py_XDECREF(py_blob);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
return py_blobs;
|
||||
|
||||
nomem:
|
||||
PyErr_NoMemory();
|
||||
fail:
|
||||
Py_XDECREF(tmp);
|
||||
Py_XDECREF(py_blob);
|
||||
Py_XDECREF(py_blobs);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user