perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@cpan.org>
Subject Re: [MP2 Patch] Bug ? Recursion in parsing of PerlSection
Date Tue, 27 May 2003 04:40:05 GMT
On Tue, 2003-05-27 at 12:00, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> [...]
> > Is evaluated in Apache::ReadConfig's namespace, even if it does nothing.
> > 
> > Once again Apache::PerlSections is called in with Apache::ReadConfig as
> > the namespace
> > 
> > This handler will once again see
> > 
> > @Apache::ReadConfig::include = "foo.conf";
> > 
> > and here starts the recursion.
> > 
> > 
> > This is a hairy problem indeed. I realized this partially in the past,
> > when re-introducing PerlSaveConfig but didn't think of this particular
> > recursive possibility.
> > 
> > The way I see it, there is only a few ways to proprely fix this.
> > 
> > 1. To use one _extra_ namespace to save the config into, if
> > PerlSaveConfig is specified, and delete or move elements from
> > Apache::ReadConfig as it is being processed.
> > 
> > 2. To use automatically-generated namespaces for each <Perl > sections,
> > like ModPerl::Registry, like Apache::ReadConfig::blocknnn or something.
> > 
> > I personally prefer solution #2.
> > 
> > Ideas/suggestions ? If not, I'll probably give a shot at implementing #2
> > sometime this week.
> 
> Do you have to process again the include directive? 

Well, if I PerlSection was smart enough it could treat @Include
directives as a special case, but that wouldn't solve the whole problem.

> If not, why not use the 
> same solution as used by require, which stores name=>path of loaded files in 
> %INC. I don't know where you currently store the processed result of include, 
> but if you lose it, why not store it in %Apache::ReadConfig::INC, with key 
> being the included filename and value the result of the include? Though need 
> to ensure that we have no duplication when two files with indentical names 
> (but located at different paths) are included. Should probably resolve these 
> to a full path? or append the parent's path?

Yes, I thought along those lines, but the simplest problem with this
approach is this (unrelated to first problem, it's a second problem)

<Perl >
push @Alias = [ '/foo', '/bar' ];
</Perl>

And later on

<Perl >
1;
</Perl>

Will cause a warning about one Alias shadowing another one.

The core reason why <Perl > blocks are a bit broken right now is
because multiple <Perl > sections add to the same namespace (if
SaveSections is on, or if @include is used), and when the PerlSection
handler kicks in , it has no way to differentiate between the content it
has processed before vs. the new stuff.

I thougth about many ways of moving stuff as it's being processed, but
it would be quite complex, as it's all recursive and all.

The following patch does work nicely for me though.

It puts each <Perl > block in it's own namespace, and keeps feeding them
to the handler as usual. It all works fine. When it's time to have
Apache::PerlSections->Dump(), it'll be just a matter of iterating over
all those namespaces, striping them out before printing them.

And since Dump() has not been ported yet (mea culpa), I figured this
change wouldn't break anything.

Thoughts ?

# $Id: Apache_PerlSections_ns.patch,v 1.1 2003/05/27 04:39:40 gozer Exp $

Index: src/modules/perl/modperl_cmd.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.47
diff -u -I$Id -r1.47 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c	16 Apr 2003 03:03:35 -0000	1.47
+++ src/modules/perl/modperl_cmd.c	27 May 2003 04:38:32 -0000
@@ -360,6 +360,7 @@
     const char *package_name = NULL;
     int status = OK;
     AV *args = Nullav;
+    static int ns_counter = 0;
 #ifdef USE_ITHREADS
     MP_dSCFG(s);
     pTHX;
@@ -392,8 +393,11 @@
             
         if (!(package_name = apr_table_get(options, "package"))) {
             package_name = apr_pstrdup(p, MP_DEFAULT_PERLSECTION_PACKAGE);
-            apr_table_set(options, "package", package_name);
         }
+
+        package_name = apr_pstrcat(p, package_name,"::", 
+                                   apr_itoa(p, ns_counter++), NULL);
+        apr_table_set(options, "package", package_name);
 
         /* put the code about to be executed in the configured package */
         arg = apr_pstrcat(p, "package ", package_name, ";", arg, NULL);
Index: t/response/TestDirective/perldo.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestDirective/perldo.pm,v
retrieving revision 1.3
diff -u -I$Id -r1.3 perldo.pm
--- t/response/TestDirective/perldo.pm	17 Mar 2003 06:46:56 -0000	1.3
+++ t/response/TestDirective/perldo.pm	27 May 2003 04:38:33 -0000
@@ -14,11 +14,11 @@
 
     ok t_cmp('yes', $TestDirective::perl::worked);
     
-    ok not exists $Apache::ReadConfig::Location{'/perl_sections'};
+    ok not exists $Apache::ReadConfig::1::Location{'/perl_sections'};
     
-    ok exists $Apache::ReadConfig::Location{'/perl_sections_saved'};
+    ok exists $Apache::ReadConfig::2::Location{'/perl_sections_saved'};
   
-    ok t_cmp('PerlSection', $Apache::ReadConfig::Location{'/perl_sections_saved'}{'AuthName'});
+    ok t_cmp('PerlSection', $Apache::ReadConfig::2::Location{'/perl_sections_saved'}{'AuthName'});
 
     ok t_cmp('yes', $TestDirective::perl::comments);
 



> 
> __________________________________________________________________
> 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
-- 
-- -----------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Mime
View raw message