develooper Front page | perl.perl5.porters | Postings from April 2012

Re: [perl #21780] odd bug with handle dup

Thread Previous
From:
Uri Guttman
Date:
April 21, 2012 10:03
Subject:
Re: [perl #21780] odd bug with handle dup
Message ID:
4F92E853.4040507@stemsystems.com
On 04/21/2012 12:02 PM, James E Keenan via RT wrote:
> On Mon Mar 31 18:43:53 2003, belg4mit@mit.edu wrote:
>> This is a bug report for perl from belg4mit@mit.edu,
>> generated with the help of perlbug 1.34 running under perl v5.8.0.
>>
>>
>> -----------------------------------------------------------------
>> While playing with code to dup DATA to STDIN I inadvertently came
>> up with the following
>>
>>    $a = tell(DATA);
>>    seek(DATA,$a,0);
>>    open(STDIN, "<&DATA");
>>    while(<STDIN>){
>>      print "STDIN: $_";
>>    }
>>    __DATA__
>>    Foo
>>    Bar
>>    Quux
>>
>> The first two lines would seem to be no-ops. And yet in several
>> instances nothing is read without them. Known configs where this
>> has failed are this box with the version of perl below as well
>> as the following perl -V [all Solaris.] I have also received reports
> of failure
>> without the first two lines on builds of 5.8 for SCO and RH
>>
>
> On Sat May 10 10:32:12 2003, ni-s wrote:
>> Strange how these things go unnoticed for ages then get discovered
>> by several people at nearly same time.
>> This is caused by "fact" that DATA handle has been read in order to
>> read the script. So some data is in the buffer. The "dup" process
>> does not copy the buffer.
>>
>> Not clear if/how this should be fixed:
>>    A. Document it
>>    B. Make dup do seek(FH,tell(FH),0)  - but with more error checking.
>>    C. Make DATA file handle do the seek/tell thing implicitly.
>
> ni-s is no longer with us to handle this old ticket.
>
> This problem appears to be OS-specific; I could not reproduce it on
> Darwin or Debian Linux.  Is there someone -- especially on Solaris --
> who can try to reproduce this bug?  How should we approach this?

just fyi, i ran into this problem without the dup call. in File::Slurp 
slurping the DATA handle which uses sysread has seek issues. my 
workaround was to detect it was DATA and to to a sysseek/tell on the 
handle before reading it with sysread. so it sounds like the same issue. 
i recall it was solaris that had this problem but i can't check it as i 
don't have solaris around anymore. so having dup do the seek isn't going 
to fix the problem as it shows up without dup.

uri

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About