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

IO::Tty: if(defined BAREWORD) is always true #7543

Closed
p5pRT opened this issue Oct 18, 2004 · 11 comments
Closed

IO::Tty: if(defined BAREWORD) is always true #7543

p5pRT opened this issue Oct 18, 2004 · 11 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 18, 2004

Migrated from rt.perl.org#32032 (status was 'rejected')

Searchable as RT32032$

@p5pRT
Copy link
Author

p5pRT commented Oct 18, 2004

From tex@gblx.net

  Included is a message I sent to the Expect.pm list regarding the
behavior of IO​::Tty. What I discovered while debugging the error was very
strange behavior of defined(). I was able to recreate this error using both
perl 5.8.0 and 5.8.4, so I suspect it is a bug endemic to the 5.8 series.

  In order to recreate the bug, TIOCSCTTY must not be defined. This
may be accomplished by using a system which doesn't define this constant
or by commenting out or undefining it.

  After building IO​::Tty, make test will warn "warning​: TIOCSCTTY failed"
because the test if(defined TIOCSCTTY) at line 118 succeeds even though
TIOCSCTTY is set to undef, and is clearly set as such by the module.

  IO​::Tty version was 1.02, I've recreated this on a couple systems
verying both by perl version and OS, so I'm not including my perl -V
information here.

  Please let me know if there is anything I can do to help fix
this bug or provide more relevant information.

  Thanks muchly,

  Austin

----- Forwarded message from Austin Schutz <tex@​off.org> -----

Date​: Fri, 8 Oct 2004 13​:48​:13 -0700
From​: Austin Schutz <tex@​off.org>
To​: Roland Giersig <RGiersig@​cpan.org>
Cc​: Austin Schutz <tex@​off.org>, Zhisong Jin <jjin@​dynaccsys.com>,
expectperl-discuss@​lists.sourceforge.net
Subject​: Re​: [Expectperl-discuss] re​: building Expect.pm on solaris 9

On Fri, Oct 08, 2004 at 11​:28​:37AM +0200, Roland Giersig wrote​:

Hmm, in the 'perl Makefile.PL' step I'm trying to figure out what
constants are defined by compiling test progs for each constant. Austin,
as you seem to have a solaris machine on your hands, could you look into
that and see why it gets defined?

On my solaris machine I'm not able to replicate the issue because

I'm running an old perl​: 5.00503, which doesn't exhibit this problem and
I can't get 5.8.4 to compile.
However, I _was_ able to replicate this on my home linux workstation
by commenting out #define TIOCSCTTY in /usr/include/asm/ioctls.h.

I'm not sure why the code in question is being executed\. Running

it in the debugger I still couldn't figure it out (output follows). It looks
to me like a perl bug. However, I was able to work around it by changing line
118 to​:

if (defined TIOCSCTTY && TIOCSCTTY) {

which \_should\_ be valid \- I doubt any vendor defines TIOCSCTTY as 0\.

Austin

DB<5> p defined TIOCSCTTY

DB<6> l
118==> if (defined TIOCSCTTY) {
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
120​: warn "warning​: TIOCSCTTY failed, slave might not be set as control
ling terminal​: $!" if $^W;
121 }
122 } elsif (defined TCSETCTTY) {
123​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TCSETCTTY, 0 )) {
124​: warn "warning​: TCSETCTTY failed, slave might not be set as control
ling terminal​: $!" if $^W;
125 }
126 }
127
DB<6> s
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/
IO/Pty.pm​:119)​:
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
DB<6> p defined TIOCSCTTY

DB<7> p defined TIOCSCTTY

DB<8> if(defined TIOCSCTTY) { print "defined\n"; }

DB<9> n
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm​:119)​:
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
DB<9> n
Use of uninitialized value in ioctl at /root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm line 119, <XT> line 1.
IO​::Pty​::make_slave_controlling_terminal('IO​::Pty=GLOB(0x8171f8c)') called at test.pl line 66
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm​:120)​:
120​: warn "warning​: TIOCSCTTY failed, slave might not be set as controlling terminal​: $!" if $^W;

----- End forwarded message -----

@p5pRT
Copy link
Author

p5pRT commented Oct 19, 2004

From nick@ing-simmons.net

Austin Schutz <perl5-porters@​perl.org> writes​:

# New Ticket Created by Austin Schutz
# Please include the string​: [perl #32032]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=32032 >

