python: Simplify calling into plugin
commit5ae45c00d1b0cc234a75b099963576d61edc6731
authorEric Blake <eblake@redhat.com>
Fri, 6 Apr 2018 20:41:17 +0000 (6 15:41 -0500)
committerEric Blake <eblake@redhat.com>
Tue, 10 Apr 2018 19:19:21 +0000 (10 14:19 -0500)
treed3a1ecbde499af6c7e956470a37fccb96e9e0cf1
parenta4a45be556f9b2d98090b06c9321251c78014795
python: Simplify calling into plugin

PyObject_CallObject() is powerful, but awkward - we have to wrap
all arguments into a temporary tuple before using it.  Furthermore,
we are failing to check for (unlikely) failure in building the
various python wrappers, which could lead to a NULL dereference
instead of a clean error message in low-memory situations.

Let python do more of the work by using PyObject_CallFunction()
anywhere that all arguments can be described by a format string,
instead of creating one-shot arguments ourselves.  In fact, for
our py_config(), this makes it easier to not worry about the
difference between python 2 String vs. python 3 Unicode.

Similarly, PyObject_CallFunctionObjArgs() is nicer when we
already have PyObjects for all parameters, including in py_open(),
where we can't use a format string for converting a C int into
Py_True or Py_False, but can easily avoid the tuple wrapper.

py_zero() is not converted, as it will be changed differently
to make 'may_trim' an optional callback parameter.

Signed-off-by: Eric Blake <eblake@redhat.com>
plugins/python/python.c