[svn:mod_parrot] r533 - in mod_parrot/trunk: . include lib lib/ModParrot/APR src t/response/TestAPI
[email protected] Mon, 8 Dec 2008 11:07:48 -0800 (PST)
| Newsgroups | perl.cvs.mod_parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: jhorwitz
Date: Mon Dec 8 11:07:47 2008
New Revision: 533
Modified:
mod_parrot/trunk/CHANGES
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/lib/ModParrot/APR/Pool.pir
mod_parrot/trunk/lib/mod_parrot.pir
mod_parrot/trunk/src/mod_parrot.c
mod_parrot/trunk/src/nci.c
mod_parrot/trunk/t/response/TestAPI/apr_pool.pir
Log:
add register_cleanup method to APR;Pool
delegate cleanup handler functionality to APR;Pool
Modified: mod_parrot/trunk/CHANGES
==============================================================================
--- mod_parrot/trunk/CHANGES (original)
+++ mod_parrot/trunk/CHANGES Mon Dec 8 11:07:47 2008
@@ -5,6 +5,8 @@
* Fixes for recent Parrot releases
* New architecture with one Apache module per HLL layer
* Apache;Module supports creating Apache modules from Parrot
+ * APR;Pool manages memory pools
+ * HLL cleanup handlers are managed by APR;Pool
* Custom HLL directives
* Per-HLL server & directory configurations
* HLL configuration merging
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Mon Dec 8 11:07:47 2008
@@ -64,6 +64,16 @@
};
typedef struct modparrot_context modparrot_context;
+/* internal info for pool cleanup handlers */
+struct modparrot_cleanup_info {
+ module *module; /* the HLL module that registered us */
+ Parrot_PMC callback; /* callback subroutine */
+ Parrot_PMC hll_data; /* a PMC to pass to the callback */
+ apr_pool_t *pool; /* the pool for which the cleanup was registered */
+ server_rec *s; /* used for context init */
+};
+typedef struct modparrot_cleanup_info modparrot_cleanup_info;
+
/* misc prototypes */
Parrot_Interp modparrot_init_interpreter(Parrot_Interp);
int modparrot_load_bytecode(Parrot_Interp, char *);
Modified: mod_parrot/trunk/lib/ModParrot/APR/Pool.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/APR/Pool.pir (original)
+++ mod_parrot/trunk/lib/ModParrot/APR/Pool.pir Mon Dec 8 11:07:47 2008
@@ -20,6 +20,10 @@
=head1 SYNOPSIS
+ $P0 = new ['ModParrot'; 'APR'; 'Pool']
+ $P0.'cleanup_register'(my_cleanup_handler, data)
+ $P0.'destroy'()
+
=head1 DESCRIPTION
This code implements the ModParrot;APR;Pool class.
@@ -89,6 +93,26 @@
.return()
.end
+=item C<cleanup_register(PMC callback, PMC data)>
+
+Registers a cleanup function that will be called when the pool is destroyed.
+Note that C<data> is passed by reference. It is up to the HLL to wrap this
+method if pass-by-value is preferred.
+
+=cut
+
+.sub cleanup_register :method
+ .param pmc handler_sub
+ .param pmc data :optional
+ .local pmc func, pool
+
+ func = get_root_global [ 'ModParrot'; 'NCI' ], "register_pool_cleanup"
+ pool = getattribute self, 'apr_pool'
+ func(pool, handler_sub, data)
+.end
+
+=back
+
=head1 AUTHOR
Jeff Horwitz
Modified: mod_parrot/trunk/lib/mod_parrot.pir
==============================================================================
--- mod_parrot/trunk/lib/mod_parrot.pir (original)
+++ mod_parrot/trunk/lib/mod_parrot.pir Mon Dec 8 11:07:47 2008
@@ -99,6 +99,9 @@
dlfunc func, nul, "mpnci_request_read", "iJPip"
set_root_global [ 'ModParrot'; 'NCI' ], "request_read", func
+ dlfunc func, nul, "mpnci_register_pool_cleanup", "vJpPP"
+ set_root_global [ 'ModParrot'; 'NCI' ], "register_pool_cleanup", func
+
# load required libraries
load_bytecode 'Protoobject.pbc'
load_bytecode 'ModParrot/Interpreter.pbc'
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Mon Dec 8 11:07:47 2008
@@ -56,18 +56,6 @@
/* thread info */
int hard_thread_limit, max_threads;
-struct modparrot_cleanup_info {
- int module_index; /* the HLL module that registered us */
- Parrot_PMC callback; /* callback subroutine */
- Parrot_PMC hll_data; /* a PMC to pass to the callback */
- union { /* internal stuff for mod_parrot */
- conn_rec *c;
- request_rec *r;
- } data;
-};
-typedef struct modparrot_cleanup_info modparrot_cleanup_info;
-
-
void modparrot_load_file(Parrot_Interp interp, server_rec *s, const char *file)
{
int ret;
@@ -294,21 +282,17 @@
return APR_SUCCESS;
}
-static apr_status_t modparrot_meta_request_cleanup(void *data)
+apr_status_t modparrot_meta_cleanup_handler(void *data)
{
modparrot_cleanup_info *ci = (modparrot_cleanup_info *)data;
modparrot_context *ctxp;
int status;
/* initialize context */
- if (!(ctxp = init_ctx(ci->data.r->server, ci->data.r->pool))) {
- MPLOG_ERROR(ci->data.r->server, "context initialization failed");
+ if (!(ctxp = init_ctx(ci->s, ci->pool))) {
return HTTP_INTERNAL_SERVER_ERROR;
}
- /* set module index to the module that registered us */
- ctxp->module_index = ci->module_index;
-
/* call cleanup sub, passing HLL data from ci */
status = Parrot_call_sub_ret_int(ctxp->interp, ci->callback, "IP",
ci->hll_data);
@@ -316,16 +300,6 @@
return status;
}
-static apr_status_t modparrot_conn_cleanup(void *data)
-{
- conn_rec *c = (conn_rec *)data;
-
- /* XXX when we stop releasing after every phase, we'll need to get the
- * context and release it here. until that happens, this is a no-op. */
-
- return APR_SUCCESS;
-}
-
#define MP_REQUEST_METAHANDLER(hname, henum, register_cleanup) \
int modparrot_meta_##hname(request_rec *r) \
{ \
@@ -408,10 +382,6 @@
mpcfg = ap_get_module_config(c->base_server->module_config, &parrot_module);
if (!(mpcfg->option_flags & MP_OPT_ENABLE)) return DECLINED;
- /* register cleanup handler to reset conn_ctx */
- apr_pool_cleanup_register(c->pool, c, modparrot_conn_cleanup,
- apr_pool_cleanup_null);
-
/* get next module in line */
modp = NEXT_HANDLER_MODULE(MP_HOOK_PRE_CONNECTION);
Modified: mod_parrot/trunk/src/nci.c
==============================================================================
--- mod_parrot/trunk/src/nci.c (original)
+++ mod_parrot/trunk/src/nci.c Mon Dec 8 11:07:47 2008
@@ -397,3 +397,31 @@
{
return(r->pool);
}
+
+apr_status_t modparrot_meta_cleanup_handler(void *);
+void mpnci_register_pool_cleanup(Parrot_Interp interp, apr_pool_t *p,
+ Parrot_PMC sub, Parrot_PMC data)
+{
+ modparrot_cleanup_info *ci;
+ modparrot_context *ctxp;
+ modparrot_srv_config *cfg;
+ module *modp;
+
+ ctxp = get_interp_ctx(interp);
+ if (!ctxp) return;
+
+ /* get current module */
+ cfg = ap_get_module_config(ctxp->s->module_config, &parrot_module);
+ modp = ((module **)cfg->module_array->elts)[ctxp->module_index];
+
+ /* populate cleanup info */
+ ci = apr_pcalloc(p, sizeof(modparrot_cleanup_info));
+ ci->module = modp;
+ ci->callback = sub;
+ ci->hll_data = data;
+ ci->s = ctxp->s;
+ ci->pool = p;
+
+ /* register the handler */
+ apr_pool_cleanup_register(p, ci, modparrot_meta_cleanup_handler, NULL);
+}
Modified: mod_parrot/trunk/t/response/TestAPI/apr_pool.pir
==============================================================================
--- mod_parrot/trunk/t/response/TestAPI/apr_pool.pir (original)
+++ mod_parrot/trunk/t/response/TestAPI/apr_pool.pir Mon Dec 8 11:07:47 2008
@@ -1,5 +1,15 @@
.namespace [ 'TestAPI::apr_pool' ]
+.sub test_cleanup_handler
+ .param pmc data
+ .local pmc ap_const
+
+ ap_const = get_root_global [ 'ModParrot'; 'Apache'; 'Constants' ], 'table'
+ printerr "in test cleanup handler\n"
+ $I0 = ap_const['OK']
+ .return($I0)
+.end
+
.sub handler
.param pmc r
.local pmc ap_const
@@ -7,7 +17,7 @@
ap_const = get_root_global [ 'ModParrot'; 'Apache'; 'Constants' ], 'table'
- r.'puts'("1..2\n")
+ r.'puts'("1..3\n")
START_1:
push_eh NOT_OK_1
@@ -34,6 +44,19 @@
OK_2:
r.'puts'("ok 2 - create pool (with request pool parent)\n")
+ START_3:
+ push_eh NOT_OK_3
+ $P0 = r.'pool'()
+ $P1 = new 'Undef'
+ $P2 = get_global 'test_cleanup_handler'
+ $P0.'cleanup_register'($P2, $P1)
+ pop_eh
+ goto OK_3
+ NOT_OK_3:
+ r.'puts'("not ")
+ OK_3:
+ r.'puts'("ok 3 - cleanup_register\n")
+
$I0 = ap_const['OK']
.return($I0)
.end