[svn:mod_parrot] r616 - in mod_parrot/trunk: . include lib lib/ModParrot src

[email protected] Sun, 22 Feb 2009 10:15:49 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Sun Feb 22 10:15:48 2009
New Revision: 616

Modified:
   mod_parrot/trunk/call_list.txt
   mod_parrot/trunk/include/mod_parrot.h
   mod_parrot/trunk/lib/ModParrot/Context.pir
   mod_parrot/trunk/lib/mod_parrot.pir
   mod_parrot/trunk/src/mod_parrot.c
   mod_parrot/trunk/src/module.c
   mod_parrot/trunk/src/nci.c

Log:
add infrastructure to support per-section context pools.  they won't actually
work properly until we can clone interpreters 


Modified: mod_parrot/trunk/call_list.txt
==============================================================================
--- mod_parrot/trunk/call_list.txt	(original)
+++ mod_parrot/trunk/call_list.txt	Sun Feb 22 10:15:48 2009
@@ -22,3 +22,4 @@
 P       Jtpi
 i       Vppp
 v       pt
+v       Jpt

Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h	(original)
+++ mod_parrot/trunk/include/mod_parrot.h	Sun Feb 22 10:15:48 2009
@@ -48,6 +48,7 @@
 /* globals! */
 struct modparrot_globals
 {
+    apr_pool_t *pconf;
     apr_hash_t *module_hash;
     apr_array_header_t *module_array;
     apr_array_header_t *handler_modules[MP_HOOK_LAST];
@@ -79,6 +80,8 @@
     server_rec *s;
     conn_rec *c;
     void *csd;
+    modparrot_module_config *raw_srv_config;
+    modparrot_module_config *raw_dir_config;
     int module_index;
 };
 typedef struct modparrot_context modparrot_context;

Modified: mod_parrot/trunk/lib/ModParrot/Context.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/Context.pir	(original)
+++ mod_parrot/trunk/lib/ModParrot/Context.pir	Sun Feb 22 10:15:48 2009
@@ -128,6 +128,26 @@
     .return($P2)
 .end
 
+=item raw_srv_config
+
+=cut
+
+.sub raw_srv_config :method
+    $P0 = get_root_global [ 'ModParrot'; 'NCI' ], 'raw_srv_config'
+    $P1 = $P0()
+    .return($P1)
+.end
+
+=item raw_dir_config
+
+=cut
+
+.sub raw_dir_config :method
+    $P0 = get_root_global [ 'ModParrot'; 'NCI' ], 'raw_dir_config'
+    $P1 = $P0()
+    .return($P1)
+.end
+
 =head1 TODO
 
 =over 4

Modified: mod_parrot/trunk/lib/mod_parrot.pir
==============================================================================
--- mod_parrot/trunk/lib/mod_parrot.pir	(original)
+++ mod_parrot/trunk/lib/mod_parrot.pir	Sun Feb 22 10:15:48 2009
@@ -108,6 +108,12 @@
     dlfunc func, lib, "mpnci_csd", "pJ"
     set_root_global [ 'ModParrot'; 'NCI' ], "csd", func
 
+    dlfunc func, lib, "mpnci_raw_srv_config", "pJ"
+    set_root_global [ 'ModParrot'; 'NCI' ], "raw_srv_config", func
+
+    dlfunc func, lib, "mpnci_raw_dir_config", "pJ"
+    set_root_global [ 'ModParrot'; 'NCI' ], "raw_dir_config", func
+
     dlfunc func, lib, "mpnci_request_read", "iJPip"
     set_root_global [ 'ModParrot'; 'NCI' ], "request_read", func
 
@@ -132,6 +138,9 @@
     dlfunc func, lib, "mpnci_cmd_parms_cmd", "pJp"
     set_root_global [ 'ModParrot'; 'NCI' ], "cmd_parms_cmd", func
 
