in reply to Dr. Watson when

Any Dr. Watson (or coredump/segfault on a Unix box) in perl is a bug in the perl interpreter or in any loaded DLLs/XS modules. You should not be able to write a script which would cause this.

Having said that, no software is bug free and one of the best ways of getting it to fail is to use too much memory.

Hmm...I attempted to do a quick example of how perl handles memory exhaustion gracefully and ended up causing a segfault on perl 5.6.0 (un-upgraded install on Red Hat 7.2) with the following:

sub big { $line = shift; $size = length $line; print "Size is [$size]\n"; $line = $line x $size; big( $line ); } big( "12" );
Running with a 3-char string to start causes different behaviour (big allocations, box slows down with memory use, perl finally prints "Out of memory!" and exits cleanly), which is more what I expected.

I really should go and grab a more recent perl and if this is fixed and/or big into the allocator and see why it doesn't like big powers of two. But I'm sure someone here will happily beat me to it :-)

Replies are listed 'Best First'.
(tye)Re: Dr. Watson when
by tye (Sage) on Jan 09, 2002 at 22:42 UTC

    I'll add a little to this. One can abuse unpack to cause a core dump, but that is probably not what is happening here.

    The easiest way to get a "Dr. Watson" w/ Perl is to use fork (under Win32). So, if you are doing that, you might want to look at (tye)Re: How to multiprocess in Win32?.

    The original seeker mentioned using lots of memory. Under Win32, if you run out of swap space, a dialogue pops up telling you that you are running low on memory. Once that happens, somewhere a call to malloc() (etc.) has failed. Many things don't check for failure of malloc() and many things that do check don't deal well with the failure anyway. So once you see that dialogue, just about any program, and indeed the operating system itself, is suspect and may fail in unusual ways.

    Even if we assume that Perl is perfect at remaining sane in the face of a failed malloc(), the Win32 libraries that Perl uses certainly aren't perfect in that respect and so Perl could certainly "Dr. Watson" after the "low memory" dialogue appeared.

    But if you haven't seen the "low memory" dialogue, then Perl using lots of memory should not be a reason for a "Dr. Watson".

            - tye (but my friends call me "Tye")