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

CORE::select ignoring timeout var's magic #13332

Closed
p5pRT opened this issue Oct 4, 2013 · 10 comments
Closed

CORE::select ignoring timeout var's magic #13332

p5pRT opened this issue Oct 4, 2013 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 4, 2013

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

Searchable as RT120102$

@p5pRT
Copy link
Author

p5pRT commented Oct 4, 2013

From @sanko

This is a bug report for perl from sanko@​cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.


Hi!

I've found that CORE​::select($$$$) mishandles magical timeout values
unless the var is used by some other means first. A minimum example
of this​:

  use Tie​::Scalar;
  tie (my $SLEEP_TIME, 'Tie​::StdScalar', 0.25);
  #print $SLEEP_TIME; # Uncomment this and select works just fine
  select (undef, undef, undef, $SLEEP_TIME);

This blocks indefinitely rather than the quarter second sleep I expect.

An example from dave_the_m shows that it isn't tie()-specific​:

  "5" =~ /(\d)/;
  #my $x = $1; # Uncomment this and select works just fine
  select (undef, undef, undef, $1);

Note that if the commented lines are uncommented in the above examples,
select works as is should.

Original discussion found on PerlMonks​: perlmonks.org/?node_id=1056913



Flags​:
  category=core
  severity=high


Site configuration information for perl 5.16.3​:

Configured by strawberry-perl at Tue Mar 12 13​:56​:09 2013.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration​:

  Platform​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
  uname='Win32 strawberry-perl 5.16.3.1 #1 Tue Mar 12 13​:55​:20 2013 i386'
  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='gcc', ccflags =' -s -O2 -DWIN32 -DPERL_TEXTMODE_SCRIPTS
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing
-mms-bitfields',
  optimize='-s -O2',
  cppflags='-DWIN32'
  ccversion='', gccversion='4.6.3', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='g++', ldflags ='-s -L"C​:\strawberry\perl\lib\CORE"
-L"C​:\strawberry\c\lib"'
  libpth=C​:\strawberry\c\lib C​:\strawberry\c\i686-w64-mingw32\lib
  libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr
-lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
  perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr
-lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
  libc=, so=dll, useshrplib=true, libperl=libperl516.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-mdll -s -L"C​:\strawberry\perl\lib\CORE"
-L"C​:\strawberry\c\lib"'

Locally applied patches​:


@​INC for perl 5.16.3​:
  C​:/strawberry/perl/site/lib/MSWin32-x86-multi-thread
  C​:/strawberry/perl/site/lib
  C​:/strawberry/perl/vendor/lib
  C​:/strawberry/perl/lib
  .


Environment for perl 5.16.3​:
  HOME=C​:\Users\Sanko
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)

PATH=C​:\Windows\system32;C​:\Windows;C​:\Windows\System32\Wbem;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\strawberry\c\bin;C​:\strawberry\perl\site\bin;C​:\strawberry\perl\bin;C​:\Ruby193\bin;C​:\Windows\system32;C​:\Windows;C​:\Windows\System32\Wbem;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Program
Files\Mercurial;C​:\strawberry\c\bin;C​:\strawberry\perl\site\bin;C​:\strawberry\perl\bin;C​:\Program
Files\Python32\Lib\site-packages\PyQt4;C​:\Program Files\Prio;C​:\Program
Files\git-cola\bin;C​:\Program Files\Git\cmd;C​:\Program Files\Git\bin;;
  PERL_BADLANG (unset)
  PERL_CPANM_OPT=--mirror http​://cpan.cpantesters.org --verbose --notest
--force
  SHELL (unset)
--
Sanko Robinson
sanko@​cpan.org

@p5pRT
Copy link
Author

p5pRT commented Oct 4, 2013

From @jkeenan

On Fri Oct 04 14​:10​:47 2013, sanko wrote​:

This is a bug report for perl from sanko@​cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.

-----------------------------------------------------------------
Hi!

I've found that CORE​::select($$$$) mishandles magical timeout values
unless the var is used by some other means first. A minimum example
of this​:

use Tie​::Scalar;
tie \(my $SLEEP\_TIME\, 'Tie​::StdScalar'\, 0\.25\);
\#print $SLEEP\_TIME; \# Uncomment this and select works just fine
select \(undef\, undef\, undef\, $SLEEP\_TIME\);

This blocks indefinitely rather than the quarter second sleep I
expect.

An example from dave_the_m shows that it isn't tie()-specific​:

"5" =~ /\(\\d\)/;
\#my $x = $1; \# Uncomment this and select works just fine
select \(undef\, undef\, undef\, $1\);

Note that if the commented lines are uncommented in the above
examples,
select works as is should.

Original discussion found on PerlMonks​: perlmonks.org/?node_id=1056913

Additional data, run on blead on Dromedary​:

Both of the following work​:

#########
"5" =~ /(\d)/;
my $x = $1;
select (undef, undef, undef, $1);
print "Done 1\n";

