summaryrefslogtreecommitdiff
path: root/typewrappers.c
Commit message (Collapse)AuthorAgeFilesLines
* typewrappers: Drop typecast in libvirt_intWrap()Michal Privoznik2023-02-131-1/+1
| | | | | | | | The libvirt_intWrap() accepts an integer and passes it to PyLong_FromLong() which accepts a long. It's perfectly okay to let compiler do that implicitly. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
* typewrappers: Rework libvirt_uintWrap()Michal Privoznik2023-02-131-1/+1
| | | | | | | Python C API offers PyLong_FromUnsignedLong() which allows us to drop typecast. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
* typewrappers: Rework libvirt_uintUnwrap()Michal Privoznik2023-02-131-4/+4
| | | | | | | | Python C API offers PyLong_AsUnsignedLong() which already raises an exception on negative values. Rewrite our libvirt_uintUnwrap() to use that and drop check for negative values. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
* Replace uint with unsigned intBastian Germann2022-09-091-1/+1
| | | | | | Mingw-w64 target does not support uint definition. Signed-off-by: Bastian Germann <bage@linutronix.de>
* Drop support for python 2Daniel P. Berrangé2019-12-041-119/+14
| | | | | | | | | python2 will be end of life by the time of the next libvirt release. All our supported build targets, including CentOS7, have a python3 build available. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* Add virDomainCheckpoint APIsEric Blake2019-07-291-0/+13
| | | | | | | | | Copies heavily from existing virDomainSnapshot handling, regarding what special cases the generator has to be taught and what overrides need to be written. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* Add support for virNetworkPort object & APIsDaniel P. Berrangé2019-06-201-0/+13
| | | | | | | | | Define the various rules in the generator to wire up methods into the virNetwork class and create the new virNetworkPort class. Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* Add support for nwfilter binding objects / apisDaniel P. Berrangé2018-06-281-0/+13
| | | | Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* typewrappers: Fix libvirt_charPtrUnwrap to set an exception if it failsPavel Hrdina2018-06-121-1/+4
| | | | | | | If the function fails it should always set an exception. Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
* Fix comparisons between signed & unsigned integersDaniel P. Berrange2017-09-261-1/+1
| | | | | | | | | When python3 builds C modules, it adds the -Wsign-compare flag to GCC. This creates lots of warnings where we compare a 'size_t' value against an 'int' value due to signed/unsigned difference. Change all the size_t types to ssize_t to address this. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Use VIR_PY_NONE instead of increment and Py_NonePavel Hrdina2015-10-051-36/+18
| | | | | | | To insert Py_None into some other python object like dict or tuple, you need to increase reference to the Py_None. We have a macro to do that. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
* fix indentationPavel Hrdina2015-10-051-4/+4
| | | | Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
* cleanup functions definitionPavel Hrdina2015-10-051-10/+22
| | | | | | Follow the libvirt hacking guide and make the code consistent. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
* Fix libvirt_longlongWrap returning a very large valueZhou Yimin2014-08-111-1/+1
| | | | | | | | | | | | | | | | If hypervisor is not Xen, the errs in struct _virDomainBlockStats will be -1. But in KVM when we call domain.blockStats(), errs is 18446744073709551615. To fix that, this patch has two changes: 1. Replace use of the PyLong_FromUnsignedLongLong with PyLong_FromLongLong in function libvirt_longlongWrap 2. If the paramemter of libvirt_longlongWrap is unsigned long long, use libvirt_ulonglongWrap instead because of above change. After this patch, errs is -1 which is consistent with virDomainBlockStats api. Signed-off-by: Zhou Yimin <zhouyimin@huawei.com> Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
* Rewrite libvirt_charPtrUnwrap to work with Python 3.0->3.2Daniel P. Berrange2013-12-121-8/+11
| | | | | | | | The PyUnicode_AsUTF8 method doesn't exist prior to Python 3.3. It is also somewhat inefficient, so rewrite it to use an intermediate PyBytes object. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* override: Switch virStreamSend wrapper to use libvirt_charPtrSizeUnwrapDaniel P. Berrange2013-12-111-0/+27
| | | | | | | | Instead of using a 'z#i' format string to receive byte array, use 'O' and then libvirt_charPtrSizeUnwrap. This lets us hide the Python 3 vs 2 differences in typewrappers.c Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* typewrappers: PyInt/PyLong merge for Python3Daniel P. Berrange2013-12-111-5/+28
| | | | | | | In Python3 the PyInt / PyLong types have merged into a single PyLong type. Conditionalize the use of PyInt to Python 2 only Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* typewrappers: Replace use of PyString classDaniel P. Berrange2013-12-111-0/+19
| | | | | | | | Replace use of PyString with either PyBytes or PyUnicode. The former is used for buffers with explicit sizes, which are used by APIs processing raw bytes. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* override: Replace Py{Int,Long}_FromLong with helpersDaniel P. Berrange2013-12-111-0/+8
| | | | | | | | | Replace use of the PyInt_FromLong and PyLong_FromLongLong with libvirt_{int,uint,longlong,ulonglong}Wrap helpers. This isolates the need for Python3 specific code in one place. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* override: Replace PyString_AsString with libvirt_charPtrUnwrapDaniel P. Berrange2013-12-111-0/+18
| | | | | | | | | | | Replace calls to PyString_AsString with the helper method libvirt_charPtrUnwrap. This isolates the code that will change in Python3. In making this change, all callers now have responsibility for free'ing the string. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Don't free passed in args in libvirt_charPtrWrap / libvirt_charPtrSizeWrapDaniel P. Berrange2013-12-111-2/+0
| | | | | | | Functions should not make assumptions about the memory management callers use for parameters Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Add missing binding of security model/label APIsv1.2.0-rc2Daniel P. Berrange2013-11-271-0/+9
| | | | | | | | The virNodeGetSecurityModel, virDomainGetSecurityLabel and virDomainGetSecurityLabelList methods were disabled in the python binding for inexplicable reasons. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Import VIR_ALLOC / VIR_ALLOC_N / VIR_REALLOC_N functionsDaniel P. Berrange2013-11-221-0/+1
| | | | | | | Import the libvirt memory allocation functions, stripping the OOM testing and error reporting pieces. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Update header file includesDaniel P. Berrange2013-11-221-4/+0
| | | | | | | | We're no longer using automake, so <config.h> files are not required. Also remove of all libvirt internal util header files. Reference generated header files in build/ subdir. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Rename memory.{c,h} to viralloc.{c,h}Daniel P. Berrange2012-12-211-1/+1
|
* python: keep consistent handling of Python integer conversionGuannan Ren2012-10-081-2/+6
| | | | | | | | | | | | | | | | | | | libvirt_ulonglongUnwrap requires the integer type of python obj. But libvirt_longlongUnwrap still could handle python obj of Pyfloat_type which causes the float value to be rounded up to an integer. For example >>> dom.setSchedulerParameters({'vcpu_quota': 0.88}) 0 libvirt_longlongUnwrap treats 0.88 as a valid value 0 However >>> dom.setSchedulerParameters({'cpu_shares': 1000.22}) libvirt_ulonglongUnwrap will throw out an error "TypeError: an integer is required" The patch make this consistent.
* python: return error if PyObject obj is NULL for unwrapper helper functionsGuannan Ren2012-09-281-2/+41
| | | | | | | | | | The result is indeterminate for NULL argument to python functions as follows. It's better to return negative value in these situations. PyObject_IsTrue will segfault if the argument is NULL PyFloat_AsDouble(NULL) is -1.000000 PyLong_AsUnsignedLongLong(NULL) is 0.000000
* Fix compilation error on 32bitStefan Berger2012-04-101-0/+4
| | | | | | | | | | | Below code failed to compile on a 32 bit machine with error typewrappers.c: In function 'libvirt_intUnwrap': typewrappers.c:135:5: error: logical 'and' of mutually exclusive tests is always false [-Werror=logical-op] cc1: all warnings being treated as errors The patch fixes this error.
* python: improve conversion validationv0.9.11showEric Blake2012-03-311-7/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* python: Add new helper functions for python to C integral conversionGuannan Ren2012-03-281-0/+132
| | | | | | | | | | | int libvirt_intUnwrap(PyObject *obj, int *val); int libvirt_uintUnwrap(PyObject *obj, unsigned int *val); int libvirt_longUnwrap(PyObject *obj, long *val); int libvirt_ulongUnwrap(PyObject *obj, unsigned long *val); int libvirt_longlongUnwrap(PyObject *obj, long long *val); int libvirt_ulonglongUnwrap(PyObject *obj, unsigned long long *val); int libvirt_doubleUnwrap(PyObject *obj, double *val); int libvirt_boolUnwrap(PyObject *obj, bool *val);
* Cleanup for a return statement in source filesMartin Kletzander2012-03-261-38/+38
| | | | | | | | | | | | | | | | | | | | | | Return statements with parameter enclosed in parentheses were modified and parentheses were removed. The whole change was scripted, here is how: List of files was obtained using this command: git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' | \ grep -e '\.[ch]$' -e '\.py$' Found files were modified with this command: sed -i -e \ 's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \ -e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_' Then checked for nonsense. The whole command looks like this: git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' | \ grep -e '\.[ch]$' -e '\.py$' | xargs sed -i -e \ 's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \ -e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_'
* python: use libvirt_util to avoid raw freeEric Blake2012-02-031-3/+5
| | | | | | | | | | | | | | | | | | | | | | | This patch starts the process of elevating the python binding code to be on the same level as the rest of libvirt when it comes to requiring good coding styles. Statically linking against the libvirt_util library makes it much easier to write good code, rather than having to open-code and reinvent things locally. Done by global search and replace of s/free(/VIR_FREE(/, followed by hand-inspection of remaining malloc and redundant memset. * cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation): Remove python from exemption. * python/Makefile.am (INCLUDES): Add gnulib and src/util. Drop $(top_builddir)/$(subdir), as automake already guarantees that. (mylibs, myqemulibs): Pull in libvirt_util and gnulib. (libvirtmod_la_CFLAGS): Catch compiler warnings if configured to use -Werror. * python/typewrappers.c (libvirt_charPtrSizeWrap) (libvirt_charPtrWrap): Convert free to VIR_FREE. * python/generator.py (print_function_wrapper): Likewise. * python/libvirt-override.c: Likewise.
* python: drop redundant functionEric Blake2012-02-031-13/+0
| | | | | | | | | I noticed some redundant code while preparing my next patch. * python/generator.py (py_types): Fix 'const char *' mapping. * python/typewrappers.h (libvirt_charPtrConstWrap): Drop. * python/typewrappers.c (libvirt_charPtrConstWrap): Delete, since it is identical to libvirt_constcharPtrWrap.
* python: Implement virStreamSend/RecvCole Robinson2011-06-211-0/+14
| | | | | | | The return values for the python version are different that the C version of virStreamSend: on success we return a string, an error raises an exception, and if the stream would block we return int(-2). We need to do this since strings aren't passed by reference in python.
* python: Use PyCapsule API if availablev0.8.8Cole Robinson2011-01-101-39/+50
| | | | | | | | | | On Fedore 14, virt-manager spews a bunch of warnings to the console: /usr/lib64/python2.7/site-packages/libvirt.py:1781: PendingDeprecationWarning: The CObject type is marked Pending Deprecation in Python 2.7. Please use capsule objects instead. Have libvirt use the capsule API if available. I've verified this compiles fine on older python (2.6 in RHEL6 which doesn't have capsules), and virt-manager seems to function fine.
* nwfilter: python bindings for nwfilterStefan Berger2010-04-291-0/+13
| | | | | I have primarily followed the pattern of the 'secret' driver to provide support for the missing python bindings for the network filter API.
* Snapshot API framework.Chris Lalancette2010-04-051-0/+15
| | | | Signed-off-by: Chris Lalancette <clalance@redhat.com>
* Introduce public API for domain async job handlingv0.7.7Daniel P. Berrange2010-03-021-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce a new public API that provides a way to get progress info on currently running jobs on a virDomainpPtr. APIs that are initially within scope of this idea are virDomainMigrate virDomainMigrateToURI virDomainSave virDomainRestore virDomainCoreDump These all take a potentially long time and benefit from monitoring. The virDomainJobInfo struct allows for various pieces of information to be reported - Percentage completion - Time - Overall data - Guest memory data - Guest disk/file data * include/libvirt/libvirt.h.in: Add virDomainGetJobInfo * python/generator.py, python/libvirt-override-api.xml, python/libvirt-override.c: Override for virDomainGetJobInfo API * python/typewrappers.c, python/typewrappers.h: Introduce wrapper for unsigned long long type
* Add public API definition for data stream handlingDaniel P. Berrange2009-09-291-0/+13
| | | | | | | | | | | | | | | | | | | * include/libvirt/libvirt.h.in: Public API contract for virStreamPtr object * src/libvirt_public.syms: Export data stream APIs * src/libvirt_private.syms: Export internal helper APIs * src/libvirt.c: Data stream API driver dispatch * src/datatypes.h, src/datatypes.c: Internal helpers for virStreamPtr object * src/driver.h: Define internal driver API for streams * .x-sc_avoid_write: Ignore src/libvirt.c because it trips up on comments including write() * python/Makefile.am: Add libvirt-override-virStream.py * python/generator.py: Add rules for virStreamPtr class * python/typewrappers.h, python/typewrappers.c: Wrapper for virStreamPtr * docs/libvirt-api.xml, docs/libvirt-refs.xml: Regenerate with new APIs
* Re-arrange python generator to make it clear what's auto-generatedDaniel P. Berrange2009-09-211-0/+269
* README: New file describing what each file is used for * livvirt-override.c, libvirt-override.py, libvirt-override-api.xml, libvirt-override-virConnect.py: Manually written code overriding the generator * typewrappers.c, typewrappers.h: Data type wrappers * generator.py: Automatically pre-prend contents of libvirt-override.py to generated libvirt.py. Output into libvirt.py directly instead of libvirtclass.py. Don't generate libvirtclass.txt at all. Write C files into libvirt.c/.h directly * Makefile.am: Remove rule for creating libvirt.py from libvirt-override.py and libvirtclass.py, since generator.py does it directly