Re: How to debug bizarre memory corruption in mod_perl - modperl
This is a discussion on Re: How to debug bizarre memory corruption in mod_perl - modperl ; On 9 Jul 2008, at 09:09, David Kaufman wrote:
> # from the POD doco at
> #
> http://search.cpan.org/~gbarr/Scalar...pm#DESCRIPTION
>
> $foo = first { defined($_) } @list; # first defined value in @list
>
>
> Who needs ...
-
Re: How to debug bizarre memory corruption in mod_perl
On 9 Jul 2008, at 09:09, David Kaufman wrote:
> # from the POD doco at
> #
> http://search.cpan.org/~gbarr/Scalar...pm#DESCRIPTION
>
> $foo = first { defined($_) } @list; # first defined value in @list
>
>
> Who needs to install a CPAN module to do that? I personally would
> have
> written it as:
>
> $foo = (grep defined, @list)[0]; # first defined value in @list
Bear in mind that first may be much more efficient if the list is
large and/or the test is expensive:
$ cat foo.pl
use List::Util qw( first );
sub even {
my ( $where, $x ) = @_;
print "$where is checking $x\n";
return $x % 2 == 0;
}
my @in = ( 1, 2, 3, 4, 5 );
my $first_even = first { even( 'first', $_ ) } @in;
my $grep_even = ( grep { even( 'grep', $_ ) } @in )[0];
print "$first_even, $grep_even\n";
$ perl foo.pl
first is checking 1
first is checking 2
grep is checking 1
grep is checking 2
grep is checking 3
grep is checking 4
grep is checking 5
2, 2
I'm not suggesting that necessarily applies in this case - just a
general observation.
--
Andy Armstrong, Hexten
-
Re: How to debug bizarre memory corruption in mod_perl
On 10 Jul 2008, at 05:05, Perrin Harkins wrote:
>> It's interesting that this didn't manifest under Perl 5.8.
>
> And a little scary, since some people definitely have this bug and the
> warning for it in 5.10 was removed before release.
Yeah, I'm thinking this thread should migrate to p5p for that reason.
While undefined behaviour can nominally include flying butt monkeys I
don't think it's desirable for it to cause rampant memory corruption.
--
Andy Armstrong, Hexten
-
Re: How to debug bizarre memory corruption in mod_perl
Hi Stephen,
"Stephen Clouse" wrote ...
> ...I did manage to figure out the issue today. You may or may not be
> surprised to find it was this:
>
> my $foo = "bar" if $baz;
Yikes! My bad :-) It must've been a different scary memory error that I
encountered with List::Util.
> Apparently one of the previous programmers left about 100 such constructs
> littered about the Perl and Mason code. Fixing them cleared up all the
> bizarre issues.
I too was "one of those guys" who liberally littered his code with the
construct:
my $foo = 'bar' if $baz;
I unlearned to do it too, a few months back, which must have been why your
errors "rang a bell" with me. My co-workers had to track down that is was
my {declaration + assignment + conditional} that was throwing the scary
memory errors. I never saw it. I'd been doing it for years, and prior to
that I had no idea it was A Bad Thing to do, and I said as much to them,
"it's always worked fine for me!"
I wish it would still DWIM, and by that I mean the compiler should detect
my declaration + assignment + conditional and rewrite it for me as what I
meant which was simply:
my $foo = $baz ? 'bar' : undef;
That's how I've been rewriting these since then.
It seems a no-brainer that when no-brain people like me write this, they
mean to make the assignment conditional, not declaration of the variable,
so that:
declaration + assignment + conditional == declaration + (conditional
assignment)
I've already (finally) unlearned to do that, but I agree with Andy that the
cost of people's ignorance (especially doing something that's worked as
expected for so long) shouln't cause "rampant memory corruption". It
should maybe DWIM or die or warn, but not dump core :-)
-dave
-
Re: How to debug bizarre memory corruption in mod_perl
On Thu, 10 Jul 2008, David Kaufman wrote:
>
> my $foo = 'bar' if $baz;
>
> I wish it would still DWIM, and by that I mean the compiler should detect
> my declaration + assignment + conditional and rewrite it for me as what I
> meant which was simply:
>
> my $foo = $baz ? 'bar' : undef;
>
I disagree. In the first, you are telling perl that you
want to create a symbol if a certain condition is true.
Maybe under some conditions you don't want to create that
symbol. Consider the same logic applied to hash assignment:
my %foo;
$foo{bar} = 'baz' if $biz;
frob() if exists $foo{bar};
You would expect that $foo{bar} would not exist if $biz was
false. But under your recommendation, it would exist. This
is not the way it should behave.
Mark
-
Re: How to debug bizarre memory corruption in mod_perl
On 10 Jul 2008, at 17:23, David Kaufman wrote:
> I've already (finally) unlearned to do that, but I agree with Andy
> that the
> cost of people's ignorance (especially doing something that's worked
> as
> expected for so long) shouln't cause "rampant memory corruption". It
> should maybe DWIM or die or warn, but not dump core :-)
Indeed. I've taken it to perl5-porters[1]. I'm not sure if it's a
known problem with 5.10.0 but I certainly hadn't heard of it.
[1] http://markmail.org/message/yfxkc6sbw2ydvcjz
--
Andy Armstrong, Hexten
-
Re: How to debug bizarre memory corruption in mod_perl
Hi Mark,
"Mark Hedges" wrote:
>
> David Kaufman wrote:
>
>> my $foo = 'bar' if $baz;
>>
>> I wish it would still DWIM, and by that I mean the compiler should
>> detect
>> my declaration + assignment + conditional and rewrite it for me as what
>> I
>> meant which was simply:
>>
>> my $foo = $baz ? 'bar' : undef;
>
> I disagree. In the first, you are telling perl that you
> want to create a symbol if a certain condition is true.
> Maybe under some conditions you don't want to create that
> symbol.
Fair enough. I've never felt the need to (or read anyone elses code that
chose to) conditionally declare a lexically local variable, but I agree
thatm if someone felt the need to do so, then:
my $foo if $necessary;
shouldn't behave any differently than:
my $foo = 'bar' if $necessary;
So I'd be happy with a warning. And, you know, not corrupting memory...
:-)
-dave