[libvirt] [PATCH libvirt-python 09/14] Import VIR_ALLOC / VIR_ALLOC_N / VIR_REALLOC_N functions
Eric Blake
eblake at redhat.com
Wed Nov 13 17:20:40 UTC 2013
On 11/12/2013 11:21 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
>
> Import the libvirt memory allocation functions, stripping the OOM
> testing and error reporting pieces.
>
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>
> - if (VIR_ALLOC_N_QUIET(ret, size) < 0) {
> + if (VIR_ALLOC_N(ret, size) < 0) {
> PyErr_NoMemory();
> return NULL;
> }
As an independent cleanup, we could simplify constructs like this...
> @@ -506,7 +506,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED,
> if (!nparams)
> return PyDict_New();
>
> - if (VIR_ALLOC_N_QUIET(params, nparams) < 0)
> + if (VIR_ALLOC_N(params, nparams) < 0)
> return PyErr_NoMemory();
...into this shorter equivalent.
> +# if !STATIC_ANALYSIS
> +/* The ternary ensures that ptr is a pointer and not an integer type,
> + * while evaluating ptr only once. This gives us extra compiler
> + * safety when compiling under gcc. For now, we intentionally cast
> + * away const, since a number of callers safely pass const char *.
Hmm - I wonder if the python bindings are clean enough that we need not
cast away const? But that may be better as a separate cleanup patch.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131113/289790bb/attachment-0001.sig>
More information about the libvir-list
mailing list