From 5.10.0's doio.c,
1031 Off_t 1032 Perl_do_tell(pTHX_ GV *gv) 1033 { 1034 dVAR; 1035 register IO *io = NULL; 1036 register PerlIO *fp; 1037 1038 if (gv && (io = GvIO(gv)) && (fp = IoIFP(io))) { 1039 #ifdef ULTRIX_STDIO_BOTCH 1040 if (PerlIO_eof(fp)) 1041 (void)PerlIO_seek(fp, 0L, 2); /* ultrix 1.2 wor +karound */ 1042 #endif 1043 return PerlIO_tell(fp); 1044 } 1045 if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) 1046 report_evil_fh(gv, io, PL_op->op_type); 1047 SETERRNO(EBADF,RMS_IFI); 1048 return (Off_t)-1; 1049 }

I don't see how passing NULL to do_tell (as shown in your stack trace) would cause any problems. The line where the segfault occurs in your strack trace explicitly checks if gv is NULL before using it. Could this be a compiler optimisation problem? I could confirm that if I saw the assembler code for that function on a machine where it crashes.


As an aside, I discovered that Perl will treat a number passed to tell as the name of a glob.

$ perl -MO=Concise -e'tell 1234' 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <1> tell[t2] vK/1 ->6 4 <1> rv2gv sK*/1 ->5 3 <#> gv[*1234] s ->4 -e syntax OK $ perl -MO=Concise -e'tell *1234' 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <1> tell[t2] vK/1 ->6 4 <1> rv2gv sKR/1 ->5 3 <#> gv[*1234] s ->4 -e syntax OK

(And not just when it's a constant. It's just easier to see there.)

That means the following are all equivalent:

my $fh = \*STDOUT; tell( 0+$fh );
my $fh = \*STDOUT; no strict 'refs'; tell( *{ ''.(0+$fh) } );
# Assuming STDOUT is still located at address 0x814ec28 tell( *135588904 );

In reply to Re^2: Perl segfaults: Why? by ikegami
in thread Perl segfaults: Why? by bv

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.