tech-net archive

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

Re: patch make struct protosw pr_input non-variadic



   Date: Fri, 13 May 2016 23:14:13 +0000 (UTC)
   From: christos%astron.com@localhost (Christos Zoulas)

   In article <20160513195611.GA8625@pris>,
   Tyler Retzlaff  <rtr%netbsd.org@localhost> wrote:
   >This patch:
   >[...]
   >* converts domain::dom_protosw to an array of pointers

   Why? What's the point of the extra indirection? You could just stick
   and & in front of the array element assignment.

Currently every struct <protospecific>protosw has to have exactly the
same size and layout so that the type-punning works -- and nothing
checks this because it is all done with explicit casts that suppress
warnings.  If we ever changed, e.g., struct ip6protosw to add another
method, then this would break, without help from the compiler to
detect the breakage.

We already abuse this type-punning to give IPv4 pr_input methods a
different true prototype from IPv6 pr_input methods, but again there's
no static checking of this, so it is easy to make a mistake.  The next
step after this change will actually give pr_input real prototypes by
moving it out of struct protosw and into struct ipprotosw, struct
ip6protosw, &c.

Changing dom_protosw to be an array of pointers to struct protosw
instead of an array of struct protosw grants us flexibility in using
struct <protospecific>protosw structure and still get real type
checking for everything -- we simply fill dom_protosw with pointers to
an embedded struct protosw inside struct <protospecific>protosw.


Home | Main Index | Thread Index | Old Index