develooper Front page | perl.perl5.porters | Postings from October 2003

[perl #24338] Attribute::Handlers will trash UNIVERSAL

Thread Previous | Thread Next
From:
perlbug-followup
Date:
October 28, 2003 20:49
Subject:
[perl #24338] Attribute::Handlers will trash UNIVERSAL
Message ID:
rt-24338-66621.18.3476231716084@rt.perl.org
# New Ticket Created by  Michael.Jacob@SCHERING.DE 
# Please include the string:  [perl #24338]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24338 >


To: perlbug@perl.org
Subject: Attribute::Handlers will trash UNIVERSAL::
Reply-To: micaja@de.ibm.com
Message-Id: <5.8.0_2416_1067350888@SCHNARCHNASE>

This is a bug report for perl from micaja@de.ibm.com,
generated with the help of perlbug 1.34 running under perl v5.8.0.


-----------------------------------------------------------------
[Please enter your report here]

Attribute::Handlers will trash UNIVERSAL with:

 push @UNIVERSAL::ISA, 'Attribute::Handlers'

this will make all modules fail that trust in

 if ( $object->can('abc') or $object->can('AUTOLOAD') ) {
   $object->abc();
 }

e.g. XML::SAX, DBI, ...

Things like 'AUTOLOAD', 'import', 'DESTROY' or such
just don't belong into UNIVERSAL. There should be at
least a big warn() along.

Suggestion: Override UNIVERSAL::can to reject inherited
methods. I tested this to work:

 my $realcan = \&UNIVERSAL::can;
 sub mycan {
   goto &$realcan if $_[0] ne 'UNIVERSAL' or $_[1] eq 'can';
   my $UV_code = &$realcan(@_);
   my $MY_code = &$realcan(__PACKAGE__, $_[1]);
   return $UV_code ne $MY_code ? $UV_code : undef;
 }
 *UNIVERSAL::can = \&mycan;

Testcase:

use CANTEST;
print UNIVERSAL->can('can'), "\n";
print UNIVERSAL->can('AUTOLOAD'), "\n";
print UNIVERSAL->can('mycan'), "\n";
print CANTEST->can('can'), "\n";
print CANTEST->can('AUTOLOAD'), "\n";
print CANTEST->can('mycan'), "\n";
^D
CODE(0x101426d8)
                   <= GOOD
                   <= GOOD
CODE(0x101426d8)
CODE(0x1014263c)
CODE(0x101426d8)

PS: I hope I was faster than any time machines this time...

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=medium
---
Site configuration information for perl v5.8.0:

Configured by Gerrit at Fri Aug 29 11:53:54 CEST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=cygwin, osvers=1.3.22(0.7832), archname=cygwin-multi-64int
    uname='cygwin_nt-5.0 ismene 1.3.22(0.7832) 2003-03-18 09:20 i586
unknown unknown cygwin '
    config_args='-de -Dmksymlinks -Dusemultiplicity -Duse64bitint
-Doptimize=-O3 -Dman3ext=3pm'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -fno-strict-aliasing',
    optimize='-O3',
    cppflags='-DPERL_USE_SAFE_PUTENV -fno-strict-aliasing'
    ccversion='', gccversion='3.2 20020927 (prerelease)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='ld2', ldflags =' -s -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib
    libs=-lgdbm -ldb -lcrypt -lutil -lgdbm_compat
    perllibs=-lcrypt -lutil -lgdbm_compat
    libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' -s'
    cccdlflags=' ', lddlflags=' -s -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.8.0:
    /usr/lib/perl5/5.8.0/cygwin-multi-64int
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/cygwin-multi-64int
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    .

---
Environment for perl v5.8.0:
    HOME=/home/MichaelJacob
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINNT/system32:/cygdrive/c/WINNT:/cygdrive/c/WINNT/system32/WBEM:/cygdrive/c/perl580/bin:/usr/bin:/cygdrive/c/Program

Files/UltraEdit:/cygdrive/c/PROGRA~1/IBM/SQLLIB/BIN:/cygdrive/c/PROGRA~1/IBM/SQLLIB/FUNCTION:/cygdrive/c/PROGRA~1/IBM/SQLLIB/SAMPLES/REPL:/cygdrive/c/WINNT/system32:/cygdrive/c/WINNT:/cygdrive/c/WINNT/system32/WBEM:/cygdrive/c/perl580/bin:/usr/bin:/usr/X11R6/bin
    PERL_BADLANG (unset)
    SHELL (unset)




Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About