[Templates] segmentation fault

David Dyer-Bennet dd-b@dd-b.net
25 Oct 2003 12:56:05 -0500


With Perl 5.6.1, templete toolkit 2.10, on Linux.

This template:

    <html><head></head><body>
    [% PERL %]
    my $art = [
               {fpath => "no match", title => "test 1"},
               {fpath => "/encyclopedia/foo/index.html", title => "test 2"},
               ];

    foreach my $aif (@{$art}) {
        print "<p>", ref($aif), ' ', $aif->{title}, ' ', $aif->{fpath}, "</p>\n";
        if ($aif->{fpath} =~ /\/encyclopedia\/(.*)\/index\.html$/ ) {
            print "foo $1";
        } else {
            print "Unexpected fpath " . $aif->{fpath};
            print "bar";
        }
    }				# foreach $aif in $art
    [% END %]
    <p>
    Nothing here.
    </p>
    </body>

Processed through ttree with this command:

    gw:ttsrc> ttree -v -a --preserve --trim -f .ttreerc --lib="lib" --lib="/www/drag3/dyndata/genlib" --src="encyclopedia" --dest=../html/encyclopedia test.html
    ttree 2.62 (Template Toolkit version 2.10)

          Source: encyclopedia
     Destination: ../html/encyclopedia
    Include Path: [ lib, /www/drag3/dyndata/genlib ]
          Ignore: [ \b(CVS|RCS)\b, ^lib$, ^# ]
            Copy: [ \.(png|gif|jpg|ico)$, \.(wav|mp3)$, ^\.htaccess$ ]
          Accept: [ \.s?html$, \.css$, \.cgi$ ]

      + test.html
    Segmentation fault

Produces a segmentation fault.  

See that print "foo $1" just after the regexp match in the if
statement?  If you take the $1 out of the string, the segmentation
fault goes away!!!!  So apparently I'm allowed to do the regexp match,
but not to know what the parenthesized bit actually matched.  Bummer! 

I've tried a lot of the usual thrashing around, of course; adding
extra variables, putting the regexp in a variable with qr, different
quoting characters on the qr, and so forth. 

This is, of course, rather far removed from the application code where
I first saw the problem.  That involved invoking a local module of my
own inside that perl module, and I was doing some postprocessing on
the array of hash refs it returned (that became the constant $art in
this test case).  I suspected my own module initially, of course, but
it turns out the problem happens with it completely removed from the
picture.

Help!

Just for completeness, here's the .ttreerc:

    # ttree config file for dragaera2
    # $Id: .ttreerc,v 1.9 2003/10/21 18:10:54 ddb Exp $
    #
    #------------------------------------------------------------------------
    # General options

    # print summary of what's going on (-v)
    #verbose 

    # recurse into any sub-directories and process files (-r)
    #recurse

    #------------------------------------------------------------------------
    # The 'cfg' option defines a directory in which other ttree configuration
    # files can be found;  you can specify a file using the '-f' option,
    # 'ttree -f myconfig' and the script will look for the file in this
    # directory.  Alteratively, provide an absolute path as an argument,
    # 'ttree -f /tmp/foo'.
    # 
    # By default, this option is commented out.  You will need to create a 
    # directory, uncomment the following line and set the value appropriately.
    # Having done that, you can then create files exactly like this in that
    # location.

    #cfg = /www/dragaera2/ttsrc/.ttreerc

    #------------------------------------------------------------------------
    # The remaining options define the default behaviour when you run ttree.
    # This file is always processed before any file specified by '-f'.  If
    # you define the 'src' and 'dest' options then these will be used by
    # default.  Values for these options defined in files loaded with '-f'
    # will override these default.  Other options such as 'lib', 'ignore',
    # 'copy' and 'accept' are accumulative.

    # The 'src' option defines the location of the template files that
    # you want to process
    #src  = /www/dragaera2/ttsrc

    # The 'dest' option specifies where the output should go.  The script
    # compares the modification dates of files in the 'src' and 'dest'
    # directories to work out which need to be processed. 
    #dest = /www/dragaera2/html

    # 'lib' tells the processor (via INCLUDE_PATH) where to find any
    # template files that may be INCLUDE'd.  You can specify many.
    #lib = /www/dragaera2/ttsrc/lib
    # lib = /usr/local/tt2/lib

    # pre-process is modules always processed first
    pre_process = config

    # Things that aren't templates and should be ignored, specified as Perl
    # regexen.
    ignore = \b(CVS|RCS)\b
    ignore = ^lib$
    ignore = ^#

    # Things that should be copied rather than processed.
    copy = \.(png|gif|jpg|ico)$ 	# copy extensions -- images
    copy = \.(wav|mp3)$		# copy extensions -- sound
    copy = ^\.htaccess$		# copy files

    # By default, everything not ignored or copied is accepted; add 'accept'
    # lines if you want to filter further. e.g.
    accept = \.s?html$
    accept = \.css$
    accept = \.cgi$

    # We need to evaluate perl stuff
    eval_perl

And here's the config template it calls in:

    [%# $Id: config,v 1.13 2003/10/19 05:58:00 ddb Exp $
        Configuration variables

        Config is split into three parts:

        The static config, applicable to all instantiations of this site,
        is in this file.

        The sitemode-specific config is copied by bldsite.pl into genlib
        as sitemode-config, which is processed into this file.

        The part absolutely specific to this instantiation (like siteroot)
        is applied as --define switches in the ttree options (in
        bldsite.pl).
    %]


    [%
        # Pallette
        SET P_hdrbck = "black";
        SET P_navbck = "rgb(255,131,63)";
        SET P_pagbck = "rgb(167,243,239)";
        SET P_hdtext = "rgb(96,30,13)";
        SET P_boxbck = "rgb(243,196,151)";

        # Standard font-lists
        SET hdrfonts = 'garamond, "times new roman", times, serif';
        SET bodyfonts = '"lucida sans", arial, geneva, swiss, sans-serif';

        # A few standard references
        SET L_sitename = "<span class=\"sitename\">dragaera.info</span>";

        # Leftnav buttongroup 1; list of hashes of button id, url
        SET buttons1 = [
                {id => 'home', url => '/'},
                {id => 'events', url => '/events'},
    #	    {id => 'articles', url => '/encyclopedia'},
                {id => 'mailinglists', url => '/mailinglists'},
    #	    {id => 'stevensweblog', url => '/weblog'},
                {id => 'booksearch', url => '/booksearch'},
                {id => 'dragaerasearch', url => '/dragaerasearch'},
                {id => 'links', url => '/links'},
                {id => 'faq', url => '/faq'},
                {id => 'aboutus', url => '/about.html'},
            ];
    %]

-- 
David Dyer-Bennet, <dd-b@dd-b.net>, <www.dd-b.net/dd-b/>
RKBA: <noguns-nomoney.com> <www.dd-b.net/carry/>
Photos: <dd-b.lighthunters.net>  Snapshots: <www.dd-b.net/dd-b/SnapshotAlbum/>
Dragaera/Steven Brust: <dragaera.info/>