perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@cpan.org>
Subject [Patch] $r->pnotes()
Date Tue, 13 Nov 2001 05:24:40 GMT
Since the per-request cleanup code was added, I am now able to send 
a $r->pnotes() implementation that doesn't leak...

/home/gozer/sources/mod_perl2/deps/perl-12948/bin/perl build/cvsdiff 
Index: xs/Apache/RequestUtil/Apache__RequestUtil.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/RequestUtil/Apache__RequestUtil.h,v
retrieving revision 1.10
diff -u -I'$Id' -I'$Revision' -r1.10 Apache__RequestUtil.h
--- xs/Apache/RequestUtil/Apache__RequestUtil.h	7 Nov 2001 03:39:08 -0000	1.10
+++ xs/Apache/RequestUtil/Apache__RequestUtil.h	13 Nov 2001 05:20:56 -0000
@@ -172,6 +172,44 @@
     return retval;
 }
 
+static MP_INLINE
+SV *mpxs_Apache__RequestRec_pnotes(pTHX_ request_rec *r, SV *k, SV *val)
+{
+    MP_dRCFG;
+    char *key = NULL;
+    SV *retval = &PL_sv_undef;
+    STRLEN len;
+    
+    if (!rcfg) {
+	    return retval;
+    }
+    
+    if (!rcfg->pnotes) {
+        rcfg->pnotes = newHV();
+    }
+    
+    if (k) {
+        key = SvPV(k, len);
+    }
+    
+    if (key) {
+        if (hv_exists(rcfg->pnotes, key, len)) {
+            retval = SvREFCNT_inc(*hv_fetch(rcfg->pnotes, key, len, FALSE));
+            sv_2mortal(retval);
+        }
+        
+        if (val) {
+            hv_store(rcfg->pnotes, key, len, SvREFCNT_inc(val), FALSE);
+        }
+    }
+    else {
+        retval = newRV_inc((SV *)rcfg->pnotes);
+        SvREFCNT_inc(sv_2mortal(retval));
+    }
+    
+    return retval;
+}
+
 #define mpxs_Apache__RequestRec_dir_config(r, key, sv_val) \
     modperl_dir_config(aTHX_ r, r->server, key, sv_val)
 

Index: t/response/TestAPI/request_rec.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/request_rec.pm,v
retrieving revision 1.9
diff -u -I'$Id' -I'$Revision' -r1.9 request_rec.pm
--- t/response/TestAPI/request_rec.pm	29 Oct 2001 01:19:16 -0000	1.9
+++ t/response/TestAPI/request_rec.pm	13 Nov 2001 05:20:56 -0000
@@ -11,7 +11,7 @@
 sub handler {
     my $r = shift;
 
-    plan $r, tests => 49;
+    plan $r, tests => 54;
 
     #Apache->request($r); #PerlOptions +GlobalRequest takes care
     my $gr = Apache->request;
@@ -78,7 +78,17 @@
     ok $r->subprocess_env;
 
     ok $r->notes;
-
+    
+    ok $r->pnotes;
+    
+    ok t_cmp('HASH', ref($r->pnotes), qq{ref($r->pnotes)});
+    
+    ok t_cmp(undef, $r->pnotes('pnotes_foo','pnotes_bar'), qq{\$r->pnotes(key,val)});
+   
+    ok t_cmp("pnotes_bar", $r->pnotes('pnotes_foo') , qq{\$r->pnotes(key)});
+    
+    ok t_cmp('pnotes_bar', $r->pnotes()->{'pnotes_foo'}, qq{\$r->pnotes()->{}});
+    
     ok $r->content_type;
 
     ok $r->handler;

Index: docs/src/api/mod_perl-2.0/Apache/RequestRec.pod
===================================================================
RCS file: /home/anoncvs/mod_perl-docs-cvs/src/api/mod_perl-2.0/Apache/RequestRec.pod,v
retrieving revision 1.2
diff -u -I'$Id' -I'$Revision' -r1.2 RequestRec.pod
--- docs/src/api/mod_perl-2.0/Apache/RequestRec.pod	10 Oct 2001 05:06:36 -0000	1.2
+++ docs/src/api/mod_perl-2.0/Apache/RequestRec.pod	13 Nov 2001 05:20:56 -0000
@@ -75,6 +75,20 @@
 values associated with the key C<$key> (and the key itself) will be
 deleted.
 
+=item * $r->pnotes( [ $key, [$value] ] )
+
+Like $r->notes, but takes any scalar as a value.
+
+  $r->pnotes("MY_HANDLER" => [qw(one two)]);
+  my $val = $r->pnotes("MY_HANDLER");
+  print $val->[0];     # prints "one"
+
+  my $hashref = $r->pnotes();
+  print $hashref->{'MY_HANDLER'}[0]; #also prints one
+
+Advantage over just using a Perl variable is that $r->pnotes gets
+cleaned up after every request.
+
 =item *
 
 =back

Index: todo/api.txt
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
retrieving revision 1.15
diff -u -I'$Id' -I'$Revision' -r1.15 api.txt
--- todo/api.txt	8 Nov 2001 03:19:48 -0000	1.15
+++ todo/api.txt	13 Nov 2001 05:20:56 -0000
@@ -10,9 +10,6 @@
 need apr_finfo_t <-> struct stat conversion (might already be there,
 haven't looked close enough yet)
 
-$r->pnotes:
-not yet implemented
-
 $r->subprocess_env:
 in void context should populate %ENV as 1.x does
 

Index: xs/maps/modperl_functions.map
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/modperl_functions.map,v
retrieving revision 1.27
diff -u -I'$Id' -I'$Revision' -r1.27 modperl_functions.map
--- xs/maps/modperl_functions.map	7 Nov 2001 04:03:07 -0000	1.27
+++ xs/maps/modperl_functions.map	13 Nov 2001 05:20:57 -0000
@@ -13,6 +13,7 @@
  mpxs_Apache__RequestRec_set_handlers
  mpxs_Apache__RequestRec_get_handlers
  mpxs_Apache__RequestRec_location
+ SV *:DEFINE_pnotes | mpxs_Apache__RequestRec_pnotes | request_rec *:r, SV *:key=NULL, SV
*:value=NULL
 
  #protocol module helpers
  mpxs_Apache__RequestRec_location_merge


-- 
Philippe M. Chiasson  <gozer@cpan.org>
  Extropia's Resident System Guru
     http://www.eXtropia.com/

/* When we have more time, we can teach the penguin to say 
  * "By your command" or "Activating turbo boost, Michael".
  */ 
	-- Linux	2.2.16
	/usr/src/linux/arch/sparc/prom/sun4prom.c

perl -e '$$=\${gozer};{$_=unpack(P26,pack(L,$$));/^Just Another Perl Hacker!\n$/&&print||$$++&&redo}'

Mime
View raw message