strange behavior

E

efoss

I've run into a strange problem. I have a program that is a few
hundred lines long. I run it and it runs fine and gives me the correct
output (at least when I check a few of the output calculations
manually.) But here are some screwy things that disturb me:

1. If I comment out a module that I'm not even using, I get a
"Segmentation fault" error. (The difference is "use FileHandle;"
versus "#use FileHandle;".)

2. If I get the "Segmentation fault" error and then I comment out a
numerical sort of an array (which is working correctly), then the
"Segmentation fault" error goes away.

3. If I run the program on my debugger rather than from a terminal,
the program runs fine.

4. If I run the program on a different computer and run it from a
terminal, the program runs fine.

I don't remember ever getting "Segmentation fault" as an error message
in Perl - I think of that as a "C error", since I've seen it many
times writing C code. Does anyone have an idea what's going wrong?
(I'm not posting the code because it's long and I'm quite certain that
the details of the code won't be relevant, but I'm happy to post it.)

Thanks.

Eric
 
U

Uri Guttman

eo> I've run into a strange problem. I have a program that is a few
eo> hundred lines long. I run it and it runs fine and gives me the correct
eo> output (at least when I check a few of the output calculations
eo> manually.) But here are some screwy things that disturb me:

eo> 1. If I comment out a module that I'm not even using, I get a
eo> "Segmentation fault" error. (The difference is "use FileHandle;"
eo> versus "#use FileHandle;".)

FileHandle is obsolete anyhow. never use it. it actually just wraps
IO::Handle. and you rarely need IO::Handle as IO::File or others are
what you want.

eo> 2. If I get the "Segmentation fault" error and then I comment out a
eo> numerical sort of an array (which is working correctly), then the
eo> "Segmentation fault" error goes away.

you are doing something very wrong. hard to divine it with no code.

eo> 3. If I run the program on my debugger rather than from a terminal,
eo> the program runs fine.

eo> 4. If I run the program on a different computer and run it from a
eo> terminal, the program runs fine.

eo> I don't remember ever getting "Segmentation fault" as an error message
eo> in Perl - I think of that as a "C error", since I've seen it many
eo> times writing C code. Does anyone have an idea what's going wrong?
eo> (I'm not posting the code because it's long and I'm quite certain that
eo> the details of the code won't be relevant, but I'm happy to post it.)

perl has rare segment faults. if you can force this everytime, then
report it to p5p (the perl core developers) with the perlbug program.

uri
 
E

efoss

A segfault is *always* a bug in perl, or in an XS module. This symptom
you describe, of the problem going away when random things are changed
slightly, probably indicates some sort of memory allocation error. If a
piece of code somewhere is (say) dereferencing a pointer after it's been
freed, whether that will segfault or not depends on whether that piece
of memory has been reused yet, and that in turn depends on the exact
details of what has been allocated so far.

Things to try, in order:
    - Try it with 5.10.1, in case the bug has been found and fixed. Try
      it with the latest versions of any XS modules you are using, for
      the same reason.

    - Get the 5.11.5 source tarball, build perl with -DDEBUGGING, and
      try it with that. If it still fails you're likely to get an
      assertion failure much nearer the real bug.

    - If you're up to it, provoke a failure under gdb and attempt to
      work out what's going on, or run perl under valgrind to checkfor
      allocation errors.

    - Report a bug, including as much detail as you can. You need to cut
      as much as you can out of your test case without making the
      failure go away. This can be tedious, especially with a heisenbug
      like this.

Ben

Thanks very much. I just tried the first one - installing Perl 5.10.1.
I had 5.10.0 before, which I checked with "perl -v". I then went
here:

http://www.activestate.com/activeperl/downloads/

and I downloaded the recommended version. (I'm using MacOS X with the
Snowleopard operating system.) Below is what it said it recommended:

Recommended version(s) for your platform:
ActivePerl 5.10.1.1007 for Mac OS X (Universal)

I then restarted my computer and tried again and got the same error.
However, then when I tried "perl -v" again, it said that I was using
5.10.0 rather than 5.10.1. I'm puzzled by this, since installing perl
was pretty straight forward - just clicking "next" a bunch of times
and accepting all the default settings. I'll screw around more with
this to see if I can figure out what I'm doing wrong.

Thanks again for your help.

Eric
 
J

John Bokma

Ben Morrow said:
Recommended by whom?

I've had unfortunate experiences with AS perl in the past, both with
extensions I needed not being available and with changes they've made to
core perl (in particular, their ActivePerl::Config stuff is just
*nasty*). Strawberry is just perl as on any other platform, with a
fairly usual level of minimal patching to make things work, most of
which gets pushed back upstream reasonably quickly.

But if AS works for you, that's fine.

I had somewhat the same question: what do you recommend over AS, and my
guess was correct (Strawberry Perl), so thanks for the clarification.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top