On Mon, Feb 19, 2018 at 01:09:27PM +0000, Daniel P. Berrangé wrote:
On Wed, Feb 07, 2018 at 05:49:30PM +0300, Edgar Kaziakhmedov wrote:
> Predefine hints for all parameters possible to avoid wrong type
> convert.
>
> Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov(a)virtuozzo.com>
> ---
> libvirt-override.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 124 insertions(+), 4 deletions(-)
Thanks, looks good, so I've pushed this now.
Actually I wanted to suggest to use static variables to store the hints:
diff --git a/libvirt-override.c b/libvirt-override.c
index 78a7f08..c41c03c 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -7739,6 +7739,25 @@ libvirt_virDomainMigrateGetMaxDowntime(PyObject *self ATTRIBUT
E_UNUSED,
#endif /* LIBVIR_CHECK_VERSION(3, 7, 0) */
#if LIBVIR_CHECK_VERSION(1, 1, 0)
+
+static virPyTypedParamsHint virDomainMigrate3Params[] = {
+ { VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING },
+ { VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING },
+ { VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING },
+ { VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING },
+ { VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG },
+ { VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING },
+ { VIR_MIGRATE_PARAM_DISKS_PORT, VIR_TYPED_PARAM_INT },
+ { VIR_MIGRATE_PARAM_COMPRESSION, VIR_TYPED_PARAM_STRING },
+ { VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS, VIR_TYPED_PARAM_INT },
+ { VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL, VIR_TYPED_PARAM_INT },
+ { VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS, VIR_TYPED_PARAM_INT },
+ { VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE, VIR_TYPED_PARAM_ULLONG },
+ { VIR_MIGRATE_PARAM_PERSIST_XML, VIR_TYPED_PARAM_STRING },
+ { VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL, VIR_TYPED_PARAM_INT },
+ { VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT, VIR_TYPED_PARAM_INT },
+};
+
static PyObject *
libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args)
@@ -7760,7 +7779,9 @@ libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);
- if (virPyDictToTypedParams(dict, ¶ms, &nparams, NULL, 0) < 0)
+ if (virPyDictToTypedParams(dict, ¶ms, &nparams,
+ virDomainMigrate3Params,
+ VIR_N_ELEMENTS(virDomainMigrate3Params)) < 0)
return NULL;
LIBVIRT_BEGIN_ALLOW_THREADS;
diff --git a/libvirt-utils.h b/libvirt-utils.h
index 779fd56..0af1e62 100644
--- a/libvirt-utils.h
+++ b/libvirt-utils.h
@@ -146,6 +146,8 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
# endif
+#define VIR_N_ELEMENTS(array) (sizeof(array) / sizeof(*(array)))
+
/* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
is so common that we encapsulate it here. Now, each use is simply
return VIR_PY_NONE; */
Which IMHO looks better.
Pavel