Author: jhorwitz
Date: Wed Dec 12 15:04:03 2007
New Revision: 267
Added:
mod_parrot/trunk/src/constants.c
Modified:
mod_parrot/trunk/Makefile.in
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/src/context.c
mod_parrot/trunk/src/mod_parrot.c
Log:
make parrot string constants globally available
Modified: mod_parrot/trunk/Makefile.in
==============================================================================
--- mod_parrot/trunk/Makefile.in (original)
+++ mod_parrot/trunk/Makefile.in Wed Dec 12 15:04:03 2007
@@ -27,14 +27,16 @@
$(SRC_DIR)/parrot_util.c \
$(SRC_DIR)/modparrot_config.c \
$(SRC_DIR)/nci.c \
- $(SRC_DIR)/context.c
+ $(SRC_DIR)/context.c \
+ $(SRC_DIR)/constants.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)/constants.lo
MPLIBS= lib/Apache/RequestRec \
lib/Apache/Constants \
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Wed Dec 12 15:04:03 2007
@@ -25,6 +25,7 @@
/* string macros */
#define MAKE_PARROT_STRING(x) (string_from_cstring(interp, x, strlen(x)))
+#define MODPARROT_CONSTANT(x) (mp_constants[x])
/* context macros */
#define MODPARROT_CTX_ISLOCKED(x) (x->locked == 1)
@@ -34,10 +35,10 @@
/* per-interpreter context */
struct modparrot_context
{
- Parrot_Interp interp; /* Parrot 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; /* Parrot 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;
@@ -63,3 +64,9 @@
void release_ctx(modparrot_context *);
modparrot_context *get_interp_ctx(Parrot_Interp);
void set_interp_ctx(Parrot_Interp, modparrot_context *);
+void mp_init_constants(Parrot_Interp);
+
+/* constants */
+#define DECLARE_MP_CONSTANTS extern Parrot_String mp_constants[];
+#define MODPARROT_CONST_CONTEXT_NAMESPACE 0
+#define MODPARROT_CONST_CONTEXT_FUNCTION 1
Added: mod_parrot/trunk/src/constants.c
==============================================================================
--- (empty file)
+++ mod_parrot/trunk/src/constants.c Wed Dec 12 15:04:03 2007
@@ -0,0 +1,39 @@
+/* $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.
+ */
+
+#include "parrot/resources.h"
+#include "parrot/embed.h"
+#include "parrot/extend.h"
+#include "mod_parrot.h"
+
+#define MODPARROT_NUM_CONSTANTS 2
+
+Parrot_String mp_constants[MODPARROT_NUM_CONSTANTS];
+
+static char *mp_constant_strings[MODPARROT_NUM_CONSTANTS] = {
+ "_modparrot", /* MP_CONST_CONTEXT_NAMESPACE 0 */
+ "__context" /* MP_CONST_CONTEXT_FUNCTION 1 */
+};
+
+void mp_init_constants(Parrot_Interp interp)
+{
+ int i;
+
+ for (i = 0; i < MODPARROT_NUM_CONSTANTS; i++) {
+ mp_constants[i] = MAKE_PARROT_STRING(mp_constant_strings[i]);
+ }
+}
Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c (original)
+++ mod_parrot/trunk/src/context.c Wed Dec 12 15:04:03 2007
@@ -32,6 +32,8 @@
#include "mod_parrot.h"
#include "modparrot_config.h"
+DECLARE_MP_CONSTANTS;
+
/* pool of mod_parrot contexts */
static apr_array_header_t *mp_ctx_pool = (apr_array_header_t *)NULL;
@@ -93,10 +95,9 @@
typenum = Parrot_PMC_typenum(interp, "UnManagedStruct");
p = Parrot_PMC_new(interp, typenum);
Parrot_PMC_set_pointer(interp, p, ctx);
- /* XXX should create parrot strings ahead of time -- they're constant! */
Parrot_store_global_s(interp,
- MAKE_PARROT_STRING("_modparrot"),
- MAKE_PARROT_STRING("__context"),
+ MODPARROT_CONSTANT(MODPARROT_CONST_CONTEXT_NAMESPACE),
+ MODPARROT_CONSTANT(MODPARROT_CONST_CONTEXT_FUNCTION),
p);
ctx->interp = interp;
@@ -107,10 +108,9 @@
Parrot_PMC p;
modparrot_context *ctx = (modparrot_context *)NULL;
- /* XXX should create parrot strings ahead of time -- they're constant! */
- p = Parrot_find_global_s(interp,
- MAKE_PARROT_STRING("_modparrot"),
- MAKE_PARROT_STRING("__context"));
+ p = Parrot_find_global_s(interp,
+ MODPARROT_CONSTANT(MODPARROT_CONST_CONTEXT_NAMESPACE),
+ MODPARROT_CONSTANT(MODPARROT_CONST_CONTEXT_FUNCTION));
if (p) {
ctx = Parrot_PMC_get_pointer(interp, p);
}
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Wed Dec 12 15:04:03 2007
@@ -58,6 +58,9 @@
interp = modparrot_init_interpreter();
Parrot_set_trace(interp, cfg->trace_flags);
+ /* initialize constants */
+ mp_init_constants(interp);
+
/* run initialization code */
if (cfg->init_path) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.