Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed bug RT#47929 which caused the XS Stash to die mysteriously

when calling code that used string evaluation (e.g. DateTime).
  • Loading branch information...
commit cb1d793924ac105c188c2a573b7233621a6c5e24 1 parent f04f2dc
Andy Wardley authored January 13, 2012
3  Changes
@@ -14,6 +14,9 @@
14 14
 # Version 2.23 - not released yet
15 15
 #------------------------------------------------------------------------
16 16
 
  17
+* Fixed bug RT#47929 which caused the XS Stash to die mysteriously when
  18
+  calling code that used string evaluation (e.g. DateTime).
  19
+
17 20
 * Added the TRACE_VARS option to keep track of what variables are used
18 21
   in a template.  It's not documented yet.  See t/trace_vars.t for an
19 22
   example of use.
2  lib/Template/Stash/XS.pm
@@ -127,7 +127,7 @@ Doug Steinwand E<lt>dsteinwand@citysearch.comE<gt>
127 127
 
128 128
 =head1 COPYRIGHT
129 129
 
130  
-Copyright (C) 1996-2009 Andy Wardley.  All Rights Reserved.
  130
+Copyright (C) 1996-2012 Andy Wardley.  All Rights Reserved.
131 131
 
132 132
 This module is free software; you can redistribute it and/or
133 133
 modify it under the same terms as Perl itself.
27  t/stash-xs.t
@@ -29,6 +29,7 @@ if ($@) {
29 29
     skip_all('cannot load Template::Stash::XS');
30 30
 }
31 31
 
  32
+
32 33
 #------------------------------------------------------------------------
33 34
 # define some simple objects for testing
34 35
 #------------------------------------------------------------------------
@@ -106,6 +107,11 @@ my $data = {
106 107
     },
107 108
     correct => sub { die @_ },
108 109
     buggy   => Buggy->new(),
  110
+    str_eval_die => sub {
  111
+        # This is to test bug RT#47929
  112
+        eval "use No::Such::Module::Exists";
  113
+        return "str_eval_die returned";
  114
+    },
109 115
 };
110 116
 
111 117
 my $stash = Template::Stash::XS->new($data);
@@ -118,6 +124,7 @@ match( $stash->get('baz.boz'), 30 );
118 124
 match( $stash->get('baz.boz'), 40 );
119 125
 match( $stash->get('baz.biz'), '<undef>' );
120 126
 match( $stash->get('baz(50).biz'), '<undef>' );   # args are ignored
  127
+#match( $stash->get('str_eval_die'), '' );
121 128
 
122 129
 $stash->set( 'bar.buz' => 100 );
123 130
 match( $stash->get('bar.buz'), 100 );
@@ -403,3 +410,23 @@ foo is { "" = "full" "one" = "baz" }
403 410
 [% cmp_ol.hello %]
404 411
 -- expect --
405 412
 Hello
  413
+
  414
+-- test --
  415
+Before
  416
+[%  TRY;
  417
+        str_eval_die;
  418
+    CATCH;
  419
+        "caught error: $error";
  420
+    END;
  421
+%]
  422
+After
  423
+-- expect --
  424
+Before
  425
+str_eval_die returned
  426
+After
  427
+
  428
+-- test --
  429
+[%  str_eval_die %]
  430
+-- expect --
  431
+str_eval_die returned
  432
+
2  t/stop.t
@@ -17,7 +17,7 @@
17 17
 #========================================================================
18 18
 
19 19
 use strict;
20  
-use lib  qw( ./lib ../lib );
  20
+use lib qw( ./lib ../lib ../blib/lib ../blib/arch ./blib/lib ./blib/arch );
21 21
 use vars qw( $DEBUG );
22 22
 use Template::Test;
23 23
 use Template::Parser;
8  xs/Stash.xs
@@ -14,7 +14,7 @@
14 14
 *   Doug Steinwand <dsteinwand@citysearch.com>
15 15
 *
16 16
 * COPYRIGHT
17  
-*   Copyright (C) 1996-2009 Andy Wardley.  All Rights Reserved.
  17
+*   Copyright (C) 1996-2012 Andy Wardley.  All Rights Reserved.
18 18
 *   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
19 19
 *
20 20
 *   This module is free software; you can redistribute it and/or
@@ -638,9 +638,13 @@ static SV *call_coderef(pTHX_ SV *code, AV *args) {
638 638
         if ((svp = av_fetch(args, i, FALSE))) 
639 639
             XPUSHs(*svp);
640 640
     PUTBACK;
641  
-    count = call_sv(code, G_ARRAY);
  641
+    count = call_sv(code, G_ARRAY|G_EVAL);
642 642
     SPAGAIN;
643 643
 
  644
+    if (SvTRUE(ERRSV)) {
  645
+        die_object(aTHX_ ERRSV);
  646
+    }
  647
+
644 648
     return fold_results(aTHX_ count);
645 649
 }
646 650
 

2 notes on commit cb1d793

Robin Smidsrød

I've just tested out my broken test case with your patch. My code in https://github.com/robinsmidsrod/datetime-template-bug now works well on these configurations (as noted in the README):

Description:    Ubuntu 10.04.3 LTS
Linux server 2.6.32-36-generic-pae #79-Ubuntu SMP Tue Nov 8 23:25:26 UTC
2011 i686 GNU/Linux
This is perl 5, version 12, subversion 2 (v5.12.2) built for i686-linux
POSIX version: 1.19
DateTime version: 0.66
Template version: 2.22_1 (commit bb1080b)
Template stash used: Template::Stash::XS
Description:    Ubuntu 10.04.3 LTS
Linux server 2.6.32-36-generic-pae #79-Ubuntu SMP Tue Nov 8 23:25:26 UTC
2011 i686 GNU/Linux
This is perl 5, version 14, subversion 0 (v5.14.0) built for i686-linux
POSIX version: 1.24
DateTime version: 0.72
Template version: 2.22_1 (commit bb1080b)
Template stash used: Template::Stash::XS
Robin Smidsrød

Thanks a bunch for finally solving this issue. Much obliged!

Please sign in to comment.
Something went wrong with that request. Please try again.