You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Torsten Foertsch <to...@gmx.net> on 2005/01/26 11:13:05 UTC

minor bugfix for Apache::Test

Hi,

while trying out Apache-IncludeHook-2.00_02 I stumbled across the lack of 
Apache::Test::have(). This patch cures it.

Torsten

--- Apache-Test/lib/Apache/Test.pm~	2005-01-22 09:28:06.000000000 +0100
+++ Apache-Test/lib/Apache/Test.pm	2005-01-26 10:18:09.819907681 +0100
@@ -29,12 +29,12 @@
               need_module need_apache need_min_apache_version
               need_apache_version need_perl need_min_perl_version
               need_min_module_version need_threads need_apache_mpm
-              need_php need_php4 need_ssl);
+              need_php need_php4 need_ssl need);
 
 my @have = map { (my $need = $_) =~ s/need/have/; $need } @need;
 
 @ISA = qw(Exporter);
-@EXPORT = (qw(ok skip sok plan skip_reason under_construction need),
+@EXPORT = (qw(ok skip sok plan skip_reason under_construction),
            @need, @have);
 
 # everything but ok(), skip(), and plan() - Test::More provides these
@@ -495,7 +495,7 @@
 # @SkipReasons
 for my $func (@have) {
     no strict 'refs';
-    (my $real_func = $func) =~ s/^have_/need_/;
+    (my $real_func = $func) =~ s/^have/need/;
     *$func = sub {
         # be nice to poor souls calling functions with $_ argument in
         # the foreach loop, etc.!

Re: minor bugfix for Apache::Test

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Torsten Foertsch wrote:
> On Wednesday 26 January 2005 15:28, Geoffrey Young wrote:
> 
>>>-  modperl_handler_t  *handler;
>>>+  modperl_handler_t  *handler=0;
>>
>>hmm, what's that about?
> 
> 
> It cures this warning:
> IncludeHook.xs: In function `handle_perl':
> IncludeHook.xs:49: warning: `handler' might be used uninitialized in this 
> function
> 
> In line 194 you are using the handler that can be uninitialized at that time 
> from the compiler's point of view. It don't see the logic behind seen_sub and 
> puts out the warning. Hence the simple assingment to cure the warning.

ah.  I compile with -Werror and it passes without issue, but I guess my
compiler isn't recent enough to catch this particular item.

thanks.

I'm working on a new Apache-IncludeHook release, which looks like it will
have the subrequest issue solved.

--Geoff

Re: minor bugfix for Apache::Test

Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 26 January 2005 15:28, Geoffrey Young wrote:
> > -  modperl_handler_t  *handler;
> > +  modperl_handler_t  *handler=0;
>
> hmm, what's that about?

It cures this warning:
IncludeHook.xs: In function `handle_perl':
IncludeHook.xs:49: warning: `handler' might be used uninitialized in this 
function

In line 194 you are using the handler that can be uninitialized at that time 
from the compiler's point of view. It don't see the logic behind seen_sub and 
puts out the warning. Hence the simple assingment to cure the warning.

Torsten

Re: minor bugfix for Apache::Test

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Geoffrey Young wrote:
>  for
> example, I can't use the same perl for mp1 and mp2 if I want this approach
> to work, since ModPerl::MM::WriteMakefile() will choose the one I installed
> last to build against.

blarg, blarg, blarg.  that was supposed to be Apache 2.0 and Apache 2.1, not
mp1 and mp2.

as if people aren't already confused enough.

sorry everyone.

--Geoff

Re: minor bugfix for Apache::Test

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Torsten Foertsch wrote:
> On Wednesday 26 January 2005 13:42, Geoffrey Young wrote:
> 
>>Torsten Foertsch wrote:
>>
>>>Hi,
>>>
>>>while trying out Apache-IncludeHook-2.00_02
>>
>>I haven't touched that in a while, so if you see it failing to work on
>>newish apache just holler.  other than that, I hope you like it :)
> 
> 
> Yes, since 10 May 2004. So, I was expecting some problems.

:)

> 
>>>I stumbled across the lack of
>>>Apache::Test::have().
>>
>>hmm... is have() really required?
> 
> 
> No, it isn't. Here is a patch to Apache-IncludeHook-2.00_02. BTW, what does 
> need { 'subrequests under construction' => 0 } mean?

it means that when I wrote it could couldn't

  $r->lookup_uri($uri)->run;

from within an SSI handler.  I spent days trying to track down the cause of
the issue but wasn't able to ever figure it out.

anyway, that way of writing skip messages isn't needed anymore - it looks like

  skip_reason('subrequests under construction')

in my local repository at the moment, but skip_reason() didn't exist at the
time of the last release :)

