[PATCH v2 01/40] util: virresctrl: convert classes to GObject

Jonathon Jongsma jjongsma at redhat.com
Tue Apr 21 16:21:36 UTC 2020


On Tue, 2020-04-21 at 15:48 +0200, Rafael Fonseca wrote:
> @@ -793,21 +830,13 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
>  virResctrlInfoPtr
>  virResctrlInfoNew(void)
>  {
> -    virResctrlInfoPtr ret = NULL;
> -
> -    if (virResctrlInitialize() < 0)
> -        return NULL;
> -
> -    ret = virObjectNew(virResctrlInfoClass);
> -    if (!ret)
> -        return NULL;
> +    g_autoptr(virResctrlInfo) ret =
> VIR_RESCTRL_INFO(g_object_new(VIR_TYPE_RESCTRL_INFO, NULL));
>  
>      if (virResctrlGetInfo(ret) < 0) {
> -        virObjectUnref(ret);
>          return NULL;
>      }
>  
> -    return ret;
> +    return g_steal_pointer(&ret);
>  }


(FYI: Glib provides a base class GInitiable (and an async variant) for
an object that requires initialization immediately after allocation and
returns NULL if said initialization fails. Not sure that it would gain
us anything here, but just thought I'd mention it.)

Jonathon




More information about the libvir-list mailing list