You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2003/03/02 05:31:58 UTC

Re: [patch] $Apache::Server::SaveConfig

Philippe M. Chiasson wrote:
> Another <Perl > section backwards-compatibility item on the TODO list.
> 
> Perl $Apache::Server::SaveConfig = 1
> 
> in httpd.conf will retain all the code of the <Perl > sections, otherwise,
> the whole namespace is whiped (modperl_clear_symtab) stolen from mp1

Great, Philippe! A few minor comments:

> Index: src/modules/perl/modperl_cmd.c
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
> retrieving revision 1.38
> diff -u -I'$Id' -I'$Revision' -r1.38 modperl_cmd.c
> --- src/modules/perl/modperl_cmd.c	26 Feb 2003 09:32:54 -0000	1.38
> +++ src/modules/perl/modperl_cmd.c	27 Feb 2003 04:58:27 -0000
> @@ -318,6 +318,8 @@
>  #define MP_DEFAULT_PERLSECTION_PACKAGE "Apache::ReadConfig"
>  #define MP_STRICT_PERLSECTIONS_SV \
>  get_sv("Apache::Server::StrictPerlSections", FALSE)

s/^/    /; (i know I've missed that on your previous one ;)

> +#define MP_PERLSECTIONS_SAVECONFIG_SV \
> +get_sv("Apache::Server::SaveConfig", FALSE)

s/^/    /;
[...]
> +            if(symtab) {

s/if\(/if (/

[...]

> Index: src/modules/perl/modperl_util.h
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.h,v
> retrieving revision 1.38
> diff -u -I'$Id' -I'$Revision' -r1.38 modperl_util.h
> --- src/modules/perl/modperl_util.h	23 Jan 2003 00:31:28 -0000	1.38
> +++ src/modules/perl/modperl_util.h	27 Feb 2003 04:58:38 -0000
> @@ -126,4 +126,6 @@
>  
>  SV *modperl_perl_gensym(pTHX_ char *pack);
>  
> +void modperl_clear_symtab(pTHX_ HV *symtab);
> +
>  #endif /* MODPERL_UTIL_H */

also needs to be added to
xs/tables/current/ModPerl/FunctionTable.pm

Finally, for this feature we actually could have a test, with a simple regex 
just to test that the config is actually there.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [patch] $Apache::Server::SaveConfig

Posted by "Philippe M. Chiasson" <go...@eXtropia.com>.
On Sun, 2003-03-02 at 12:31, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > Another <Perl > section backwards-compatibility item on the TODO list.
> > 
> > Perl $Apache::Server::SaveConfig = 1
> > 
> > in httpd.conf will retain all the code of the <Perl > sections, otherwise,
> > the whole namespace is whiped (modperl_clear_symtab) stolen from mp1
> 
> Great, Philippe! A few minor comments:

Ack and will resubmit later today. Thanks for the extra pair of
ever-vigilant eyes ;-)

> 
> > Index: src/modules/perl/modperl_cmd.c
> > ===================================================================
> > RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
> > retrieving revision 1.38
> > diff -u -I'$Id' -I'$Revision' -r1.38 modperl_cmd.c
> > --- src/modules/perl/modperl_cmd.c	26 Feb 2003 09:32:54 -0000	1.38
> > +++ src/modules/perl/modperl_cmd.c	27 Feb 2003 04:58:27 -0000
> > @@ -318,6 +318,8 @@
> >  #define MP_DEFAULT_PERLSECTION_PACKAGE "Apache::ReadConfig"
> >  #define MP_STRICT_PERLSECTIONS_SV \
> >  get_sv("Apache::Server::StrictPerlSections", FALSE)
> 
> s/^/    /; (i know I've missed that on your previous one ;)
> 
> > +#define MP_PERLSECTIONS_SAVECONFIG_SV \
> > +get_sv("Apache::Server::SaveConfig", FALSE)
> 
> s/^/    /;
> [...]
> > +            if(symtab) {
> 
> s/if\(/if (/
> 
> [...]
> 
> > Index: src/modules/perl/modperl_util.h
> > ===================================================================
> > RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.h,v
> > retrieving revision 1.38
> > diff -u -I'$Id' -I'$Revision' -r1.38 modperl_util.h
> > --- src/modules/perl/modperl_util.h	23 Jan 2003 00:31:28 -0000	1.38
> > +++ src/modules/perl/modperl_util.h	27 Feb 2003 04:58:38 -0000
> > @@ -126,4 +126,6 @@
> >  
> >  SV *modperl_perl_gensym(pTHX_ char *pack);
> >  
> > +void modperl_clear_symtab(pTHX_ HV *symtab);
> > +
> >  #endif /* MODPERL_UTIL_H */
> 
> also needs to be added to
> xs/tables/current/ModPerl/FunctionTable.pm
>
> Finally, for this feature we actually could have a test, with a simple regex 
> just to test that the config is actually there.

True, I will do that also.

> 
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
> 
> 


Re: [patch] $Apache::Server::SaveConfig

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> On Sun, 2003-03-02 at 12:31, Stas Bekman wrote:
> 
>>Philippe M. Chiasson wrote:
>>
>>>Another <Perl > section backwards-compatibility item on the TODO list.
>>>
>>>Perl $Apache::Server::SaveConfig = 1
>>>
>>>in httpd.conf will retain all the code of the <Perl > sections, otherwise,
>>>the whole namespace is whiped (modperl_clear_symtab) stolen from mp1
>>
>>Great, Philippe! A few minor comments:
>>
>>[snip]
>>also needs to be added to
>>xs/tables/current/ModPerl/FunctionTable.pm
> 
> 
> BTW, what's the state on the source scanner nowadays ?

I don't think anything has changed. It was broken for me for a long time and 
since then I was manually adding the new functions.

Gerald Richter hasn't popped up here for a long time, I don't know what's the 
status of his WrapXS generalization project. I remember he had a better 
scanner, based on Parse::RecDescent.

>>Finally, for this feature we actually could have a test, with a simple regex 
>>just to test that the config is actually there.
> 
> 
> Turned out like a very good idea to do that. Turns out the simple logic
> for SaveConfig was backwards ;-(

;)

> Following is a patch of better quality...

+1, just one comment re: test

> Index: t/response/TestDirective/perldo.pm
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/t/response/TestDirective/perldo.pm,v
> retrieving revision 1.1
> diff -u -I'$Id' -I'$Revision' -r1.1 perldo.pm
> --- t/response/TestDirective/perldo.pm	7 Oct 2002 02:35:18 -0000	1.1
> +++ t/response/TestDirective/perldo.pm	3 Mar 2003 08:51:16 -0000
> @@ -10,9 +10,13 @@
>  sub handler {
>      my $r = shift;
>  
> -    plan $r, tests => 1;
> +    plan $r, tests => 3;
>  
>      ok t_cmp('yes', $TestDirective::perl::worked);
> +    
> +    ok not exists $Apache::ReadConfig::Location{'/perl_sections'};
> +    
> +    ok exists $Apache::ReadConfig::Location{'/perl_sections_test'};

could we have one more test:

use Apache::TestUtil;

my $config = $Apache::ReadConfig::Location{'/perl_sections_test'};
ok t_cmp(qr/something/, $config, "matching something");

assuming that you can have qr/something/ that will much on all possible 
platforms and machines? see what I mean?


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [patch] $Apache::Server::SaveConfig

Posted by "Philippe M. Chiasson" <go...@eXtropia.com>.
On Sun, 2003-03-02 at 12:31, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > Another <Perl > section backwards-compatibility item on the TODO list.
> > 
> > Perl $Apache::Server::SaveConfig = 1
> > 
> > in httpd.conf will retain all the code of the <Perl > sections, otherwise,
> > the whole namespace is whiped (modperl_clear_symtab) stolen from mp1
> 
> Great, Philippe! A few minor comments:
> 
> [snip]
> also needs to be added to
> xs/tables/current/ModPerl/FunctionTable.pm

BTW, what's the state on the source scanner nowadays ?

> Finally, for this feature we actually could have a test, with a simple regex 
> just to test that the config is actually there.

Turned out like a very good idea to do that. Turns out the simple logic
for SaveConfig was backwards ;-(

Following is a patch of better quality...

Index: Changes
===================================================================
RCS file: /home/cvs/modperl-2.0/Changes,v
retrieving revision 1.141
diff -u -I'$Id' -I'$Revision' -r1.141 Changes
--- Changes	3 Mar 2003 03:39:07 -0000	1.141
+++ Changes	3 Mar 2003 08:51:15 -0000
@@ -18,6 +18,10 @@
 rflush. adjust tests, which were counting the number of invocations.
 [Stas]
 
+$Apache::Server::SaveConfig added. When set to a true value,
+will not clear the content of Apache::ReadConfig:: once <Perl >
+sections are processed. [Philippe M. Chiasson <gozer@cpan.org]
+
 move ModPerl::RegistryCooker to use a hash as object (similar to mp1),
 to make it easier to subclass. [Nathan Byrd <na...@byrd.net>]
 
Index: STATUS
===================================================================
RCS file: /home/cvs/modperl-2.0/STATUS,v
retrieving revision 1.37
diff -u -I'$Id' -I'$Revision' -r1.37 STATUS
--- STATUS	3 Mar 2003 03:50:55 -0000	1.37
+++ STATUS	3 Mar 2003 08:51:15 -0000
@@ -177,7 +177,6 @@
 ----
 
 * Apache::PerlSections missing features for backwards compatibility:
- - $Apache::Server::SaveConfig
  - $Apache::ReadConfig::DocumentRoot
  - Apache::PerlSections->store(filename)
 
Index: src/modules/perl/modperl_cmd.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.39
diff -u -I'$Id' -I'$Revision' -r1.39 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c	3 Mar 2003 05:16:07 -0000	1.39
+++ src/modules/perl/modperl_cmd.c	3 Mar 2003 08:51:15 -0000
@@ -318,6 +318,8 @@
 #define MP_DEFAULT_PERLSECTION_PACKAGE "Apache::ReadConfig"
 #define MP_STRICT_PERLSECTIONS_SV \
     get_sv("Apache::Server::StrictPerlSections", FALSE)
+#define MP_PERLSECTIONS_SAVECONFIG_SV \
+    get_sv("Apache::Server::SaveConfig", FALSE)
 
 MP_CMD_SRV_DECLARE(perldo)
 {
@@ -385,6 +387,7 @@
     }
     
     if (handler) {
+        SV *saveconfig;
         modperl_handler_make_args(aTHX_ &args,
                                   "Apache::CmdParms", parms,
                                   "APR::Table", options,
@@ -394,6 +397,13 @@
 
         SvREFCNT_dec((SV*)args);
 
+        if ( !(saveconfig = MP_PERLSECTIONS_SAVECONFIG_SV) || !SvTRUE(saveconfig) ) {
+            HV *symtab = (HV*)gv_stashpv(package_name, FALSE);
+            if (symtab) {
+                modperl_clear_symtab(aTHX_ symtab);
+            }
+        }
+        
         if (status != OK) {
             return SvTRUE(ERRSV) ? SvPVX(ERRSV) :
                 apr_psprintf(p, "<Perl> handler %s failed with status=%d",
Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.c,v
retrieving revision 1.50
diff -u -I'$Id' -I'$Revision' -r1.50 modperl_util.c
--- src/modules/perl/modperl_util.c	11 Jan 2003 00:02:16 -0000	1.50
+++ src/modules/perl/modperl_util.c	3 Mar 2003 08:51:15 -0000
@@ -615,3 +615,56 @@
     return rv;
 }
 
+static int modperl_gvhv_is_stash(GV *gv)
+{
+    int len = GvNAMELEN(gv);
+    char *name = GvNAME(gv);
+
+    if ((len > 2) && (name[len - 1] == ':') && (name[len - 2] == ':')) {
+        return 1;
+    }
+
+    return 0;
+}
+
+/*
+ * we do not clear symbols within packages, the desired behavior
+ * for directive handler classes.  and there should never be a package
+ * within the %Apache::ReadConfig.  nothing else that i'm aware of calls
+ * this function, so we should be ok.
+ */
+
+void modperl_clear_symtab(pTHX_ HV *symtab) 
+{
+    SV *val;
+    char *key;
+    I32 klen;
+
+    hv_iterinit(symtab);
+    
+    while ((val = hv_iternextsv(symtab, &key, &klen))) {
+        SV *sv;
+        HV *hv;
+        AV *av;
+        CV *cv;
+
+        if ((SvTYPE(val) != SVt_PVGV) || GvIMPORTED((GV*)val)) {
+            continue;
+        }
+        if ((sv = GvSV((GV*)val))) {
+            sv_setsv(GvSV((GV*)val), &PL_sv_undef);
+        }
+        if ((hv = GvHV((GV*)val)) && !modperl_gvhv_is_stash((GV*)val)) {
+            hv_clear(hv);
+        }
+        if ((av = GvAV((GV*)val))) {
+            av_clear(av);
+        }
+        if ((cv = GvCV((GV*)val)) && (GvSTASH((GV*)val) == GvSTASH(CvGV(cv)))) {
+            GV *gv = CvGV(cv);
+            cv_undef(cv);
+            CvGV(cv) = gv;
+            GvCVGEN(gv) = 1; /* invalidate method cache */
+        }
+    }
+}
Index: src/modules/perl/modperl_util.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.h,v
retrieving revision 1.38
diff -u -I'$Id' -I'$Revision' -r1.38 modperl_util.h
--- src/modules/perl/modperl_util.h	23 Jan 2003 00:31:28 -0000	1.38
+++ src/modules/perl/modperl_util.h	3 Mar 2003 08:51:15 -0000
@@ -126,4 +126,6 @@
 
 SV *modperl_perl_gensym(pTHX_ char *pack);
 
+void modperl_clear_symtab(pTHX_ HV *symtab);
+
 #endif /* MODPERL_UTIL_H */
Index: t/conf/extra.last.conf.in
===================================================================
RCS file: /home/cvs/modperl-2.0/t/conf/extra.last.conf.in,v
retrieving revision 1.4
diff -u -I'$Id' -I'$Revision' -r1.4 extra.last.conf.in
--- t/conf/extra.last.conf.in	13 Dec 2002 10:06:55 -0000	1.4
+++ t/conf/extra.last.conf.in	3 Mar 2003 08:51:15 -0000
@@ -12,6 +12,12 @@
 	};
 </Perl>
 
+<Perl >
+    $Apache::Server::SaveConfig = 1;
+    #This entry should survive and persist
+    $Location{'/perl_sections_test'} = {};
+</Perl>
+
 ### --------------------------------- ###
 Perl $TestDirective::perl::worked="yes";
 
Index: t/response/TestDirective/perldo.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestDirective/perldo.pm,v
retrieving revision 1.1
diff -u -I'$Id' -I'$Revision' -r1.1 perldo.pm
--- t/response/TestDirective/perldo.pm	7 Oct 2002 02:35:18 -0000	1.1
+++ t/response/TestDirective/perldo.pm	3 Mar 2003 08:51:16 -0000
@@ -10,9 +10,13 @@
 sub handler {
     my $r = shift;
 
-    plan $r, tests => 1;
+    plan $r, tests => 3;
 
     ok t_cmp('yes', $TestDirective::perl::worked);
+    
+    ok not exists $Apache::ReadConfig::Location{'/perl_sections'};
+    
+    ok exists $Apache::ReadConfig::Location{'/perl_sections_test'};
 
     Apache::OK;
 }
Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
retrieving revision 1.107
diff -u -I'$Id' -I'$Revision' -r1.107 FunctionTable.pm
--- xs/tables/current/ModPerl/FunctionTable.pm	3 Mar 2003 03:39:06 -0000	1.107
+++ xs/tables/current/ModPerl/FunctionTable.pm	3 Mar 2003 08:51:17 -0000
@@ -3635,6 +3635,20 @@
       }
     ]
   },
+    {
+    'return_type' => 'void',
+    'name' => 'modperl_clear_symtab',
+    'args' => [
+      {
+        'type' => 'PerlInterpreter *',
+        'name' => 'my_perl'
+      },
+      {
+        'type' => 'HV *',
+        'name' => 'symtab'
+      },
+    ],
+  },
   {
     'return_type' => 'HE *',
     'name' => 'modperl_perl_hv_fetch_he',


--------------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@e(x|X)tropia\.com/     88C3A5A5
(122FF51B/C634E37B)
http://www.eXtropia.com/       F9BF E0C2 480E 7680 1AE5 3631 CB32 A107
88C3 A5A5