You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philippe M . Chiasson" <go...@cpan.org> on 2001/10/02 09:47:51 UTC
[Patch] Apache->module()
Hi, this patch implements the Apache->module() functionnality with a few differences.
Apache->module() is in Apache::compat and the real name for this is Apache::Module::loaded()
and I am open for better suggestions. "if (Apache->module('Apache::Auth'))" doesn't quite
make as much sense to me than "if (Apache::Module::loaded('Apache::Auth'))"
Added a fet test cases for it and took the time to rewrite the module.t tests
with Stas's cool t_cmp()
The behavious is now 3-fold instead of 2 like mod_perl 1.x
1- if the name ends in '.c' then it will return true/false if that apache
module is present or not.
2- if the name ends in '.so' then it will return true/false if that apache
module is present and was loaded as a DSO
3- else it returns true/false if a perl module of that name is already loaded.
Comments most welcome.
Index: todo/api.txt
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
retrieving revision 1.6
diff -u -I'$Id' -I'$Revision' -r1.6 api.txt
--- todo/api.txt 2001/09/28 13:51:57 1.6
+++ todo/api.txt 2001/10/02 07:17:48
@@ -28,9 +28,6 @@
$r->log_reason:
should be simple, see modperl_log.h
-Apache->module:
-not yet implemented
-
Apache->server_root_relative:
needs to default to current pool (pconf at startup, r->pool at request
time)
Index: xs/maps/apache_functions.map
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/apache_functions.map,v
retrieving revision 1.30
diff -u -I'$Id' -I'$Revision' -r1.30 apache_functions.map
--- xs/maps/apache_functions.map 2001/09/17 01:06:08 1.30
+++ xs/maps/apache_functions.map 2001/10/02 07:17:48
@@ -180,6 +180,7 @@
>ap_show_directives
>ap_show_modules
>ap_register_hooks
+ mpxs_Apache__Module_loaded
MODULE=Apache::Directive
ap_directive_t *:DEFINE_conftree | | SV *:CLASS
Index: xs/Apache/Module/Apache__Module.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/Module/Apache__Module.h,v
retrieving revision 1.2
diff -u -I'$Id' -I'$Revision' -r1.2 Apache__Module.h
--- xs/Apache/Module/Apache__Module.h 2001/03/26 15:51:50 1.2
+++ xs/Apache/Module/Apache__Module.h 2001/10/02 07:17:48
@@ -1,2 +1,31 @@
#define mpxs_Apache__Module_top_module(CLASS) \
(CLASS ? ap_top_module : ap_top_module)
+
+static MP_INLINE
+int mpxs_Apache__Module_loaded(const char *name)
+{
+ dTHX; /*XXX*/
+ module *mod;
+
+ if (0 == ap_strcmp_match(name,"*.c")) {
+ mod = modperl_get_ap_module(name);
+ return ( NULL != mod );
+ }
+ else if (0 == ap_strcmp_match(name,"*.so")) {
+ size_t len = strlen(name);
+ char *so = malloc(len+1);
+
+ apr_cpystrn(so, name, len+1);
+ so[len-2] = 'c';
+ so[len-1] = '\0';
+ mod = modperl_get_ap_module(so);
+ free(so);
+
+ return (mod && (NULL != mod->dynamic_load_handle));
+ }
+ else {
+ return modperl_is_module_loaded(aTHX_ name);
+ }
+
+
+}
Index: t/response/TestAPI/module.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/module.pm,v
retrieving revision 1.1
diff -u -I'$Id' -I'$Revision' -r1.1 module.pm
--- t/response/TestAPI/module.pm 2001/04/04 05:45:48 1.1
+++ t/response/TestAPI/module.pm 2001/10/02 07:17:48
@@ -4,32 +4,51 @@
use warnings FATAL => 'all';
use Apache::Test;
+use Apache::TestConfig;
+use Apache::TestUtil;
use Apache::Module ();
use DynaLoader ();
sub handler {
my $r = shift;
- plan $r, tests => 6;
+ my $cfg = Apache::TestConfig->thaw;
+
+ plan $r, tests => 11;
my $top_module = Apache::Module->top_module;
ok $top_module;
- ok $top_module->version;
+ ok t_cmp($cfg->{httpd_info}{MODULE_MAGIC_NUMBER}, $top_module->version . ':0' , q{$top_module->version});
- ok $top_module->module_index;
+ ok t_cmp(scalar(keys(%{$cfg->{modules}})), $top_module->module_index, q{$top_module->module_index});
- ok $top_module->name;
+ ok t_cmp('mod_perl.c', $top_module->name(), q{$top_module->name});
- ok $top_module->cmds;
-
- for (my $modp = $top_module; $modp; $modp = $modp->next) {
- if ($modp->name eq 'mod_perl.c') {
- ok 1;
- last;
+ my $cmd = $top_module->cmds;
+
+ ok defined $cmd;
+
+ ok UNIVERSAL::isa($cmd, 'Apache::Command');
+
+ {
+ local $cfg->{modules}{'mod_perl.c'} = 1;
+ my $modules = {};
+
+ for (my $modp = $top_module; $modp; $modp = $modp->next) {
+ if ($modp && $modp->name) {
+ $modules->{$modp->name} = 1;
+ }
}
+
+ ok t_cmp($cfg->{modules}, $modules,"Modules list");
}
+
+ ok t_cmp(1, Apache::Module::loaded('mod_perl.c'), "Apache::Module::loaded('mod_perl.c')");
+ ok t_cmp(1, Apache::Module::loaded('mod_perl.so'), "Apache::Module::loaded('mod_perl.so')");
+ ok t_cmp(0, Apache::Module::loaded('foo'), "Apache::Module::loaded('foo')");
+ ok t_cmp(1, Apache::Module::loaded('Apache::Module'), "Apache::Module::loaded('Apache::Module')");
0;
}
Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/src/modules/perl/modperl_util.c,v
retrieving revision 1.19
diff -u -I'$Id' -I'$Revision' -r1.19 modperl_util.c
--- src/modules/perl/modperl_util.c 2001/09/28 20:11:01 1.19
+++ src/modules/perl/modperl_util.c 2001/10/02 07:17:48
@@ -443,3 +443,19 @@
return RETVAL;
}
+
+MP_INLINE module *modperl_get_ap_module(const char *name)
+{
+ module *modp;
+ for (modp = ap_top_module; modp; modp = modp->next) {
+ if (modp && modp->name && ( 0 == apr_strnatcmp(modp->name, name))) {
+ return modp;
+ }
+ }
+ return NULL;
+}
+
+MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name)
+{
+ return (NULL != gv_stashpv(name, FALSE));
+}
Index: src/modules/perl/modperl_util.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/src/modules/perl/modperl_util.h,v
retrieving revision 1.19
diff -u -I'$Id' -I'$Revision' -r1.19 modperl_util.h
--- src/modules/perl/modperl_util.h 2001/09/28 20:11:01 1.19
+++ src/modules/perl/modperl_util.h 2001/10/02 07:17:48
@@ -72,4 +72,8 @@
SV *modperl_table_get_set(pTHX_ apr_table_t *table, char *key,
SV *sv_val, bool do_taint);
+MP_INLINE module *modperl_get_ap_module(const char *name);
+
+MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name);
+
#endif /* MODPERL_UTIL_H */
Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/lib/Apache/compat.pm,v
retrieving revision 1.15
diff -u -I'$Id' -I'$Revision' -r1.15 compat.pm
--- lib/Apache/compat.pm 2001/10/01 09:04:10 1.15
+++ lib/Apache/compat.pm 2001/10/02 07:17:48
@@ -42,6 +42,11 @@
sub untaint {
}
+sub module {
+ eval { require Apache::Module; };
+ return Apache::Module::loaded($_[1]);
+}
+
package Apache::Constants;
use Apache::Const ();
--
Philippe M. Chiasson <go...@cpan.org>
Extropia's Resident System Guru
http://www.eXtropia.com/
NULL regexp argument
: The internal pattern matching routines blew it big time.
-- perldiag(1)
perl -e '$$=\${gozer};{$_=unpack(P26,pack(L,$$));/^Just Another Perl Hacker!\n$/&&print||$$++&&redo}'
Re: [Patch] Apache->module()
Posted by Stas Bekman <st...@stason.org>.
Philippe M . Chiasson wrote:
> Right on all counts Stas...
>
> Only unresolved issue left is the malloc stuff....
>
> I just't can't figure out how to get my hands on an apr_pool at this time.
> I agree, using malloc if _bad_ , just tell me where can I get a pool from?
There are 2 places malloc is used in mod_perl c files. I don't know if it's correct or not.
Using a string of predefined length? not very scalable... could also
remove the const() from the args and modify the 'name' variable, since
it always shrinks, but it's probably a bad idea.
Doug hasn't said yet what's his position for using malloc...
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [Patch] Apache->module()
Posted by "Philippe M . Chiasson" <go...@cpan.org>.
Right on all counts Stas...
Only unresolved issue left is the malloc stuff....
I just't can't figure out how to get my hands on an apr_pool at this time.
I agree, using malloc if _bad_ , just tell me where can I get a pool from?
Gozer out.
Index: todo/api.txt
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
retrieving revision 1.6
diff -u -I'$Id' -I'$Revision' -r1.6 api.txt
--- todo/api.txt 2001/09/28 13:51:57 1.6
+++ todo/api.txt 2001/10/02 10:47:30
@@ -28,9 +28,6 @@
$r->log_reason:
should be simple, see modperl_log.h
-Apache->module:
-not yet implemented
-
Apache->server_root_relative:
needs to default to current pool (pconf at startup, r->pool at request
time)
Index: xs/maps/apache_functions.map
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/apache_functions.map,v
retrieving revision 1.30
diff -u -I'$Id' -I'$Revision' -r1.30 apache_functions.map
--- xs/maps/apache_functions.map 2001/09/17 01:06:08 1.30
+++ xs/maps/apache_functions.map 2001/10/02 10:47:30
@@ -180,6 +180,7 @@
>ap_show_directives
>ap_show_modules
>ap_register_hooks
+ mpxs_Apache__Module_loaded
MODULE=Apache::Directive
ap_directive_t *:DEFINE_conftree | | SV *:CLASS
Index: xs/Apache/Module/Apache__Module.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/Module/Apache__Module.h,v
retrieving revision 1.2
diff -u -I'$Id' -I'$Revision' -r1.2 Apache__Module.h
--- xs/Apache/Module/Apache__Module.h 2001/03/26 15:51:50 1.2
+++ xs/Apache/Module/Apache__Module.h 2001/10/02 10:47:30
@@ -1,2 +1,31 @@
#define mpxs_Apache__Module_top_module(CLASS) \
(CLASS ? ap_top_module : ap_top_module)
+
+static MP_INLINE
+int mpxs_Apache__Module_loaded(const char *name)
+{
+ dTHX; /*XXX*/
+ module *mod;
+
+ if (0 == ap_strcmp_match(name,"*.c")) {
+ mod = modperl_get_ap_module(name);
+ return ( NULL != mod );
+ }
+ else if (0 == ap_strcmp_match(name,"*.so")) {
+ size_t len = strlen(name);
+ char *so = malloc(len+1);
+
+ apr_cpystrn(so, name, len+1);
+ so[len-2] = 'c';
+ so[len-1] = '\0';
+ mod = modperl_get_ap_module(so);
+ free(so);
+
+ return (mod && (NULL != mod->dynamic_load_handle));
+ }
+ else {
+ return modperl_is_module_loaded(aTHX_ name);
+ }
+
+
+}
Index: t/response/TestAPI/module.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/module.pm,v
retrieving revision 1.1
diff -u -I'$Id' -I'$Revision' -r1.1 module.pm
--- t/response/TestAPI/module.pm 2001/04/04 05:45:48 1.1
+++ t/response/TestAPI/module.pm 2001/10/02 10:47:30
@@ -4,32 +4,59 @@
use warnings FATAL => 'all';
use Apache::Test;
+use Apache::TestConfig;
+use Apache::TestUtil;
use Apache::Module ();
use DynaLoader ();
sub handler {
my $r = shift;
- plan $r, tests => 6;
+ my $cfg = Apache::Test::config();
+
+ plan $r, tests => 11;
my $top_module = Apache::Module->top_module;
ok $top_module;
- ok $top_module->version;
-
- ok $top_module->module_index;
-
- ok $top_module->name;
-
- ok $top_module->cmds;
-
- for (my $modp = $top_module; $modp; $modp = $modp->next) {
- if ($modp->name eq 'mod_perl.c') {
- ok 1;
- last;
+ ok t_cmp($cfg->{httpd_info}{MODULE_MAGIC_NUMBER},
+ $top_module->version . ':0',
+ q{$top_module->version});
+
+ ok t_cmp(scalar(keys(%{ $cfg->{modules} })),
+ $top_module->module_index,
+ q{$top_module->module_index});
+
+ ok t_cmp('mod_perl.c', $top_module->name(), q{$top_module->name});
+
+ my $cmd = $top_module->cmds;
+
+ ok defined $cmd;
+
+ ok UNIVERSAL::isa($cmd, 'Apache::Command');
+
+ {
+ local $cfg->{modules}{'mod_perl.c'} = 1;
+ my $modules = {};
+
+ for (my $modp = $top_module; $modp; $modp = $modp->next) {
+ if ($modp && $modp->name) {
+ $modules->{$modp->name} = 1;
+ }
}
+
+ ok t_cmp($cfg->{modules}, $modules,"Modules list");
}
+
+ ok t_cmp(1, Apache::Module::loaded('mod_perl.c'),
+ "Apache::Module::loaded('mod_perl.c')");
+ ok t_cmp(1, Apache::Module::loaded('mod_perl.so'),
+ "Apache::Module::loaded('mod_perl.so')");
+ ok t_cmp(0, Apache::Module::loaded('Apache__Module_foo'),
+ "Apache::Module::loaded('Apache__Module_foo')");
+ ok t_cmp(1, Apache::Module::loaded('Apache::Module'),
+ "Apache::Module::loaded('Apache::Module')");
0;
}
Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/src/modules/perl/modperl_util.c,v
retrieving revision 1.19
diff -u -I'$Id' -I'$Revision' -r1.19 modperl_util.c
--- src/modules/perl/modperl_util.c 2001/09/28 20:11:01 1.19
+++ src/modules/perl/modperl_util.c 2001/10/02 10:47:30
@@ -443,3 +443,19 @@
return RETVAL;
}
+
+MP_INLINE module *modperl_get_ap_module(const char *name)
+{
+ module *modp;
+ for (modp = ap_top_module; modp; modp = modp->next) {
+ if (modp && modp->name && ( 0 == apr_strnatcmp(modp->name, name))) {
+ return modp;
+ }
+ }
+ return NULL;
+}
+
+MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name)
+{
+ return (NULL != gv_stashpv(name, FALSE));
+}
Index: src/modules/perl/modperl_util.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/src/modules/perl/modperl_util.h,v
retrieving revision 1.19
diff -u -I'$Id' -I'$Revision' -r1.19 modperl_util.h
--- src/modules/perl/modperl_util.h 2001/09/28 20:11:01 1.19
+++ src/modules/perl/modperl_util.h 2001/10/02 10:47:30
@@ -72,4 +72,8 @@
SV *modperl_table_get_set(pTHX_ apr_table_t *table, char *key,
SV *sv_val, bool do_taint);
+MP_INLINE module *modperl_get_ap_module(const char *name);
+
+MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name);
+
#endif /* MODPERL_UTIL_H */
Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/lib/Apache/compat.pm,v
retrieving revision 1.15
diff -u -I'$Id' -I'$Revision' -r1.15 compat.pm
--- lib/Apache/compat.pm 2001/10/01 09:04:10 1.15
+++ lib/Apache/compat.pm 2001/10/02 10:47:30
@@ -42,6 +42,11 @@
sub untaint {
}
+sub module {
+ eval { require Apache::Module; };
+ return Apache::Module::loaded($_[1]);
+}
+
package Apache::Constants;
use Apache::Const ();
On Tue, Oct 02, 2001 at 06:14:11PM +0800, Stas Bekman wrote:
> Philippe M . Chiasson wrote:
>
> > Hi, this patch implements the Apache->module() functionnality with a few differences.
> >
> > Apache->module() is in Apache::compat and the real name for this is Apache::Module::loaded()
> > and I am open for better suggestions. "if (Apache->module('Apache::Auth'))" doesn't quite
> > make as much sense to me than "if (Apache::Module::loaded('Apache::Auth'))"
> >
> > Added a fet test cases for it and took the time to rewrite the module.t tests
> > with Stas's cool t_cmp()
> >
> > The behavious is now 3-fold instead of 2 like mod_perl 1.x
> >
> > 1- if the name ends in '.c' then it will return true/false if that apache
> > module is present or not.
> >
> > 2- if the name ends in '.so' then it will return true/false if that apache
> > module is present and was loaded as a DSO
> >
> > 3- else it returns true/false if a perl module of that name is already loaded.
> >
> > Comments most welcome.
> >
> > Index: todo/api.txt
> > ===================================================================
> > RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
> > retrieving revision 1.6
> > diff -u -I'$Id' -I'$Revision' -r1.6 api.txt
> > --- todo/api.txt 2001/09/28 13:51:57 1.6
> > +++ todo/api.txt 2001/10/02 07:17:48
> > @@ -28,9 +28,6 @@
> > $r->log_reason:
> > should be simple, see modperl_log.h
> >
> > -Apache->module:
> > -not yet implemented
> > -
> > Apache->server_root_relative:
> > needs to default to current pool (pconf at startup, r->pool at request
> > time)
> > Index: xs/maps/apache_functions.map
> > ===================================================================
> > RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/apache_functions.map,v
> > retrieving revision 1.30
> > diff -u -I'$Id' -I'$Revision' -r1.30 apache_functions.map
> > --- xs/maps/apache_functions.map 2001/09/17 01:06:08 1.30
> > +++ xs/maps/apache_functions.map 2001/10/02 07:17:48
> > @@ -180,6 +180,7 @@
> > >ap_show_directives
> > >ap_show_modules
> > >ap_register_hooks
> > + mpxs_Apache__Module_loaded
> >
> > MODULE=Apache::Directive
> > ap_directive_t *:DEFINE_conftree | | SV *:CLASS
> > Index: xs/Apache/Module/Apache__Module.h
> > ===================================================================
> > RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/Module/Apache__Module.h,v
> > retrieving revision 1.2
> > diff -u -I'$Id' -I'$Revision' -r1.2 Apache__Module.h
> > --- xs/Apache/Module/Apache__Module.h 2001/03/26 15:51:50 1.2
> > +++ xs/Apache/Module/Apache__Module.h 2001/10/02 07:17:48
> > @@ -1,2 +1,31 @@
> > #define mpxs_Apache__Module_top_module(CLASS) \
> > (CLASS ? ap_top_module : ap_top_module)
> > +
> > +static MP_INLINE
> > +int mpxs_Apache__Module_loaded(const char *name)
> > +{
> > + dTHX; /*XXX*/
> > + module *mod;
> > +
> > + if (0 == ap_strcmp_match(name,"*.c")) {
> > + mod = modperl_get_ap_module(name);
> > + return ( NULL != mod );
> > + }
> > + else if (0 == ap_strcmp_match(name,"*.so")) {
> > + size_t len = strlen(name);
> > + char *so = malloc(len+1);
>
>
> should we actually use malloc? I thought that we have to use APR for
> this kind of staff? In any case if you use malloc, you should check for
> success, right?
>
>
> > Index: t/response/TestAPI/module.pm
> > ===================================================================
> > RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/module.pm,v
> > retrieving revision 1.1
> > diff -u -I'$Id' -I'$Revision' -r1.1 module.pm
> > --- t/response/TestAPI/module.pm 2001/04/04 05:45:48 1.1
> > +++ t/response/TestAPI/module.pm 2001/10/02 07:17:48
> > @@ -4,32 +4,51 @@
> > use warnings FATAL => 'all';
> >
> > use Apache::Test;
> > +use Apache::TestConfig;
> > +use Apache::TestUtil;
> > use Apache::Module ();
> > use DynaLoader ();
> >
> > sub handler {
> > my $r = shift;
> >
> > - plan $r, tests => 6;
> > + my $cfg = Apache::TestConfig->thaw;
>
>
> that's too heavy. please use Apache::Test::config() instead. I'll
> correct other tests not to use thaw.
>
>
> > - ok $top_module->version;
> > + ok t_cmp($cfg->{httpd_info}{MODULE_MAGIC_NUMBER}, $top_module->version . ':0' , q{$top_module->version});
>
>
> < 74-80 char wrap here please, and the rest of the file
>
>
> > - ok $top_module->module_index;
> > + ok t_cmp(scalar(keys(%{$cfg->{modules}})), $top_module->module_index, q{$top_module->module_index});
>
>
> better readable as %{ $cfg->{modules} }
>
>
> > - ok $top_module->name;
> > + ok t_cmp('mod_perl.c', $top_module->name(), q{$top_module->name});
>
>
> > + ok t_cmp(0, Apache::Module::loaded('foo'), "Apache::Module::loaded('foo')");
>
>
> 'foo' is too useful to be make sure that it won't fail in the future, if
> someone adds module_foo (like module_example). When in doubt, use the
> test package name, e.g. TestAPI__module, it's unique in t.
>
> ...the rest looks good :) thanks Philippe
>
> _____________________________________________________________________
> Stas Bekman JAm_pH -- Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide http://perl.apache.org/guide
> mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
> http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
>
--
Philippe M. Chiasson <go...@cpan.org>
Extropia's Resident System Guru
http://www.eXtropia.com/
/* After several hours of tedious analysis, the following
hash * function won. Do not mess with it... -DaveM */
-- Linux 2.2.16 /usr/src/linux/fs/buffer.c
perl -e '$$=\${gozer};{$_=unpack(P26,pack(L,$$));/^Just Another Perl Hacker!\n$/&&print||$$++&&redo}'
Re: [Patch] Apache->module()
Posted by Stas Bekman <st...@stason.org>.
Philippe M . Chiasson wrote:
> Hi, this patch implements the Apache->module() functionnality with a few differences.
>
> Apache->module() is in Apache::compat and the real name for this is Apache::Module::loaded()
> and I am open for better suggestions. "if (Apache->module('Apache::Auth'))" doesn't quite
> make as much sense to me than "if (Apache::Module::loaded('Apache::Auth'))"
>
> Added a fet test cases for it and took the time to rewrite the module.t tests
> with Stas's cool t_cmp()
>
> The behavious is now 3-fold instead of 2 like mod_perl 1.x
>
> 1- if the name ends in '.c' then it will return true/false if that apache
> module is present or not.
>
> 2- if the name ends in '.so' then it will return true/false if that apache
> module is present and was loaded as a DSO
>
> 3- else it returns true/false if a perl module of that name is already loaded.
>
> Comments most welcome.
>
> Index: todo/api.txt
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
> retrieving revision 1.6
> diff -u -I'$Id' -I'$Revision' -r1.6 api.txt
> --- todo/api.txt 2001/09/28 13:51:57 1.6
> +++ todo/api.txt 2001/10/02 07:17:48
> @@ -28,9 +28,6 @@
> $r->log_reason:
> should be simple, see modperl_log.h
>
> -Apache->module:
> -not yet implemented
> -
> Apache->server_root_relative:
> needs to default to current pool (pconf at startup, r->pool at request
> time)
> Index: xs/maps/apache_functions.map
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/apache_functions.map,v
> retrieving revision 1.30
> diff -u -I'$Id' -I'$Revision' -r1.30 apache_functions.map
> --- xs/maps/apache_functions.map 2001/09/17 01:06:08 1.30
> +++ xs/maps/apache_functions.map 2001/10/02 07:17:48
> @@ -180,6 +180,7 @@
> >ap_show_directives
> >ap_show_modules
> >ap_register_hooks
> + mpxs_Apache__Module_loaded
>
> MODULE=Apache::Directive
> ap_directive_t *:DEFINE_conftree | | SV *:CLASS
> Index: xs/Apache/Module/Apache__Module.h
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/Module/Apache__Module.h,v
> retrieving revision 1.2
> diff -u -I'$Id' -I'$Revision' -r1.2 Apache__Module.h
> --- xs/Apache/Module/Apache__Module.h 2001/03/26 15:51:50 1.2
> +++ xs/Apache/Module/Apache__Module.h 2001/10/02 07:17:48
> @@ -1,2 +1,31 @@
> #define mpxs_Apache__Module_top_module(CLASS) \
> (CLASS ? ap_top_module : ap_top_module)
> +
> +static MP_INLINE
> +int mpxs_Apache__Module_loaded(const char *name)
> +{
> + dTHX; /*XXX*/
> + module *mod;
> +
> + if (0 == ap_strcmp_match(name,"*.c")) {
> + mod = modperl_get_ap_module(name);
> + return ( NULL != mod );
> + }
> + else if (0 == ap_strcmp_match(name,"*.so")) {
> + size_t len = strlen(name);
> + char *so = malloc(len+1);
should we actually use malloc? I thought that we have to use APR for
this kind of staff? In any case if you use malloc, you should check for
success, right?
> Index: t/response/TestAPI/module.pm
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/module.pm,v
> retrieving revision 1.1
> diff -u -I'$Id' -I'$Revision' -r1.1 module.pm
> --- t/response/TestAPI/module.pm 2001/04/04 05:45:48 1.1
> +++ t/response/TestAPI/module.pm 2001/10/02 07:17:48
> @@ -4,32 +4,51 @@
> use warnings FATAL => 'all';
>
> use Apache::Test;
> +use Apache::TestConfig;
> +use Apache::TestUtil;
> use Apache::Module ();
> use DynaLoader ();
>
> sub handler {
> my $r = shift;
>
> - plan $r, tests => 6;
> + my $cfg = Apache::TestConfig->thaw;
that's too heavy. please use Apache::Test::config() instead. I'll
correct other tests not to use thaw.
> - ok $top_module->version;
> + ok t_cmp($cfg->{httpd_info}{MODULE_MAGIC_NUMBER}, $top_module->version . ':0' , q{$top_module->version});
< 74-80 char wrap here please, and the rest of the file
> - ok $top_module->module_index;
> + ok t_cmp(scalar(keys(%{$cfg->{modules}})), $top_module->module_index, q{$top_module->module_index});
better readable as %{ $cfg->{modules} }
> - ok $top_module->name;
> + ok t_cmp('mod_perl.c', $top_module->name(), q{$top_module->name});
> + ok t_cmp(0, Apache::Module::loaded('foo'), "Apache::Module::loaded('foo')");
'foo' is too useful to be make sure that it won't fail in the future, if
someone adds module_foo (like module_example). When in doubt, use the
test package name, e.g. TestAPI__module, it's unique in t.
...the rest looks good :) thanks Philippe
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [Patch] Apache->module()
Posted by Doug MacEachern <do...@covalent.net>.
On Thu, 4 Oct 2001, Philippe M . Chiasson wrote:
> Okay, it sure makes sense to _really_ check in @INC, it's just quite complicated
> compared to checking the stash. One question about that stuff. Why isn't there
> a generic function somwehre in perl to convert Perl package name to a filename ? Or haven't
> I looked enough... Because I have the impression that simply s/::/\//g and slapping
> a '.pm' at the end most definitely doesn't work on all platforms ...
dunno why perl doesn't have a generic function (normally happens in
Perl_ck_require). but s,::,/,g and .= '.pm' will work on all platforms,
Perl always stores the %INC filename in that format.
> I just wonder what should be the clean way to dynamically allocate memory when
> you need it, if you need it, without a handle on things like the current
> request/pool...
require an APR::Pool to be passed into the function.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [Patch] Apache->module()
Posted by "Philippe M . Chiasson" <go...@cpan.org>.
On Wed, Oct 03, 2001 at 08:40:40PM -0700, Doug MacEachern wrote:
> On Thu, 4 Oct 2001, Philippe M . Chiasson wrote:
>
> > Can you tell me exactly why ? I started doing it the way 1.x used to do it
> > but it was pretty complicated and I thought about this method instead, that
> > sounded as good yet a lot simpler. Care to explain why we need to check %INC
> > for real ?
>
> just because it is possible for a %package:: to exist with the .pm loaded.
> but i guess we could just check the package for now and change later if
> needed. pretty sure 1.x goes through the trouble for a reason, but we can
> wait and seen if there actually is a problem which just checking the
> stash.
Okay, it sure makes sense to _really_ check in @INC, it's just quite complicated
compared to checking the stash. One question about that stuff. Why isn't there
a generic function somwehre in perl to convert Perl package name to a filename ? Or haven't
I looked enough... Because I have the impression that simply s/::/\//g and slapping
a '.pm' at the end most definitely doesn't work on all platforms ...
> > One question remains though, if I am stuck in some bit of code that doesn't
> > get passed anything interesting as arguments, how can I cleanly get my hands
> > on the current apr_pool ?
>
> there is apr_pool_t *modperl_global_pconf_get() to get the server pool,
> and modperl_global_request_rec_get() for the current request_rec (only
> with PerlOptions +GlobalRequest). we should try to avoid using these
> globals at all costs though.
Yes, I understand why these things should be avoided ;-)
I just wonder what should be the clean way to dynamically allocate memory when
you need it, if you need it, without a handle on things like the current
request/pool...
--
+----------------------------------------------------+
| Philippe M. Chiasson <go...@cpan.org> |
+----------------------------------------------------+
| F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5 |
+----------------------------------------------------+
gethostent not implemented : Your C library apparently
doesn't implement gethostent(), probably because if it did,
it'd feel morally obligated to return every hostname on the
Internet.
-- perldiag(1)
perl -e '$$=\${gozer};{$_=unpack(P26,pack(L,$$));/^Just Another Perl Hacker!\n$/&&print||$$++&&redo}'
Re: [Patch] Apache->module() (take 2)
Posted by Doug MacEachern <do...@covalent.net>.
looks great, i will test/apply later today or tommorrow once i'm caught up
with some other things.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
[Patch] Apache->module() (take 2)
Posted by "Philippe M . Chiasson" <go...@cpan.org>.
On Wed, Oct 03, 2001 at 08:40:40PM -0700, Doug MacEachern wrote:
> On Thu, 4 Oct 2001, Philippe M . Chiasson wrote:
>
> > Can you tell me exactly why ? I started doing it the way 1.x used to do it
> > but it was pretty complicated and I thought about this method instead, that
> > sounded as good yet a lot simpler. Care to explain why we need to check %INC
> > for real ?
>
> just because it is possible for a %package:: to exist with the .pm loaded.
> but i guess we could just check the package for now and change later if
> needed. pretty sure 1.x goes through the trouble for a reason, but we can
> wait and seen if there actually is a problem which just checking the
> stash.
>
> > One question remains though, if I am stuck in some bit of code that doesn't
> > get passed anything interesting as arguments, how can I cleanly get my hands
> > on the current apr_pool ?
>
> there is apr_pool_t *modperl_global_pconf_get() to get the server pool,
> and modperl_global_request_rec_get() for the current request_rec (only
> with PerlOptions +GlobalRequest). we should try to avoid using these
> globals at all costs though.
With all that considered and the previous code suggestion, here is a new
patch that hopefully should be better ;-)
/home/gozer/sources/mod_perl2/deps/perl/bin/perl build/cvsdiff
Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/lib/Apache/compat.pm,v
retrieving revision 1.15
diff -u -U5 -b -B -I'$Id' -I'$Revision' -r1.15 compat.pm
--- lib/Apache/compat.pm 2001/10/01 09:04:10 1.15
+++ lib/Apache/compat.pm 2001/10/02 05:44:01
@@ -40,10 +40,15 @@
}
sub untaint {
}
+sub module {
+ eval { require Apache::Module; };
+ return Apache::Module::loaded($_[1]);
+}
+
package Apache::Constants;
use Apache::Const ();
sub import {
Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/src/modules/perl/modperl_util.c,v
retrieving revision 1.19
diff -u -U5 -b -B -I'$Id' -I'$Revision' -r1.19 modperl_util.c
--- src/modules/perl/modperl_util.c 2001/09/28 20:11:01 1.19
+++ src/modules/perl/modperl_util.c 2001/10/04 08:52:53
@@ -441,5 +441,10 @@
apr_table_set(table, key, SvPV_nolen(sv_val));
}
return RETVAL;
}
+
+MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name)
+{
+ return (NULL != gv_stashpv(name, FALSE));
+}
Index: src/modules/perl/modperl_util.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/src/modules/perl/modperl_util.h,v
retrieving revision 1.19
diff -u -U5 -b -B -I'$Id' -I'$Revision' -r1.19 modperl_util.h
--- src/modules/perl/modperl_util.h 2001/09/28 20:11:01 1.19
+++ src/modules/perl/modperl_util.h 2001/10/04 08:53:04
@@ -70,6 +70,8 @@
char *key, SV *sv_val);
SV *modperl_table_get_set(pTHX_ apr_table_t *table, char *key,
SV *sv_val, bool do_taint);
+MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name);
+
#endif /* MODPERL_UTIL_H */
Index: t/response/TestAPI/module.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/module.pm,v
retrieving revision 1.1
diff -u -U5 -b -B -I'$Id' -I'$Revision' -r1.1 module.pm
--- t/response/TestAPI/module.pm 2001/04/04 05:45:48 1.1
+++ t/response/TestAPI/module.pm 2001/10/04 06:58:02
@@ -2,36 +2,76 @@
use strict;
use warnings FATAL => 'all';
use Apache::Test;
+use Apache::TestConfig;
+use Apache::TestUtil;
use Apache::Module ();
use DynaLoader ();
sub handler {
my $r = shift;
- plan $r, tests => 6;
+ my $cfg = Apache::Test::config();
+ plan $r, tests => 14;
+
my $top_module = Apache::Module->top_module;
ok $top_module;
+
+ ok t_cmp($cfg->{httpd_info}{MODULE_MAGIC_NUMBER},
+ $top_module->version . ':0',
+ q{$top_module->version});
+
+ ok t_cmp(scalar(keys(%{ $cfg->{modules} })),
+ $top_module->module_index,
+ q{$top_module->module_index});
+
+ ok t_cmp('mod_perl.c', $top_module->name(), q{$top_module->name});
- ok $top_module->version;
+ my $cmd = $top_module->cmds;
- ok $top_module->module_index;
+ ok defined $cmd;
- ok $top_module->name;
+ ok UNIVERSAL::isa($cmd, 'Apache::Command');
- ok $top_module->cmds;
+ {
+ local $cfg->{modules}{'mod_perl.c'} = 1;
+ my $modules = {};
for (my $modp = $top_module; $modp; $modp = $modp->next) {
- if ($modp->name eq 'mod_perl.c') {
- ok 1;
- last;
+ if ($modp && $modp->name) {
+ $modules->{$modp->name} = 1;
}
}
+ ok t_cmp($cfg->{modules}, $modules,"Modules list");
+ }
+
+ #.c
+ ok t_cmp(1, Apache::Module::loaded('mod_perl.c'),
+ "Apache::Module::loaded('mod_perl.c')");
+ ok t_cmp(0, Apache::Module::loaded('Apache__Module_foo.c'),
+ "Apache::Module::loaded('Apache__MOdule_foo.c')");
+
+ #.so
+ ok t_cmp(1, Apache::Module::loaded('mod_perl.so'),
+ "Apache::Module::loaded('mod_perl.so')");
+ ok t_cmp(0, Apache::Module::loaded('Apache__Module__foo.so'),
+ "Apache::Module::loaded('Apache__Module_foo.so')");
+
+ #perl
+ ok t_cmp(1, Apache::Module::loaded('Apache::Module'),
+ "Apache::Module::loaded('Apache::Module')");
+ ok t_cmp(0, Apache::Module::loaded('Apache__Module_foo'),
+ "Apache::Module::loaded('Apache__Module_foo')");
+
+ #bogus
+ ok t_cmp(0, Apache::Module::loaded('Apache__Module_foo.foo'),
+ "Apache::Module::loaded('Apache__Module_foo.foo')");
+
0;
}
1;
Index: todo/api.txt
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
retrieving revision 1.7
diff -u -U5 -b -B -I'$Id' -I'$Revision' -r1.7 api.txt
--- todo/api.txt 2001/10/02 13:36:10 1.7
+++ todo/api.txt 2001/10/03 02:22:58
@@ -26,13 +26,10 @@
instead.
$r->log_reason:
should be simple, see modperl_log.h
-Apache->module:
-not yet implemented
-
Apache->server_root_relative:
needs to default to current pool (pconf at startup, r->pool at request
time)
Apache::Util::*
Index: xs/Apache/Module/Apache__Module.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/Module/Apache__Module.h,v
retrieving revision 1.2
diff -u -U5 -b -B -I'$Id' -I'$Revision' -r1.2 Apache__Module.h
--- xs/Apache/Module/Apache__Module.h 2001/03/26 15:51:50 1.2
+++ xs/Apache/Module/Apache__Module.h 2001/10/04 09:12:08
@@ -1,2 +1,36 @@
#define mpxs_Apache__Module_top_module(CLASS) \
(CLASS ? ap_top_module : ap_top_module)
+
+static MP_INLINE int mpxs_Apache__Module_loaded(char *name)
+{
+ dTHX; /*XXX*/
+ char nameptr[255];
+ char *base;
+ module *modp;
+
+ /* Does the module name have a '.' in it ? */
+ if ((base = ap_strchr(name, '.'))) {
+ int len = base - name;
+
+ memcpy(nameptr, name, len);
+ memcpy(nameptr + len, ".c\0", 3);
+
+ /* is that module NOT loaded at all? */
+ modp = ap_find_linked_module(nameptr);
+ if (NULL == modp)
+ return 0;
+
+ if ('c' == *(base + 1))
+ return 1;
+
+ /* if it ends in '.so', check if it was dynamically loaded */
+ if ('s' == *(base + 1) && 'o' == *(base + 2)
+ && modp->dynamic_load_handle)
+ return 1;
+
+ return 0;
+ }
+ else {
+ return modperl_is_module_loaded(aTHX_ name);
+ }
+}
Index: xs/maps/apache_functions.map
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/apache_functions.map,v
retrieving revision 1.30
diff -u -U5 -b -B -I'$Id' -I'$Revision' -r1.30 apache_functions.map
--- xs/maps/apache_functions.map 2001/09/17 01:06:08 1.30
+++ xs/maps/apache_functions.map 2001/10/01 10:58:47
@@ -178,10 +178,11 @@
>ap_single_module_configure
>ap_setup_prelinked_modules
>ap_show_directives
>ap_show_modules
>ap_register_hooks
+ mpxs_Apache__Module_loaded
MODULE=Apache::Directive
ap_directive_t *:DEFINE_conftree | | SV *:CLASS
!ap_add_node
!ap_build_config
--
+----------------------------------------------------+
| Philippe M. Chiasson <go...@cpan.org> |
+----------------------------------------------------+
| F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5 |
+----------------------------------------------------+
gethostent not implemented : Your C library apparently
doesn't implement gethostent(), probably because if it did,
it'd feel morally obligated to return every hostname on the
Internet.
-- perldiag(1)
perl -e '$$=\${gozer};{$_=unpack(P26,pack(L,$$));/^Just Another Perl Hacker!\n$/&&print||$$++&&redo}'
Re: [Patch] Apache->module()
Posted by Doug MacEachern <do...@covalent.net>.
On Thu, 4 Oct 2001, Philippe M . Chiasson wrote:
> Can you tell me exactly why ? I started doing it the way 1.x used to do it
> but it was pretty complicated and I thought about this method instead, that
> sounded as good yet a lot simpler. Care to explain why we need to check %INC
> for real ?
just because it is possible for a %package:: to exist with the .pm loaded.
but i guess we could just check the package for now and change later if
needed. pretty sure 1.x goes through the trouble for a reason, but we can
wait and seen if there actually is a problem which just checking the
stash.
> One question remains though, if I am stuck in some bit of code that doesn't
> get passed anything interesting as arguments, how can I cleanly get my hands
> on the current apr_pool ?
there is apr_pool_t *modperl_global_pconf_get() to get the server pool,
and modperl_global_request_rec_get() for the current request_rec (only
with PerlOptions +GlobalRequest). we should try to avoid using these
globals at all costs though.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [Patch] Apache->module()
Posted by "Philippe M . Chiasson" <go...@cpan.org>.
On Wed, Oct 03, 2001 at 09:51:09AM -0700, Doug MacEachern wrote:
> On Tue, 2 Oct 2001, Philippe M . Chiasson wrote:
>
> > Hi, this patch implements the Apache->module() functionnality with a few differences.
> >
> > Apache->module() is in Apache::compat and the real name for this is Apache::Module::loaded()
> > and I am open for better suggestions. "if (Apache->module('Apache::Auth'))" doesn't quite
> > make as much sense to me than "if (Apache::Module::loaded('Apache::Auth'))"
>
> name is fine.
>
> > +
> > +MP_INLINE module *modperl_get_ap_module(const char *name)
> > +{
> > + module *modp;
> > + for (modp = ap_top_module; modp; modp = modp->next) {
> > + if (modp && modp->name && ( 0 == apr_strnatcmp(modp->name, name))) {
> > + return modp;
> > + }
> > + }
> > + return NULL;
> > +}
>
> why not just use ap_find_linked_module like 1.x does?
Good idea, I must have overlooked that one.
>
> > +MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name)
> > +{
> > + return (NULL != gv_stashpv(name, FALSE));
> > +}
>
> this also needs to be as 1.x is, checking that the module exists in %INC
Can you tell me exactly why ? I started doing it the way 1.x used to do it
but it was pretty complicated and I thought about this method instead, that
sounded as good yet a lot simpler. Care to explain why we need to check %INC
for real ?
> as for the malloc, we should avoid that. see if you can work off
> this..
Good idea, will try to get that in soon.
One question remains though, if I am stuck in some bit of code that doesn't
get passed anything interesting as arguments, how can I cleanly get my hands
on the current apr_pool ?
> #include <stdio.h>
> #include <string.h>
>
> int module_loaded(const char *module_name)
> {
> char name[256]; /* should be plenty of space */
> const char *nameptr = name, *base;
>
> if ((base = strchr(module_name, '.'))) {
> int len = base - module_name;
> int shared;
>
> memcpy((void*)nameptr, module_name, len);
> memcpy((void*)nameptr + len, ".c\0", 3);
>
> fprintf(stderr, "cmodule name=%s\n", nameptr);
> /* if (!(modp = ap_find_linked_module(nameptr))) return 0; */
>
> shared = *(base + 1) == 'c' ? 0 : 1;
>
> if (shared) {
> fprintf(stderr, "checking for shared module\n");
> /* if (!modp->dynamic_load_handle) return 0; */
> }
>
> return 1;
> }
>
>
> fprintf(stderr, "perl module name=%s\n", module_name);
> /* if (modperl_perl_module_loaded(module_name) return 1; else */
> return 0;
> }
>
> static const char *modules[] = {
> "mod_perl.c", "mod_perl.so", "Apache::Status", NULL,
> };
>
> int main(int argc, char **argv, char **env)
> {
> int i;
> for (i=0; modules[i]; i++) {
> module_loaded(modules[i]);
> }
> return 0;
> }
>
>
--
+----------------------------------------------------+
| Philippe M. Chiasson <go...@cpan.org> |
+----------------------------------------------------+
| F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5 |
+----------------------------------------------------+
gethostent not implemented : Your C library apparently
doesn't implement gethostent(), probably because if it did,
it'd feel morally obligated to return every hostname on the
Internet.
-- perldiag(1)
perl -e '$$=\${gozer};{$_=unpack(P26,pack(L,$$));/^Just Another Perl Hacker!\n$/&&print||$$++&&redo}'
Re: [Patch] Apache->module()
Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 2 Oct 2001, Philippe M . Chiasson wrote:
> Hi, this patch implements the Apache->module() functionnality with a few differences.
>
> Apache->module() is in Apache::compat and the real name for this is Apache::Module::loaded()
> and I am open for better suggestions. "if (Apache->module('Apache::Auth'))" doesn't quite
> make as much sense to me than "if (Apache::Module::loaded('Apache::Auth'))"
name is fine.
> +
> +MP_INLINE module *modperl_get_ap_module(const char *name)
> +{
> + module *modp;
> + for (modp = ap_top_module; modp; modp = modp->next) {
> + if (modp && modp->name && ( 0 == apr_strnatcmp(modp->name, name))) {
> + return modp;
> + }
> + }
> + return NULL;
> +}
why not just use ap_find_linked_module like 1.x does?
> +MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name)
> +{
> + return (NULL != gv_stashpv(name, FALSE));
> +}
this also needs to be as 1.x is, checking that the module exists in %INC
as for the malloc, we should avoid that. see if you can work off
this..
#include <stdio.h>
#include <string.h>
int module_loaded(const char *module_name)
{
char name[256]; /* should be plenty of space */
const char *nameptr = name, *base;
if ((base = strchr(module_name, '.'))) {
int len = base - module_name;
int shared;
memcpy((void*)nameptr, module_name, len);
memcpy((void*)nameptr + len, ".c\0", 3);
fprintf(stderr, "cmodule name=%s\n", nameptr);
/* if (!(modp = ap_find_linked_module(nameptr))) return 0; */
shared = *(base + 1) == 'c' ? 0 : 1;
if (shared) {
fprintf(stderr, "checking for shared module\n");
/* if (!modp->dynamic_load_handle) return 0; */
}
return 1;
}
fprintf(stderr, "perl module name=%s\n", module_name);
/* if (modperl_perl_module_loaded(module_name) return 1; else */
return 0;
}
static const char *modules[] = {
"mod_perl.c", "mod_perl.so", "Apache::Status", NULL,
};
int main(int argc, char **argv, char **env)
{
int i;
for (i=0; modules[i]; i++) {
module_loaded(modules[i]);
}
return 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org