> 
> Another question, where should the include files reside? On my system they are installed at
> /usr/include/apache2/modules/perl/mod_perl.h and /usr/include/apache2/mod_include.h. 
> Is that correct?

I don't think so.  I have both under my local apache install tree

  /apache/2.0/worker/perl-5.8.6/include/mod_perl.h
  /apache/2.0/worker/perl-5.8.6/include/mod_include.h

which matches the results of an apxs query:

  $ /apache/2.0/worker/perl-5.8.6/bin/apxs -q includedir
  /apache/2.0/worker/perl-5.8.6/include

> 
> Torsten
> 
> diff -Naur Apache-IncludeHook-2.00_02/IncludeHook.xs Apache-IncludeHook-2.00_02.new/IncludeHook.xs
> --- Apache-IncludeHook-2.00_02/IncludeHook.xs	2004-05-10 20:37:26.000000000 +0200
> +++ Apache-IncludeHook-2.00_02.new/IncludeHook.xs	2005-01-25 20:50:37.000000000 +0100
> @@ -2,8 +2,8 @@
>  #include "perl.h"
>  #include "XSUB.h"
>  
> -#include "mod_perl.h"
> -#include "mod_include.h"
> +#include <modules/perl/mod_perl.h>
> +#include <mod_include.h>

that shouldn't be required at all.  if it is then something is broken someplace.

the resulting Makefile from my Apache-IncludeHook build includes this

  INC => q[-I/apache/2.0/worker/perl-5.8.6/include]

which matches this entry in Apache/BuildConfig.pm in my installed site_lib

  'APXS_INCLUDEDIR' => '/apache/2.0/prefork/perl-5.8.6/include

basically what happens is that when you install mod_perl it retains the
memory of where things were when it was built, what header files it used,
and so on.  the third-party hook into all this information is
ModPerl::MM::WriteMakefile(), which is called from Makefile.PL - it is very
important to use ModPerl::MM::WriteMakefile() for mp2 CPAN modules.  world,
are you listening?  :)

anyway... if INC and APXS_INCLUDEDIR don't match eachother or don't properly
reflect which apache you used to build mod_perl something went wrong
someplace.  but keep in mind that all these are helpers for the majority of
users, but will get seriously mucked up if you use multiple mod_perl
versions, shuffle things around post-install, or do other hacking.  for
example, I can't use the same perl for mp1 and mp2 if I want this approach
to work, since ModPerl::MM::WriteMakefile() will choose the one I installed
last to build against.

hope that all makes sense.

>  
>  #define REFCNT_AND_ERROR(buffer,obj,av,hv,rv) \
>    MP_TRACE_f(MP_FUNC, "final reference counts: buffer=%d, obj=%d, av=%d, hv=%d\n", \
> @@ -46,7 +46,7 @@
>    server_rec  *s     = r->server;
>    apr_pool_t  *p     = r->pool;
>  
> -  modperl_handler_t  *handler;
> +  modperl_handler_t  *handler=0;

hmm, what's that about?

> -plan tests => 5, (have_lwp &&
> -                  have_module('mod_perl.c') &&
> -                  have_module('include') &&
> -                  have { 'subrequests under construction' => 0 } );
> +plan tests => 5, (need_lwp &&
> +                  need_module('mod_perl.c') &&
> +                  need_module('include') &&
> +                  need { 'subrequests under construction' => 0 } );

yes, that's right.  I actually have that in my local repository already.
I'll look into making a new release soon.

thanks for the feedback.

--Geoff

Re: minor bugfix for Apache::Test

Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 26 January 2005 13:42, Geoffrey Young wrote:
> Torsten Foertsch wrote:
> > Hi,
> >
> > while trying out Apache-IncludeHook-2.00_02
>
> I haven't touched that in a while, so if you see it failing to work on
> newish apache just holler.  other than that, I hope you like it :)

