You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Ken Williams <ke...@forum.swarthmore.edu> on 2001/03/31 05:04:38 UTC

Looking for magic in Apache->request

Hi,

Consider the following code under mod_perl (current CVS 1.25):


   # Get the original request object
   my $r = Apache->request;
   $r->send_http_header('text/html');

   # Subclass Apache and install new $r
   my $r2 = bless {'_r' => $r}, 'OtherPackage';
   @OtherPackage::ISA = ('Apache');
   Apache->request($r2);

   # Verify that the changes took effect
   $r = Apache->request;
   print "New \$r: $r<br>\n";


This doesn't work as intended, because Apache->request($r2) extracts the
original request from $r2 and stores that internally.

The thing I can't figure out from the XS code is how/where
Apache->request calls sv2request_rec(), which actually does the
extraction work.  Somehow it's automatically converted, because I see no
manual conversion in the Apache->request code below:

void
request(self, r=NULL)
    SV *self
    Apache r

    PPCODE: 
    self = self;
    if(items > 1) perl_request_rec(r);
    XPUSHs(perl_bless_request_rec(perl_request_rec(NULL)));

Any pointers?

The reason I'm asking is that the current behavior of
Apache->request($r) makes it really hard to subclass Apache::Registry
and the like, because lots of code (like CGI.pm) call Apache->request to
get the current request object.


  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum

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


Re: Looking for magic in Apache->request

Posted by Doug MacEachern <do...@covalent.net>.
On Fri, 30 Mar 2001, Ken Williams wrote:
 
> The thing I can't figure out from the XS code is how/where
> Apache->request calls sv2request_rec(), which actually does the
> extraction work.  Somehow it's automatically converted, because I see no
> manual conversion in the Apache->request code below:

you don't need to change sv2request_rec(), the `Apache' typemap that calls
it needs to dig out the real request_rec for use with the apache api.

> void
> request(self, r=NULL)
>     SV *self
>     Apache r

what you can do is change 'Apache r' to 'SV *r', the global mp_request_rec
(in mod_perl.c) from an IV to SV.  then adjust things that fetch/modify
mp_request_rec acordingly.  this would require some SvREFCNT_{inc,dec}
managment, since the lifetime of mp_request_rec is longer than the object
you want it to point to.
i plan to catchup on 1.xx stuff after apachecon, i will look into it
then if you get stuck.


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


Re: Looking for magic in Apache->request

Posted by Matt Sergeant <ma...@sergeant.org>.
On Sun, 1 Apr 2001, Ken Williams wrote:

> Dang.  So that would mean that in order to fix this, Apache->request($r)
> would have to accept an arbitrary scalar, not something automatically
> converted to an Apache object, right?

Right.

> And then there's the matter of how it should be stored...

I have a feeling it would be pretty much impossible (because everything
in XS in mod_perl expects just an SvIV that points to the apache object),
but maybe Doug has some ideas. It *might* be possible to change the
typemap to detect whether the thing is an "Apache" or a something else,
and do something specific, but I'm kinda just pointing in the dark.

-- 
<Matt/>

    /||    ** Founder and CTO  **  **   http://axkit.com/     **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // ** mod_perl news and resources: http://take23.org  **
     \\//
     //\\
    //  \\


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


Re: Looking for magic in Apache->request

Posted by Ken Williams <ke...@forum.swarthmore.edu>.
matt@sergeant.org (Matt Sergeant) wrote:
>On Fri, 30 Mar 2001, Ken Williams wrote:
>
>> The thing I can't figure out from the XS code is how/where
>> Apache->request calls sv2request_rec(), which actually does the
>> extraction work.  Somehow it's automatically converted, because I see no
>> manual conversion in the Apache->request code below:
>> 
>> void
>> request(self, r=NULL)
>>     SV *self
>>     Apache r
>> 
>>     PPCODE: 
>>     self = self;
>>     if(items > 1) perl_request_rec(r);
>>     XPUSHs(perl_bless_request_rec(perl_request_rec(NULL)));
>> 
>> Any pointers?
>
>It's done in the typemap.

Dang.  So that would mean that in order to fix this, Apache->request($r)
would have to accept an arbitrary scalar, not something automatically
converted to an Apache object, right?

And then there's the matter of how it should be stored...

>
>> The reason I'm asking is that the current behavior of
>> Apache->request($r) makes it really hard to subclass Apache::Registry
>> and the like, because lots of code (like CGI.pm) call Apache->request to
>> get the current request object.
>
>Yeah I have this same "bug" in AxKit. It's a real pain.

If I get some time this week I'll see whether I can make a patch.  But
I'm in pretty unfamiliar territory.


  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum

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


Re: Looking for magic in Apache->request

Posted by Matt Sergeant <ma...@sergeant.org>.
On Fri, 30 Mar 2001, Ken Williams wrote:

> The thing I can't figure out from the XS code is how/where
> Apache->request calls sv2request_rec(), which actually does the
> extraction work.  Somehow it's automatically converted, because I see no
> manual conversion in the Apache->request code below:
> 
> void
> request(self, r=NULL)
>     SV *self
>     Apache r
> 
>     PPCODE: 
>     self = self;
>     if(items > 1) perl_request_rec(r);
>     XPUSHs(perl_bless_request_rec(perl_request_rec(NULL)));
> 
> Any pointers?

It's done in the typemap.

> The reason I'm asking is that the current behavior of
> Apache->request($r) makes it really hard to subclass Apache::Registry
> and the like, because lots of code (like CGI.pm) call Apache->request to
> get the current request object.

Yeah I have this same "bug" in AxKit. It's a real pain.

-- 
<Matt/>

    /||    ** Founder and CTO  **  **   http://axkit.com/     **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // ** mod_perl news and resources: http://take23.org  **
     \\//
     //\\
    //  \\


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