From: Nicholas Clark Date: Fri, 10 May 2013 09:03:57 +0000 (+0200) Subject: An alternative test that CvOUTSIDE is being followed. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1606314d140904fbbb6dbfae31f48552985d4c1c;p=p5sagit%2FDevel-Size.git An alternative test that CvOUTSIDE is being followed. As of v5.17.2, CvOUTSIDE is NULL on cloned closures, unless they contain a string eval. Hence the size of closures should differ, as long as Size.xs is correctly following CvOUTSIDE. (See blead commit a0d2bbd5c47035a4) --- diff --git a/CHANGES b/CHANGES index fe605c7..d290c44 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ Revision history for Perl extension Devel::Size. + * Alternative test for CvOUTSIDE, and one for CvPADLIST * v5.17 changes the type of PADLIST [CPAN #83904] * stubbed subs no longer have CvOUTSIDE set [CPAN #77913] * Fix for v5.17.2's OP slab allocator [CPAN #83903] diff --git a/t/code.t b/t/code.t index 1a76276..8b32e37 100644 --- a/t/code.t +++ b/t/code.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 13; +use Test::More tests => 14; use Devel::Size ':all'; sub zwapp; @@ -66,3 +66,26 @@ bloop(42); my $after_size = total_size(\&bloop); cmp_ok($after_size, '>', $before_size, 'Recursion increases the PADLIST'); + +sub closure_with_eval { + my $a; + return sub { eval ""; $a }; +} + +sub closure_without_eval { + my $a; + return sub { require ""; $a }; +} + +if ($] > 5.017001) { + # Again relying too much on the core's implementation, but while that holds, + # this does test that CvOUTSIDE() is being followed. + cmp_ok(total_size(closure_with_eval()), '>', + total_size(closure_without_eval()) + 256, + 'CvOUTSIDE is now NULL on cloned closures, unless they have eval'); +} else { + # Seems that they differ by a few bytes on 5.8.x + cmp_ok(total_size(closure_with_eval()), '<=', + total_size(closure_without_eval()) + 256, + "CvOUTSIDE is set on all cloned closures, so these won't differ by much"); +}