From: Nicholas Clark Date: Sun, 1 May 2011 20:06:51 +0000 (+0100) Subject: Set the pointer alignment (in bits) via a C macro generated by the Makefile.PL X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5f03b77e418d07ecc0a99453ba27df9be95ee32d;p=p5sagit%2FDevel-Size.git Set the pointer alignment (in bits) via a C macro generated by the Makefile.PL The previous approach of using sizeof(void *) is flat out wrong on a 64 bit system. The right answer is 3. It gives 4. Which isn't a problem once the pointer rotation code in check_new() isn't buggy, but isn't as efficient as desired. --- diff --git a/Makefile.PL b/Makefile.PL index 2066fe8..d1b6a31 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,9 +1,15 @@ use 5.008; use ExtUtils::MakeMaker; +use Config; +(unpack "B*", pack "N", $Config{ptrsize}) =~ /^0+1(0+)$/ + or die "Your pointer size of $Config{ptrsize} is very confusing"; +my $ptr_bits = length $1; + WriteMakefile( NAME => 'Devel::Size', VERSION_FROM => 'lib/Devel/Size.pm', + DEFINE => "-DALIGN_BITS=$ptr_bits", ($ExtUtils::MakeMaker::VERSION >= 6.47 ? (MIN_PERL_VERSION => '5.008') : ()), ($ExtUtils::MakeMaker::VERSION >= 6.31 ? (LICENSE => 'perl') : ()), ); diff --git a/Size.xs b/Size.xs index c276e44..1911d2e 100644 --- a/Size.xs +++ b/Size.xs @@ -46,7 +46,6 @@ without excessive memory needs. The assumption is that your CPU cache works :-) (And that we're not going to bust it) */ -#define ALIGN_BITS ( sizeof(void*) >> 1 ) #define BYTE_BITS 3 #define LEAF_BITS (16 - BYTE_BITS) #define LEAF_MASK 0x1FFF