From 245910861dd79291fd875934ea86c46b5ad4dee9 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Fri, 29 Nov 2019 16:08:37 +0100 Subject: [PATCH] Simplify ACL.append to not duplicate Entry creation Similar to the pattern for Entry.permset, this removes the duplication with the (child object) init. --- acl.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/acl.c b/acl.c index b5f887b..9b599c3 100644 --- a/acl.c +++ b/acl.c @@ -624,25 +624,22 @@ static char __ACL_append_doc__[] = /* Convenience method to create a new Entry */ static PyObject* ACL_append(PyObject *obj, PyObject *args) { - ACL_Object* self = (ACL_Object*) obj; Entry_Object* newentry; Entry_Object* oldentry = NULL; int nret; - newentry = (Entry_Object*)PyType_GenericNew(&Entry_Type, NULL, NULL); - if(newentry == NULL) { + if (!PyArg_ParseTuple(args, "|O!", &Entry_Type, &oldentry)) { return NULL; } - if (!PyArg_ParseTuple(args, "|O!", &Entry_Type, &oldentry)) { - Py_DECREF(newentry); + PyObject *new_arglist = Py_BuildValue("(O)", obj); + if (new_arglist == NULL) { return NULL; } - - nret = acl_create_entry(&self->acl, &newentry->entry); - if(nret == -1) { - Py_DECREF(newentry); - return PyErr_SetFromErrno(PyExc_IOError); + newentry = (Entry_Object*) PyObject_CallObject((PyObject*)&Entry_Type, new_arglist); + Py_DECREF(new_arglist); + if(newentry == NULL) { + return NULL; } if(oldentry != NULL) { @@ -653,9 +650,6 @@ static PyObject* ACL_append(PyObject *obj, PyObject *args) { } } - newentry->parent_acl = obj; - Py_INCREF(obj); - return (PyObject*)newentry; } -- 2.39.5