develooper Front page | perl.perl5.porters | Postings from May 2008

RE: [PATCH] Fix bit-fields for VC [was RE: [perl #50386] GIMME_V broken with 5.10.0/GCC and XS?]

Thread Previous | Thread Next
From:
Jan Dubois
Date:
May 27, 2008 14:41
Subject:
RE: [PATCH] Fix bit-fields for VC [was RE: [perl #50386] GIMME_V broken with 5.10.0/GCC and XS?]
Message ID:
060d01c8c042$64725c50$2d5714f0$@com
On Tue, 27 May 2008, Dave Mitchell wrote:
> On Fri, Feb 01, 2008 at 01:40:41PM -0800, Jan Dubois wrote:
> > On Wed, 30 Jan 2008, Jan Dubois wrote:
> > > This is not really a core Perl bug; the problem is that VC++ and GCC
> > > are incompatible as far as bit-fields are concerned.  In Perl 5.10
> > > the BASEOP structure contains bitfields:
> > >
> > >     unsigned	op_type:9;		\
> > >     unsigned	op_opt:1;		\
> > >     unsigned	op_latefree:1;		\
> > >     unsigned	op_latefreed:1;		\
> > >     unsigned	op_attached:1;		\
> > >     unsigned	op_spare:3;		\
> > >
> > > In VC++ the combined size of the fields above is 4 bytes, whereas
> > > in GCC it is only 2.  This also pushes the size of the complete
> > > structure from 20 to 24 bytes for VC++.
> >
> > [...]
> >
> > > VC++ uses the base type (unsigned int, in this case) to determine
> > > the alignment requirements and total size of the combined bit-field.
> > > You can use the non-standard extension of using smaller integer sizes
> > > to force the fields into a smaller size and different alignment.
> > > In this case using "unsigned short" for the type of the bit-fields
> > > should work.
> > >
> > > I guess for Perl 5.12 we need a way to let us use the smaller base
> > > size for VC++ to keep the size of the OP structure down.  I'll create
> > > a patch for it eventually, when I get a bit more time.  I also need
> > > to check if there are other places where Perl is now using bit fields
> > > in its structure definitions.
> >
> > I've attached a patch that defined PERL_BITFIELD8, PERL_BITFIELD16
> > and PERL_BITFIELD32 symbols to be used to specify bitfields whose
> > base size and alignment requirements are 1, 2 or 4 bytes respectively.
> > The "PERL_" prefix is a bit awkward, but these are names that must
> > be defined even when PERL_CORE is not.
> >
> > These symbols are then being redefined for VC (and MinGW GCC) to use the
> > corresponding smaller sizes as the base types.
> >
> > I've also added -mms-bitfields to the default options for MinGW in
> > makefile.mk.  That way building additional XS modules that interface
> > to VC compatible libraries using bit-fields in their external APIs
> > should be easier.
> 
> 
> Jan, is this patch safe for 5.10.1 - specifically is it binary compatible?

No, it is not. :( For 5.10 we'll have to live with the slightly bloated
OP structures.

Cheers,
-Jan



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About