[libvirt] [PATCH 4/5] python: Use a pure python implementation of 'vir*GetConnect'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The API docs explictly warn that we shouldn't use the C vir*GetConnect calls
in bindings: doing so can close the internal connection pointer and cause
things to get screwy. Implement these calls in python.

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 python/generator.py |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/python/generator.py b/python/generator.py
index aea2120..f87540b 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -376,6 +376,16 @@ skip_function = (
     "virSecretRef",
     "virStoragePoolRef",
     "virStorageVolRef",
+
+    # This functions shouldn't be called via the bindings (and even the docs
+    # contain an explicit warning to that effect). The equivalent should be
+    # implemented in pure python for each class
+    "virDomainGetConnect",
+    "virInterfaceGetConnect",
+    "virNetworkGetConnect",
+    "virSecretGetConnect",
+    "virStoragePoolGetConnect",
+    "virStorageVolGetConnect",
 )
 
 
@@ -669,6 +679,11 @@ classes_destructors = {
     "virSecret": "virSecretFree"
 }
 
+class_skip_connect_impl = {
+    "virConnect" : True
+}
+
+
 functions_noexcept = {
     'virDomainGetID': True,
     'virDomainGetName': True,
@@ -1080,6 +1095,12 @@ def buildWrappers():
 			      classes_destructors[classname]);
 		classes.write("        self._o = None\n\n");
 		destruct=classes_destructors[classname]
+
+            if not class_skip_connect_impl.has_key(classname):
+                # Build python safe 'connect' method
+                classes.write("    def connect(self):\n")
+                classes.write("        return self._conn\n\n")
+
 	    flist = function_classes[classname]
 	    flist.sort(functionCompare)
 	    oldfile = ""
-- 
1.6.4.4

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]