Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All: My problem amounts to this: when I have AUTOLOAD defined in a C file as
test.c: ---------------------------------------------------- /* a bunch of standard includes here */ XS(MyAutoload){ /* some code here */ } XS(boot_test){ newXS("test::AUTOLOAD", MyAutoload, __FILE__); } ----------------------------------------------------- test.pm: ----------------------------------------------------- package test; Require DynaLoader; Require AutoLoader; @ISA = qw(AutoLoader DynaLoader); $VARSION = "1.0"; bootstrap test $VERSION; 1; ------------------------------------------------------
module test has no trouble dispatching calls to undefined methods to this AUTOLOAD in perl 5.005, but not in 5.6.1. I have tried to find an answer in changelogs, but with not much luck. Anyone has any idea whats going on?

Replies are listed 'Best First'.
(tye)Re: Help: 5.6.1: XSUB and AUTOLOAD
by tye (Sage) on Jul 19, 2001 at 21:06 UTC

    I don't know why this changed between versions of Perl. However, my first reaction on seeing what you were doing (without knowing what the problems were) was "Oh, you should define your AUTOLOAD in Perl and have it dispatch to the XS code." And that would probably solve your problem.

    The reason that I thought that was that I feel that you should write as much of your code as possible in Perl and as little as possible in C/XS. Code you write in C/XS is much more likely to break between versions of Perl, is usually quite a bit less robust (on things like tied or "magic" variables and often even on much simpler stuff), and is harder to write/read/understand/debug/extend/work-around/etc. than the equivalent Perl code.

            - tye (but my friends call me "Tye")
      Well, the whole story goes like this: there used to be a package PerlQt which I happened to like a lot. However the guy who wrote it seems to have abandoned his baby. So I tried to bring it up to date -- when I found that 99% of the code relies on AUTOLOAD, kinda like I described before. Yes, my first reaction was the same: dispatch from Perl, and this is the fix that works for me now (I am yet to try to get in touch with the author again on this) -- however, it means having tons of "use Qt::ThisAndThat;" statements, whereas XS allowed to have a single AUTOLOAD for everything. I have a few ideas how to patch this, however first I wanted to be sure I am not doing something stupid.

      Thanx for reply, anyway. I posted to a couple of newsgroups too, and it looks like not to many people are intimately familiar with the topic.

      Best,

      Mishka

        Well, I was thinking more along the lines of:

        sub AUTOLOAD { AutoLoad( $AUTOLOAD, @_ ); }
        and have AutoLoad() be the XS routine. Passing in $AUTOLOAD could be optional since you probably already have code that knows how to fetch that.

        But maybe something that simple wouldn't be enough to overcome the bug you hit. (:

                - tye (but my friends call me "Tye")
Re: Help: 5.6.1: XSUB and AUTOLOAD
by Anonymous Monk on Jul 20, 2001 at 09:22 UTC
    Oh, and by the way, this is mishka@mishka.ne.mediaone.net (too lazy to register)