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

[perl #31455] Dup DATA filehandle, lose initial data

Thread Previous
From:
James E Keenan via RT
Date:
September 29, 2012 19:17
Subject:
[perl #31455] Dup DATA filehandle, lose initial data
Message ID:
rt-3.6.HEAD-11172-1348971468-380.31455-15-0@perl.org
On Thu Sep 16 02:18:01 2004, ni-s wrote:
> Jim Carter <jimc@math.ucla.edu> writes:
> >On Mon, 6 Sep 2004, Nick Ing-Simmons via RT wrote:
> >> Can you try this with
> >> PERLIO=perlio perl ...
> >> and
> >> PERLIO=stdio perl ...
> >
> >Yes, it fails equally with perlio and stdio.
> 
> Good - principle of least surprise seems to be working for our perlio
> clone of stdio behaviour ;-)
> 
> >
> >Do I _need_ to do a dup?  My original motivation was to use standard
> >features to encompass this unusual case: normally the table is a
> plain file
> >named on the command line, but for ultra paranoia I concatenate the
> script
> >and the table, and then specify '<&DATA'.  As a workaround, what I'm
> doing
> >now is to test for the string '<&DATA', and in that case return
> \*DATA
> >rather than opening the so-called filename.
> >
> >I kind of figured that when a stream was duped, the remainder of the
> >original filehandle's buffer would be pre-stuffed into the new stream
> >object, so the duplication would be exact.
> 
> It does not work like that (as you have discovered). Pre-stuffing
> buffer is no use if (as is common) dup is for benefit of a sub-
> process.
> Instead it tries to achieve same effect by doing seek().
> 
> >But of course that takes work,
> 
> We could probably pre-stuff buffers most places (at least with
> :perlio),
> but I am unconvinced it would be a big win.
> 
> >and the cross-platform issues are probably a disaster.  If a
> partially used
> >stream object were copied either by memcpy
> 
> Wouldn't work - two streams would try and use same buffer memory.
> 
> >or by its copy constructor,
> 
> Most IO libraries are not C++ but C - so no such thing as a "copy
> constructor".
> 
> As I say for :perlio we could make ->Dup() call pre-stuff the buffer.
> Perhaps we could do that if seek fails, but that won't help
> if dup'ed handle is handed off to a sub-process or accessed
> with unbuffered IO.
> So I am not sure it is enough "better" to be worth the
> complexity speed hit etc.
> 
> >I
> >wonder if the result would be useable on most platforms?
> >
> >Your point is well taken that both instances share the same file
> pointer,
> >so if you do buffered I/O from both instances interleaved, the data
> would
> >be totally trashed.
> >
> >James F. Carter          Voice 310 825 2897    FAX 310 206 6673
> >UCLA-Mathnet;  6115 MSA; 405 Hilgard Ave.; Los Angeles, CA, USA
> 90095-1555
> >Email: jimc@math.ucla.edu    http://www.math.ucla.edu/~jimc (q.v. for
> PGP key)
> 

This is another RT where the person who was responding to the OP's
problem is no longer with us.

Is there anyone who could review the issues raised in this ticket and
make a recommendation?

Thank you very much.
Jim Keenan


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=31455

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