Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 src/python-lxc/lxc.c | 69 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 60 insertions(+), 9 deletions(-)

diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index 5a20ff4..b4f1da3 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -510,16 +510,33 @@ Container_add_device_node(Container *self, PyObject 
*args, PyObject *kwds)
     static char *kwlist[] = {"src_path", "dest_path", NULL};
     char *src_path = NULL;
     char *dst_path = NULL;
+    PyObject *py_src_path = NULL;
+    PyObject *py_dst_path = NULL;
 
-    if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|s", kwlist,
-                                      &src_path, &dst_path))
+    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&", kwlist,
+                                      PyUnicode_FSConverter, &py_src_path,
+                                      PyUnicode_FSConverter, &py_dst_path))
         return NULL;
 
+    if (py_src_path != NULL) {
+        src_path = PyBytes_AS_STRING(py_src_path);
+        assert(src_path != NULL);
+    }
+
+    if (py_dst_path != NULL) {
+        dst_path = PyBytes_AS_STRING(py_dst_path);
+        assert(dst_path != NULL);
+    }
+
     if (self->container->add_device_node(self->container, src_path,
                                          dst_path)) {
+        Py_XDECREF(py_src_path);
+        Py_XDECREF(py_dst_path);
         Py_RETURN_TRUE;
     }
 
+    Py_XDECREF(py_src_path);
+    Py_XDECREF(py_dst_path);
     Py_RETURN_FALSE;
 }
 
@@ -611,14 +628,16 @@ Container_clone(Container *self, PyObject *args, PyObject 
*kwds)
     char **hookargs = NULL;
 
     PyObject *py_hookargs = NULL;
+    PyObject *py_config_path = NULL;
     struct lxc_container *new_container = NULL;
     int i = 0;
 
     static char *kwlist[] = {"newname", "config_path", "flags", "bdevtype",
                              "bdevdata", "newsize", "hookargs", NULL};
-    if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|sisskO", kwlist,
-                                      &newname, &config_path, &flags,
-                                      &bdevtype, &bdevdata, &newsize,
+    if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|O&isskO", kwlist,
+                                      &newname,
+                                      PyUnicode_FSConverter, &py_config_path,
+                                      &flags, &bdevtype, &bdevdata, &newsize,
                                       &py_hookargs))
         return NULL;
 
@@ -635,10 +654,17 @@ Container_clone(Container *self, PyObject *args, PyObject 
*kwds)
         }
     }
 
+    if (py_config_path != NULL) {
+        config_path = PyBytes_AS_STRING(py_config_path);
+        assert(config_path != NULL);
+    }
+
     new_container = self->container->clone(self->container, newname,
                                            config_path, flags, bdevtype,
                                            bdevdata, newsize, hookargs);
 
+    Py_XDECREF(py_config_path);
+
     if (hookargs) {
         for (i = 0; i < PyTuple_GET_SIZE(py_hookargs); i++)
             free(hookargs[i]);
@@ -1010,16 +1036,33 @@ Container_remove_device_node(Container *self, PyObject 
*args, PyObject *kwds)
     static char *kwlist[] = {"src_path", "dest_path", NULL};
     char *src_path = NULL;
     char *dst_path = NULL;
+    PyObject *py_src_path = NULL;
+    PyObject *py_dst_path = NULL;
 
-    if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|s", kwlist,
-                                      &src_path, &dst_path))
+    if (! PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&", kwlist,
+                                      PyUnicode_FSConverter, &py_src_path,
+                                      PyUnicode_FSConverter, &py_dst_path))
         return NULL;
 
+    if (py_src_path != NULL) {
+        src_path = PyBytes_AS_STRING(py_src_path);
+        assert(src_path != NULL);
+    }
+
+    if (py_dst_path != NULL) {
+        dst_path = PyBytes_AS_STRING(py_dst_path);
+        assert(dst_path != NULL);
+    }
+
     if (self->container->remove_device_node(self->container, src_path,
                                             dst_path)) {
+        Py_XDECREF(py_src_path);
+        Py_XDECREF(py_dst_path);
         Py_RETURN_TRUE;
     }
 
+    Py_XDECREF(py_src_path);
+    Py_XDECREF(py_dst_path);
     Py_RETURN_FALSE;
 }
 
@@ -1126,13 +1169,21 @@ Container_snapshot(Container *self, PyObject *args, 
PyObject *kwds)
     int retval = 0;
     int ret = 0;
     char newname[20];
+    PyObject *py_comment_path;
 
-    if (! PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist,
-                                      &comment_path))
+    if (! PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist,
+                                      PyUnicode_FSConverter, &py_comment_path))
         return NULL;
 
+    if (py_comment_path != NULL) {
+        comment_path = PyBytes_AS_STRING(py_comment_path);
+        assert(comment_path != NULL);
+    }
+
     retval = self->container->snapshot(self->container, comment_path);
 
+    Py_XDECREF(py_comment_path);
+
     if (retval < 0) {
         Py_RETURN_FALSE;
     }
-- 
1.8.4.4


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to