Included is a message I sent to the Expect.pm list regarding the
behavior of IO​::Tty. What I discovered while debugging the error was very
strange behavior of defined(). I was able to recreate this error using both
perl 5.8.0 and 5.8.4, so I suspect it is a bug endemic to the 5.8 series.

In order to recreate the bug, TIOCSCTTY must not be defined. This
may be accomplished by using a system which doesn't define this constant
or by commenting out or undefining it.

After building IO​::Tty, make test will warn "warning​: TIOCSCTTY failed"
because the test if(defined TIOCSCTTY) at line 118 succeeds even though
TIOCSCTTY is set to undef, and is clearly set as such by the module.

If TIOSCTTY isn't a constant sub it is a bareword i.e. a string.
So that is like writing

  if (defined("TIOSCTTY"))

ands strings are always defined.

I think it should be written as

  if (defined(&TIOSCTTY) && TIOSCTTY())

IO​::Tty version was 1.02, I've recreated this on a couple systems
verying both by perl version and OS, so I'm not including my perl -V
information here.

Please let me know if there is anything I can do to help fix
this bug or provide more relevant information.

Thanks muchly,

Austin

----- Forwarded message from Austin Schutz <tex@​off.org> -----

Date​: Fri, 8 Oct 2004 13​:48​:13 -0700
From​: Austin Schutz <tex@​off.org>
To​: Roland Giersig <RGiersig@​cpan.org>
Cc​: Austin Schutz <tex@​off.org>, Zhisong Jin <jjin@​dynaccsys.com>,
expectperl-discuss@​lists.sourceforge.net
Subject​: Re​: [Expectperl-discuss] re​: building Expect.pm on solaris 9

On Fri, Oct 08, 2004 at 11​:28​:37AM +0200, Roland Giersig wrote​:

Hmm, in the 'perl Makefile.PL' step I'm trying to figure out what
constants are defined by compiling test progs for each constant. Austin,
as you seem to have a solaris machine on your hands, could you look into
that and see why it gets defined?

On my solaris machine I'm not able to replicate the issue because

I'm running an old perl​: 5.00503, which doesn't exhibit this problem and
I can't get 5.8.4 to compile.
However, I _was_ able to replicate this on my home linux workstation
by commenting out #define TIOCSCTTY in /usr/include/asm/ioctls.h.

I'm not sure why the code in question is being executed\. Running

it in the debugger I still couldn't figure it out (output follows). It looks
to me like a perl bug. However, I was able to work around it by changing line
118 to​:

if (defined TIOCSCTTY && TIOCSCTTY) {

which \_should\_ be valid \- I doubt any vendor defines TIOCSCTTY as 0\.

Austin

DB<5> p defined TIOCSCTTY

DB<6> l
118==> if (defined TIOCSCTTY) {
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
120​: warn "warning​: TIOCSCTTY failed, slave might not be set as control
ling terminal​: $!" if $^W;
121 }
122 } elsif (defined TCSETCTTY) {
123​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TCSETCTTY, 0 )) {
124​: warn "warning​: TCSETCTTY failed, slave might not be set as control
ling terminal​: $!" if $^W;
125 }
126 }
127
DB<6> s
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/
IO/Pty.pm​:119)​:
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
DB<6> p defined TIOCSCTTY

DB<7> p defined TIOCSCTTY

DB<8> if(defined TIOCSCTTY) { print "defined\n"; }

DB<9> n
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm​:119)​:
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
DB<9> n
Use of uninitialized value in ioctl at /root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm line 119, <XT> line 1.
IO​::Pty​::make_slave_controlling_terminal('IO​::Pty=GLOB(0x8171f8c)') called at test.pl line 66
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm​:120)​:
120​: warn "warning​: TIOCSCTTY failed, slave might not be set as controlling terminal​: $!" if $^W;

----- End forwarded message -----

@p5pRT
Copy link
Author

p5pRT commented Oct 19, 2004

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

@p5pRT
Copy link
Author

p5pRT commented Oct 20, 2004

From tex@off.org

On Tue, Oct 19, 2004 at 01​:21​:52PM -0000, Nick Ing-Simmons via RT wrote​:

Austin Schutz <perl5-porters@​perl.org> writes​:

# New Ticket Created by Austin Schutz
# Please include the string​: [perl #32032]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org​:80/rt3/Ticket/Display.html?id=32032 >

Included is a message I sent to the Expect.pm list regarding the
behavior of IO​::Tty. What I discovered while debugging the error was very
strange behavior of defined(). I was able to recreate this error using both
perl 5.8.0 and 5.8.4, so I suspect it is a bug endemic to the 5.8 series.

