]> xenbits.xensource.com Git - libvirt.git/commit
internal: Introduce VIR_RETURN_PTR
authorPeter Krempa <pkrempa@redhat.com>
Fri, 5 Apr 2019 15:29:40 +0000 (17:29 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 10 Apr 2019 14:34:57 +0000 (16:34 +0200)
commit267f1e6da53076c482f12791162a7364cf18d319
treeb723fd7d51f14c3f0d2613e7ba5dd9bac8c78ead
parentc9cec6a8b03a8c85c51d97649ee4727b9e0e0d72
internal: Introduce VIR_RETURN_PTR

With the introduction of more and more internal data types which support
VIR_AUTOPTR it's becoming common to see the following pattern:

  VIR_AUTOPTR(virSomething) some = NULL
  virSomethingPtr ret = NULL;

  ... (ret is not touched ) ...

  VIR_STEAL_PTR(ret, some);
  return ret;

This patch introduces a macro named VIR_RETURN_PTR which returns the
pointer directly without the need for an explicitly defined return
variable and use of VIR_STEAL_PTR. Internally obviously a temporary
pointer is created to allow setting the original pointer to NULL so that
the VIR_AUTOPTR function does not free the memory which we want to
actually return.

The name of the temporary variable is deliberately long and complex to
minimize the possibility of collision.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/internal.h