perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@ectoplasm.org>
Subject [patch] Only cleanup pnotes if pnotes have been used
Date Fri, 10 Mar 2006 21:14:24 GMT
I've been toying around with certain bits of pnotes, and a small cleanup came
to mind. It's conceptually cleaner, IMO, but I'd like to know other folks opinions.

The bulk of the idea is not to cleanup pnotes in mod_perl's global request pool
cleanup handler (spreading pnotes knoledge around) but rather have $r->pnotes()
register it's own cleanup, keeping the initialization/cleanup code side by
side and has the added (small) benefit that pnotes are not even looked at
anymore at cleanup time unless they were actually used.

A good idea or not ?:

Index: src/modules/perl/modperl_config.c
===================================================================
--- src/modules/perl/modperl_config.c   (revision 384626)
+++ src/modules/perl/modperl_config.c   (working copy)
@@ -351,11 +351,6 @@

     retval = modperl_callback_per_dir(MP_CLEANUP_HANDLER, r, MP_HOOK_RUN_ALL);

-    if (rcfg->pnotes) {
-        SvREFCNT_dec(rcfg->pnotes);
-        rcfg->pnotes = Nullhv;
-    }
-
     /* undo changes to %ENV caused by +SetupEnv, perl-script, or
      * $r->subprocess_env, so the values won't persist  */
     if (MpReqSETUP_ENV(rcfg)) {
Index: xs/Apache2/RequestUtil/Apache2__RequestUtil.h
===================================================================
--- xs/Apache2/RequestUtil/Apache2__RequestUtil.h       (revision 384626)
+++ xs/Apache2/RequestUtil/Apache2__RequestUtil.h       (working copy)
@@ -209,6 +209,20 @@
 }

 static MP_INLINE
+apr_status_t modperl_cleanup_pnotes(void *data) {
+    request_rec *r = data;
+    MP_dRCFG;
+    MP_dTHX;
+
+    if (rcfg->pnotes) {
+        SvREFCNT_dec(rcfg->pnotes);
+        rcfg->pnotes = Nullhv;
+    }
+
+    return APR_SUCCESS;
+}
+
+static MP_INLINE
 SV *mpxs_Apache2__RequestRec_pnotes(pTHX_ request_rec *r, SV *key, SV *val)
 {
     MP_dRCFG;
@@ -218,6 +232,9 @@
         return &PL_sv_undef;
     }
     if (!rcfg->pnotes) {
+        apr_pool_cleanup_register(r->pool, r,
+                                  modperl_cleanup_pnotes,
+                                  apr_pool_cleanup_null);
         rcfg->pnotes = newHV();
     }


--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Mime
View raw message