qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC 15/15] [test only] Use 'Error *err[static 1]' inst


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [RFC 15/15] [test only] Use 'Error *err[static 1]' instead of 'Error **errp' to catch NULL errp arguments
Date: Sat, 17 Jun 2017 16:33:49 -0300
User-agent: Mutt/1.8.0 (2017-02-23)

On Thu, Jun 15, 2017 at 01:14:15PM +0100, Dr. David Alan Gilbert wrote:
> * Eduardo Habkost (address@hidden) wrote:
> > This is being included in the RFC just to help validating the series,
> > and ensure we don't use NULL errp anywhere.
> > 
> > I don't propose we actually change all code to use the
> > 'Error *errp[static 1]' syntax because it confuses Cocinelle.
> > 
> > I am considering including a assert(errp) line in the ERR_IS_SET()
> > macro, so we can catch NULL errp at runtime in case somebody forgets
> > about it.
> > 
> > Generated by the following Coccinelle patch:
> > 
> >   @@
> >   typedef Error;
> >   type T;
> >   identifier FN !~ "os_mem_prealloc|qemu_fork";
> >   identifier errp;
> >   @@
> >    T FN(...,
> >   -     Error **errp
> >   +     Error *errp[STATIC_1]
> >        );
> > 
> >   @@
> >   typedef Error;
> >   type T;
> >   identifier FN !~ "os_mem_prealloc|qemu_fork";
> >   identifier errp;
> >   @@
> >    T FN(...,
> >   -     Error **errp
> >   +     Error *errp[STATIC_1]
> >        ) { ... }
> > 
> > Followed by the following sed command:
> > 
> >   $ sed -i -e 's/\[STATIC_1\]/[static 1]/g' $(g grep -w -l STATIC_1)
> > 
> > Signed-off-by: Eduardo Habkost <address@hidden>
> > ---
> 
> <snip>
> 
> >  void visit_start_struct(Visitor *v, const char *name, void **obj,
> > -                        size_t size, Error **errp);
> > +                        size_t size, Error *errp[static 1]);
> >  
> 
> Is it possible to typedef that to something that hides the magic syntax?
> Then we could get that down to QError errp   or something like that?

Unfortunately it is not possible to hide it in a typedef: the
"static" keyword inside the square brackets is a feature of
function parameter declarations only.  Using it on a typedef
results in:

a.c:3:16: error: static or type qualifiers in non-parameter array declarator
 typedef Error *ErrorPtr[static 1];

We could use a preprocessor macro, but I suspect this would also
confuse Coccinelle.

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]