From: Nicholas Clark Date: Thu, 5 May 2011 09:00:07 +0000 (+0200) Subject: For other-than-gcc, generate calls to check_new(...) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec404c2370ba877301e093207215b59f5de80a7a;p=p5sagit%2FDevel-Size.git For other-than-gcc, generate calls to check_new(...) Only use a static array of vtables on gcc. Some other compilers may be happy with it, but VC certainly isn't. It's only trivial to determine gcc or not. --- diff --git a/CHANGES b/CHANGES index a6fefbe..18ab31e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Revision history for Perl extension Devel::Size. +0.75_51 2011-05-05 nicholas + * Only use a static array of vtables on gcc. + 0.75_50 2011-05-04 nicholas * The core's magic vtables are global constants, so aren't part of the size. * Follow mg_obj and mg_ptr. diff --git a/Makefile.PL b/Makefile.PL index 5eb43c6..2f91101 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -29,15 +29,13 @@ my %special = ( open FH, ">$vtable_file" or die "Can't open $vtable_file: $!"; foreach (sort keys %vtables) { - if ($special{$_}) { - print FH <<"EOT"; -#ifdef $special{$_} - &$_, -#endif -EOT - } else { + print FH "#ifdef $special{$_}\n" if ($special{$_}); + if ($Config{gccversion}) { print FH " &$_,\n"; + } else { + print FH " check_new(st, &$_);\n"; } + print FH "#endif\n" if ($special{$_}); } close FH or die "Error closing $vtable_file: $!"; diff --git a/Size.xs b/Size.xs index 8373101..14be0be 100644 --- a/Size.xs +++ b/Size.xs @@ -738,17 +738,27 @@ sv_size(pTHX_ struct state *const st, const SV * const orig_thing, return TRUE; } +/* Frustratingly, the vtables aren't const in perl.h + gcc is happy enough to have non-const initialisers in a static array. + VC seems not to be. (Is it actually treating the file as C++?) + So do the maximally portable thing, unless we know it's gcc, in which case + we can do the more space efficient version. */ + +#if __GNUC__ void *vtables[] = { #include "vtables.inc" NULL }; +#endif static struct state * new_state(pTHX) { SV *warn_flag; struct state *st; +#if __GNUC__ void **vt_p = vtables; +#endif Newxz(st, 1, struct state); st->go_yell = TRUE; @@ -761,8 +771,12 @@ new_state(pTHX) check_new(st, &PL_sv_undef); check_new(st, &PL_sv_no); check_new(st, &PL_sv_yes); +#if __GNUC__ while(*vt_p) check_new(st, *vt_p++); +#else +#include "vtables.inc" +#endif return st; }