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

[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:
February 1, 2008 13:40
Subject:
[PATCH] Fix bit-fields for VC [was RE: [perl #50386] GIMME_V broken with 5.10.0/GCC and XS?]
Message ID:
02ee01c8651b$17ef72f0$47ce58d0$@com
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.

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