In order to recreate the bug, TIOCSCTTY must not be defined. This
may be accomplished by using a system which doesn't define this constant
or by commenting out or undefining it.

After building IO​::Tty, make test will warn "warning​: TIOCSCTTY failed"
because the test if(defined TIOCSCTTY) at line 118 succeeds even though
TIOCSCTTY is set to undef, and is clearly set as such by the module.

If TIOSCTTY isn't a constant sub it is a bareword i.e. a string.

  It is a constant sub.

So that is like writing

     if \(defined\("TIOSCTTY"\)\)

ands strings are always defined.

  The behavior is not consistent between older and newer perls. But
the real problem is it is not consistent here either. Note that the
debugger admits that defined(TIOSCTTY) is not defined, but if() follows
it anyway. I actually tried changing the code to defined(&TIOSCTTY) and
it _still_ followed the wrong branch.

  Austin

I think it should be written as

     if \(defined\(&TIOSCTTY\) && TIOSCTTY\(\)\)

IO​::Tty version was 1.02, I've recreated this on a couple systems
verying both by perl version and OS, so I'm not including my perl -V
information here.

Please let me know if there is anything I can do to help fix
this bug or provide more relevant information.

Thanks muchly,

Austin

----- Forwarded message from Austin Schutz <tex@​off.org> -----

Date​: Fri, 8 Oct 2004 13​:48​:13 -0700
From​: Austin Schutz <tex@​off.org>
To​: Roland Giersig <RGiersig@​cpan.org>
Cc​: Austin Schutz <tex@​off.org>, Zhisong Jin <jjin@​dynaccsys.com>,
expectperl-discuss@​lists.sourceforge.net
Subject​: Re​: [Expectperl-discuss] re​: building Expect.pm on solaris 9

On Fri, Oct 08, 2004 at 11​:28​:37AM +0200, Roland Giersig wrote​:

Hmm, in the 'perl Makefile.PL' step I'm trying to figure out what
constants are defined by compiling test progs for each constant. Austin,
as you seem to have a solaris machine on your hands, could you look into
that and see why it gets defined?

On my solaris machine I'm not able to replicate the issue because

I'm running an old perl​: 5.00503, which doesn't exhibit this problem and
I can't get 5.8.4 to compile.
However, I _was_ able to replicate this on my home linux workstation
by commenting out #define TIOCSCTTY in /usr/include/asm/ioctls.h.

I'm not sure why the code in question is being executed\. Running

it in the debugger I still couldn't figure it out (output follows). It looks
to me like a perl bug. However, I was able to work around it by changing line
118 to​:

if (defined TIOCSCTTY && TIOCSCTTY) {

which \_should\_ be valid \- I doubt any vendor defines TIOCSCTTY as 0\.

Austin

DB<5> p defined TIOCSCTTY

DB<6> l
118==> if (defined TIOCSCTTY) {
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
120​: warn "warning​: TIOCSCTTY failed, slave might not be set as control
ling terminal​: $!" if $^W;
121 }
122 } elsif (defined TCSETCTTY) {
123​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TCSETCTTY, 0 )) {
124​: warn "warning​: TCSETCTTY failed, slave might not be set as control
ling terminal​: $!" if $^W;
125 }
126 }
127
DB<6> s
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/
IO/Pty.pm​:119)​:
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
DB<6> p defined TIOCSCTTY

DB<7> p defined TIOCSCTTY

DB<8> if(defined TIOCSCTTY) { print "defined\n"; }

DB<9> n
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm​:119)​:
119​: if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
DB<9> n
Use of uninitialized value in ioctl at /root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm line 119, <XT> line 1.
IO​::Pty​::make_slave_controlling_terminal('IO​::Pty=GLOB(0x8171f8c)') called at test.pl line 66
IO​::Pty​::make_slave_controlling_terminal(/root/.cpan/build/IO-Tty-1.02/blib/lib/IO/Pty.pm​:120)​:
120​: warn "warning​: TIOCSCTTY failed, slave might not be set as controlling terminal​: $!" if $^W;

----- End forwarded message -----

@p5pRT
Copy link
Author

p5pRT commented Oct 20, 2004

From tex@off.org

If TIOSCTTY isn't a constant sub it is a bareword i.e. a string.

It is a constant sub\.

  Err, sorry, no coffee yet. I don't think it's a constant sub, it's
