[PATCH 08/15] maint: avoid 'const fooPtr' in python bindings

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

 



'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can).  But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).

Fix up offenders in the python bindings.

* python/generator.py (py_types): Drop useless conversions.
* python/libvirt-override.c (getPyVirTypedParameter)
(setPyVirTypedParameter): Use intended type.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 python/generator.py       | 11 -----------
 python/libvirt-override.c |  4 ++--
 2 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/python/generator.py b/python/generator.py
index 12c14f1..87ecf5a 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -294,57 +294,46 @@ py_types = {
     'size_t': ('n', None, "size_t", "size_t"),

     'virDomainPtr':  ('O', "virDomain", "virDomainPtr", "virDomainPtr"),
-    'const virDomainPtr':  ('O', "virDomain", "virDomainPtr", "virDomainPtr"),
     'virDomain *':  ('O', "virDomain", "virDomainPtr", "virDomainPtr"),
     'const virDomain *':  ('O', "virDomain", "virDomainPtr", "virDomainPtr"),

     'virNetworkPtr':  ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"),
-    'const virNetworkPtr':  ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"),
     'virNetwork *':  ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"),
     'const virNetwork *':  ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"),

     'virInterfacePtr':  ('O', "virInterface", "virInterfacePtr", "virInterfacePtr"),
-    'const virInterfacePtr':  ('O', "virInterface", "virInterfacePtr", "virInterfacePtr"),
     'virInterface *':  ('O', "virInterface", "virInterfacePtr", "virInterfacePtr"),
     'const virInterface *':  ('O', "virInterface", "virInterfacePtr", "virInterfacePtr"),

     'virStoragePoolPtr':  ('O', "virStoragePool", "virStoragePoolPtr", "virStoragePoolPtr"),
-    'const virStoragePoolPtr':  ('O', "virStoragePool", "virStoragePoolPtr", "virStoragePoolPtr"),
     'virStoragePool *':  ('O', "virStoragePool", "virStoragePoolPtr", "virStoragePoolPtr"),
     'const virStoragePool *':  ('O', "virStoragePool", "virStoragePoolPtr", "virStoragePoolPtr"),

     'virStorageVolPtr':  ('O', "virStorageVol", "virStorageVolPtr", "virStorageVolPtr"),
-    'const virStorageVolPtr':  ('O', "virStorageVol", "virStorageVolPtr", "virStorageVolPtr"),
     'virStorageVol *':  ('O', "virStorageVol", "virStorageVolPtr", "virStorageVolPtr"),
     'const virStorageVol *':  ('O', "virStorageVol", "virStorageVolPtr", "virStorageVolPtr"),

     'virConnectPtr':  ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
-    'const virConnectPtr':  ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
     'virConnect *':  ('O', "virConnect", "virConnectPtr", "virConnectPtr"),
     'const virConnect *':  ('O', "virConnect", "virConnectPtr", "virConnectPtr"),

     'virNodeDevicePtr':  ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),
-    'const virNodeDevicePtr':  ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),
     'virNodeDevice *':  ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),
     'const virNodeDevice *':  ('O', "virNodeDevice", "virNodeDevicePtr", "virNodeDevicePtr"),

     'virSecretPtr':  ('O', "virSecret", "virSecretPtr", "virSecretPtr"),
-    'const virSecretPtr':  ('O', "virSecret", "virSecretPtr", "virSecretPtr"),
     'virSecret *':  ('O', "virSecret", "virSecretPtr", "virSecretPtr"),
     'const virSecret *':  ('O', "virSecret", "virSecretPtr", "virSecretPtr"),

     'virNWFilterPtr':  ('O', "virNWFilter", "virNWFilterPtr", "virNWFilterPtr"),
-    'const virNWFilterPtr':  ('O', "virNWFilter", "virNWFilterPtr", "virNWFilterPtr"),
     'virNWFilter *':  ('O', "virNWFilter", "virNWFilterPtr", "virNWFilterPtr"),
     'const virNWFilter *':  ('O', "virNWFilter", "virNWFilterPtr", "virNWFilterPtr"),

     'virStreamPtr':  ('O', "virStream", "virStreamPtr", "virStreamPtr"),
-    'const virStreamPtr':  ('O', "virStream", "virStreamPtr", "virStreamPtr"),
     'virStream *':  ('O', "virStream", "virStreamPtr", "virStreamPtr"),
     'const virStream *':  ('O', "virStream", "virStreamPtr", "virStreamPtr"),

     'virDomainSnapshotPtr':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
-    'const virDomainSnapshotPtr':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
     'virDomainSnapshot *':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
     'const virDomainSnapshot *':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
 }
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index e659bae..4800d1d 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -73,7 +73,7 @@ static char *py_str(PyObject *obj)
  * Python dictionary for return to the user.  Return NULL on failure,
  * after raising a python exception.  */
 static PyObject *
-getPyVirTypedParameter(const virTypedParameterPtr params, int nparams)
+getPyVirTypedParameter(const virTypedParameter *params, int nparams)
 {
     PyObject *key, *val, *info;
     size_t i;
@@ -149,7 +149,7 @@ cleanup:
  * raising a python exception.  */
 static virTypedParameterPtr ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
 setPyVirTypedParameter(PyObject *info,
-                       const virTypedParameterPtr params, int nparams)
+                       const virTypedParameter *params, int nparams)
 {
     PyObject *key, *value;
 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
-- 
1.8.3.1

--
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]