Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a possible Perl bug about IO::String and $/ in Perl 5.8.6 on Linux/Solaris/MacOS X #7923

Closed
p5pRT opened this issue May 22, 2005 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented May 22, 2005

Migrated from rt.perl.org#35929 (status was 'resolved')

Searchable as RT35929$

@p5pRT
Copy link
Author

p5pRT commented May 22, 2005

From hseuming@cs.nyu.edu

Dear fellow Perl lovers,

The Perl version i use is 5.8.6 on Linux, Mac OS X,
and Sun Solaris 8.

The following self-contained program dies with a
"read failed" message​:

  #!/usr/local/bin/perl -w

  use strict;

  my $s = <<'EOF';
  line A
  line B
  a third line
  EOF

  open (F, '<', \$s)
  or die "Could not open string as a file";
  local $/ = "";
  my $ln = <F>;
  die "read failed" unless defined $ln;
  close F;

However, if I have it read from a file with the
same contents as $s instead of $s itself, it
succeeds. To wit​:

  #!/usr/local/bin/perl -w

  use strict;

  my $s = <<'EOF';
  line A
  line B
  a third line
  EOF

  open (F, '>', "/var/tmp/Z");
  print F $s;
  close F;

  open (F, '<', "/var/tmp/Z")
  or die "Could not open string as a file";
  local $/ = "";
  my $ln = <F>;
  die "read failed" unless defined $ln;
  close F;

This looks like a bona-fide Perl bug. Am I
missing something?

Note that reading from them works fine as long
as I don't touch $/.

-- Hseuming


Emails :​: hseuming.chen@​citigroup.com hseuming@​cs.nyu.edu
  hseuming@​gnu.mit.edu hseuming@​yahoo.com
  hseuming@​gmail.com hseuming@​hotmail.com

Phones :​: (908)563-0029 (o) (973)597-1801 (h)
--------------------------------------------------------------_

@p5pRT
Copy link
Author

p5pRT commented May 22, 2005

From @schwern

On Sun, May 22, 2005 at 06​:09​:41AM -0000, Hseu-Ming Chen wrote​:

The following self-contained program dies with a
"read failed" message​:

#!/usr/local/bin/perl -w

use strict;

my $s = <<'EOF';
line A
line B
a third line
EOF

open (F, '<', \$s)
or die "Could not open string as a file";
local $/ = "";
my $ln = <F>;
die "read failed" unless defined $ln;
close F;

Note that reading from them works fine as long
as I don't touch $/.

Yeah, I can repeat this bug and confirm that "local $/ = ''"; is the
problem. Interestingly, "local $/;" works as does "local $/ = undef;".

--
Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern
Don't try the paranormal until you know what's normal.
  -- "Lords and Ladies" by Terry Prachett

@p5pRT
Copy link
Author

p5pRT commented May 22, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 22, 2005

From @rgarcia

On 22 May 2005 06​:09​:41 -0000, via RT Hseu-Ming Chen
<perlbug-followup@​perl.org> wrote​:

The following self-contained program dies with a
"read failed" message​:

#!/usr/local/bin/perl -w

use strict;

my $s = <<'EOF';
line A
line B
a third line
EOF

open (F, '<', \$s)
or die "Could not open string as a file";
local $/ = "";
my $ln = <F>;
die "read failed" unless defined $ln;
close F;

The bug is in PerlIOScalar_unread, which doesn't do what it should.
The following patch solves this particular problem, but it's obviously
not sufficient... it's late and I'll try to work out a proper solution
another day.

==== //depot/perl/ext/PerlIO/scalar/scalar.xs#12 -
/opt/bleadperl/p4/perl/ext/PerlIO/scalar/scalar.xs ====
--- /home/rafael/tmp/tmp.21342.0 2005-05-23 00​:36​:44.351368184 +0200
+++ /opt/bleadperl/p4/perl/ext/PerlIO/scalar/scalar.xs 2005-05-23
00​:36​:37.732374424 +0200
@​@​ -105,11 +105,7 @​@​ SSize_t
PerlIOScalar_unread(pTHX_ PerlIO * f, const void *vbuf, Size_t count)
{
  PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar);
- char *dst = SvGROW(s->var, (STRLEN)s->posn + count);
- Move(vbuf, dst + s->posn, count, char);
- s->posn += count;
- SvCUR_set(s->var, (STRLEN)s->posn);
- SvPOK_on(s->var);
+ s->posn -= count;
  return count;
}

@p5pRT
Copy link
Author

p5pRT commented May 23, 2005

From @rgarcia

On 5/23/05, Rafael Garcia-Suarez <rgarciasuarez@​gmail.com> wrote​:

The bug is in PerlIOScalar_unread, which doesn't do what it should.
The following patch solves this particular problem, but it's obviously
not sufficient... it's late and I'll try to work out a proper solution
another day.

Now hopefully implemented in bleadperl as :

Change 24543 on 2005/05/23 by rgs@​marais

  Fix [perl #35929] : PerlIO​::scalar didn't understand $/ = ""
  because PerlIOScalar_unread was broken.
  Bump version number of PerlIO​::scalar to 0.04.

@p5pRT p5pRT closed this as completed May 23, 2005
@p5pRT
Copy link
Author

p5pRT commented May 23, 2005

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant