SPUG: Bad Function Names

Andrew Sweger andy at n2h2.com
Fri Feb 25 01:39:47 CST 2000


It can't be detected at compile time always because sometimes the function
name isn't known until run-time. Witness Perl's OOP ability. The @ISA is
searched for a class (package) that defines the function corresponding to
the invoked method (message). There are scripts in the B modules that can
compile a cross reference of function calls (that are known as subroutine
names). That might allow one to analyze a simple script for such potential
problems.

One could also implement a UNIVERSAL::AUTOLOAD function to provide an
ultimate trap for undefined functions. Wait, is UNIVERSAL correct? Does
main inherit from UNIVERSAL? Ah well. Whatever. ZZzzzzzzzzzzzzz

On Feb 24, 2000 @ 4:56pm, Asim Jalis wrote:

> This question was triggered by Bob Abarbanel's excellent ESPUG
> presentation last night.
> 
> Suppose I am accidentally calling a function that I have not defined.
> I have no desire to use AUTOLOAD. When I run the program it will keep
> running until it encounters the function call and then after not being
> able to handle it it will give me a run-time error.
> 
> The question is: Can I catch this at compile-time?
> 
> This would be nice to have because otherwise I keep worrying that I
> might have typos in my code waiting to explode in production. Is there
> a way to catch any of this at compile-time?
> 
> Here is an example:
> 
> --------------------cut here--------------------
> #!/usr/bin/perl
> 
> use strict;
>   
> sub bad_hello {
>   bad_function ("hi there from bad_hello\n");
> }
> 
> sub good_hello {
>   print ("hi there from good_hello\n");
> }
> 
> my $date = localtime();
> if ($date =~ /sun/i) { bad_hello  (); }
> else                 { good_hello (); }
> --------------------cut here--------------------
> 
> This program will compile and run all week and then crash on Sunday
> because bad_function is not defined. Is there a way to have it crash
> at compile-time so that this bug can be caught before Sunday?
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>     POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
>  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>  SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
>         Email to majordomo at pm.org: ACTION spug-list your_address
> 
> 

-- 
  Andrew Sweger <andy at n2h2.com>  |  N2H2, Incorporated
  v=206.336.2947 f=206.336.1541  |  900 Fourth Avenue, Suite 3400
     Advanced Technologies       |  Seattle WA 98164-1059
          Development            |  http://www.n2h2.com/

                       "Wuhaha~~~" -- Heechul



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list