1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2024-10-26 16:25:10 +03:00
Commit Graph

24 Commits

Author SHA1 Message Date
Michal Privoznik
4b51aedfc7 Fix sign compare offenders
In a few places we compare signed and unsigned integers. In
majority of cases it's because the iteration variable is declared
as ssize_t but then in the for() loop it's compared against an
unsigned int. But there is one case where the opposite happens
(libvirt_virDomainSendKey()), or where an UINT_MAX (which is
inherently unsigned) is compared against signed long.

Also, use this opportunity to decrease scope of 'j' variable
inside of libvirt_virDomainInterfaceAddresses().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-13 15:42:58 +01:00
Michal Privoznik
050ed3e629 Implement virDomainQemuMonitorCommandWithFiles() override
With libvirt-8.2.0 there's a new API:
virDomainQemuMonitorCommandWithFiles(). Since the API has both
input and output arguments we need to provide an alternative
implementation. Moreover, since FD passing works only on
UNIX-like systems we can query the returned FDs for their flags
and construct mode for python File object.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-03-10 09:51:33 +01:00
Philipp Hahn
a14161f01c debug: Fix bit-rot in debug output
Let the compiler optimize out the printf() call instead of doing it with the
pre-processor as the later does not catch format string errors or the following
case, where NULLSTR() is used but not defined:

> libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
> libvirt-qemu-override.c:271:34: warning: implicit declaration of function ‘NULLSTR’; did you mean ‘NULL’? [-Wimplicit-function-declaration]
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ^~~~~~~
> libvirt-qemu-override.c:39:28: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                            ^~~~~~~~~~~
> libvirt-qemu-override.c:270:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat=]
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ~~~~~~~~~~~~~~
>       |                                  |
>       |                                  int
> libvirt-qemu-override.c:39:23: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                       ^~~
> libvirt-qemu-override.c:270:73: note: format string is defined here
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |                                                                        ~^
>       |                                                                         |
>       |                                                                         char *
>       |                                                                        %d

Copy the definition of NULLSTR from libvirt/src/internal.h to typewrappers.h

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Daniel P. Berrangé
b22e4f2441 Drop support for python 2
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>
2019-12-04 12:14:51 +00:00
Michal Privoznik
2236fb90fa PyArg_ParseTuple: Provide correct function names
At the end of the format string we put :virFunctionName where ':'
says "this is the end of argument list", and virFunctionName is
the prefix for error messages then.  However, in some cases we
have had wrong names there. Some of them are actually quite
funny: xmlRegisterErrorHandler.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-08-24 17:05:18 +02:00
Pavel Hrdina
61411050cb Return NULL if python exception is set
There is a rule, python API fails, it also in those cases sets an
exception.  We should follow those rules and in those cases return NULL.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-10-05 08:35:52 +02:00
Pavel Hrdina
7178a63e23 fix indentation
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-10-05 08:35:37 +02:00
Pavel Hrdina
c982604ef8 indent labels by one space
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-10-05 08:35:30 +02:00
Pavel Hrdina
862a94aebf cleanup functions definition
Follow the libvirt hacking guide and make the code consistent.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-10-05 08:35:15 +02:00
Pavel Hrdina
a7d71b769d Move utils and shared code into libvirt-utils
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-10-05 08:35:05 +02:00
Peter Krempa
7aaa02b47a Fix rest of unsigned integer handling
As in the previous patch, fix all places where 'flags' is converted as a
signed argument to unsigned including the python code generator.
2014-10-22 09:43:47 +02:00
Mo Yuxiang
2175f4f3da build: Fix build warning on libvirt-python
On compiling libvirt-python, we get such a warning:

libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
libvirt-qemu-override.c:304: warning: suggest explicit braces to avoid ambiguous ‘else’

Py_DECREF is a macro using if/else on older Python releases.
The solution is to add braces.
Python 2.7 and newer has the macro wrapped in a do { } while(0) block.

Signed-off-by: Mo Yuxiang <Moyuxiang@huawei.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2014-08-19 12:43:28 +02:00
Eric Blake
e3da8f178e qemu: support arbitrary monitor events
Wrap the new virConnectDomainQemuMonitorEventRegister function
added in libvirt 1.2.3.  This patch copies heavily from
network events (commit 6ea5be0) and from event loop callbacks
in libvirt-override.c, since in the libvirt_qemu module, we
must expose top-level functions rather than class members.

* generator.py (qemu_skip_function): Don't generate event code.
(qemuBuildWrappers): Delay manual portion until after imports.
* libvirt-qemu-override.py (qemuMonitorEventRegister)
(qemuMonitorEventDeregister): New file.
* libvirt-qemu-override.c
(libvirt_qemu_virConnectDomainQemuMonitorEventFreeFunc)
(libvirt_qemu_virConnectDomainQemuMonitorEventCallback)
(libvirt_qemu_virConnectDomainQemuMonitorEventRegister)
(libvirt_qemu_virConnectDomainQemuMonitorEventDeregister)
(libvirt_qemu_lookupPythonFunc, getLibvirtQemuDictObject)
(getLibvirtQemuModuleObject): New functions.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-25 09:12:22 -06:00
Daniel P. Berrange
e5161dec9e override: Replace PyString_FromString with libvirt_constcharPtrWrap
Make use of libvirt_constcharPtrWrap in all override code,
to match generated code. This will isolate Python3 specific
changes in one place.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:54 +00:00
Daniel P. Berrange
1b4dc72140 override: Fix native module registration to work with Python3
The way native modules are registered has completely
changed, so the code must be #ifdef'd for Python2 & 3

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:54 +00:00
Daniel P. Berrange
a7651a3284 virDomainQemuAgentCommand appeared in 0.10.0
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:06 +00:00
Daniel P. Berrange
4f1ea70fd1 Import VIR_ALLOC / VIR_ALLOC_N / VIR_REALLOC_N functions
Import the libvirt memory allocation functions, stripping the OOM
testing and error reporting pieces.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:06 +00:00
Daniel P. Berrange
3bfb20266b Update header file includes
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>
2013-11-22 15:58:05 +00:00
Ján Tomko
ed0a51292d Fix leaks in python bindings
https://bugzilla.redhat.com/show_bug.cgi?id=1003828
2013-09-03 13:19:17 +02:00
Osier Yang
919889aa59 syntax-check: Only allows to include public headers in external tools
With this patch, include public headers in "" form is only allowed
for "internal.h". And only the external tools (examples|tools|python
|include/libvirt) can include the public headers in <> form.
2013-04-18 11:31:19 +08:00
MATSUDA Daiki
55eb5dac68 agent: add python module support
Add virDomainQemuAgentCommand() support function to python module.

Signed-off-by: MATSUDA Daiki <matsudadik@intellilink.co.jp>
2012-08-23 19:07:53 +08:00
Martin Kletzander
a8e031a749 Cleanup for a return statement in source files
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_'
2012-03-26 14:45:22 -06:00
Eric Blake
2b9c2fecd1 python: drop unused function
Gcc warned about an unused static function.

* python/libvirt-qemu-override.c (py_str): Delete.
2012-02-07 17:14:11 -07:00
Osier Yang
6d0e34c14f qemu_api: Add override XML and C files for QEMU APIs
There is only one function (virDomainQemuMonitorCommand) need to
be hand-craft.
2011-09-14 11:38:51 +08:00