Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

Bug in IO::Handle method ioctl #1147

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

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

Searchable as RT2109$

p5pRT commented 24 years ago

From private@claudio.ch

Created by private@claudio.ch

my $file=new IO​::File; ... correct open of file ... $file->ioctl(someReadOP\,$value);

does not work\, while ioctl($file\,someReadOp\,$value) does.

This is ioctl in IO​::Handle.pm

560​: sub ioctl { 561​: @​_ == 3 || croak 'usage​: $io->ioctl( OP\, VALUE );'; 562​: my ($io\, $op\, $val) = @​_; 563​: my $r = ioctl($io\, $op\, $val); 564​: defined $r && $r eq "0 but true" ? 0 : $r; 565​: }

The $val passed to ioctl in line 563 is a local variable because of the declaration in line 562. So any ioctl which reads a value will fill in $val instead of the parameter passed to $file->ioctl.

To fix this\, line 563 has to be changed into​:

  my $r = ioctl($io\, $op\, $_[2]);

This works (tested) because $_[2] is really the 2nd parameter passed to $file->ioctl(someReadOp\,$value).

Perl Info ``` Site configuration information for perl 5.00503: Configured by claudio at Sat Nov 13 01:05:54 Local time zone must be set--see zic manual page 1999. Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=linux, osvers=2.2.13, archname=ppc-linux-thread uname='linux pb.claudio.ch 2.2.13 #1 tue oct 12 22:10:46 cest 1999 ppc unknow n ' hint=previous, useposix=true, d_sigaction=define usethreads=define useperlio=undef d_sfio=undef Compiler: cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314 (egcs-1.1.2 release ) cppflags='-D_REENTRANT -Dbool=char -DHAS_BOOL' ccflags ='-D_REENTRANT -Dbool=char -DHAS_BOOL' stdchar='char', d_stdstdio=undef, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8 alignbytes=8, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags ='' libpth=/usr/lib libs=-lnsl -lndbm -ldb -ldl -lm -lpthread -lc -lposix -lcrypt libc=, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared' Locally applied patches: @INC for perl 5.00503: /opt/perl-5.005_03/lib/5.00503/ppc-linux-thread /opt/perl-5.005_03/lib/5.00503 /opt/perl-5.005_03/lib/site_perl/5.005/ppc-linux-thread /opt/perl-5.005_03/lib/site_perl/5.005 . Environment for perl 5.00503: HOME=/home/claudio LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/usr/lib LOGDIR (unset) PATH=/usr/bin PERL_BADLANG (unset) SHELL=/usr/bin/bash -- Claudio Nieder, Kanalweg 1, CH-8610 Uster ,'`.,'`.,'`.,'`.,'`.,'`.,'` mailto:private@claudio.ch http://www.claudio.ch phone:+41 79 357 6743 ```
p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

Why would you use IO​::Handle's ioctl function!? Why isn't this a function call? I see no reason to cloak all possible perl I/O functions in method calls. There's no benefit to writing

  FH->ioctl(...) over   ioctl(FH\, ...)

--tom

p5pRT commented 24 years ago

From The RT System itself

Hi\,

Why would you use IO​::Handle's ioctl function!? Why isn't this a function call? I see no reason to cloak all possible perl I/O functions in method calls. There's no benefit to writing

FH\->ioctl\(\.\.\.\)

Because I got used to do my $file=new IO​::File; $file->open $file->getline etc.

But I could very well live with an IO​::Handle who doesn't implement any method except new\, and use my $file=new IO​::File; open($file) \<$file> etc. if that is thought to be the preferred way of doing it.

I just think it's bad when $file->ioctl() looks like if it would work\, but then doesn't fully. Either fix it\, or throw it away.

  claudio -- Claudio Nieder\, Kanalweg 1\, CH-8610 Uster \,'`.\,'`.\,'`.\,'`.\,'`.\,'`.\,'` mailto​:private@​claudio.ch http​://www.claudio.ch phone​:+41 79 357 6743