[ovs-dev] [PATCH v4 01/14] ofpbuf: New function ofpbuf_const_initializer().

Ben Pfaff blp at ovn.org
Fri Feb 19 23:01:09 UTC 2016


On Fri, Feb 19, 2016 at 01:48:06PM -0800, Jarno Rajahalme wrote:
> With a note and a question below:
> 
> Acked-by: Jarno Rajahalme <jarno at ovn.org>

Thanks for the review.

> I’m curious if there is a specific reason to define
> ofpbuf_const_initializer() as an inline function, and keep the
> OFPBUF_STUB_INITIALIZER() as a macro?

Yes.

OFPBUF_STUB_INITIALIZER has to be a macro so that it can usefully use
sizeof on its argument.  (It could require the size to be provided, but
then it would be more of a hassle to use.)

ofpbuf_const_initializer() should be a function to avoid expanding its
'data' argument twice.  Unlike OFPBUF_STUB_INITIALIZER, some of its
callers actually do call it with arguments that have side effects.

> > +unsigned int init_ofpbuf(const void *p, size_t size);
> > +unsigned int
> > +init_ofpbuf(const void *p, size_t size)
> > +{
> > +    struct ofpbuf b = ofpbuf_const_initializer(p, size);
> > +    ofpbuf_pull(&b, 8);
> > +    return b.size;
> > +}
> > +
> 
> This seems unused.

Oops.  That was an experiment that I thought I deleted.  I deleted it
now.



More information about the dev mailing list