2005-12-19 16:34:11 +00:00
|
|
|
/*
|
|
|
|
* types.c: converter functions between the internal representation
|
|
|
|
* and the Python objects
|
|
|
|
*
|
2012-02-02 22:45:54 +00:00
|
|
|
* Copyright (C) 2005, 2007, 2012 Red Hat, Inc.
|
2005-12-19 16:34:11 +00:00
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-12-07 10:08:06 +00:00
|
|
|
|
2008-04-18 18:31:32 +00:00
|
|
|
/* Horrible kludge to work around even more horrible name-space pollution
|
|
|
|
* via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
|
|
|
|
* which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
|
|
|
|
#undef HAVE_PTHREAD_H
|
|
|
|
|
2009-09-16 13:03:53 +00:00
|
|
|
#include "typewrappers.h"
|
2005-12-19 16:34:11 +00:00
|
|
|
|
2012-02-02 22:45:54 +00:00
|
|
|
#include "memory.h"
|
|
|
|
|
2010-12-02 17:15:10 +00:00
|
|
|
#ifndef Py_CAPSULE_H
|
|
|
|
typedef void(*PyCapsule_Destructor)(void *, void *);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
libvirt_buildPyObject(void *cobj,
|
|
|
|
const char *name,
|
|
|
|
PyCapsule_Destructor destr)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
#ifdef Py_CAPSULE_H
|
|
|
|
ret = PyCapsule_New(cobj, name, destr);
|
|
|
|
#else
|
|
|
|
ret = PyCObject_FromVoidPtrAndDesc(cobj, (void *) name, destr);
|
|
|
|
#endif /* _TEST_CAPSULE */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-19 16:34:11 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_intWrap(int val)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyInt_FromLong((long) val);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_longWrap(long val)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyInt_FromLong(val);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
|
|
|
|
2006-11-15 19:40:00 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_ulongWrap(unsigned long val)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromLong(val);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-02-05 19:27:37 +00:00
|
|
|
}
|
2006-11-15 19:40:00 +00:00
|
|
|
|
2006-01-31 10:24:12 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_longlongWrap(long long val)
|
2006-01-31 10:24:12 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromUnsignedLongLong((unsigned long long) val);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2006-01-31 10:24:12 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 11:31:45 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_ulonglongWrap(unsigned long long val)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
ret = PyLong_FromUnsignedLongLong(val);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2010-02-03 11:31:45 +00:00
|
|
|
}
|
|
|
|
|
2011-06-14 20:07:43 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_charPtrSizeWrap(char *str, Py_ssize_t size)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2011-06-14 20:07:43 +00:00
|
|
|
}
|
|
|
|
ret = PyString_FromStringAndSize(str, size);
|
2012-02-02 22:45:54 +00:00
|
|
|
VIR_FREE(str);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2011-06-14 20:07:43 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 16:34:11 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_charPtrWrap(char *str)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
2012-02-02 22:45:54 +00:00
|
|
|
VIR_FREE(str);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_constcharPtrWrap(const char *str)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
|
|
|
ret = PyString_FromString(str);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
int
|
|
|
|
libvirt_intUnwrap(PyObject *obj, int *val)
|
|
|
|
{
|
|
|
|
long long_val;
|
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
/* If obj is type of PyInt_Type, PyInt_AsLong converts it
|
|
|
|
* to C long type directly. If it is of PyLong_Type, PyInt_AsLong
|
|
|
|
* will call PyLong_AsLong() to deal with it automatically.
|
|
|
|
*/
|
|
|
|
long_val = PyInt_AsLong(obj);
|
|
|
|
if ((long_val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
|
2012-04-10 10:24:03 +00:00
|
|
|
#if LONG_MAX != INT_MAX
|
python: improve conversion validation
Laszlo Ersek pointed out that in trying to convert a long to an
unsigned int, we used:
long long_val = ...;
if ((unsigned int)long_val == long_val)
According to C99 integer promotion rules, the if statement is
equivalent to:
(unsigned long)(unsigned int)long_val == (unsigned long)long_val
since you get an unsigned comparison if at least one side is
unsigned, using the largest rank of the two sides; but on 32-bit
platforms, where unsigned long and unsigned int are the same size,
this comparison is always true and ends up converting negative
long_val into posigive unsigned int values, rather than rejecting
the negative value as we had originally intended (python longs
are unbounded size, and we don't want to do silent modulo
arithmetic when converting to C code).
Fix this by using direct comparisons, rather than casting.
* python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap)
(libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion
checks.
2012-03-30 18:03:20 +00:00
|
|
|
if (long_val >= INT_MIN && long_val <= INT_MAX) {
|
2012-03-27 06:06:10 +00:00
|
|
|
*val = long_val;
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"Python int too large to convert to C int");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-04-10 10:24:03 +00:00
|
|
|
#else
|
|
|
|
*val = long_val;
|
|
|
|
#endif
|
2012-03-27 06:06:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libvirt_uintUnwrap(PyObject *obj, unsigned int *val)
|
|
|
|
{
|
|
|
|
long long_val;
|
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
long_val = PyInt_AsLong(obj);
|
|
|
|
if ((long_val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
|
python: improve conversion validation
Laszlo Ersek pointed out that in trying to convert a long to an
unsigned int, we used:
long long_val = ...;
if ((unsigned int)long_val == long_val)
According to C99 integer promotion rules, the if statement is
equivalent to:
(unsigned long)(unsigned int)long_val == (unsigned long)long_val
since you get an unsigned comparison if at least one side is
unsigned, using the largest rank of the two sides; but on 32-bit
platforms, where unsigned long and unsigned int are the same size,
this comparison is always true and ends up converting negative
long_val into posigive unsigned int values, rather than rejecting
the negative value as we had originally intended (python longs
are unbounded size, and we don't want to do silent modulo
arithmetic when converting to C code).
Fix this by using direct comparisons, rather than casting.
* python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap)
(libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion
checks.
2012-03-30 18:03:20 +00:00
|
|
|
if (long_val >= 0 && long_val <= UINT_MAX) {
|
2012-03-27 06:06:10 +00:00
|
|
|
*val = long_val;
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"Python int too large to convert to C unsigned int");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libvirt_longUnwrap(PyObject *obj, long *val)
|
|
|
|
{
|
|
|
|
long long_val;
|
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
long_val = PyInt_AsLong(obj);
|
|
|
|
if ((long_val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*val = long_val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libvirt_ulongUnwrap(PyObject *obj, unsigned long *val)
|
|
|
|
{
|
|
|
|
long long_val;
|
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
long_val = PyInt_AsLong(obj);
|
|
|
|
if ((long_val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
|
python: improve conversion validation
Laszlo Ersek pointed out that in trying to convert a long to an
unsigned int, we used:
long long_val = ...;
if ((unsigned int)long_val == long_val)
According to C99 integer promotion rules, the if statement is
equivalent to:
(unsigned long)(unsigned int)long_val == (unsigned long)long_val
since you get an unsigned comparison if at least one side is
unsigned, using the largest rank of the two sides; but on 32-bit
platforms, where unsigned long and unsigned int are the same size,
this comparison is always true and ends up converting negative
long_val into posigive unsigned int values, rather than rejecting
the negative value as we had originally intended (python longs
are unbounded size, and we don't want to do silent modulo
arithmetic when converting to C code).
Fix this by using direct comparisons, rather than casting.
* python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap)
(libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion
checks.
2012-03-30 18:03:20 +00:00
|
|
|
if (long_val >= 0) {
|
|
|
|
*val = long_val;
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"negative Python int cannot be converted to C unsigned long");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-03-27 06:06:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libvirt_longlongUnwrap(PyObject *obj, long long *val)
|
|
|
|
{
|
|
|
|
long long llong_val;
|
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
/* If obj is of PyInt_Type, PyLong_AsLongLong
|
|
|
|
* will call PyInt_AsLong() to handle it automatically.
|
|
|
|
*/
|
|
|
|
llong_val = PyLong_AsLongLong(obj);
|
|
|
|
if ((llong_val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*val = llong_val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libvirt_ulonglongUnwrap(PyObject *obj, unsigned long long *val)
|
|
|
|
{
|
|
|
|
unsigned long long ullong_val = -1;
|
python: improve conversion validation
Laszlo Ersek pointed out that in trying to convert a long to an
unsigned int, we used:
long long_val = ...;
if ((unsigned int)long_val == long_val)
According to C99 integer promotion rules, the if statement is
equivalent to:
(unsigned long)(unsigned int)long_val == (unsigned long)long_val
since you get an unsigned comparison if at least one side is
unsigned, using the largest rank of the two sides; but on 32-bit
platforms, where unsigned long and unsigned int are the same size,
this comparison is always true and ends up converting negative
long_val into posigive unsigned int values, rather than rejecting
the negative value as we had originally intended (python longs
are unbounded size, and we don't want to do silent modulo
arithmetic when converting to C code).
Fix this by using direct comparisons, rather than casting.
* python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap)
(libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion
checks.
2012-03-30 18:03:20 +00:00
|
|
|
long long llong_val;
|
2012-03-27 06:06:10 +00:00
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
/* The PyLong_AsUnsignedLongLong doesn't check the type of
|
|
|
|
* obj, only accept argument of PyLong_Type, so we check it instead.
|
|
|
|
*/
|
python: improve conversion validation
Laszlo Ersek pointed out that in trying to convert a long to an
unsigned int, we used:
long long_val = ...;
if ((unsigned int)long_val == long_val)
According to C99 integer promotion rules, the if statement is
equivalent to:
(unsigned long)(unsigned int)long_val == (unsigned long)long_val
since you get an unsigned comparison if at least one side is
unsigned, using the largest rank of the two sides; but on 32-bit
platforms, where unsigned long and unsigned int are the same size,
this comparison is always true and ends up converting negative
long_val into posigive unsigned int values, rather than rejecting
the negative value as we had originally intended (python longs
are unbounded size, and we don't want to do silent modulo
arithmetic when converting to C code).
Fix this by using direct comparisons, rather than casting.
* python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap)
(libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion
checks.
2012-03-30 18:03:20 +00:00
|
|
|
if (PyInt_Check(obj)) {
|
|
|
|
llong_val = PyInt_AsLong(obj);
|
|
|
|
if (llong_val < 0)
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"negative Python int cannot be converted to C unsigned long long");
|
|
|
|
else
|
|
|
|
ullong_val = llong_val;
|
|
|
|
} else if (PyLong_Check(obj)) {
|
2012-03-27 06:06:10 +00:00
|
|
|
ullong_val = PyLong_AsUnsignedLongLong(obj);
|
python: improve conversion validation
Laszlo Ersek pointed out that in trying to convert a long to an
unsigned int, we used:
long long_val = ...;
if ((unsigned int)long_val == long_val)
According to C99 integer promotion rules, the if statement is
equivalent to:
(unsigned long)(unsigned int)long_val == (unsigned long)long_val
since you get an unsigned comparison if at least one side is
unsigned, using the largest rank of the two sides; but on 32-bit
platforms, where unsigned long and unsigned int are the same size,
this comparison is always true and ends up converting negative
long_val into posigive unsigned int values, rather than rejecting
the negative value as we had originally intended (python longs
are unbounded size, and we don't want to do silent modulo
arithmetic when converting to C code).
Fix this by using direct comparisons, rather than casting.
* python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap)
(libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion
checks.
2012-03-30 18:03:20 +00:00
|
|
|
} else {
|
2012-03-27 06:06:10 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
python: improve conversion validation
Laszlo Ersek pointed out that in trying to convert a long to an
unsigned int, we used:
long long_val = ...;
if ((unsigned int)long_val == long_val)
According to C99 integer promotion rules, the if statement is
equivalent to:
(unsigned long)(unsigned int)long_val == (unsigned long)long_val
since you get an unsigned comparison if at least one side is
unsigned, using the largest rank of the two sides; but on 32-bit
platforms, where unsigned long and unsigned int are the same size,
this comparison is always true and ends up converting negative
long_val into posigive unsigned int values, rather than rejecting
the negative value as we had originally intended (python longs
are unbounded size, and we don't want to do silent modulo
arithmetic when converting to C code).
Fix this by using direct comparisons, rather than casting.
* python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap)
(libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion
checks.
2012-03-30 18:03:20 +00:00
|
|
|
}
|
2012-03-27 06:06:10 +00:00
|
|
|
|
|
|
|
if ((ullong_val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*val = ullong_val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libvirt_doubleUnwrap(PyObject *obj, double *val)
|
|
|
|
{
|
|
|
|
double double_val;
|
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:06:10 +00:00
|
|
|
double_val = PyFloat_AsDouble(obj);
|
|
|
|
if ((double_val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*val = double_val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
libvirt_boolUnwrap(PyObject *obj, bool *val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2012-09-26 17:33:50 +00:00
|
|
|
if (!obj) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "unexpected type");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = PyObject_IsTrue(obj)) < 0)
|
2012-03-27 06:06:10 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
*val = ret > 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-19 16:34:11 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_virDomainPtrWrap(virDomainPtr node)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virDomainPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
|
|
|
|
2007-03-09 15:42:50 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virNetworkPtrWrap(virNetworkPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2007-03-09 15:42:50 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virNetworkPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2007-03-09 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 10:57:05 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virInterfacePtrWrap(virInterfacePtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2009-05-21 10:57:05 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virInterfacePtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-05-21 10:57:05 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 15:26:22 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2008-02-20 15:26:22 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virStoragePoolPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-02-20 15:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
libvirt_virStorageVolPtrWrap(virStorageVolPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2008-02-20 15:26:22 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virStorageVolPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-02-20 15:26:22 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 16:34:11 +00:00
|
|
|
PyObject *
|
2006-02-09 17:45:11 +00:00
|
|
|
libvirt_virConnectPtrWrap(virConnectPtr node)
|
2005-12-19 16:34:11 +00:00
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virConnectPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2005-12-19 16:34:11 +00:00
|
|
|
}
|
2008-10-31 10:13:45 +00:00
|
|
|
|
2008-11-21 12:41:15 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2008-11-21 12:41:15 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virNodeDevicePtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-21 12:41:15 +00:00
|
|
|
}
|
|
|
|
|
Secret manipulation API docs refresh & wire up python generator
Sample session:
>>> import libvirt
>>> c = libvirt.open('qemu:///session')
>>> c.listSecrets()
['12247729-47d2-a783-88ce-b329d4781cd3', 'reee', 'abc']
>>> s = c.secretDefineXML("<secret ephemeral='no' private='no'>\n<description>Something for use</description>\n<volume>/foo/bar</volume>\n</secret>\n")
>>> s.UUIDString()
'340c2dfb-811b-eda8-da9e-25ccd7bfd650'
>>> s.XMLDesc()
"<secret ephemeral='no' private='no'>\n <uuid>340c2dfb-811b-eda8-da9e-25ccd7bfd650</uuid>\n <description>Something for use</description>\n <volume>/foo/bar</volume>\n</secret>\n"
>>> s.setValue('abc\0xx\xffx')
0
>>> s.value()
'abc\x00xx\xffx'
>>> s.undefine()
0
* python/generator.py: Add rules for virSecret APIs
* python/libvir.c, python/libvirt-python-api.xml: Manual impl of
virSecretSetValue, virSecretGetValue$ and virConnectListSecrets APIs
* python/libvirt_wrap.h, python/types.c: Wrapper for virSecret objects
* docs/libvirt-api.xml, docs/libvirt-refs.xml,
docs/html/libvirt-virterror.html, docs/html/libvirt-libvirt.html,
docs/devhelp/libvirt-virterror.html, docs/devhelp/libvirt-libvirt.html:
Re-generate with 'make api'
2009-08-04 18:38:21 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virSecretPtrWrap(virSecretPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virSecretPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2010-04-29 10:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
libvirt_virNWFilterPtrWrap(virNWFilterPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virNWFilterPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
Secret manipulation API docs refresh & wire up python generator
Sample session:
>>> import libvirt
>>> c = libvirt.open('qemu:///session')
>>> c.listSecrets()
['12247729-47d2-a783-88ce-b329d4781cd3', 'reee', 'abc']
>>> s = c.secretDefineXML("<secret ephemeral='no' private='no'>\n<description>Something for use</description>\n<volume>/foo/bar</volume>\n</secret>\n")
>>> s.UUIDString()
'340c2dfb-811b-eda8-da9e-25ccd7bfd650'
>>> s.XMLDesc()
"<secret ephemeral='no' private='no'>\n <uuid>340c2dfb-811b-eda8-da9e-25ccd7bfd650</uuid>\n <description>Something for use</description>\n <volume>/foo/bar</volume>\n</secret>\n"
>>> s.setValue('abc\0xx\xffx')
0
>>> s.value()
'abc\x00xx\xffx'
>>> s.undefine()
0
* python/generator.py: Add rules for virSecret APIs
* python/libvir.c, python/libvirt-python-api.xml: Manual impl of
virSecretSetValue, virSecretGetValue$ and virConnectListSecrets APIs
* python/libvirt_wrap.h, python/types.c: Wrapper for virSecret objects
* docs/libvirt-api.xml, docs/libvirt-refs.xml,
docs/html/libvirt-virterror.html, docs/html/libvirt-libvirt.html,
docs/devhelp/libvirt-virterror.html, docs/devhelp/libvirt-libvirt.html:
Re-generate with 'make api'
2009-08-04 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
2009-07-10 11:18:12 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virStreamPtrWrap(virStreamPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virStreamPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-10 11:18:12 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 20:33:13 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virDomainSnapshotPtr", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2010-03-31 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
2008-10-31 10:13:45 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2008-12-18 12:25:11 +00:00
|
|
|
printf("%s: WARNING - Wrapping None\n", __func__);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2008-10-31 10:13:45 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virEventHandleCallback", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-10-31 10:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
2008-12-18 12:25:11 +00:00
|
|
|
printf("%s: WARNING - Wrapping None\n", __func__);
|
2008-10-31 10:13:45 +00:00
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2008-10-31 10:13:45 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virEventTimeoutCallback", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-10-31 10:13:45 +00:00
|
|
|
}
|
|
|
|
|
2008-11-19 16:24:01 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virFreeCallbackWrap(virFreeCallback node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2008-11-19 16:24:01 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "virFreeCallback", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-11-19 16:24:01 +00:00
|
|
|
}
|
|
|
|
|
2008-10-31 10:13:45 +00:00
|
|
|
PyObject *
|
|
|
|
libvirt_virVoidPtrWrap(void* node)
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
2012-03-22 11:33:35 +00:00
|
|
|
return Py_None;
|
2008-10-31 10:13:45 +00:00
|
|
|
}
|
2010-12-02 17:15:10 +00:00
|
|
|
|
|
|
|
ret = libvirt_buildPyObject(node, "void*", NULL);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2008-10-31 10:13:45 +00:00
|
|
|
}
|