my $y = 5;
select (undef, undef, undef, $y);
print "Done 2\n";
#########

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Oct 4, 2013

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

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2013

From @ikegami

Patch attached.

On Fri, Oct 4, 2013 at 7​:15 PM, James E Keenan via RT <
perlbug-followup@​perl.org> wrote​:

On Fri Oct 04 14​:10​:47 2013, sanko wrote​:

This is a bug report for perl from sanko@​cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.

-----------------------------------------------------------------
Hi!

I've found that CORE​::select($$$$) mishandles magical timeout values
unless the var is used by some other means first. A minimum example
of this​:

use Tie&#8203;::Scalar;
tie \(my $SLEEP\_TIME\, 'Tie&#8203;::StdScalar'\, 0\.25\);
\#print $SLEEP\_TIME; \# Uncomment this and select works just fine
select \(undef\, undef\, undef\, $SLEEP\_TIME\);

This blocks indefinitely rather than the quarter second sleep I
expect.

An example from dave_the_m shows that it isn't tie()-specific​:

"5" =~ /\(\\d\)/;
\#my $x = $1; \# Uncomment this and select works just fine
select \(undef\, undef\, undef\, $1\);

Note that if the commented lines are uncommented in the above
examples,
select works as is should.

Original discussion found on PerlMonks​: perlmonks.org/?node_id=1056913

Additional data, run on blead on Dromedary​:

Both of the following work​:

#########
"5" =~ /(\d)/;
my $x = $1;
select (undef, undef, undef, $1);
print "Done 1\n";

my $y = 5;
select (undef, undef, undef, $y);
print "Done 2\n";
#########

Thank you very much.
Jim Keenan

---
via perlbug​: queue​: perl5 status​: new
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=120102

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2013

From @ikegami

0001-Call-select-s-4th-arg-s-magic.patch
From f27c6568d352c694815e5e1ed29fe30c993deef7 Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Fri, 4 Oct 2013 17:42:34 -0700
Subject: [PATCH] Call select's 4th arg's magic

---
 pp_sys.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/pp_sys.c b/pp_sys.c
index 5656e5a..a7ab233 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1159,6 +1159,7 @@ PP(pp_sselect)
 #  endif
 
     sv = SP[4];
+    SvGETMAGIC(sv);
     if (SvOK(sv)) {
 	value = SvNV(sv);
 	if (value < 0.0)
-- 
1.7.2.5

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2013

From @bulk88

On Fri Oct 04 17​:44​:59 2013, ikegami@​adaelis.com wrote​:

Patch attached.

The patch isn't the best. A SvGETMAGIC is added, and then SvNV (another
get magic call) is made. SvNV_nomg and other *_nomg (if any) need to be
used later on.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2013

From @ikegami

On Fri, Oct 4, 2013 at 9​:04 PM, bulk88 via RT <perlbug-followup@​perl.org>wrote​:

On Fri Oct 04 17​:44​:59 2013, ikegami@​adaelis.com wrote​:

Patch attached.

The patch isn't the best. A SvGETMAGIC is added, and then SvNV (another
get magic call) is made. SvNV_nomg and other *_nomg (if any) need to be
used later on.

Oops, been a while. Updated patch attached. That's the only other time that
scalar is accessed.

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2013

From @ikegami

0001-Call-select-s-4th-arg-s-magic.patch
From ce86b68b2ced2b12047b58e07b37d9128a9bb1eb Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Fri, 4 Oct 2013 17:42:34 -0700
Subject: [PATCH] Call select's 4th arg's magic

---
 pp_sys.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/pp_sys.c b/pp_sys.c
index 5656e5a..b5ed33f 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1159,8 +1159,9 @@ PP(pp_sselect)
 #  endif
 
     sv = SP[4];
+    SvGETMAGIC(sv);
     if (SvOK(sv)) {
-	value = SvNV(sv);
+	value = SvNV_nomg(sv);
 	if (value < 0.0)
 	    value = 0.0;
 	timebuf.tv_sec = (long)value;
-- 
1.7.2.5

@p5pRT
Copy link
Author

p5pRT commented Oct 18, 2013

From @iabyn

On Sat, Oct 05, 2013 at 12​:55​:26AM -0400, Eric Brine wrote​:

On Fri, Oct 4, 2013 at 9​:04 PM, bulk88 via RT <perlbug-followup@​perl.org>wrote​:

On Fri Oct 04 17​:44​:59 2013, ikegami@​adaelis.com wrote​:

Patch attached.

The patch isn't the best. A SvGETMAGIC is added, and then SvNV (another
get magic call) is made. SvNV_nomg and other *_nomg (if any) need to be
used later on.

Oops, been a while. Updated patch attached. That's the only other time that
scalar is accessed.

Thanks, applied as

  90eaaf0

I added a test in the same commit.

--
Standards (n). Battle insignia or tribal totems.

@p5pRT
Copy link
Author

p5pRT commented Oct 18, 2013

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

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