Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[perl #5971] IO::Handle setvbuf bug

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-followup at perl

May 5, 2012, 4:59 AM

Post #1 of 4 (86 views)
Permalink
[perl #5971] IO::Handle setvbuf bug

On Wed Jul 28 20:27:39 2010, greerga wrote:
> This isn't "PerlIO" per se because the documentation notes:
>
> - - - 8< - - - 8< - - -
> WARNING: The IO::Handle::setvbuf() is not available by default on Perls
> 5.8.0 and later because setvbuf() is rather specific to using the stdio
> library, while Perl prefers the new perlio subsystem instead.
> - - - 8< - - - 8< - - -
>
> Indeed on Linux I get:
> IO::Handle::setvbuf not implemented on this architecture at -e line 1.

How would I need to compile Perl to test if this is still present?


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


tony at develop-help

May 7, 2012, 4:54 PM

Post #2 of 4 (76 views)
Permalink
Re: [perl #5971] IO::Handle setvbuf bug [In reply to]

On Sat, May 05, 2012 at 04:59:02AM -0700, Brian Fraser via RT wrote:
> On Wed Jul 28 20:27:39 2010, greerga wrote:
> > This isn't "PerlIO" per se because the documentation notes:
> >
> > - - - 8< - - - 8< - - -
> > WARNING: The IO::Handle::setvbuf() is not available by default on Perls
> > 5.8.0 and later because setvbuf() is rather specific to using the stdio
> > library, while Perl prefers the new perlio subsystem instead.
> > - - - 8< - - - 8< - - -
> >
> > Indeed on Linux I get:
> > IO::Handle::setvbuf not implemented on this architecture at -e line 1.
>
> How would I need to compile Perl to test if this is still present?

You'd have to build perl without perlio, but Configure now always
enables perlio.

Tony


nick at ccl4

May 8, 2012, 6:51 AM

Post #3 of 4 (72 views)
Permalink
Re: [perl #5971] IO::Handle setvbuf bug [In reply to]

On Tue, May 08, 2012 at 09:54:20AM +1000, Tony Cook wrote:
> On Sat, May 05, 2012 at 04:59:02AM -0700, Brian Fraser via RT wrote:
> > On Wed Jul 28 20:27:39 2010, greerga wrote:
> > > This isn't "PerlIO" per se because the documentation notes:
> > >
> > > - - - 8< - - - 8< - - -
> > > WARNING: The IO::Handle::setvbuf() is not available by default on Perls
> > > 5.8.0 and later because setvbuf() is rather specific to using the stdio
> > > library, while Perl prefers the new perlio subsystem instead.
> > > - - - 8< - - - 8< - - -
> > >
> > > Indeed on Linux I get:
> > > IO::Handle::setvbuf not implemented on this architecture at -e line 1.
> >
> > How would I need to compile Perl to test if this is still present?
>
> You'd have to build perl without perlio, but Configure now always
> enables perlio.

"Now" as in post 5.15.0

If I build 5.14.0 like this:

./Configure -de -Uuseperlio && make -j5 test_prep

I see the same confusing difference:

$ strace -oout -ewrite ./perl -Ilib -wle 'use IO::Handle '_IOLBF'; STDERR->setvbuf(my $buffer_var, _IOLBF, 1024); print STDERR "hoidyhu", "wowgrrr"'
hoidyhuwowgrrr
$ cat out
write(2, "hoidyhuwowgrrr\n", 15) = 15

$ strace -oout -ewrite ./perl -Ilib -wle 'use IO::Handle '_IOLBF'; STDERR->setvbuf($buffer_var, _IOLBF, 1024); print STDERR "hoidyhu", "wowgrrr"'
Name "main::buffer_var" used only once: possible typo at -e line 1.
hoidyhuwowgrrr
$ cat out
write(2, "Name \"main::buffer_var\" used onl"..., 68) = 68
write(2, "h", 1) = 1
write(2, "oidyhu", 6) = 6
write(2, "w", 1) = 1
write(2, "owgrrr", 6) = 6
write(2, "\n", 1) = 1


Nicholas Clark


nick at ccl4

May 8, 2012, 8:03 AM

Post #4 of 4 (86 views)
Permalink
Re: [perl #5971] IO::Handle setvbuf bug [In reply to]

On Tue, May 08, 2012 at 02:51:51PM +0100, Nicholas Clark wrote:
> On Tue, May 08, 2012 at 09:54:20AM +1000, Tony Cook wrote:
> > On Sat, May 05, 2012 at 04:59:02AM -0700, Brian Fraser via RT wrote:
> > > On Wed Jul 28 20:27:39 2010, greerga wrote:
> > > > This isn't "PerlIO" per se because the documentation notes:
> > > >
> > > > - - - 8< - - - 8< - - -
> > > > WARNING: The IO::Handle::setvbuf() is not available by default on Perls
> > > > 5.8.0 and later because setvbuf() is rather specific to using the stdio
> > > > library, while Perl prefers the new perlio subsystem instead.
> > > > - - - 8< - - - 8< - - -
> > > >
> > > > Indeed on Linux I get:
> > > > IO::Handle::setvbuf not implemented on this architecture at -e line 1.
> > >
> > > How would I need to compile Perl to test if this is still present?
> >
> > You'd have to build perl without perlio, but Configure now always
> > enables perlio.
>
> "Now" as in post 5.15.0
>
> If I build 5.14.0 like this:
>
> ./Configure -de -Uuseperlio && make -j5 test_prep
>
> I see the same confusing difference:
>
> $ strace -oout -ewrite ./perl -Ilib -wle 'use IO::Handle '_IOLBF'; STDERR->setvbuf(my $buffer_var, _IOLBF, 1024); print STDERR "hoidyhu", "wowgrrr"'
> hoidyhuwowgrrr
> $ cat out
> write(2, "hoidyhuwowgrrr\n", 15) = 15
>
> $ strace -oout -ewrite ./perl -Ilib -wle 'use IO::Handle '_IOLBF'; STDERR->setvbuf($buffer_var, _IOLBF, 1024); print STDERR "hoidyhu", "wowgrrr"'
> Name "main::buffer_var" used only once: possible typo at -e line 1.
> hoidyhuwowgrrr
> $ cat out
> write(2, "Name \"main::buffer_var\" used onl"..., 68) = 68
> write(2, "h", 1) = 1
> write(2, "oidyhu", 6) = 6
> write(2, "w", 1) = 1
> write(2, "owgrrr", 6) = 6
> write(2, "\n", 1) = 1

Ho ho ho.

$ strace -ofixed -ewrite ./perl -Ilib -wle 'use IO::Handle '_IOLBF'; STDERR->setvbuf($buffer_var, _IOLBF, 1024); print STDERR "hoidyhu", "wowgrrr"; 0 if $buffer_var;'
hoidyhuwowgrrr
$ cat fixed
write(2, "hoidyhuwowgrrr\n", 15) = 15

From the C library man page:

Except for unbuffered files, the buf argument should point to a buffer
at least size bytes long; this buffer will be used instead of the cur-
rent buffer. If the argument buf is NULL, only the mode is affected; a
new buffer will be allocated on the next read or write operation. The
setvbuf() function may only be used after opening a stream and before
any other operations have been performed on it.


What's going wrong in the test case is that the used only once warning is
causing output to STDERR before setvbuf() is called, which violates the
calling constraints.


IO::Handle's documentation says.

You should only change the buffer before any I/O, or immediately after
calling flush.


This actually seems to be erroneous, as calling flush on the handle *doesn't*
make setvbuf "work".

$ strace -obug -ewrite ./perl -Ilib -wle 'use IO::Handle '_IOLBF'; STDERR->flush or die; STDERR->setvbuf($buffer_var, _IOLBF, 1024); print STDERR "hoidyhu", "wowgrrr";'
Name "main::buffer_var" used only once: possible typo at -e line 1.
hoidyhuwowgrrr
$ cat bug
write(2, "Name \"main::buffer_var\" used onl"..., 68) = 68
write(2, "h", 1) = 1
write(2, "oidyhu", 6) = 6
write(2, "w", 1) = 1
write(2, "owgrrr", 6) = 6
write(2, "\n", 1) = 1


Looks like a fix to IO::Handle's documentation is needed.

Also, I guess that we should take this part out of its synopsis:

# setvbuf is not available by default on Perls 5.8.0 and later.
use IO::Handle '_IOLBF';
$io->setvbuf($buffer_var, _IOLBF, 1024);

as it's really not useful any more.

Nicholas Clark

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.