philou has asked for the wisdom of the Perl Monks concerning the following question:
test.pl :#include "EXTERN.h" #include "perl.h" #include "XSUB.h" void inspect( char* name ) { if( get_cv( name, (I32)0 ) != NULL ) { printf( " &%s is defined\n", name ); { dSP ; PUSHMARK(SP) ; call_pv( name, G_DISCARD | G_NOARGS ); } } } MODULE = CCC PACKAGE = CCC void inspect( name ) INPUT: char* name;
When I run `make test', I get the following output :sub mysub { print "Hello from mysub !\n"; } &CCC::inspect( "main::mysub" ); undef &mysub; &CCC::inspect( "main::mysub" );
So the first time it gets called, it works fine, but after undefining the sub, it does not detect the sub is undef and calls it. Note that the perlapi says that with get_cv you get NULL if "create" is not set and the subroutine does not exist. Is there a way to check for sub definedness rather then for sub existence ? Cheers, Philou1..1 ok 1 &main::mysub is defined Hello from mysub ! &main::mysub is defined Undefined subroutine &main::mysub called at test.pl line 27. make: *** [test_dynamic] Erreur 255
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to check for subroutine existence from within XS code
by Elian (Parson) on May 23, 2003 at 18:24 UTC | |
|
Re: How to check for subroutine existence from within XS code
by dug (Chaplain) on May 23, 2003 at 18:11 UTC |