set to &PL_sv_undef, which I guess would be an undef scalar.
  That still doesn't explain why the debugger admits to it not being
defined but it still following the branch anyway.

  Austin

@p5pRT
Copy link
Author

p5pRT commented May 27, 2012

From @jkeenan

On Tue Oct 19 17​:21​:50 2004, tex@​off.org wrote​:

If TIOSCTTY isn't a constant sub it is a bareword i.e. a string.

It is a constant sub\.
Err\, sorry\, no coffee yet\.  I don't think it's a constant sub\, it's

set to &PL_sv_undef, which I guess would be an undef scalar.
That still doesn't explain why the debugger admits to it not being
defined but it still following the branch anyway.

Austin

Discussion in this RT petered out nearly eight years ago, and ni-s has
passed away. Is there anyone familiar with IO​::Tty who could review
this ticket and see whether we have a bug in Perl's defined built-in, a
bug in that module, or some combination thereof?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented May 31, 2012

From @doy

On Sat, May 26, 2012 at 06​:52​:22PM -0700, James E Keenan via RT wrote​:

On Tue Oct 19 17​:21​:50 2004, tex@​off.org wrote​:

If TIOSCTTY isn't a constant sub it is a bareword i.e. a string.

It is a constant sub\.
Err\, sorry\, no coffee yet\.  I don't think it's a constant sub\, it's

set to &PL_sv_undef, which I guess would be an undef scalar.
That still doesn't explain why the debugger admits to it not being
defined but it still following the branch anyway.

Austin

Discussion in this RT petered out nearly eight years ago, and ni-s has
passed away. Is there anyone familiar with IO​::Tty who could review
this ticket and see whether we have a bug in Perl's defined built-in, a
bug in that module, or some combination thereof?

Thank you very much.
Jim Keenan

The changes in IO​::Tty 1.03 look possibly relevant here.

-doy

@p5pRT
Copy link
Author

p5pRT commented Jun 19, 2013

From @jkeenan

On Thu May 31 15​:16​:07 2012, doy@​tozt.net wrote​:

On Sat, May 26, 2012 at 06​:52​:22PM -0700, James E Keenan via RT wrote​:

On Tue Oct 19 17​:21​:50 2004, tex@​off.org wrote​:

If TIOSCTTY isn't a constant sub it is a bareword i.e. a string.

It is a constant sub\.
Err\, sorry\, no coffee yet\.  I don't think it's a constant sub\, it's

set to &PL_sv_undef, which I guess would be an undef scalar.
That still doesn't explain why the debugger admits to it not being
defined but it still following the branch anyway.

Austin

Discussion in this RT petered out nearly eight years ago, and ni-s has
passed away. Is there anyone familiar with IO​::Tty who could review
this ticket and see whether we have a bug in Perl's defined built-in, a
bug in that module, or some combination thereof?

Thank you very much.
Jim Keenan

The changes in IO​::Tty 1.03 look possibly relevant here.

-doy

They do look relevant, but they don't help with respect to writing a
test to reproduce the original problem. The original poster said that
on a system which does have TIOCSCTTY -- which I believe my Linux/i386
does -- one can "comment it out or undefine it" (paraphrase). But I
don't know how to do that.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jul 7, 2016

@dcollinsn - Status changed from 'open' to 'stalled'

@p5pRT
Copy link
Author

p5pRT commented Jul 7, 2016

From @dcollinsn

Requestor suggests that we edit our system headers to #undef TIOCSCTTL in order to reproduce. Because apparently I like breaking my everything, I tried it. Among other configurations, I tried to build and test IO​::Tty 1.02 on perl 5.8.4.

Makefile.PL detected that TIOCSCTTL was undefined on my system, make test passed, and there were no errors related to TIOCSCTTL. I even instrumented Pty.pm​: At line 118, TIOCSCTTL is undef according to Data​::Dumper, and the program does not execute the body of the `if (defined TIOCSCTTL)`.

I did try re#defining TIOCSCTTL to 0 in my system headers. Data​::Dumper now agrees that TIOCSCTTL is 0, and since 0 is defined, I get the behavior Austin reports. Similarly, #defining it to "" gives that behavior. In both cases, the symbol is defined to something that ioctl doesn't know what to do with. Garbage in, garbage out.

@p5pRT
Copy link
Author

p5pRT commented Jul 7, 2016

@dcollinsn - Status changed from 'stalled' to 'rejected'

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

1 participant