+    dlfunc func, lib, "mpnci_set_config_ctx_pool", "vJpt"
+    set_root_global [ 'ModParrot'; 'NCI' ], "set_config_ctx_pool", func
+
     # load required libraries
     load_bytecode 'P6object.pbc'
     load_bytecode 'ModParrot/Constants.pbc'

Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c	(original)
+++ mod_parrot/trunk/src/mod_parrot.c	Sun Feb 22 10:15:48 2009
@@ -58,6 +58,7 @@
 {
     int i;
 
+    mp_globals.pconf = p;
     mp_globals.is_started = 0;
     mp_globals.debug_level = 0;
     mp_globals.max_threads = 0;
@@ -178,14 +179,23 @@
 {
     modparrot_module_config *cfg;
     modparrot_module_info *minfo = modp->dynamic_load_handle;
+    apr_array_header_t *cp;
 
     /* try section scope first */
     if (per_dir_config) {
         cfg = ap_get_module_config(per_dir_config, modp);
         if (cfg) {
-            if (cfg->ctx_pool) {
-                MP_TRACE_c(s, "select_ctx_pool: using section pool %p", cfg->ctx_pool);
-                return(cfg->ctx_pool);
+            /* section pools might be dynamic, so always look up by name */
+            if (cfg->ctx_pool_name) {
+                MP_TRACE_c(s, "select_ctx_pool: using section pool '%s'", cfg->ctx_pool_name);
+                cp = modparrot_get_named_ctx_pool(cfg->ctx_pool_name);
+                if (!cp) {
+                    /* XXX need a startup w/o init_ctx side-effect */
+                    modparrot_context *ctxp = modparrot_startup(
+                        mp_globals.pconf, s, NULL, cfg->ctx_pool_name);
+                    release_ctx(ctxp);
+                }
+                return(cp);
             }
         }
     }
@@ -194,13 +204,15 @@
     cfg = ap_get_module_config(s->module_config, modp);
     if (cfg) {
         if (cfg->ctx_pool) {
-            MP_TRACE_c(s, "select_ctx_pool: using server pool %p", cfg->ctx_pool);
+            MP_TRACE_c(s, "select_ctx_pool: using server pool '%s'", cfg->ctx_pool_name);
+            /* server pools are static, so return the cached pool */
             return(cfg->ctx_pool);
         }
     }
 
     /* fall back to the module's default pool */
-    MP_TRACE_c(s, "select_ctx_pool: using module default pool %p", minfo->ctx_pool);
+    MP_TRACE_c(s, "select_ctx_pool: using module default pool");
+    /* module pools are static, so return the cached pool */
     return(minfo->ctx_pool);
 }
 
@@ -458,7 +470,8 @@
         if (!(mpcfg->option_flags & MP_OPT_ENABLE)) return DECLINED; \
         modp = NEXT_HANDLER_MODULE(henum); \
         cloned = clone_ctx_state(ctxp, \
-            select_ctx_pool(modp, r->server, NULL), r->server, r->pool); \
+            select_ctx_pool(modp, r->server, r->per_dir_config), r->server, \
+                r->pool); \
         if (cloned != ctxp) { \
             release_ctx(ctxp); \
             ctxp = cloned; \

Modified: mod_parrot/trunk/src/module.c
==============================================================================
--- mod_parrot/trunk/src/module.c	(original)
+++ mod_parrot/trunk/src/module.c	Sun Feb 22 10:15:48 2009
@@ -92,6 +92,10 @@
 
     mergedcfg->name = basecfg->name; /* XXX should we copy this instead? */
     mergedcfg->minfo = basecfg->minfo;
+    mergedcfg->ctx_pool_name = apr_pstrdup(p, newcfg->ctx_pool_name ?
+        newcfg->ctx_pool_name : basecfg->ctx_pool_name);
+    mergedcfg->ctx_pool = newcfg->ctx_pool ?
+        newcfg->ctx_pool : basecfg->ctx_pool;
 
     /* unregister existing config */
     if (mergedcfg->cfg) {
@@ -142,6 +146,10 @@
     
     mergedcfg->name = basecfg->name; /* XXX should we copy this instead? */
     mergedcfg->minfo = basecfg->minfo;
+    mergedcfg->ctx_pool_name = apr_pstrdup(p, newcfg->ctx_pool_name ?
+        newcfg->ctx_pool_name : basecfg->ctx_pool_name);
+    mergedcfg->ctx_pool = newcfg->ctx_pool ?
+        newcfg->ctx_pool : basecfg->ctx_pool;
 
     /* unregister existing config */
     if (mergedcfg->cfg) {
@@ -226,6 +234,7 @@
     /* create/fetch module server config */
     srvcfg = (modparrot_module_config *)ap_get_module_config(
         cmd->server->module_config, data->modp);
+    ctxp->raw_srv_config = srvcfg;
     if (srvcfg) {
         if (!srvcfg->cfg) {
             srvcfg->name = apr_pstrdup(cmd->pool, data->modp->name);
@@ -243,6 +252,7 @@
 
     /* create/fetch module directory config */
     dircfg = (modparrot_module_config *)mconfig;
+    ctxp->raw_dir_config = dircfg;
     if (dircfg) {
         if (!dircfg->cfg) {
             dircfg->name = apr_pstrdup(cmd->pool, data->modp->name);
@@ -263,6 +273,9 @@
     ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IPPP", parms_pmc,
         dircfg->cfg, args);
 
+    /* we might not get a chance to clear these later, so do it now */
+    ctxp->raw_srv_config = ctxp->raw_dir_config = NULL;
+
     Parrot_unregister_pmc(ctxp->interp, parms_pmc);
 
     return NULL;

Modified: mod_parrot/trunk/src/nci.c
==============================================================================
--- mod_parrot/trunk/src/nci.c	(original)
+++ mod_parrot/trunk/src/nci.c	Sun Feb 22 10:15:48 2009
@@ -128,6 +128,24 @@
     return(ctxp->csd);
 }
 
+modparrot_module_config *mpnci_raw_srv_config(Parrot_Interp interp)
+{
+    modparrot_context *ctxp;
+
+    ctxp = get_interp_ctx(interp);
+    if (!ctxp) return NULL;
+    return(ctxp->raw_srv_config);
+}
+
+modparrot_module_config *mpnci_raw_dir_config(Parrot_Interp interp)
+{
+    modparrot_context *ctxp;
+
+    ctxp = get_interp_ctx(interp);
+    if (!ctxp) return NULL;
+    return(ctxp->raw_dir_config);
+}
+
 request_rec *mpnci_request_rec_main(Parrot_Interp interp, request_rec *r)
 {
     return(r->main);
@@ -257,7 +275,6 @@
     modparrot_srv_config *mpcfg;
     modparrot_module_config *cfg;
     module *modp;
-    apr_pool_t *pool;
 
     ctxp = get_interp_ctx(interp);
     if (!ctxp) return NULL;
@@ -268,9 +285,6 @@
         return(NULL);
     }
 
-    /* use request pool if we're in a request so we don't leak */
-    pool = ctxp->r ? ctxp->r->pool : ctxp->pconf;
-
     if (is_directory) {
         /* possibly do more here if not in a request */
         cfg = ap_get_module_config(ctxp->r->per_dir_config, modp);
@@ -343,3 +357,10 @@
     /* register the handler */
     apr_pool_cleanup_register(p, ci, modparrot_meta_cleanup_handler, NULL);
 }
+
+void mpnci_set_config_ctx_pool(Parrot_Interp interp,
+    modparrot_module_config *cfg, char *pool_name)
+{
+    modparrot_context *ctxp = get_interp_ctx(interp);
+    cfg->ctx_pool_name = (char *)apr_pstrdup(ctxp->pconf, pool_name);
+}