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

autouse misbehaves if target module is already loaded #15185

Closed
p5pRT opened this issue Feb 16, 2016 · 9 comments
Closed

autouse misbehaves if target module is already loaded #15185

p5pRT opened this issue Feb 16, 2016 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 16, 2016

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

Searchable as RT127553$

@p5pRT
Copy link
Author

p5pRT commented Feb 16, 2016

From @exodist

Created by @exodist

autouse has a short-circuit when the module being processed is already
loaded.
It *appears* that the shortcut results in different behavior than the
codepath
that is taken if the module is not already loaded.

autouse has 1 test file, inside a BEGIN it calls

  autouse->import('Scalar​::Util' => 'Scalar​::Util​::prototype');

If Scalar​::Util is not loaded (as is the case
currently) the test passes. However if you, or anything else, loads
Scalar​::Util before this BEGIN block then the test will fail.

This is a problem for the upcoming Test​::More which loads Scalar​::Util. In
my
patch in ticket 127000 I ignorantly patch the test to simply load Test​::More
after the begin block, with lets it pass again. However I was just informed
that the module is dual-life and the cpan version fails to install with the
new
Test​::More.

I have not looked in-depth into why the test fail, or how exactly the
behavior
is different. But it does seem to me that it is a bug in autouse to have
the
import fail when the module is already loaded.

-Chad

Perl Info

Flags:
    category=library
    severity=medium
    module=autouse

Site configuration information for perl 5.22.1:

Configured by exodist at Mon Dec 21 07:49:57 PST 2015.

Summary of my perl5 (revision 5 version 22 subversion 1) configuration:
___
  Platform:
    osname=linux, osvers=3.13.0-44-generic,
archname=x86_64-linux-thread-multi
    uname='linux work 3.13.0-44-generic #73-ubuntu smp tue dec 16 00:22:43
utc 2014 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/exodist/perl5/perlbrew/perls/main
-Dusethreads -Aeval:scriptdir=/home/exodist/perl5/perlbrew/perls/main/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.8.4', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678,
doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16,
longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'



@INC for perl 5.22.1:
    /home/exodist/.perlbrew/libs/main@exodist
/lib/perl5/x86_64-linux-thread-multi
    /home/exodist/.perlbrew/libs/main@exodist/lib/perl5

/home/exodist/perl5/perlbrew/perls/main/lib/site_perl/5.22.1/x86_64-linux-thread-multi
    /home/exodist/perl5/perlbrew/perls/main/lib/site_perl/5.22.1

/home/exodist/perl5/perlbrew/perls/main/lib/5.22.1/x86_64-linux-thread-multi
    /home/exodist/perl5/perlbrew/perls/main/lib/5.22.1
    .


Environment for perl 5.22.1:
    HOME=/home/exodist
    LANG=en_US.UTF-8
    LANGUAGE=en_US
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/exodist/.perlbrew/libs/main@exodist
/bin:/home/exodist/perl5/perlbrew/bin:/home/exodist/perl5/perlbrew/perls/main/bin:/home/exodist/bin:/home/exodist/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERL5LIB=/home/exodist/.perlbrew/libs/main@exodist/lib/perl5
    PERLBREW_BASHRC_VERSION=0.66
    PERLBREW_HOME=/home/exodist/.perlbrew
    PERLBREW_LIB=exodist
    PERLBREW_MANPATH=/home/exodist/.perlbrew/libs/main@exodist
/man:/home/exodist/perl5/perlbrew/perls/main/man
    PERLBREW_PATH=/home/exodist/.perlbrew/libs/main@exodist
/bin:/home/exodist/perl5/perlbrew/bin:/home/exodist/perl5/perlbrew/perls/main/bin
    PERLBREW_PERL=main
    PERLBREW_ROOT=/home/exodist/perl5/perlbrew
    PERLBREW_VERSION=0.66
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=/home/exodist/.perlbrew/libs/main@exodist
    PERL_MB_OPT=--install_base /home/exodist/.perlbrew/libs/main@exodist
    PERL_MM_OPT=INSTALL_BASE=/home/exodist/.perlbrew/libs/main@exodist
    SHELL=/usr/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Feb 16, 2016

From @exodist

Actually, it looks like I patched the test to delay loading Test​::More back in 2014. The cpan version just needs to be updated to include the change.

That said I think there is still a bug, and that the *fix* simply hid it.

It looks like the short-circuit when a module is already loaded assumes that Exporter.pm is used as the exporter. It simply bumps $Exporter​::ExportLevel, and then call $module->import. This will not work on modules that do not use Exporter.pm. The non-shortcircuit version actually checks if there is a custom import() and handles it properly.

This can probably be fixed by changing line 28 to use goto to enter \&{"$module​::import"} (some $@​ management may also be needed)

@p5pRT
Copy link
Author

p5pRT commented Feb 16, 2016

From @exodist

On Tue Feb 16 07​:23​:09 2016, exodist7@​gmail.com wrote​:

It looks like the short-circuit when a module is already loaded
assumes that Exporter.pm is used as the exporter. It simply bumps
$Exporter​::ExportLevel, and then call $module->import. This will not
work on modules that do not use Exporter.pm. The non-shortcircuit
version actually checks if there is a custom import() and handles it
properly.

This can probably be fixed by changing line 28 to use goto to enter
\&{"$module​::import"} (some $@​ management may also be needed)

Scratch that, it doesn't blindly assume Exporter.pm. I am not sure where the bug is.

@p5pRT
Copy link
Author

p5pRT commented Feb 16, 2016

From @exodist

Actually it looks like my 2014 patch was correct. The test is verifying that it cannot load Scalar​::Util as Scalar​::Util has a custom import(). Problem is that having Scalar​::Util already loaded makes it fail too soon.

So it appears the only bug is that the autouse version on cpan does not include the patch applied to blead in 2014.

Can someone do a cpan release of the latest autouse and then close this ticket?

-Chad

@p5pRT
Copy link
Author

p5pRT commented Feb 16, 2016

From @jkeenan

On Tue Feb 16 07​:27​:43 2016, exodist7@​gmail.com wrote​:

Actually it looks like my 2014 patch was correct. The test is
verifying that it cannot load Scalar​::Util as Scalar​::Util has a
custom import(). Problem is that having Scalar​::Util already loaded
makes it fail too soon.

So it appears the only bug is that the autouse version on cpan does
not include the patch applied to blead in 2014.

I downloaded the latest version of the 'autouse' distribution from CPAN​:

http​://search.cpan.org/CPAN/authors/id/W/WO/WOLFSAGE/autouse-1.08.tar.gz

After unpacking the tarball I diff-ed it against dist/autouse/lib/autouse.pm in blead​:

#####
$ diff -w dist/autouse/lib/autouse.pm \

/home/jkeenan/Downloads/autouse-1.08/lib/autouse.pm
$
#####

No difference; hence, nothing to be released (AFAICT).

Can someone do a cpan release of the latest autouse and then close
this ticket?

Can you clarify?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Feb 16, 2016

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

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2016

From @rjbs

The problem is in a test, not the module.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2016

From @rjbs

I believe this is now fixed in latest.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2016

@rjbs - 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