Yes, since 10 May 2004. So, I was expecting some problems.
>
> > I stumbled across the lack of
> > Apache::Test::have().
>
> hmm... is have() really required?

No, it isn't. Here is a patch to Apache-IncludeHook-2.00_02. BTW, what does 
need { 'subrequests under construction' => 0 } mean?

Another question, where should the include files reside? On my system they are installed at
/usr/include/apache2/modules/perl/mod_perl.h and /usr/include/apache2/mod_include.h. 
Is that correct?

Torsten

diff -Naur Apache-IncludeHook-2.00_02/IncludeHook.xs Apache-IncludeHook-2.00_02.new/IncludeHook.xs
--- Apache-IncludeHook-2.00_02/IncludeHook.xs	2004-05-10 20:37:26.000000000 +0200
+++ Apache-IncludeHook-2.00_02.new/IncludeHook.xs	2005-01-25 20:50:37.000000000 +0100
@@ -2,8 +2,8 @@
 #include "perl.h"
 #include "XSUB.h"
 
-#include "mod_perl.h"
-#include "mod_include.h"
+#include <modules/perl/mod_perl.h>
+#include <mod_include.h>
 
 #define REFCNT_AND_ERROR(buffer,obj,av,hv,rv) \
   MP_TRACE_f(MP_FUNC, "final reference counts: buffer=%d, obj=%d, av=%d, hv=%d\n", \
@@ -46,7 +46,7 @@
   server_rec  *s     = r->server;
   apr_pool_t  *p     = r->pool;
 
-  modperl_handler_t  *handler;
+  modperl_handler_t  *handler=0;
   apr_bucket         *tmp_buck;
   apr_bucket         *b_new;
   apr_bucket_brigade *bb_new;
diff -Naur Apache-IncludeHook-2.00_02/t/05perl-subreq.t Apache-IncludeHook-2.00_02.new/t/05perl-subreq.t
--- Apache-IncludeHook-2.00_02/t/05perl-subreq.t	2004-05-10 18:01:52.000000000 +0200
+++ Apache-IncludeHook-2.00_02.new/t/05perl-subreq.t	2005-01-26 14:10:59.898868917 +0100
@@ -9,10 +9,10 @@
 
 # tests for handlers that run subrequests
 
-plan tests => 5, (have_lwp &&
-                  have_module('mod_perl.c') &&
-                  have_module('include') &&
-                  have { 'subrequests under construction' => 0 } );
+plan tests => 5, (need_lwp &&
+                  need_module('mod_perl.c') &&
+                  need_module('include') &&
+                  need { 'subrequests under construction' => 0 } );
 
 t_write_file(catfile('htdocs', 'flat.shtml'), 
              '<!-- #echo var="INCLUDE_HOOK" -->');

Re: minor bugfix for Apache::Test

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Torsten Foertsch wrote:
> Hi,
> 
> while trying out Apache-IncludeHook-2.00_02

I haven't touched that in a while, so if you see it failing to work on
newish apache just holler.  other than that, I hope you like it :)

> I stumbled across the lack of 
> Apache::Test::have().

hmm... is have() really required?

what need() provides is a way to aggregate tests in a single call to plan(),
allowing you to see "all skipped - foo not available, bar not available." so
you can satisfy all the prerequisites at once so the test file will run.
the "foo not available, bar not available" message is aquired because need()
populates a global variable behind the scenes and passes that to plan() (in
essence anyway).

have(), by definition of being a have*() variant, would not manipulate some
global variable.  so

  if (have have_cgi, have_php) { ... }

would be functionally equivalent to

  if (have_cgi && have_php) { ... }

while the same cannot be said for need() when used in plan().

so, I don't see a compelling reason to add have().  in fact, I think we left
it out on purpose if you check the archives.

--Geoff