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

Benchmark calls coderef with spurious arguments #7578

Closed
p5pRT opened this issue Nov 4, 2004 · 4 comments
Closed

Benchmark calls coderef with spurious arguments #7578

p5pRT opened this issue Nov 4, 2004 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 4, 2004

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

Searchable as RT32327$

@p5pRT
Copy link
Author

p5pRT commented Nov 4, 2004

From siegel@zrz.tu-berlin.de

This is a bug report for perl from anno4000@​lublin.zrz.tu-berlin.de,
generated with the help of perlbug 1.34 running under perl v5.8.1.

Benchmark​::runloop calls a benchmarked coderef with two spurious
arguments (the arguments of the call to runloop itself). That
is mostly no big deal, but a sub may check its argumets. In particular,
Inline-compiled parameterless functions do this and die in Benchmark.
(That is how the subject came up on clpm.)

The fix below (against 1.06 from Perl 5.8.5) changes the call to $subref
in runloop() so that @​_ is cleared. The (presumably timing-sensitive)
call to $c is unchanged. Clearing @​_ explicitly, say after line 648
is another possibility.

Note​: perlbug was run on a different machine from the one where the
patch was prepared. The auto-included "Site configuration information"
below is irrelevant to the report.

Regards, Anno

Inline Patch
--- orig/lib/Benchmark.pm	Mon Feb 23 19:50:27 2004
+++ perl-5.8.5/lib/Benchmark.pm	Thu Nov  4 20:21:07 2004
@@ -648,7 +648,7 @@
     # &runloop a lot, and thus reduce additive errors.
     my $tbase = Benchmark->new(0)->[1];
     while ( ( $t0 = Benchmark->new(0) )->[1] == $tbase ) {} ;
-    &$subref;
+    $subref->();
     $t1 = Benchmark->new($n);
     $td = &timediff($t1, $t0);
     timedebug("runloop:",$td);
--- orig/lib/Benchmark.t	Thu Aug  7 21:26:47 2003
+++ perl-5.8.5/lib/Benchmark.t	Thu Nov  4 20:40:19 2004
@@ -8,7 +8,7 @@
 use warnings;
 use strict;
 use vars qw($foo $bar $baz $ballast);
-use Test::More tests => 193;
+use Test::More tests => 194;
 
 use Benchmark qw(:all);
 
@@ -41,6 +41,11 @@
 
 isa_ok(timeit(5, '++$bar'), 'Benchmark', "timeit eval");
 is ($bar, 5, "benchmarked code was run 5 times");
+
+# is coderef called with spurious arguments?
+timeit( 1, sub { $foo = @_ });
+is ($foo, 0, "benchmarked code called without arguments");
+
 
 print "# Burning CPU to benchmark things will take time...\n";
 
---
Flags:   category=library   severity=low

Site configuration information for perl v5.8.1​:

Configured by anno4000 at Wed Oct 1 12​:15​:29 MEST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration​:
  Platform​:
  osname=linux, osvers=2.0.36, archname=i586-linux
  uname='linux lublin.zrz.tu-berlin.de 2.0.36 #2 mon jun 26 12​:24​:02 mest 2000 i586 unknown '
  config_args='-des'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-I/usr/local/include'
  ccversion='', gccversion='2.7.2.3', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lposix
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc -lposix
  libc=/lib/libc-2.0.7.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.0'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl v5.8.1​:
  /opt/home/anno4000/lib/perl
  /usr/local/lib/perl5/5.8.1/i586-linux
  /usr/local/lib/perl5/5.8.1
  /usr/local/lib/perl5/site_perl/5.8.1/i586-linux
  /usr/local/lib/perl5/site_perl/5.8.1
  /usr/local/lib/perl5/site_perl
  .


Environment for perl v5.8.1​:
  HOME=/opt/home/anno4000
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH=/usr/X11R6/lib​:/usr/local/LessTif/Motif1.2/lib
  LOGDIR (unset)
  PATH=/opt/home/anno4000/bin​:/sbin​:/usr/local/bin​:/bin​:/usr/bin​:/usr/sbin​:/usr/X11R6/bin​:/usr/openwin/bin​:/usr/games
  PERL5LIB=/opt/home/anno4000/lib/perl
  PERL_BADLANG (unset)
  PERL_PRIVLIB=/usr/local/lib/perl5/5.8.1
  PERL_SITELIB=/usr/local/lib/perl5/site_perl/5.8.1
  SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2004

From @rgs

Anno Siegel (via RT) wrote​:

Benchmark​::runloop calls a benchmarked coderef with two spurious
arguments (the arguments of the call to runloop itself). That
is mostly no big deal, but a sub may check its argumets. In particular,
Inline-compiled parameterless functions do this and die in Benchmark.
(That is how the subject came up on clpm.)

The fix below (against 1.06 from Perl 5.8.5) changes the call to $subref
in runloop() so that @​_ is cleared. The (presumably timing-sensitive)
call to $c is unchanged. Clearing @​_ explicitly, say after line 648
is another possibility.

Thanks, applied to bleadperl, bumping $Benchmark​::VERSION to 1.07,
as change #23473.

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2004

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

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2004

@rgs - Status changed from 'new' 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