Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Jul 2004 18:59:13 +0200 (CEST)
From:      Harti Brandt <harti@freebsd.org>
To:        Anil Madhavapeddy <anil@recoil.org>
Cc:        Roman Kurakin <rik@cronyx.ru>
Subject:   Re: Packing netgraph structs
Message-ID:  <20040701185404.G81202@beagle.kn.op.dlr.de>
In-Reply-To: <931572E3-CB5E-11D8-99F8-000A95DA50A6@recoil.org>
References:  <122AE07F-CB5B-11D8-99F8-000A95DA50A6@recoil.org> <40E40839.20500@cronyx.ru> <931572E3-CB5E-11D8-99F8-000A95DA50A6@recoil.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 1 Jul 2004, Anil Madhavapeddy wrote:

AM>On 1 Jul 2004, at 13:48, Roman Kurakin wrote:
AM>> 
AM>> If this is a problem why can't you make some wrapper that will pack/unpack
AM>> written on C,
AM>> which will be a lib for you?
AM>
AM>Because I want to minimise the size of the foreign bindings - this would
AM>require C code for every single Netgraph struct.  If they were packed, I
AM>could just do it all in OCaml.
AM>
AM>Isn't this a problem for other language bindings as well, or is everyone
AM>doing Netgraph userland hacking in C at the moment?

Packing structs is a evil thing to do because this requires non-standard 
compiler support. Traditionally this was done with carefully designing the 
struct and inserting explicit spare fields where the compiler would pad.
Unfortunately with decreasing $/bit for memory this knowledge has been 
lost and in any case it helps only for a concrete compiler/platform 
combination. So why can't you just guess the padding and handle it 
explicitely? Have a look at ng_parse.c.

harti



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040701185404.G81202>