We've got a Perl script, it's reliably giving us a Segfault. I put debug in, and presto! Problem solved. Put it in the debugger? Works fine.

We've narrowed down the problem as follows. Our code:

... eval { $DT = DateTime->new( year => $year, time_zone => $tz ); }; return if $@; ...

Specifically, the above code executes normally several dozen times, and then segfaults when passed a $year of "2011", and a $tz of "Europe/London". BUT! Here's the catch, and here's where I'm getting out of my league:

JUST before that, it calls the same code with $year = "2010" and $tz = "Europe/London". THAT call fails and is successfully caught by the wrapped eval, which actually returns us an error message like this:

The 'name' parameter (undef) to DateTime::TimeZone::new was an 'undef' +, which is not one of the allowed types: scalar at /idcom/weblive/extperl/lib/perl5/site_perl/5.8.5/DateTime/TimeZone +.pm line 34 DateTime::TimeZone::new('undef', 'name', 'undef') called at /idcom/weblive/extperl/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread +-multi/DateTime.pm line 192 DateTime::new('undef', 'year', 2010, 'time_zone', 'Europe/Lond +on') called at TZInfo.pm line 33 TZInfo::get_dst_changes(2010, 'Europe/London') called at ./nz. +pl line 1039

The NEXT call (for 2011, same time zone), causes the segfault, and isn't caught by the wrapped eval.

So. One thing I noticed is that it reports that I called both DateTime::new and DateTime::TimeZone::new with a leading "undef" parameter! Shouldn't that be the package name?

Beyond that, I'm at a loss. I can't replicate it in a smaller, standalone test, and I have no idea why it should actually segfault. And looking at DateTime::new, it looks like it's possible that the Params::Validate module is what's processing the arguments and turning the name field into an undef-- but it seems wholly unlikely to me that there would be a bug in either DateTime, DateTime::TimeZone, or Params::Validate.

Any ideas?

DaveE

UPDATE

Well, not much to say apart from the fact that I've quasi-confirmed that Params::Validate isn't doing what it's supposed to do (probably thanks to some error state that we've created, but I have no idea how). Within DateTime.pm:
... sub new { my $class = shift; my %p = validate( @_, $NewValidate ); ...

I added in debug (that still contained the failure) to print out @_, %p, and $NewValidate both before and after the call to Params::Validate. Result?

@_ set to: $VAR1 = [ 'year', 2010, 'time_zone', 'Europe/London' ]; %p set to: $VAR1 = {};

So, it properly shifted off the $class (it was being set correctly it seems), but when attempting to pass off to Params::Validate::validate, the resultant hash comes back empty! Trying to hack into Params::Validate now, but I have a feeling I'm barking up the wrong tree-- maybe something's screwed up the stack and comes unstuck at the return from Params::Validate or something, but again, I have doubts that the library itself has a problem.


In reply to Tracking down a segfault by davee123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.