|
|
Author: particle
Date: Thu Jul 24 07:13:01 2008
New Revision: 372
Added:
mod_parrot/branches/configure/eg/perl6/counter
- copied unchanged from r371, /mod_parrot/trunk/eg/perl6/counter
mod_parrot/branches/configure/languages/
- copied from r371, /mod_parrot/trunk/languages/
mod_parrot/branches/configure/languages/perl6/
- copied from r371, /mod_parrot/trunk/languages/perl6/
mod_parrot/branches/configure/languages/perl6/lib/
- copied from r371, /mod_parrot/trunk/languages/perl6/lib/
mod_parrot/branches/configure/languages/perl6/lib/ModPerl6/
- copied from r371, /mod_parrot/trunk/languages/perl6/lib/ModPerl6/
mod_parrot/branches/configure/languages/perl6/lib/ModPerl6/Registry.pm
- copied unchanged from r371,
/mod_parrot/trunk/languages/perl6/lib/ModPerl6/Registry.pm
mod_parrot/branches/configure/languages/perl6/lib/mod_perl6.pm
- copied unchanged from r371,
/mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm
mod_parrot/branches/configure/lib/Apache/Module.pir
- copied unchanged from r371, /mod_parrot/trunk/lib/Apache/Module.pir
mod_parrot/branches/configure/lib/ModParrot/HLL/lolcode.pir
- copied unchanged from r371,
/mod_parrot/trunk/lib/ModParrot/HLL/lolcode.pir
mod_parrot/branches/configure/lib/ModParrot/HLL/perl6-pir.pir
- copied unchanged from r371,
/mod_parrot/trunk/lib/ModParrot/HLL/perl6-pir.pir
mod_parrot/branches/configure/lib/ModParrot/HLL/pipp.pir
- copied unchanged from r371, /mod_parrot/trunk/lib/ModParrot/HLL/pipp.pir
mod_parrot/branches/configure/patches/
- copied from r371, /mod_parrot/trunk/patches/
mod_parrot/branches/configure/patches/parrot-r29231-modperl6.patch
- copied unchanged from r371,
/mod_parrot/trunk/patches/parrot-r29231-modperl6.patch
mod_parrot/branches/configure/src/module.c
- copied unchanged from r371, /mod_parrot/trunk/src/module.c
Removed:
mod_parrot/branches/configure/lib/ModParrot/HLL/plumhead.pir
Modified:
mod_parrot/branches/configure/Configure.pl
mod_parrot/branches/configure/Makefile.in
mod_parrot/branches/configure/call_list.txt
mod_parrot/branches/configure/docs/apache-conf.txt
mod_parrot/branches/configure/eg/perl6/ModPerl6/Counter.pm
mod_parrot/branches/configure/eg/perl6/ModPerl6/Polly.pm
mod_parrot/branches/configure/eg/perl6/README
mod_parrot/branches/configure/include/mod_parrot.h
mod_parrot/branches/configure/include/modparrot_config.h
mod_parrot/branches/configure/lib/APR/Table.pir
mod_parrot/branches/configure/lib/Apache/RequestRec.pir
mod_parrot/branches/configure/lib/ModParrot/Context.pir
mod_parrot/branches/configure/lib/ModParrot/HLL/perl6.pir
mod_parrot/branches/configure/lib/ModParrot/Interpreter.pir
mod_parrot/branches/configure/lib/mod_parrot.pir
mod_parrot/branches/configure/src/mod_parrot.c
mod_parrot/branches/configure/src/modparrot_config.c
mod_parrot/branches/configure/src/nci.c
mod_parrot/branches/configure/src/parrot_util.c
mod_parrot/branches/configure/t/response/TestAPI/request_rec.pir
Log:
[SVN MERGE] -r 335:HEAD http://svn.perl.org/parrot-modules/mod_parrot/trunk
Modified: mod_parrot/branches/configure/Configure.pl
==============================================================================
--- mod_parrot/branches/configure/Configure.pl (original)
+++ mod_parrot/branches/configure/Configure.pl Thu Jul 24 07:13:01 2008
@@ -275,7 +275,7 @@
sub parrot_config
{
my $config = shift;
- my $value = `cd $parrot_build_dir; ./parrot parrot-config $config`;
+ my $value = `$parrot_build_dir/parrot_config $config`;
chomp($value);
return $value;
}
Modified: mod_parrot/branches/configure/Makefile.in
==============================================================================
--- mod_parrot/branches/configure/Makefile.in (original)
+++ mod_parrot/branches/configure/Makefile.in Thu Jul 24 07:13:01 2008
@@ -28,24 +28,28 @@
$(SRC_DIR)/parrot_util.c \
$(SRC_DIR)/modparrot_config.c \
$(SRC_DIR)/nci.c \
- $(SRC_DIR)/context.c
+ $(SRC_DIR)/context.c \
+ $(SRC_DIR)/module.c
OBJ_FILES= \
$(SRC_DIR)/mod_parrot.lo \
$(SRC_DIR)/parrot_util.lo \
$(SRC_DIR)/modparrot_config.lo \
$(SRC_DIR)/nci.lo \
- $(SRC_DIR)/context.lo
+ $(SRC_DIR)/context.lo \
+ $(SRC_DIR)/module.lo
MPLIBS= lib/Apache/RequestRec \
lib/Apache/Constants \
+ lib/Apache/Module \
lib/APR/Table \
lib/mod_parrot \
lib/ModParrot/Context \
lib/ModParrot/Interpreter \
lib/ModParrot/HLL/pir \
lib/ModParrot/HLL/perl6 \
- lib/ModParrot/HLL/plumhead \
+ lib/ModParrot/HLL/pipp \
+ lib/ModParrot/HLL/lolcode \
lib/ModParrot/HLL/nqp
all: gen-src $(SRC_DIR)/mod_parrot.la
Modified: mod_parrot/branches/configure/call_list.txt
==============================================================================
--- mod_parrot/branches/configure/call_list.txt (original)
+++ mod_parrot/branches/configure/call_list.txt Thu Jul 24 07:13:01 2008
@@ -18,3 +18,5 @@
v pit
v ptt
v Jtiiipt
+p JtP
+P Jtti
Modified: mod_parrot/branches/configure/docs/apache-conf.txt
==============================================================================
--- mod_parrot/branches/configure/docs/apache-conf.txt (original)
+++ mod_parrot/branches/configure/docs/apache-conf.txt Thu Jul 24 07:13:01 2008
@@ -22,6 +22,13 @@
Context: server config (will eventually be allowed in directory config)
Description: Load PBC, PIR, or high level language code
+ParrotLoadImmediate
+-------------------
+Syntax: ParrotLoadImmediate path
+Default: none
+Context: server config
+Description: Start the interpreter, load and run PBC or PIR
+
ParrotTrace
-----------
Syntax: ParrotTrace level
Modified: mod_parrot/branches/configure/eg/perl6/ModPerl6/Counter.pm
==============================================================================
--- mod_parrot/branches/configure/eg/perl6/ModPerl6/Counter.pm (original)
+++ mod_parrot/branches/configure/eg/perl6/ModPerl6/Counter.pm Thu Jul 24
07:13:01 2008
@@ -23,6 +23,8 @@
module ModPerl6::Counter;
+use v6;
+
sub handler($r)
{
our $x;
Modified: mod_parrot/branches/configure/eg/perl6/ModPerl6/Polly.pm
==============================================================================
--- mod_parrot/branches/configure/eg/perl6/ModPerl6/Polly.pm (original)
+++ mod_parrot/branches/configure/eg/perl6/ModPerl6/Polly.pm Thu Jul 24
07:13:01 2008
@@ -20,6 +20,8 @@
module ModPerl6::Polly;
+use v6;
+
sub handler($r)
{
my $text = $r.args();
Modified: mod_parrot/branches/configure/eg/perl6/README
==============================================================================
--- mod_parrot/branches/configure/eg/perl6/README (original)
+++ mod_parrot/branches/configure/eg/perl6/README Thu Jul 24 07:13:01 2008
@@ -1,5 +1,13 @@
-This directory contains example mod_perl6 handlers. Until the perl6 compiler
-implements search paths, the HLL layer needs some help loading handler modules.
-In particular, you'll need to set the PARROT_RUNTIME and PERL6LIB environment
-variables, which you can do on the command line or in Apache's envvars script
-(found in the same directory as apachectl).
+This directory contains example mod_perl6 handlers.
+
+How to use mod_perl6:
+
+1) Apply the modperl6 patch in the patches directory to the parrot source tree.
+2) Rebuild perl6.
+3) In the Apache's envvars script:
+ a) set PERL6LIB to the absolute path to languages/perl6/lib, or add it to
+ the path (colon-separated) if PERL6LIB is already set.
+ b) Add any local Perl 6 include paths where your handler modules will live.
+ c) Add set PARROT_RUNTIME to your parrot source directory.
+4) Configure your handlers in httpd.conf (the examples contain instructions)
+5) Restart Apache (do a full stop and start if you updated envvars).
Modified: mod_parrot/branches/configure/include/mod_parrot.h
==============================================================================
--- mod_parrot/branches/configure/include/mod_parrot.h (original)
+++ mod_parrot/branches/configure/include/mod_parrot.h Thu Jul 24 07:13:01 2008
@@ -15,7 +15,11 @@
* limitations under the License.
*/
+#ifndef _MODPARROT_H
+#define _MODPARROT_H
+
#include "httpd.h"
+#include "http_config.h"
/* apache handler name */
#define MODPARROT_MAGIC "parrot-code"
@@ -34,14 +38,17 @@
#define MODPARROT_CTX_LOCK(x) (x->locked = 1)
#define MODPARROT_CTX_UNLOCK(x) (x->locked = 0)
+/* we need to move things around to avoid this */
+#include "modparrot_config.h"
+
/* per-interpreter context */
struct modparrot_context
{
- Parrot_Interp interp; /* this context's interpreter */
- Parrot_Interp parent_interp; /* parent interpreter */
- long count; /* number of interpreter invocations */
- int locked; /* 0=available, 1=in use */
- request_rec *r; /* request_rec structure for this request */
+ Parrot_Interp interp; /* this context's interpreter */
+ Parrot_Interp parent_interp; /* parent interpreter */
+ long count; /* number of interpreter invocations */
+ int locked; /* 0=available, 1=in use */
+ request_rec *r; /* request_rec structure for this request */
apr_pool_t *pconf;
apr_pool_t *plog;
apr_pool_t *ptemp;
@@ -49,6 +56,8 @@
server_rec *s;
conn_rec *c;
void *csd;
+ modparrot_dir_config *dircfg; /* used by HLL directives */
+ modparrot_srv_config *srvcfg; /* used by HLL directives */
};
typedef struct modparrot_context modparrot_context;
@@ -70,3 +79,9 @@
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 *);
+void modparrot_load_file(Parrot_Interp, server_rec *, char *, char *);
+module *modparrot_add_module(Parrot_Interp, apr_pool_t *, const char *,
+ Parrot_PMC);
+
+#endif /* _MODPARROT_H */
Modified: mod_parrot/branches/configure/include/modparrot_config.h
==============================================================================
--- mod_parrot/branches/configure/include/modparrot_config.h (original)
+++ mod_parrot/branches/configure/include/modparrot_config.h Thu Jul 24
07:13:01 2008
@@ -15,11 +15,32 @@
* limitations under the License.
*/
+#ifndef _MODPARROT_CONFIG_H
+#define _MODPARROT_CONFIG_H
+
#include "apr_tables.h"
/* per-server options */
#define MP_OPT_ENABLE 1
#define MP_OPT_PARENT 2
+#define MP_OPT_TRACE_INIT 4
+
+/* deal with absurdity from http_config.h */
+#if defined(AP_HAVE_DESIGNATED_INITIALIZER) || defined(DOXYGEN)
+# define MP_INIT_CMD_TAKE1(c) (c.func.take1 = modparrot_module_cmd_take1)
+# define MP_INIT_CMD_TAKE2(c) (c.func.take2 = modparrot_module_cmd_take2)
+# define MP_INIT_CMD_TAKE12(c) (c.func.take2 = modparrot_module_cmd_take2)
+# define MP_INIT_CMD_TAKE3(c) (c.func.take3 = modparrot_module_cmd_take3)
+# define MP_INIT_CMD_TAKE23(c) (c.func.take3 = modparrot_module_cmd_take3)
+# define MP_INIT_CMD_TAKE123(c) (c.func.take3 = modparrot_module_cmd_take3)
+#else /* (AP_HAVE_DESIGNATED_INITIALIZER) || defined(DOXYGEN) */
+# define MP_INIT_CMD_TAKE1(c) (c.func = modparrot_module_cmd_take1)
+# define MP_INIT_CMD_TAKE2(c) (c.func = modparrot_module_cmd_take2)
+# define MP_INIT_CMD_TAKE12(c) (c.func = modparrot_module_cmd_take2)
+# define MP_INIT_CMD_TAKE3(c) (c.func = modparrot_module_cmd_take3)
+# define MP_INIT_CMD_TAKE23(c) (c.func = modparrot_module_cmd_take3)
+# define MP_INIT_CMD_TAKE123(c) (c.func = modparrot_module_cmd_take3)
+#endif /* (AP_HAVE_DESIGNATED_INITIALIZER) || defined(DOXYGEN) */
/* configuration */
struct modparrot_handler_info
@@ -72,6 +93,15 @@
};
typedef struct modparrot_dir_config modparrot_dir_config;
+struct modparrot_module_cmd_data
+{
+ Parrot_PMC func; /* parrot callback sub */
+ Parrot_PMC cmd_data; /* directive-specific cmd_data */
+};
+typedef struct modparrot_module_cmd_data modparrot_module_cmd_data;
+
+void modparrot_recalc_options(modparrot_srv_config *);
+
void *create_modparrot_srv_config(apr_pool_t *, server_rec *);
void *create_modparrot_dir_config(apr_pool_t *, char *path);
void *merge_modparrot_dir_config(apr_pool_t *, void *, void *);
@@ -104,7 +134,24 @@
const char *modparrot_cmd_trace(cmd_parms *, void *, const char *);
const char *modparrot_cmd_language(cmd_parms *, void *, const char *);
const char *modparrot_cmd_load(cmd_parms *, void *, const char *);
+const char *modparrot_cmd_load_immediate(cmd_parms *, void *, const char *);
const char *modparrot_cmd_include_path(cmd_parms *, void *, const char *);
const char *modparrot_cmd_add_type(cmd_parms *, void *, const char *, const
char *);
const char *modparrot_cmd_add_handler(cmd_parms *, void *, const char *, const
char *);
const char *modparrot_cmd_options(cmd_parms *, void *, const char *);
+
+/* for HLL apache modules */
+const char *modparrot_set_config_ptrs(cmd_parms *, void *);
+const char *modparrot_module_cmd_take1(cmd_parms *, void *, const char *);
+const char *modparrot_module_cmd_take2(cmd_parms *, void *, const char *,
+ const char*);
+const char *modparrot_module_cmd_take12(cmd_parms *, void *, const char *,
+ const char*);
+const char *modparrot_module_cmd_take3(cmd_parms *, void *, const char *,
+ const char *, const char*);
+const char *modparrot_module_cmd_take23(cmd_parms *, void *, const char *,
+ const char *, const char*);
+const char *modparrot_module_cmd_take123(cmd_parms *, void *, const char *,
+ const char *, const char*);
+
+#endif /* _MODPARROT_CONFIG_H */
Modified: mod_parrot/branches/configure/lib/APR/Table.pir
==============================================================================
--- mod_parrot/branches/configure/lib/APR/Table.pir (original)
+++ mod_parrot/branches/configure/lib/APR/Table.pir Thu Jul 24 07:13:01 2008
@@ -48,10 +48,6 @@
newclass table_class, [ 'APR'; 'Table' ]
addattribute table_class, 'apr_table'
- # a proto-object will allow HLLs to create new instances of this class
- $P0 = get_hll_global 'Protomaker'
- $P0.'new_proto'(table_class)
-
dlfunc func, nul, "apr_table_get", "tpt"
set_root_global [ 'APR'; 'NCI' ], "apr_table_get", func
Modified: mod_parrot/branches/configure/lib/Apache/RequestRec.pir
==============================================================================
--- mod_parrot/branches/configure/lib/Apache/RequestRec.pir (original)
+++ mod_parrot/branches/configure/lib/Apache/RequestRec.pir Thu Jul 24
07:13:01 2008
@@ -52,10 +52,6 @@
addattribute rr_class, 'r'
addattribute rr_class, 'pmc_notes'
- # a proto-object will allow HLLs to create new instances of this class
- $P0 = get_hll_global 'Protomaker'
- $P0.'new_proto'(rr_class)
-
dlfunc func, nul, "ap_rputs", "itp"
set_root_global [ 'Apache'; 'NCI' ], "ap_rputs", func
Modified: mod_parrot/branches/configure/lib/ModParrot/Context.pir
==============================================================================
--- mod_parrot/branches/configure/lib/ModParrot/Context.pir (original)
+++ mod_parrot/branches/configure/lib/ModParrot/Context.pir Thu Jul 24
07:13:01 2008
@@ -36,12 +36,7 @@
.local pmc context_class
load_bytecode 'ModParrot/Interpreter.pbc'
-
newclass context_class, [ 'ModParrot'; 'Context' ]
-
- # a proto-object will allow HLLs to create new instances of this class
- $P0 = get_hll_global 'Protomaker'
- $P0.'new_proto'(context_class)
.end
=over 4
Modified: mod_parrot/branches/configure/lib/ModParrot/HLL/perl6.pir
==============================================================================
--- mod_parrot/branches/configure/lib/ModParrot/HLL/perl6.pir (original)
+++ mod_parrot/branches/configure/lib/ModParrot/HLL/perl6.pir Thu Jul 24
07:13:01 2008
@@ -14,150 +14,70 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-.namespace [ 'ModParrot'; 'HLL'; 'perl6' ]
-
-# XXX should we replace this with .HLL?
.sub __onload :anon :load
+ .local string mp6_path
+ .local pmc find_file_in_path
+
load_bytecode 'languages/perl6/perl6.pbc'
- $P0 = new Hash
- set_hll_global 'loaded', $P0
-.end
-.sub load
- .param string handler
- .local string path
- .local pmc libdirs
- .local string prefix
- .local string module_path
- .local pmc env
- .local pmc handler_key
- .local string handler_sub
- .local pmc loaded
-
- loaded = get_hll_global 'loaded'
- $P0 = loaded[handler]
- handler_sub = 'handler'
- handler_key = split '::', handler
- unless_null $P0, RETURN_SUB
-
- module_path = join '/', handler_key
- env = new 'Env'
- $S0 = env['PERL6LIB']
- unless $S0, LOAD_HANDLER
- libdirs = split ':', $S0
- $I0 = elements libdirs
-LIBDIR_LOOP:
- dec $I0
- prefix = libdirs[$I0]
- path = prefix
- path .= '/'
- path .= module_path
- path .= '.pm'
- $I1 = stat path, 0
- if $I1 goto LOAD_HANDLER
- if $I0 goto LIBDIR_LOOP
-
-LOAD_HANDLER:
- # load & compile the Perl6 handler
+ $P0 = new 'Env'
+ $S0 = $P0['PERL6LIB']
+ find_file_in_path = get_hll_global ['_modparrot'], 'find_file_in_path'
+ mp6_path = find_file_in_path($S0, 'mod_perl6.pm')
$P0 = compreg 'Perl6'
- $P1 = $P0.'evalfiles'(path)
+ $P1 = $P0.'evalfiles'(mp6_path)
-RETURN_SUB:
- # return the sub
- $P1 = get_hll_global handler_key, handler_sub
- loaded[handler] = 1
- .return($P1)
-.end
+ # register mod_parrot classes as Perl6 meta classes so Perl 6 can access
+ # them natively
+ $P0 = get_hll_global 'P6metaclass'
+ $P1 = get_class ['Apache'; 'RequestRec']
+ $P0.'register'($P1)
+ $P1 = get_class ['APR'; 'Table']
+ $P0.'register'($P1)
+ $P1 = get_class ['ModParrot'; 'Interpreter']
+ $P0.'register'($P1)
+ $P1 = get_class ['ModParrot'; 'Context']
+ $P0.'register'($P1)
+
+ # register apache directives
+ .local pmc add_module, cmds
+
+ load_bytecode 'Apache/Module.pbc'
+
+ cmds = new 'Array'
+ cmds = 1
+ $P0 = new 'Hash'
+
+ $P1 = new 'String'
+ $P1 = 'Perl6ResponseHandler'
+ $P0['name'] = $P1
+ $P1 = new 'Integer'
+ $P1 = 1 # TAKE1
+ $P0['args_how'] = $P1
+ $P1 = get_hll_global 'cmd_perl6responsehandler'
+ $P0['func'] = $P1
+ $P1 = new 'Integer'
+ $P1 = 8 # OR_AUTHCFG
+ $P0['req_override'] = $P1
+ $P1 = new 'String'
+ $P1 = "usage: Perl6ResponseHandler handler-name"
+ $P0['errmsg'] = $P1
+ cmds[0] = $P0
-#.sub config
-
-# response handler
-.sub handler
- .param pmc ctx
- .param string handler_name
- .local string handler_sub
- .local pmc handler
- .local pmc r
- .local pmc ap_const
- .local int status
-
- # get apache constants
- ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
-
- # get the request_rec object
- r = ctx.'request_rec'()
-
- # set the default handler sub name
- handler_sub = 'handler'
-
- # load the handler
- push_eh REPORT_ERROR
- handler = load(handler_name)
- pop_eh
-
- # set default content type
- r.'content_type'("text/html")
-
- # run the handler, passing in Apache::RequestRec object
- push_eh REPORT_ERROR
- status = handler(r)
- pop_eh
- goto RETURN_STATUS
-
-REPORT_ERROR:
- get_results '0,0', $P0, $S0
- $S1 = handler_name
- concat $S1, ": "
- concat $S1, $S0
- $I0 = ap_const['APLOG_ERR']
- r.'log_rerror'(handler_name, 0, $I0, $S1)
- status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
-
-RETURN_STATUS:
- # return status code
- .return(status)
+ add_module = get_hll_global [ 'Apache'; 'Module' ], 'add'
+ $P1 = add_module("modparrot_perl6_module", cmds)
.end
-# authen handler
-.sub authen_handler
- .param pmc ctx
- .param string handler_name
- .local string handler_sub
- .local pmc handler
- .local pmc r
- .local pmc ap_const
- .local int status
-
- # get apache constants
- ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
-
- # get the request_rec object
- r = ctx.'request_rec'()
-
- # set the default handler sub name
- handler_sub = 'handler'
-
- # load the handler
- push_eh REPORT_ERROR
- handler = load(handler_name)
- pop_eh
-
- # run the handler, passing in Apache::RequestRec object
- push_eh REPORT_ERROR
- status = handler(r)
- pop_eh
- goto RETURN_STATUS
-
-REPORT_ERROR:
- get_results '0,0', $P0, $S0
- $S1 = handler_name
- concat $S1, ": "
- concat $S1, $S0
- $I0 = ap_const['APLOG_ERR']
- r.'log_rerror'(handler_name, 0, $I0, $S1)
- status = ap_const['HTTP_INTERNAL_SERVER_ERROR']
-
-RETURN_STATUS:
- # return status code
- .return(status)
+.sub cmd_perl6responsehandler
+ .param pmc args
+ .local string handler
+ handler = args[0]
+ $P0 = get_hll_global ['Apache'; 'Module'], 'modparrot_dircfg_handler'
+ $P1 = $P0('perl6', handler)
.end
+
+# declare namespace AFTER loading compiler
+# otherwise we get method resolution errors
+.namespace [ 'ModParrot'; 'HLL'; 'perl6' ]
+
+# helper functions go here
Modified: mod_parrot/branches/configure/lib/ModParrot/Interpreter.pir
==============================================================================
--- mod_parrot/branches/configure/lib/ModParrot/Interpreter.pir (original)
+++ mod_parrot/branches/configure/lib/ModParrot/Interpreter.pir Thu Jul 24
07:13:01 2008
@@ -39,10 +39,6 @@
.local pmc interp_class
newclass interp_class, [ 'ModParrot'; 'Interpreter' ]
-
- # a proto-object will allow HLLs to create new instances of this class
- $P0 = get_hll_global 'Protomaker'
- $P0.'new_proto'(interp_class)
.end
=over 4
@@ -144,8 +140,57 @@
.return($S0)
.end
+=item C<capture_stdout(INT flag)>
+
+=over 4
+
+WARNING: This method is temporary and WILL go away. Enables capture of
+standard output to an internal string buffer.
+
+=back
+
+=cut
+
+.sub capture_stdout :method
+ .param int enabled
+ .local pmc pio
+
+ pio = getstdout
+ unless enabled goto disable_capture
+ push pio, "string"
+ goto done
+ disable_capture:
+ $S0 = pop pio
+ done:
+.end
+
+=item C<STRING dump_stdout(INT flag)>
+
+=over 4
+
+WARNING: This method is temporary and WILL go away. Returns the contents of
+the stdout string buffer created by C<capture_stdout()>.
+
+=back
+
=cut
+.sub dump_stdout :method
+ .local pmc pio
+ .local string buf, data
+
+ pio = getstdout
+ data = ""
+
+ read_loop:
+ buf = read pio, 4096
+ data .= buf
+ $I0 = length buf
+ if $I0 == 4096 goto read_loop
+
+ .return(data)
+.end
+
=back
=head1 AUTHOR
Modified: mod_parrot/branches/configure/lib/mod_parrot.pir
==============================================================================
--- mod_parrot/branches/configure/lib/mod_parrot.pir (original)
+++ mod_parrot/branches/configure/lib/mod_parrot.pir Thu Jul 24 07:13:01 2008
@@ -78,6 +78,9 @@
dlfunc func, nul, "mpnci_csd", "pJ"
set_root_global [ '_modparrot'; 'NCI' ], "csd", func
+ dlfunc func, nul, "mpnci_dirconfig", "pJ"
+ set_root_global [ '_modparrot'; 'NCI' ], "modparrot_dirconfig", func
+
# load required libraries
load_bytecode 'Protoobject.pbc'
load_bytecode 'ModParrot/Interpreter.pbc'
@@ -107,11 +110,32 @@
count = elements pathlist
$I0 = count
-PATH_LOOP:
+ path_loop:
dec $I0
path = pathlist[$I0]
unshift include_paths, path
- if $I0 > 0 goto PATH_LOOP
+ if $I0 > 0 goto path_loop
.return(count)
.end
+
+.sub find_file_in_path
+ .param string search_path
+ .param string filename
+ .local string path
+ .local pmc iter
+
+ $P0 = split ':', search_path
+ iter = new 'Iterator', $P0
+ iter_start:
+ null path
+ unless iter goto return_path
+ $S0 = shift iter
+ path = concat $S0, '/'
+ path .= filename
+ $I0 = stat path, 0
+ unless $I0 goto iter_start
+
+ return_path:
+ .return(path)
+.end
Modified: mod_parrot/branches/configure/src/mod_parrot.c
==============================================================================
--- mod_parrot/branches/configure/src/mod_parrot.c (original)
+++ mod_parrot/branches/configure/src/mod_parrot.c Thu Jul 24 07:13:01 2008
@@ -54,18 +54,57 @@
*/
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;
+
+void modparrot_load_file(Parrot_Interp interp, server_rec *s, char *hll,
+ char *file)
+{
+ int ret;
+
+ char *ext = strrchr(file, '.');
+ /* load any PBC files */
+ if (ext && (!strcmp(ext, ".pbc") || !strcmp(ext, ".pir") ||
+ !strcmp(ext, ".pasm"))) {
+ modparrot_load_bytecode(interp, file);
+ }
+ else {
+ /* call the HLL load handler to handle the loading */
+ if (!modparrot_hll_handler(interp, hll, "load", file,
+ &ret)) {
+ MPLOG_ERRORF(s, "no HLL load handler for '%s'", hll);
+ }
+ }
+}
+
+/* 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];
+ modparrot_load_file(interp, s, l->hll, l->id);
+ }
+}
+
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;
/* initialize interpreter */
interp = modparrot_init_interpreter(ctx->parent_interp);
- Parrot_set_trace(interp, cfg->trace_flags);
+
+ /* enable tracing */
+ Parrot_set_trace(interp, (cfg->option_flags & MP_OPT_TRACE_INIT) ?
+ cfg->trace_flags : 0);
/* load the init code */
modparrot_load_bytecode(interp,
@@ -86,24 +125,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);
- }
- }
- }
return(interp);
}
@@ -136,6 +157,37 @@
return(ctxp);
}
+/* public interface for starting an interpreter */
+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))) {
+ mp_is_started = 1;
+ }
+ else {
+ MPLOG_ERROR(s, "context initialization failed");
+ return NULL;
+ }
+
+ /* we assume that the passed in pool is the configuration pool. we'll use
+ * this for early startups, but it will be overwritten by later handlers.
+ */
+ ctxp->pconf = p;
+
+ return(ctxp);
+}
+
int modparrot_hll_handler(Parrot_Interp interp, char *hll, char *hll_handler,
char *handler, int *ret)
{
@@ -897,16 +949,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 */
@@ -1199,6 +1253,13 @@
RSRC_CONF,
"preload Parrot code"
),
+ AP_INIT_ITERATE(
+ "ParrotLoadImmediate",
+ modparrot_cmd_load_immediate,
+ NULL,
+ RSRC_CONF,
+ "start interpreter early and load Parrot code"
+ ),
AP_INIT_TAKE1(
"ParrotIncludePath",
modparrot_cmd_include_path,
Modified: mod_parrot/branches/configure/src/modparrot_config.c
==============================================================================
--- mod_parrot/branches/configure/src/modparrot_config.c (original)
+++ mod_parrot/branches/configure/src/modparrot_config.c Thu Jul 24
07:13:01 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;
}
@@ -228,6 +230,13 @@
return(l);
}
+/* calculate option bit vector from enabled and disabled bits */
+void modparrot_recalc_options(modparrot_srv_config *cfg)
+{
+ cfg->option_flags |= cfg->enable_option_flags;
+ cfg->option_flags &= ~(cfg->disable_option_flags);
+}
+
/* set an option from ParrotOptions
* this is not static so we can call it from a handler
*/
@@ -243,10 +252,15 @@
else if (!strncasecmp(option, "Enable", 6)) {
*flags |= MP_OPT_ENABLE;
}
+ else if (!strncasecmp(option, "TraceInit", 9)) {
+ *flags |= MP_OPT_TRACE_INIT;
+ }
else {
return 0;
}
+ modparrot_recalc_options(cfg);
+
return 1;
}
@@ -274,6 +288,27 @@
return NULL;
}
+const char *modparrot_cmd_load_immediate(cmd_parms *cmd, void *mconfig,
+ const char *handler)
+{
+ modparrot_srv_config *cfg;
+ modparrot_handler_info *l;
+ modparrot_context *ctxp;
+
+ cfg = GET_SERVER_CONFIG(cmd);
+ l = (modparrot_handler_info *)apr_array_push(cfg->preload);
+
+ /* XXX how do we get the context if we've already started? */
+ if (!mp_is_started) {
+ ctxp = modparrot_startup(cmd->pool, cmd->server);
+ }
+
+ parse_handler(cmd->pool, handler, l);
+ modparrot_load_file(ctxp->interp, cmd->server, l->hll, l->id);
+
+ return NULL;
+}
+
const char *modparrot_cmd_open_logs_handler(cmd_parms *cmd, void *mconfig,
const char *handler)
{
modparrot_srv_config *cfg;
@@ -457,7 +492,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;
@@ -524,3 +559,128 @@
}
return errmsg;
}
+
+static Parrot_PMC make_cmd_args_array(Parrot_Interp interp, apr_pool_t *p,
+ int nargs, ...)
+{
+ va_list ap;
+ Parrot_PMC args;
+ int i=0, typenum;
+
+ typenum = Parrot_PMC_typenum(interp, "SArray");
+ args = (Parrot_PMC)Parrot_PMC_new(interp, typenum);
+ Parrot_register_pmc(interp, args);
+ Parrot_PMC_set_intval(interp, args, nargs);
+
+ va_start(ap, nargs);
+ for (i = 0; i < nargs; i++) {
+ char *arg = va_arg(ap, char *);
+ Parrot_PMC_set_cstring_intkey(interp, args, i, arg);
+ }
+ va_end(ap);
+
+ return(args);
+}
+
+static void set_mp_config_vectors(modparrot_context *ctxp, cmd_parms *cmd)
+{
+ modparrot_dir_config *cfg = (modparrot_dir_config *)ap_set_config_vectors(
+ cmd->server, cmd->context, cmd->path, &parrot_module, cmd->pool);
+ ctxp->dircfg = cfg;
+ ctxp->srvcfg = (modparrot_srv_config *)ap_get_module_config(
+ cmd->server->module_config, &parrot_module);
+}
+
+const char *modparrot_module_cmd_take1(cmd_parms *cmd, void *mconfig,
+ const char *arg)
+{
+ modparrot_context *ctxp;
+ Parrot_PMC dircfg;
+ Parrot_PMC args;
+ modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+ int ret;
+
+ ctxp = modparrot_startup(cmd->pool, cmd->server);
+ set_mp_config_vectors(ctxp, cmd);
+ args = make_cmd_args_array(ctxp->interp, cmd->pool, 1, arg);
+ ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+ return NULL;
+}
+
+const char *modparrot_module_cmd_take2(cmd_parms *cmd, void *mconfig,
+ const char *arg1,
+ const char *arg2)
+{
+ modparrot_context *ctxp;
+ Parrot_PMC args;
+ modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+ int ret;
+
+ ctxp = modparrot_startup(cmd->pool, cmd->server);
+ args = make_cmd_args_array(ctxp->interp, cmd->pool, 2, arg1, arg2);
+ ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+ return NULL;
+}
+
+const char *modparrot_module_cmd_take12(cmd_parms *cmd, void *mconfig,
+ const char *arg1,
+ const char *arg2)
+{
+ modparrot_context *ctxp;
+ Parrot_PMC args;
+ modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+ int ret;
+
+ ctxp = modparrot_startup(cmd->pool, cmd->server);
+ args = make_cmd_args_array(ctxp->interp, cmd->pool, 2, arg1, arg2);
+ ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+ return NULL;
+}
+
+const char *modparrot_module_cmd_take3(cmd_parms *cmd, void *mconfig,
+ const char *arg1,
+ const char *arg2,
+ const char *arg3)
+{
+ modparrot_context *ctxp;
+ Parrot_PMC args;
+ modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+ int ret;
+
+ ctxp = modparrot_startup(cmd->pool, cmd->server);
+ args = make_cmd_args_array(ctxp->interp, cmd->pool, 3, arg1, arg2, arg3);
+ ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+ return NULL;
+}
+
+const char *modparrot_module_cmd_take23(cmd_parms *cmd, void *mconfig,
+ const char *arg1,
+ const char *arg2,
+ const char *arg3)
+{
+ modparrot_context *ctxp;
+ Parrot_PMC args;
+ modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+ int ret;
+
+ ctxp = modparrot_startup(cmd->pool, cmd->server);
+ args = make_cmd_args_array(ctxp->interp, cmd->pool, 3, arg1, arg2, arg3);
+ ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+ return NULL;
+}
+
+const char *modparrot_module_cmd_take123(cmd_parms *cmd, void *mconfig,
+ const char *arg1,
+ const char *arg2,
+ const char *arg3)
+{
+ modparrot_context *ctxp;
+ Parrot_PMC args;
+ modparrot_module_cmd_data *data = cmd->cmd->cmd_data;
+ int ret;
+
+ ctxp = modparrot_startup(cmd->pool, cmd->server);
+ args = make_cmd_args_array(ctxp->interp, cmd->pool, 3, arg1, arg2, arg3);
+ ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IP", args);
+ return NULL;
+}
Modified: mod_parrot/branches/configure/src/nci.c
==============================================================================
--- mod_parrot/branches/configure/src/nci.c (original)
+++ mod_parrot/branches/configure/src/nci.c Thu Jul 24 07:13:01 2008
@@ -29,6 +29,7 @@
#include "parrot/extend.h"
#include "mod_parrot.h"
+#include "modparrot_config.h"
#include "../build/src/nci/request_rec.c"
@@ -129,7 +130,7 @@
* Instead, we return the results in a PMC array passed in from the caller.
*/
int mpnci_request_rec_get_basic_auth_pw(Parrot_Interp interp, request_rec *r,
- PMC *results)
+ Parrot_PMC results)
{
int status;
char *pw = NULL;
@@ -146,7 +147,7 @@
return(status);
}
-int mpnci_rwrite(Parrot_Interp interp, PMC *p, int size, request_rec *r)
+int mpnci_rwrite(Parrot_Interp interp, Parrot_PMC p, int size, request_rec *r)
{
modparrot_context *ctxp;
Parrot_Interp interpreter;
@@ -176,3 +177,54 @@
{
ap_log_rerror(file, line, level, status, r, "%s", msg);
}
+
+module *mpnci_add_apache_module(Parrot_Interp interp, char *name,
+ Parrot_PMC cmd_array)
+{
+ modparrot_context *ctxp;
+ module *modp;
+
+ ctxp = get_interp_ctx(interp);
+ if (!ctxp) return NULL;
+ modp = modparrot_add_module(interp, ctxp->pconf, name, cmd_array);
+ return(modp);
+}
+
+Parrot_PMC mpnci_dircfg_handler(Parrot_Interp interp, char *hll, char *id,
+ int update)
+{
+ modparrot_context *ctxp;
+ Parrot_PMC handler;
+ int typenum;
+
+ ctxp = get_interp_ctx(interp);
+ if (!ctxp) return NULL;
+
+ if (update) {
+ if (!ctxp->dircfg->handler) {
+ ctxp->dircfg->handler = (modparrot_handler_info *)apr_pcalloc(
+ ctxp->pconf, sizeof(modparrot_handler_info));
+ }
+ ctxp->dircfg->handler->hll = apr_pstrdup(ctxp->pconf, hll);
+ ctxp->dircfg->handler->id = apr_pstrdup(ctxp->pconf, id);
+ }
+
+ typenum = Parrot_PMC_typenum(interp, "SArray");
+ handler = (Parrot_PMC)Parrot_PMC_new(interp, typenum);
+ /* XXX how do we unregister this after it's used? */
+ Parrot_register_pmc(interp, handler);
+ Parrot_PMC_set_intval(interp, handler, 2);
+
+ if (ctxp->dircfg->handler) {
+ Parrot_PMC_set_cstring_intkey(interp, handler, 0,
+ ctxp->dircfg->handler ? ctxp->dircfg->handler->hll : "");
+ Parrot_PMC_set_cstring_intkey(interp, handler, 1,
+ ctxp->dircfg->handler ? ctxp->dircfg->handler->id : "");
+ }
+ else {
+ Parrot_PMC_set_pmc_intkey(interp, handler, 0, PMCNULL);
+ Parrot_PMC_set_pmc_intkey(interp, handler, 1, PMCNULL);
+ }
+
+ return(handler);
+}
Modified: mod_parrot/branches/configure/src/parrot_util.c
==============================================================================
--- mod_parrot/branches/configure/src/parrot_util.c (original)
+++ mod_parrot/branches/configure/src/parrot_util.c Thu Jul 24 07:13:01 2008
@@ -22,17 +22,24 @@
#include "parrot/extend.h"
#include "mod_parrot.h"
-extern void imcc_init(Parrot_Interp);
-
static Parrot_PMC get_sub_pmc_s(Parrot_Interp interp, char *namespace, char
*name)
{
Parrot_PMC sub;
- sub = Parrot_find_global_s(
- interp,
- namespace ? MAKE_PARROT_STRING(namespace) : NULL,
- MAKE_PARROT_STRING(name)
- );
+ if (namespace) {
+ sub = Parrot_find_global_s(
+ interp,
+ MAKE_PARROT_STRING(namespace),
+ MAKE_PARROT_STRING(name)
+ );
+ }
+ else {
+ Parrot_find_global_cur(
+ interp,
+ MAKE_PARROT_STRING(name)
+ );
+ }
+
return(sub);
}
@@ -76,7 +83,6 @@
Parrot_PackFile pf;
interp = Parrot_new(parent);
- imcc_init(interp);
pf = PackFile_new_dummy(interp, "mod_parrot_code");
return(interp);
}
@@ -93,8 +99,8 @@
static void modparrot_interp_cleanup(Parrot_Interp interp, int status)
{
- Parrot_block_DOD(interp);
- Parrot_block_GC(interp);
+ Parrot_block_GC_mark(interp);
+ Parrot_block_GC_sweep(interp);
handler_node_t *node = interp->exit_handler_list;
while (node) {
Modified: mod_parrot/branches/configure/t/response/TestAPI/request_rec.pir
==============================================================================
--- mod_parrot/branches/configure/t/response/TestAPI/request_rec.pir
(original)
+++ mod_parrot/branches/configure/t/response/TestAPI/request_rec.pir Thu Jul
24 07:13:01 2008
@@ -9,7 +9,7 @@
ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
- r.'puts'("1..31\n")
+ r.'puts'("1..32\n")
# XXX this should be fatal on failure
START_1:
@@ -330,30 +330,41 @@
OK_29:
r.'puts'("ok 29 - is_initial_req()\n")
- # NOTE: this test will emit authentication headers, but we don't return
- # a 401 unauthorized status, so it shouldn't cause a problem
+ # this happens to set up auth environment for note_basic_auth_failure()
START_30:
push_eh NOT_OK_30
- r.'note_basic_auth_failure'()
+ $P0 = r.'get_basic_auth_pw'()
pop_eh
goto OK_30
NOT_OK_30:
r.'puts'("not ")
OK_30:
- r.'puts'("ok 30 - note_basic_auth_failure()\n")
+ r.'puts'("ok 30 - get_basic_auth_pw()\n")
- # XXX putc() "succeeds" but doesn't output the proper character
+ # NOTE: this test will emit authentication headers, but we don't return
+ # a 401 unauthorized status, so it shouldn't cause a problem
START_31:
- # push_eh NOT_OK_31
+ push_eh NOT_OK_31
+ r.'note_basic_auth_failure'()
+ pop_eh
+ goto OK_31
+ NOT_OK_31:
+ r.'puts'("not ")
+ OK_31:
+ r.'puts'("ok 31 - note_basic_auth_failure()\n")
+
+ # XXX putc() "succeeds" but doesn't output the proper character
+ START_32:
+ # push_eh NOT_OK_32
# r.'putc'('#')
# pop_eh
# r.'puts'("\n")
- # goto OK_31
- #NOT_OK_31:
+ # goto OK_32
+ #NOT_OK_32:
# r.'puts'("not ")
- #OK_31:
- # r.'puts'("ok 31 - putc()\n")
- r.'puts'("not ok 31 - putc() # TODO succeeds with incorrect output\n")
+ #OK_32:
+ # r.'puts'("ok 32 - putc()\n")
+ r.'puts'("not ok 32 - putc() # TODO succeeds with incorrect output\n")
# STILL TODO (not tested in original client-side tests)
# assbackwards
|
|