Subroutine exec redefined warning with perl 5.12.2

M

Marc Girod

Hello,

I installed Strawberry perl 5.12.2 on my new laptop and started to
install my modules on it.
And I met some surprises. I'll mention 3, but the first is the one
that bothers me for now.

1. I got a new warning, and I'd like to understand whether it displays
a yet unknown problem (with perl up to 5.10) or should just be
silenced (with the next question of how?)

The warning is:

Subroutine exec redefined at C:/strawberry/perl/site/lib/Argv.pm line
852.

I get it in running a command line involving ClearCase::Wrapper::MGi.
This is hard to reproduce without ClearCase, even if the modules are
all on CPAN.
I tried to extract the significant code, but could not reproduce the
symptom.
So, here is my failed attempt at rproducing.
Could you please help me guessing what I could add to reproduce the
symptom, i.e. explain me what precisely it warns against?
There is indeed a redefinition of exec on line 852 of Argv.pm, but I
cannot see how it differes from the one below.

#!/usr/bin/perl

use warnings;
use strict;

package Foo;

sub exec {
print "overloaded in Foo\n";
}
sub new {
return bless {}, __PACKAGE__;
}

package Bar;
our @ISA = qw(Foo);

sub exec {
my $self = shift;
print "overloaded in Bar\n";
return $self->SUPER::exec;
}
sub new {
return bless {}, __PACKAGE__;
}

package main;
my $bar = new Bar;
$bar->exec;
exit 0;

This works the same on 5.12 as on 5.10:

$ ~/tmp/execdemo
overloaded in Bar
overloaded in Foo



2. Running: 'perl Makefile.PL' for all the modules I have tried
produces makefiles with a systematic syntax error:
double opening braces instead of single ones.

Running the following solves the problem:

W:\atcctest\Clone>perl -pi.bak -e "s/{{/{/g" Makefile



3. I fail to build the Clone package (from CPAN) with the following
error:

W:\atcctest\Clone>gmake
Skip blib\lib\Clone.pm (unchanged)
gcc -c -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -
DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-
bitfields -DPERL_MSVCRT_READFIX -O3 -DVERSION=\"0.28\" -DXS_VERSION=
\"0.28\" "-IC:\strawberry\perl\lib\CORE" Clone.c
Clone.xs: In function 'sv_clone':
Clone.xs:160: error: duplicate case value
Clone.xs:154: error: previously used here
gmake: *** [Clone.o] Error 1

Thanks,
Marc
 
M

Marc Girod

Clone.xs: In function 'sv_clone':
Clone.xs:160: error: duplicate case value
Clone.xs:154: error: previously used here

BTW, this isn't true:

W:\atcctest\Clone>perl -nle "print if $. == 154 or $. == 160" Clone..xs
case SVt_IV: /* 1 */
case SVt_RV: /* 3 */

This is version 0.28.

Marc
 
C

C.DeRykus

Hello,

I installed Strawberry perl 5.12.2 on my new laptop and started to
install my modules on it.
And I met some surprises. I'll mention 3, but the first is the one
that bothers me for now.

1. I got a new warning, and I'd like to understand whether it displays
a yet unknown problem (with perl up to 5.10) or should just be
silenced (with the next question of how?)

The warning is:

Subroutine exec redefined at C:/strawberry/perl/site/lib/Argv.pm line
852.

I get it in running a command line involving ClearCase::Wrapper::MGi.
This is hard to reproduce without ClearCase, even if the modules are
all on CPAN.
I tried to extract the significant code, but could not reproduce the
symptom.
So, here is my failed attempt at rproducing.
Could you please help me guessing what I could add to reproduce the
symptom, i.e. explain me what precisely it warns against?
There is indeed a redefinition of exec on line 852 of Argv.pm, but I
cannot see how it differes from the one below.

#!/usr/bin/perl

use warnings;
use strict;

package Foo;

sub exec {
  print "overloaded in Foo\n";}

sub new {
  return bless {}, __PACKAGE__;

}

package Bar;
our @ISA = qw(Foo);

sub exec {
  my $self = shift;
  print "overloaded in Bar\n";
  return $self->SUPER::exec;}

sub new {
  return bless {}, __PACKAGE__;

}

package main;
my $bar = new Bar;
$bar->exec;
exit 0;

This works the same on 5.12 as on 5.10:

$ ~/tmp/execdemo
overloaded in Bar
overloaded in Foo

But AFAIK a "subroutine redefined..." occurs
only if a sub is redefined within a class -
not because there are sub's of the same name
in its inheritance tree.

The only workaround is mentioned here:

perl -Mdiagnostics=-verbose -wlE
"BEGIN { $diagnostics::DEBUG = 1 };
sub x{say 'first x'};
sub x{say 'second x'};"

DESCRIPTION OF DIAGNOSTICS
...

Trappable errors may be trapped using the
eval operator. See perlfunc/eval. In
almost all cases, warnings may be selectively
disabled or promoted to fatal errors using the
warnings pragma.
See warnings.

Subroutine x redefined at -e line 1 (#1)
(W redefine) You redefined a subroutine.
To suppress this warning,

{
no warnings 'redefine';
eval "sub name { ... }";
}


....
 
M

Marc Girod

But AFAIK a "subroutine redefined..." occurs
only if a sub is redefined within a class -
not because there are sub's of the same name
in its inheritance tree.

This is surprising: there is only one redefinition of exec per class.
There are two in the hierachy classes with similar names: Argv and
ClearCase::Argv (of course, it would be a bug if it affected,and it
doesn't seem to).
The only workaround is mentioned here:

perl -Mdiagnostics=-verbose -wlE

Excellent! Thanks!
    Subroutine x redefined at -e line 1 (#1)
    (W redefine) You redefined a subroutine.
     To suppress this warning,

        {
        no warnings 'redefine';
        eval "sub name { ... }";
        }

Thanks. Very useful indeed.
I do get a similar output with my script:

Subroutine exec redefined at C:/strawberry/perl/site/lib/Argv.pm line
852 (#2)
(W redefine) You redefined a subroutine. To suppress this
warning, say

Now, this doesn't tell where #1 would be... (which I cannot find).
Thanks again.
I continue my investigations.

Marc
 
M

Marc Girod

Now, this doesn't tell where #1 would be... (which I cannot find).

Sorry, I understand now that #1 was unrelated:

Name "main::rem" used only once: possible typo at
c:\strawberry\perl\site\bin\cleartool.bat line 1 (#1)

A hack to get the Perl script run as a Windows batch.
But no clue about where the 'first definition' might be...

Marc
 
M

Marc Girod

To suppress this warning, say

{
no warnings 'redefine';
eval "sub name { ... }";
}

Unfortunately, this is not very practical...
I used actually: eval qq(sub name { ... });
It results in a large batch of errors for all the variables used:

Variable "@cmd" is not imported at C:/strawberry/perl/site/lib/Argv.pm
line 854.
....

Putting: no warnings 'redefine';
at file scope is likely to be *very* counterproductive...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top