[libvirt] [PATCH 7/9] virobject: Introduce VIR_CLASS_NEW() macro

Erik Skultety eskultet at redhat.com
Mon Apr 16 10:04:53 UTC 2018


On Fri, Apr 13, 2018 at 04:47:14PM +0200, Michal Privoznik wrote:
> So far we are repeating the following lines over and over:
>
>   virClassNew(virClassForObject(),
>               "virSomeObject",
>               sizeof(virSomeObject),
>               virSomeObjectDispose);
>
> While this works, it is impossible to do some checking. Firstly,
> the class name (the 2nd argument) doesn't match the name in the
> code in all cases (the 3rd argument). Secondly, the current style
> is needlessly verbose. This commit turns example into following:
>
>   VIR_CLASS_NEW(virClassForObject(),
>                 virSomeObject);
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>

...

> diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
> index cc2402febb..8acccf8940 100644
> --- a/src/interface/interface_backend_netcf.c
> +++ b/src/interface/interface_backend_netcf.c
> @@ -55,10 +55,8 @@ static void virNetcfDriverStateDispose(void *obj);
>  static int
>  virNetcfDriverStateOnceInit(void)
>  {
> -    if (!(virNetcfDriverStateClass = virClassNew(virClassForObjectLockable(),
> -                                       "virNetcfDriverState",
> -                                       sizeof(virNetcfDriverState),
> -                                       virNetcfDriverStateDispose)))
> +    if (!(virNetcfDriverStateClass = VIR_CLASS_NEW(virClassForObjectLockable(),
> +                                                   virNetcfDriverStat)))

There's a typo in the 2nd parameter which makes the patch fail the compilation.

Erik




More information about the libvir-list mailing list