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

:encoding() returns wrong value on eof #9882

Open
p5pRT opened this issue Sep 23, 2009 · 6 comments
Open

:encoding() returns wrong value on eof #9882

p5pRT opened this issue Sep 23, 2009 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 23, 2009

Migrated from rt.perl.org#69332 (status was 'open')

Searchable as RT69332$

@p5pRT
Copy link
Author

p5pRT commented Sep 23, 2009

From @ikegami

Created by @ikegami

When using :encoding, read() returns undef at eof rather than zero.

----- BEGIN code -----
#!/usr/bin/perl

use strict;
use warnings;

sub test {
  my ($fh) = @​_;
  my $buf = '';
  for (1..3) {
  my $rv = read($fh, $buf, 1, length($buf));
  if (defined($rv)) {
  print("read = $rv\n");
  } else {
  print("read = undef, \$!=$!\n");
  }
  }
}

{ open(my $fh, '<', \'ab') or die; test($fh); }
{ open(my $fh, '<​:encoding(iso-8859-1)', \'ab') or die; test($fh); }
----- END code -----

----- BEGIN output -----
read = 1
read = 1
read = 0

read = 1
read = 1
read = undef, $!=
----- END output -----

(newline added for readability)

I haven't managed to track down the cause.

Perl Info

Flags:
    category=library
    severity=low
    module=PerlIO::encoding

Site configuration information for perl 5.10.1:

Configured by SYSTEM at Mon Aug 24 13:48:02 2009.

Summary of my perl5 (revision 5 version 10 subversion 1) configuration:

  Platform:
    osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE
-DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.00.8804', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf
-libpath:"C:\progs\perl5101\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf  -libpath:"C:\progs\perl5101\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY
    32728 64-bit fix for Time::Local


@INC for perl 5.10.1:
    c:/Progs/perl5101/site/lib
    c:/Progs/perl5101/lib
    .


Environment for perl 5.10.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=c:\bin;c:\progs\perl5101\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\WBEM
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2009

From @obra

Replicated on 5.10.0, vanilla 5.10.1 and 5.11.0

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2009

@obra - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2009

From @obra

On Sat Oct 10 12​:33​:53 2009, jesse wrote​:

Replicated on 5.10.0, vanilla 5.10.1 and 5.11.0

Also, 5.8.8

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2009

From @obra

When using :encoding, read() returns undef at eof rather than zero.

Thanks very much for your report, Eric. As it turns out, this is a somewhat
longstanding bug and pertains to all PerlIO layers, not just :encoding().

I've added a TODO test based on your report to blead as of commit 86cb0d3.

Best,
Jesse

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 2009

From @obra

16​:21 <@​Nicholas> also, as to PerIO behaviour
16​:21 <@​Nicholas> I think that the answer is "whatever 5.005 does without
  PerlIO is more likely to be the 'right' answer"

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

No branches or pull requests

2 participants