geoff 2004/01/30 10:20:10
Modified: t/response/TestModperl subenv.pm xs/Apache/RequestRec Apache__RequestRec.h Log: fix calling $r->subprocess_env() in a void context so that it only populates %ENV if also called with no arguments. also, make sure it can be called more than once and still populate %ENV. Revision Changes Path 1.4 +61 -13 modperl-2.0/t/response/TestModperl/subenv.pm Index: subenv.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/response/TestModperl/subenv.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- subenv.pm 29 Jan 2004 23:34:00 -0000 1.3 +++ subenv.pm 30 Jan 2004 18:20:10 -0000 1.4 @@ -11,35 +11,83 @@ use Apache::Const -compile => 'OK'; sub handler { + my $r = shift; - plan $r, tests => 19; + plan $r, tests => 31; + + # subprocess_env in void context with arguments does + # nothing to %ENV + { + my $env = $r->subprocess_env; + + my $key = 'ONCE'; + + ok_false($r, $key); - my $env = $r->subprocess_env; - ok $env; + $r->subprocess_env($key => 1); # void context but with args + + ok_true($r, $key); + + ok ! $ENV{$key}; # %ENV not populated yet + } - # subprocess_env in void context populates the same as +SetEnv + # subprocess_env in void context with no arguments + # populates the same as +SetEnv { + my $env = $r->subprocess_env; + my $key = 'REMOTE_ADDR'; - ok_false($r, $key); - $r->subprocess_env; + + ok_false($r, $key); # still not not there yet + + ok ! $ENV{$key}; # %ENV not populated yet + + $r->subprocess_env; # void context with no arguments + ok_true($r, $key); - ok $ENV{$key}; # mod_cgi emulation + + ok $ENV{$key}; # mod_cgi emulation } + # handlers can use a void context more than once to force + # population of %ENV with new table entries { + my $env = $r->subprocess_env; + + my $key = 'AGAIN'; + + $env->set($key => 1); # new table entry + + ok_true($r, $key); + + ok ! $ENV{$key}; # shouldn't affect %ENV yet + + $r->subprocess_env; # now called in in void context twice + + ok $ENV{$key}; # so %ENV is populated with new entry + } + + { + my $env = $r->subprocess_env; # table may have been overlayed + my $key = 'FOO'; - $env = $r->subprocess_env; #table may have been overlayed - $env->set($key => 1); + + $env->set($key => 1); # direct call to set() + ok_true($r, $key); - ok ! $ENV{$key}; # shouldn't affect %ENV + + ok ! $ENV{$key}; # shouldn't affect %ENV $r->subprocess_env($key => undef); - ok_false($r, $key); + + ok_false($r, $key); # removed $r->subprocess_env($key => 1); - ok_true($r, $key); - ok ! $ENV{$key}; # shouldn't affect %ENV + + ok_true($r, $key); # reset + + ok ! $ENV{$key}; # still shouldn't affect %ENV } Apache::OK; 1.9 +8 -1 modperl-2.0/xs/Apache/RequestRec/Apache__RequestRec.h Index: Apache__RequestRec.h =================================================================== RCS file: /home/cvs/modperl-2.0/xs/Apache/RequestRec/Apache__RequestRec.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Apache__RequestRec.h 14 Jan 2004 21:27:41 -0000 1.8 +++ Apache__RequestRec.h 30 Jan 2004 18:20:10 -0000 1.9 @@ -46,8 +46,15 @@ SV *mpxs_Apache__RequestRec_subprocess_env(pTHX_ request_rec *r, char *key, SV *val) { - if (GIMME_V == G_VOID) { + /* if called in a void context with no arguments, just + * populate %ENV and stop. resetting SetupEnv off makes + * calling in a void context more than once meaningful. + */ + if (key == NULL && GIMME_V == G_VOID) { + MP_dRCFG; + MpReqSETUP_ENV_Off(rcfg); modperl_env_request_populate(aTHX_ r); + return &PL_sv_undef; } return modperl_table_get_set(aTHX_ r->subprocess_env,