]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
pylibmount: cleanup cxt usage
authorKarel Zak <kzak@redhat.com>
Wed, 21 Aug 2013 08:02:19 +0000 (10:02 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 21 Aug 2013 08:02:19 +0000 (10:02 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/python/context.c
libmount/python/pylibmount.h

index 383e6a6e6522116ecef63166af4b1384df148e4d..8d9680f5cccaf37a28d38669d90fe5bf009973f2 100644 (file)
@@ -48,28 +48,9 @@ static void Context_dealloc(ContextObjext *self)
        if (!self->cxt) /* if init fails */
                return;
 
-       if (!(self->cxt->flags & MNT_FL_EXTERN_FS)) {
-               if (self->cxt->fs && self->cxt->fs->userdata)
-                       Py_DECREF(self->cxt->fs->userdata);
-               else
-                       mnt_free_fs(self->cxt->fs);
-               self->cxt->fs = NULL;
-       }
-
-       if (self->cxt->fstab && !(self->cxt->flags & MNT_FL_EXTERN_FSTAB)) {
-               if (self->cxt->fstab->userdata)
-                       Py_DECREF(self->cxt->fstab->userdata);
-               else
-                       pymnt_free_table(self->cxt->fstab);
-               self->cxt->fstab = NULL;
-       }
-       if (self->cxt->mtab) {
-               if (self->cxt->mtab->userdata)
-                       Py_DECREF(self->cxt->mtab->userdata);
-               else
-                       pymnt_free_table(self->cxt->mtab);
-               self->cxt->mtab = NULL;
-       }
+       Py_XDECREF(mnt_context_get_fs_userdata(self->cxt));
+       Py_XDECREF(mnt_context_get_fstab_userdata(self->cxt));
+       Py_XDECREF(mnt_context_get_mtab_userdata(self->cxt));
 
        mnt_free_context(self->cxt);
        self->ob_type->tp_free((PyObject*) self);
@@ -558,8 +539,8 @@ static int Context_set_fs(ContextObjext *self, PyObject *value, void *closure __
                return -1;
        }
        Py_INCREF(fs);
-       if (self->cxt->fs)
-               Py_XDECREF(self->cxt->fs->userdata);
+       Py_XDECREF(mnt_context_get_fs_userdata(self->cxt));
+
        return mnt_context_set_fs(self->cxt, fs->fs);
 }
 
@@ -576,8 +557,8 @@ static int Context_set_fstab(ContextObjext *self, PyObject *value, void *closure
                return -1;
        }
        Py_INCREF(fstab);
-       if (self->cxt->fstab)
-               Py_XDECREF(self->cxt->fstab->userdata);
+       Py_XDECREF(mnt_context_get_fstab_userdata(self->cxt));
+
        return mnt_context_set_fstab(self->cxt, fstab->tab);
 }
 
@@ -833,14 +814,7 @@ This function is optional.\n\
 Returns self or raises an exception in case of an error."
 static PyObject *Context_apply_fstab(ContextObjext *self)
 {
-       int rc;
-
-       if (!self->cxt->fs) {
-               PyErr_SetString(PyExc_AssertionError, NOFS_ERR);
-               return NULL;
-       }
-
-       rc = mnt_context_apply_fstab(self->cxt);
+       int rc = mnt_context_apply_fstab(self->cxt);
        return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
 }
 
@@ -956,14 +930,7 @@ Returns self on success\n\
 or an exception in case of other errors."
 static PyObject *Context_do_mount(ContextObjext *self)
 {
-       int rc;
-
-       if (!self->cxt->fs) {
-               PyErr_SetString(PyExc_AssertionError, NOFS_ERR);
-               return NULL;
-       }
-
-       rc = mnt_context_do_mount(self->cxt);
+       int rc = mnt_context_do_mount(self->cxt);
        return rc ? UL_RaiseExc(rc < 0 ? -rc : rc) : UL_IncRef(self);
 }
 
@@ -1011,14 +978,7 @@ Returns self on success\n\
 or an exception in case of other errors."
 static PyObject *Context_mount(ContextObjext *self)
 {
-       int rc;
-
-       if (!self->cxt->fs) {
-               PyErr_SetString(PyExc_AssertionError, NOFS_ERR);
-               return NULL;
-       }
-
-       rc = mnt_context_mount(self->cxt);
+       int rc = mnt_context_mount(self->cxt);
        return rc ? UL_RaiseExc(rc < 0 ? -rc : rc) : UL_IncRef(self);
 }
 
@@ -1042,7 +1002,7 @@ Returns self on success\n\
 or an exception in case of other errors."
 static PyObject *Context_umount(ContextObjext *self)
 {
-       int rc =  mnt_context_umount(self->cxt);
+       int rc = mnt_context_umount(self->cxt);
        return rc ? UL_RaiseExc(rc < 0 ? -rc : rc) : UL_IncRef(self);
 }
 
@@ -1053,14 +1013,7 @@ after Cxt.do_mount(). See also Cxt.syscall_status.\n\
 Returns self or raises an exception in case of an error."
 static PyObject *Context_finalize_mount(ContextObjext *self)
 {
-       int rc;
-
-       if (!self->cxt->fs) {
-               PyErr_SetString(PyExc_AssertionError, NOFS_ERR);
-               return NULL;
-       }
-
-       rc = mnt_context_finalize_mount(self->cxt);
+       int rc = mnt_context_finalize_mount(self->cxt);
        return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
 }
 
@@ -1080,14 +1033,7 @@ Prepare context for mounting, unnecessary for Cxt.mount().\n\
 Returns self or raises an exception in case of an error."
 static PyObject *Context_prepare_mount(ContextObjext *self)
 {
-       int rc;
-
-       if (!self->cxt->fs) {
-               PyErr_SetString(PyExc_AssertionError, NOFS_ERR);
-               return NULL;
-       }
-
-       rc = mnt_context_prepare_mount(self->cxt);
+       int rc = mnt_context_prepare_mount(self->cxt);
        return rc ? UL_RaiseExc(-rc) : UL_IncRef(self);
 }
 
@@ -1256,11 +1202,8 @@ static PyMethodDef Context_methods[] = {
 
 static PyObject *Context_repr(ContextObjext *self)
 {
-       return PyString_FromFormat("<libmount.Context object at %p, mtab_path=%s, utab_path=%s, restricted=%s>",
-                       self,
-                       self->cxt->mtab_path ? self->cxt->mtab_path : "None",
-                       self->cxt->utab_path ? self->cxt->utab_path : "None",
-                       self->cxt->restricted ? "True" : "False");
+       return PyString_FromFormat("<libmount.Context object at %p, restricted=%s>",
+                       self, mnt_context_is_restricted(self->cxt) ? "True" : "False");
 }
 
 PyTypeObject ContextType = {
index a2ea25a6230f7c7fed1ac66385e8f790fe551bcd..eb50c5874ed6e1b6f68c0e433a340417b699f29f 100644 (file)
@@ -5,7 +5,6 @@
 #include <structmember.h>
 
 #include "libmount.h"
-#include "mountP.h"
 
 #define NODEL_ATTR     "This attribute cannot be deleted"
 #define CONSTRUCT_ERR  "Error during object construction"