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 2003/11/11 21:29:52 UTC

[PATCH mp2] sections not setting filename/lineno correctly

Until now, code executing within <Perl > sections was not 'tweaked' to
match the filename/lineno of the httpd configuration file it was in.

So, for example, error reporting would appear to be coming from obscure
eval contexts.

Following patch restores the same behaviour than in mp1.


Index: Changes
===================================================================
RCS file: /home/cvs/modperl-2.0/Changes,v
retrieving revision 1.249
diff -u -I$Id: -r1.249 Changes
--- Changes	10 Nov 2003 21:11:53 -0000	1.249
+++ Changes	11 Nov 2003 20:24:24 -0000
@@ -14,6 +14,9 @@
 
 =item 1.99_11 - November 10, 2003
 
+<Perl> sections now proprely set filename and line number information,
+making error messages report the correct location. [Philippe M. Chiasson]
+
 add a build/win32_fetch_apxs script (called within the top-level
 Makefile.PL) to offer to fetch and install a Win32 development
 version of apxs and (apr|apu)-config [Randy Kobes]
Index: src/modules/perl/modperl_cmd.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.49
diff -u -I$Id: -r1.49 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c	20 Oct 2003 17:44:48 -0000	1.49
+++ src/modules/perl/modperl_cmd.c	11 Nov 2003 20:24:24 -0000
@@ -310,6 +310,7 @@
     char line[MAX_STRING_LEN];
     apr_table_t *args;
     ap_directive_t **current = mconfig;
+    int line_num;
 
     if (!endp) {
         return modperl_cmd_unclosed_directive(parms);
@@ -321,6 +322,7 @@
         return errmsg;
     }
 
+    line_num = parms->config_file->line_number+1;
     while (!ap_cfg_getline(line, sizeof(line), parms->config_file)) {
         /*XXX: Not sure how robust this is */
         if (strEQ(line, "</Perl>")) {
@@ -337,7 +339,7 @@
     }
     
     (*current)->filename = parms->config_file->name;
-    (*current)->line_num = parms->config_file->line_number;
+    (*current)->line_num = line_num;
     (*current)->directive = apr_pstrdup(p, "Perl");
     (*current)->args = code;
     (*current)->data = args;
@@ -360,6 +362,7 @@
     const char *handler_name = NULL;
     modperl_handler_t *handler = NULL;
     const char *package_name = NULL;
+    const char *line_header = NULL;
     int status = OK;
     AV *args = Nullav;
 #ifdef USE_ITHREADS
@@ -397,8 +400,10 @@
             apr_table_set(options, "package", package_name);
         }
 
+        line_header = apr_psprintf(p, "\n#line %d %s\n", parms->directive->line_num, parms->directive->filename);
+
         /* put the code about to be executed in the configured package */
-        arg = apr_pstrcat(p, "package ", package_name, ";", arg, NULL);
+        arg = apr_pstrcat(p, "package ", package_name, ";", line_header, arg, NULL);
     }
 
     eval_pv(arg, FALSE);
Index: t/conf/extra.last.conf.in
===================================================================
RCS file: /home/cvs/modperl-2.0/t/conf/extra.last.conf.in,v
retrieving revision 1.7
diff -u -I$Id: -r1.7 extra.last.conf.in
--- t/conf/extra.last.conf.in	17 Mar 2003 06:46:55 -0000	1.7
+++ t/conf/extra.last.conf.in	11 Nov 2003 20:24:24 -0000
@@ -21,6 +21,12 @@
 $TestDirective::perl::comments="yes";
 </Perl>
 
+<Perl >
+$Apache::Server::SaveConfig = 1;
+$TestDirective::perl::filename = __FILE__;
+$TestDirective::perl::line =  __LINE__;
+</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.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	11 Nov 2003 20:24:24 -0000
@@ -10,7 +10,7 @@
 sub handler {
     my $r = shift;
 
-    plan $r, tests => 5;
+    plan $r, tests => 7;
 
     ok t_cmp('yes', $TestDirective::perl::worked);
     
@@ -21,6 +21,11 @@
     ok t_cmp('PerlSection', $Apache::ReadConfig::Location{'/perl_sections_saved'}{'AuthName'});
 
     ok t_cmp('yes', $TestDirective::perl::comments);
+
+    ok t_cmp(qr/extra.last.conf/, $TestDirective::perl::filename, '__FILE__');
+
+    # 3 would mean we are still counting lines from the context of the eval
+    ok $TestDirective::perl::line > 3;
 
     Apache::OK;
 }


-- 
--------------------------------------------------------------------------------
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}'


Re: [PATCH mp2] sections not setting filename/lineno correctly

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Tue, 2003-11-11 at 17:04, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > Until now, code executing within <Perl > sections was not 'tweaked' to
> > match the filename/lineno of the httpd configuration file it was in.
> > 
> > So, for example, error reporting would appear to be coming from obscure
> > eval contexts.
> > 
> > Following patch restores the same behaviour than in mp1.
> 
> +1, with a single style fix below

I lack in style ;-p

Style fixed and change applied!

> > Index: Changes
> > ===================================================================
> > RCS file: /home/cvs/modperl-2.0/Changes,v
> > retrieving revision 1.249
> > diff -u -I$Id: -r1.249 Changes
> > --- Changes	10 Nov 2003 21:11:53 -0000	1.249
> > +++ Changes	11 Nov 2003 20:24:24 -0000
> > @@ -14,6 +14,9 @@
> >  
> >  =item 1.99_11 - November 10, 2003
> >  
> > +<Perl> sections now proprely set filename and line number information,
> > +making error messages report the correct location. [Philippe M. Chiasson]
> 
> You probably didn't cvs update your Changes ;)
> 
> > Index: src/modules/perl/modperl_cmd.c
> > ===================================================================
> [...]
> > +        line_header = apr_psprintf(p, "\n#line %d %s\n", parms->directive->line_num, parms->directive->filename);
> 
> This line needs to be wrapped.
> 
> 
> __________________________________________________________________
> 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}'

Re: [PATCH mp2] sections not setting filename/lineno correctly

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> Until now, code executing within <Perl > sections was not 'tweaked' to
> match the filename/lineno of the httpd configuration file it was in.
> 
> So, for example, error reporting would appear to be coming from obscure
> eval contexts.
> 
> Following patch restores the same behaviour than in mp1.

+1, with a single style fix below

> Index: Changes
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/Changes,v
> retrieving revision 1.249
> diff -u -I$Id: -r1.249 Changes
> --- Changes	10 Nov 2003 21:11:53 -0000	1.249
> +++ Changes	11 Nov 2003 20:24:24 -0000
> @@ -14,6 +14,9 @@
>  
>  =item 1.99_11 - November 10, 2003
>  
> +<Perl> sections now proprely set filename and line number information,
> +making error messages report the correct location. [Philippe M. Chiasson]

You probably didn't cvs update your Changes ;)

> Index: src/modules/perl/modperl_cmd.c
> ===================================================================
[...]
> +        line_header = apr_psprintf(p, "\n#line %d %s\n", parms->directive->line_num, parms->directive->filename);

This line needs to be wrapped.


__________________________________________________________________
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