|
|
Author: jhorwitz
Date: Thu Jul 17 19:43:08 2008
New Revision: 359
Modified:
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/src/mod_parrot.c
mod_parrot/trunk/src/modparrot_config.c
Log:
refactor initialization code into modparrot_startup()
implement early interpreter startup for HLL config blocks and directives
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Thu Jul 17 19:43:08 2008
@@ -70,3 +70,4 @@
void release_ctx(modparrot_context *);
modparrot_context *get_interp_ctx(Parrot_Interp);
void set_interp_ctx(Parrot_Interp, modparrot_context *);
+modparrot_context *modparrot_startup(apr_pool_t *, server_rec *);
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Thu Jul 17 19:43:08 2008
@@ -54,11 +54,39 @@
*/
Parrot_PMC Parrot_Class_instantiate(PARROT_INTERP, PMC *, PMC *init);
+/* have we started? this can be global since it's written to at startup */
+int mp_is_started = 0;
+
+/* should we return something? */
+static void modparrot_load_files(Parrot_Interp interp, server_rec *s,
+ apr_array_header_t *files)
+{
+ int i, ret;
+
+ for (i = 0; i < files->nelts; i++) {
+ modparrot_handler_info *l =
+ &((modparrot_handler_info *)files->elts)[i];
+ char *ext = strrchr(l->id, '.');
+ /* load any PBC files */
+ if (ext && (!strcmp(ext, ".pbc") || !strcmp(ext, ".pir") ||
+ !strcmp(ext, ".pasm"))) {
+ modparrot_load_bytecode(interp, l->id);
+ }
+ else {
+ /* call the HLL load handler to handle the loading */
+ if (!modparrot_hll_handler(interp, l->hll, "load", l->id,
+ &ret)) {
+ MPLOG_ERRORF(s, "no HLL load handler for '%s'", l->hll);
+ }
+ }
+ }
+}
+
static Parrot_Interp modparrot_init(modparrot_context *ctx, server_rec *s)
{
Parrot_Interp interp;
- int i, ret;
modparrot_srv_config *cfg;
+ int i;
cfg = ap_get_module_config(s->module_config, &parrot_module);
if (cfg->trace_flags == -1) cfg->trace_flags = 0;
@@ -89,30 +117,6 @@
*/
set_interp_ctx(interp, ctx);
- /* load ParrotLoad files */
- for (i = 0; i < cfg->preload->nelts; i++) {
- modparrot_handler_info *l =
- &((modparrot_handler_info *)cfg->preload->elts)[i];
- char *ext = strrchr(l->id, '.');
- /* load any PBC files */
- if (ext && (!strcmp(ext, ".pbc") || !strcmp(ext, ".imc") ||
- !strcmp(ext, ".pir") || !strcmp(ext, ".pasm"))) {
- modparrot_load_bytecode(interp, l->id);
- }
- else {
- /* call the HLL load handler to handle the loading */
- if (!modparrot_hll_handler(ctx->interp, l->hll, "load", l->id,
- &ret)) {
- MPLOG_ERRORF(s, "no HLL load handler for '%s'", l->hll);
- }
- }
- }
-
- /* if we weren't tracing the initialization phase, enable tracing now */
- if (!(cfg->option_flags & MP_OPT_TRACE_INIT)) {
- Parrot_set_trace(interp, cfg->trace_flags);
- }
-
return(interp);
}
@@ -145,6 +149,30 @@
return(ctxp);
}
+/* public interface for starting an interpreter (used for early startups) */
+modparrot_context *modparrot_startup(apr_pool_t *p, server_rec *s)
+{
+ modparrot_context *ctxp;
+ modparrot_srv_config *cfg;
+
+ cfg = ap_get_module_config(s->module_config, &parrot_module);
+
+ if (!mp_is_started) {
+ if (!(cfg->ctx_pool = mp_ctx_pool_init(p, NULL, 1))) {
+ MPLOG_ERROR(s, "context pool creation failed");
+ return NULL;
+ }
+ }
+
+ if (!(ctxp = init_ctx(s))) {
+ MPLOG_ERROR(s, "context initialization failed");
+ return NULL;
+ }
+
+ mp_is_started = 1;
+ return ctxp;
+}
+
int modparrot_hll_handler(Parrot_Interp interp, char *hll, char *hll_handler,
char *handler, int *ret)
{
@@ -906,16 +934,18 @@
cfg = ap_get_module_config(s->module_config, &parrot_module);
if (cfg->option_flags & MP_OPT_ENABLE) {
- /* ALWAYS INIT THE CONTEXT POOL AND START THE INTERPRETER HERE! */
- if (!(cfg->ctx_pool = mp_ctx_pool_init(pconf, NULL, 1))) {
- MPLOG_ERROR(s, "context pool creation failed");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- if (!(ctxp = init_ctx(s))) {
- MPLOG_ERROR(s, "context initialization failed");
+ if (!(ctxp = modparrot_startup(pconf, s))) {
return HTTP_INTERNAL_SERVER_ERROR;
}
parent_interp = ctxp->interp;
+
+ /* load ParrotLoad files */
+ modparrot_load_files(ctxp->interp, s, cfg->preload);
+
+ /* if we weren't tracing the initialization phase, enable tracing now
*/
+ if (!(cfg->option_flags & MP_OPT_TRACE_INIT)) {
+ Parrot_set_trace(ctxp->interp, cfg->trace_flags);
+ }
}
/* init per-server (MP_OPT_PARENT) or per-process (default) pools */
Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c (original)
+++ mod_parrot/trunk/src/modparrot_config.c Thu Jul 17 19:43:08 2008
@@ -36,6 +36,7 @@
#define DEFAULT_OPTION_FLAGS (MP_OPT_ENABLE)
extern module AP_MODULE_DECLARE_DATA parrot_module;
+extern int mp_is_started;
static apr_status_t modparrot_cleanup(void *data)
{
@@ -45,6 +46,7 @@
cfg = ap_get_module_config(s->module_config, &parrot_module);
mp_ctx_pool_destroy(cfg->ctx_pool);
cfg->ctx_pool = NULL;
+ mp_is_started = 0;
return APR_SUCCESS;
}
@@ -469,7 +471,7 @@
const char *modparrot_cmd_language(cmd_parms *cmd, void *mconfig, const char
*hll)
{
modparrot_dir_config *cfg;
-
+
cfg = (modparrot_dir_config *)mconfig;
cfg->hll = (char *)apr_pstrdup(cmd->pool, hll);
return NULL;
|
|