Include the size of constants in constant subs (resolves CPAN #58485)
Nicholas Clark [Thu, 14 Apr 2011 19:31:15 +0000 (20:31 +0100)]
CHANGES
Size.xs
t/basic.t

diff --git a/CHANGES b/CHANGES
index 8d45bd3..e62fb4a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,7 +8,7 @@ Revision history for Perl extension Devel::Size.
    the fatal error introduced in 0.72 when the assumption was violated.
  * Convert to XSLoader
  * Resolve CPAN #49437 (Devel::Size adds magic in Perl 5.10)
- * Resolve CPAN #58484
+ * Resolve CPAN #58484 and #58485 (related to CVs that are XSUBs)
 
 0.72 2008-10-14 BrowserUk 70 tests
  * Added bit-vector pointer tracking mechanism.
diff --git a/Size.xs b/Size.xs
index 2d33d54..08cbb7e 100644 (file)
--- a/Size.xs
+++ b/Size.xs
@@ -672,7 +672,12 @@ UV thing_size(const SV * const orig_thing, TRACKING *tv) {
     if (check_new(tv, CvOUTSIDE(thing))) {
       total_size += thing_size((SV *)CvOUTSIDE(thing), tv);
     }
-    if (!CvISXSUB(thing)) {
+    if (CvISXSUB(thing)) {
+       SV *sv = cv_const_sv((CV *)thing);
+       if (sv) {
+           total_size += thing_size(sv, tv);
+       }
+    } else {
        if (check_new(tv, CvSTART(thing))) {
            total_size += op_size(CvSTART(thing), tv);
        }
index 31e1810..62c7535 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -97,6 +97,7 @@ isnt( total_size( sub{ do{ my $t=0 }; } ), 0, 'total_size( sub{ my $t=0 } ) > 0'
 # CPAN RT #58484 and #58485
 isnt (total_size(\&total_size), 0, 'total_size(\&total_size) > 0');
 
-use constant LARGE => 'N' x 4096;
+use constant LARGE => 'N' x 8192;
 
-isnt (total_size(\&LARGE), 0, 'total_size for a constant > 0');
+cmp_ok (total_size(\&LARGE), '>', 8192,
+        'total_size for a constant includes the constant');