[svn:mod_parrot] r310 - in mod_parrot/trunk: . include lib lib/ModParrot lib/ModParrot/HLL src
[email protected] Tue, 15 Jan 2008 14:22:21 -0800 (PST)
| Newsgroups | perl.cvs.mod_parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: jhorwitz
Date: Tue Jan 15 14:22:20 2008
New Revision: 310
Added:
mod_parrot/trunk/lib/ModParrot/Context.pir
Modified:
mod_parrot/trunk/CHANGES
mod_parrot/trunk/Makefile.in
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir
mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir
mod_parrot/trunk/lib/ModParrot/HLL/pir.pir
mod_parrot/trunk/lib/ModParrot/HLL/plumhead.pir
mod_parrot/trunk/lib/mod_parrot.pir
mod_parrot/trunk/src/mod_parrot.c
mod_parrot/trunk/src/parrot_util.c
Log:
implement ModParrot;Context class for passing state to HLL handlers
update HLL layers to get the Apache;RequestRec object from the context
Modified: mod_parrot/trunk/CHANGES
==============================================================================
--- mod_parrot/trunk/CHANGES (original)
+++ mod_parrot/trunk/CHANGES Tue Jan 15 14:22:20 2008
@@ -18,6 +18,7 @@
* Can pass a PMC note via pmc_notes()
* Implement mod_perl-like cleanup handlers
* Use proto-objects make mod_parrot classes instantiable from an HLL
+ * New ModParrot;Context class for accessing mod_parrot data structures
* New ModParrot;Interpreter class for interpreter introspection
* New TODO list replaces the outdated ROADMAP
* Update documentation and examples
@@ -32,6 +33,7 @@
- ParrotAddHandler
- ParrotOptions
o Parent
+ o Embed
0.3 August 2, 2005
* Support for Parrot 0.2.2 (geeksunite)
Modified: mod_parrot/trunk/Makefile.in
==============================================================================
--- mod_parrot/trunk/Makefile.in (original)
+++ mod_parrot/trunk/Makefile.in Tue Jan 15 14:22:20 2008
@@ -41,6 +41,7 @@
lib/Apache/Constants \
lib/APR/Table \
lib/mod_parrot \
+ lib/ModParrot/Context \
lib/ModParrot/Interpreter \
lib/ModParrot/HLL/pir \
lib/ModParrot/HLL/perl6 \
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Tue Jan 15 14:22:20 2008
@@ -59,6 +59,8 @@
int modparrot_call_sub(Parrot_Interp, char *, char *);
int modparrot_call_sub_Iv(Parrot_Interp, char *, char *, int *);
int modparrot_call_sub_IS(Parrot_Interp, char *, char *, int *, char *);
+int modparrot_call_sub_IPS(Parrot_Interp, char *, char *, int *, Parrot_PMC,
+ char *);
char *modparrot_backtrace(Parrot_Interp);
int modparrot_hll_handler(Parrot_Interp, char *, char *, char *, int *);
Parrot_PMC get_sub_pmc(Parrot_Interp , char *, char *);
Added: mod_parrot/trunk/lib/ModParrot/Context.pir
==============================================================================
--- (empty file)
+++ mod_parrot/trunk/lib/ModParrot/Context.pir Tue Jan 15 14:22:20 2008
@@ -0,0 +1,111 @@
+# $Id$
+
+# Copyright (c) 2007 Jeff Horwitz
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+=head1 NAME
+
+Context.pir
+
+=head1 SYNOPSIS
+
+interp = new [ 'ModParrot'; 'Context' ]
+
+=head1 DESCRIPTION
+
+Context object for HLL handlers.
+
+=head2 Methods
+
+=cut
+
+.namespace [ 'ModParrot'; 'Context' ]
+
+.sub _initialize :load
+ .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
+
+=item ModParrot::Interpreter C<interp()>
+
+=over 4
+
+Returns the current interpreter as a ModParrot::Interpreter object.
+
+=back
+
+=cut
+
+.sub interp :method
+ .local pmc mpi
+
+ $P0 = get_class [ 'ModParrot'; 'Interpreter' ]
+ mpi = new $P0
+
+ .return(mpi)
+.end
+
+=item Apache::RequestRec request_rec()
+
+=over 4
+
+Returns the current Apache::RequestRec object.
+
+=back
+
+=cut
+
+.sub request_rec :method
+ .local pmc r
+
+ $P0 = new [ 'Apache'; 'RequestRec' ]
+
+ .return($P0)
+.end
+
+=back
+
+=head1 TODO
+
+=over 4
+
+=item server_rec
+
+=item conn_rec
+
+=item request_pool
+
+=item conf_pool
+
+=item log_pool
+
+=item temp_pool
+
+=back
+
+=head1 AUTHOR
+
+Jeff Horwitz
+
+=cut
+
Modified: mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir (original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/nqp.pir Tue Jan 15 14:22:20 2008
@@ -49,6 +49,7 @@
# response handler
.sub handler
+ .param pmc ctx
.param string handler_name
.local string handler_path
.local string handler_sub
@@ -63,8 +64,7 @@
ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# NQP::Registry is a special case:
# 1. set handler path to apache's parsed filename
Modified: mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir (original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir Tue Jan 15 14:22:20 2008
@@ -73,6 +73,7 @@
# response handler
.sub handler
+ .param pmc ctx
.param string handler_name
.local string handler_sub
.local pmc handler
@@ -85,8 +86,7 @@
ap_const = get_root_global [ 'Apache'; 'Constants' ], 'ap_constants'
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# set the default handler sub name
handler_sub = 'handler'
Modified: mod_parrot/trunk/lib/ModParrot/HLL/pir.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/pir.pir (original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/pir.pir Tue Jan 15 14:22:20 2008
@@ -25,14 +25,14 @@
# response handler
.sub handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -44,14 +44,14 @@
# authen handler
.sub authen_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -63,14 +63,14 @@
# authz handler
.sub authz_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -82,14 +82,14 @@
# access handler
.sub access_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -101,6 +101,7 @@
# open logs handler
.sub open_logs_handler
+ .param pmc ctx
.param string handler_name
.local pmc pconf
.local pmc plog
@@ -132,6 +133,7 @@
# post_config handler
.sub post_config_handler
+ .param pmc ctx
.param string handler_name
.local pmc pconf
.local pmc plog
@@ -163,6 +165,7 @@
# child init handler
.sub child_init_handler
+ .param pmc ctx
.param string handler_name
.local pmc pchild
.local pmc s
@@ -188,6 +191,7 @@
# pre connection handler
.sub pre_connection_handler
+ .param pmc ctx
.param string handler_name
.local pmc c
.local pmc csd
@@ -213,6 +217,7 @@
# process connection handler
.sub process_connection_handler
+ .param pmc ctx
.param string handler_name
.local pmc c
.local pmc handler
@@ -233,6 +238,7 @@
# trans handler
.sub trans_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
@@ -240,8 +246,7 @@
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -253,6 +258,7 @@
# fixup handler
.sub fixup_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
@@ -260,8 +266,7 @@
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -273,6 +278,7 @@
# type handler
.sub type_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
@@ -280,8 +286,7 @@
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -293,6 +298,7 @@
# log handler
.sub log_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
@@ -300,8 +306,7 @@
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -313,6 +318,7 @@
# map_to_storage handler
.sub map_to_storage_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
@@ -320,8 +326,7 @@
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -333,6 +338,7 @@
# post_read_request handler
.sub post_read_request_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
@@ -340,8 +346,7 @@
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -353,14 +358,14 @@
# header_parser handler
.sub header_parser_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
@@ -372,14 +377,14 @@
# cleanup handler
.sub cleanup_handler
+ .param pmc ctx
.param string handler_name
.local pmc r
.local pmc handler
.local int status
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# find the handler sub and call it
find_global handler, handler_name, 'handler'
Modified: mod_parrot/trunk/lib/ModParrot/HLL/plumhead.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/plumhead.pir (original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/plumhead.pir Tue Jan 15 14:22:20 2008
@@ -34,6 +34,7 @@
# response handler
.sub handler
+ .param pmc ctx
.param string php_file
.local pmc r
.local pmc ap_const
@@ -44,8 +45,7 @@
.local pmc get_hash, post_hash
# get the request_rec object
- $P0 = get_class [ 'Apache'; 'RequestRec' ]
- r = new $P0
+ r = ctx.'request_rec'()
# parse query string
args = r.'args'()
Modified: mod_parrot/trunk/lib/mod_parrot.pir
==============================================================================
--- mod_parrot/trunk/lib/mod_parrot.pir (original)
+++ mod_parrot/trunk/lib/mod_parrot.pir Tue Jan 15 14:22:20 2008
@@ -81,6 +81,7 @@
# load required libraries
load_bytecode 'Protoobject.pbc'
load_bytecode 'ModParrot/Interpreter.pbc'
+ load_bytecode 'ModParrot/Context.pbc'
load_bytecode 'Apache/Constants.pbc'
load_bytecode 'Apache/RequestRec.pbc'
load_bytecode 'APR/Table.pbc'
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Tue Jan 15 14:22:20 2008
@@ -133,8 +133,26 @@
int modparrot_hll_handler(Parrot_Interp interp, char *hll, char *hll_handler,
char *handler, int *ret)
{
+ Parrot_PMC ctx_class;
+ Parrot_PMC ctx_pmc;
+ Parrot_PMC namespace;
+ int typenum;
+
+ typenum = Parrot_PMC_typenum(interp, "ResizableStringArray");
+ namespace = (Parrot_PMC)Parrot_PMC_new(interp, typenum);
+ Parrot_register_pmc(interp, namespace);
+ Parrot_PMC_set_intval(interp, namespace, 2);
+ Parrot_PMC_set_cstring_intkey(interp, namespace, 0, "ModParrot");
+ Parrot_PMC_set_cstring_intkey(interp, namespace, 1, "Context");
+
+ ctx_class = Parrot_oo_get_class(interp, namespace);
+ ctx_pmc = VTABLE_instantiate(interp, ctx_class, PMCNULL);
+
if (!hll) hll = MODPARROT_DEFAULT_HLL;
- modparrot_call_sub_IS(interp, hll, hll_handler, ret, handler);
+ modparrot_call_sub_IPS(interp, hll, hll_handler, ret, ctx_pmc, handler);
+
+ Parrot_unregister_pmc(interp, namespace);
+
return(1);
}
Modified: mod_parrot/trunk/src/parrot_util.c
==============================================================================
--- mod_parrot/trunk/src/parrot_util.c (original)
+++ mod_parrot/trunk/src/parrot_util.c Tue Jan 15 14:22:20 2008
@@ -149,6 +149,20 @@
return(1);
}
+int modparrot_call_sub_IPS(Parrot_Interp interp, char *namespace, char *name,
+ int *ret, Parrot_PMC pmc, char *arg)
+{
+ Parrot_PMC sub;
+
+ sub = get_sub_pmc(interp, namespace, name);
+ if (!sub) {
+ return(0);
+ }
+ *ret = Parrot_call_sub_ret_int(interp, sub, "IPS", pmc,
+ MAKE_PARROT_STRING(arg));
+ return(1);
+}
+
/* adapted from Parrot's PDB_backtrace */
char *modparrot_backtrace(Parrot_Interp interp)
{