Author: stas
Date: Tue Dec 21 16:03:35 2004
New Revision: 123020

URL: http://svn.apache.org/viewcvs?view=rev&rev=123020
Log:
move the various perl context macros to mod_perl.h so we can reuse them in 
other files. while doing that rename the macros to be more consistent

Modified:
   perl/modperl/trunk/src/modules/perl/mod_perl.h
   perl/modperl/trunk/src/modules/perl/modperl_cmd.c
   perl/modperl/trunk/src/modules/perl/modperl_config.c

Modified: perl/modperl/trunk/src/modules/perl/mod_perl.h
Url: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/src/modules/perl/mod_perl.h?view=diff&rev=123020&p1=perl/modperl/trunk/src/modules/perl/mod_perl.h&r1=123019&p2=perl/modperl/trunk/src/modules/perl/mod_perl.h&r2=123020
==============================================================================
--- perl/modperl/trunk/src/modules/perl/mod_perl.h      (original)
+++ perl/modperl/trunk/src/modules/perl/mod_perl.h      Tue Dec 21 16:03:35 2004
@@ -154,4 +154,46 @@
 
 APR_DECLARE_OPTIONAL_FN(apr_status_t,modperl_interp_unselect,(void *));
 
+/*
+ * perl context overriding and restoration is required when
+ * PerlOptions +Parent/+Clone is used in vhosts, and perl is used to
+ * at the server startup. So that <Perl> sections, PerlLoadModule,
+ * PerlModule and PerlRequire are all run using the right perl context
+ * and restore to the original context when they are done.
+ *
+ * As of perl-5.8.3 it's unfortunate that it uses PERL_GET_CONTEXT and
+ * doesn't rely on the passed pTHX internally. When and if perl is
+ * fixed to always use pTHX if available, this context switching mess
+ * can be removed.
+ */
+#ifdef USE_ITHREADS
+
+#define MP_PERL_CONTEXT_DECLARE                 \
+    PerlInterpreter *orig_perl;                 \
+    pTHX;
+
+#define MP_PERL_CONTEXT_STORE                   \
+    orig_perl = PERL_GET_CONTEXT;
+
+#define MP_PERL_CONTEXT_OVERRIDE(new_perl)      \
+    aTHX = new_perl;                            \
+    PERL_SET_CONTEXT(aTHX);
+
+#define MP_PERL_CONTEXT_STORE_OVERRIDE(new_perl)        \
+    MP_PERL_CONTEXT_STORE;                              \
+    MP_PERL_CONTEXT_OVERRIDE(new_perl)
+
+#define MP_PERL_CONTEXT_RESTORE                 \
+    PERL_SET_CONTEXT(orig_perl);
+
+#else /* #ifdef USE_ITHREADS */
+
+#define MP_PERL_CONTEXT_DECLARE
+#define MP_PERL_CONTEXT_STORE
+#define MP_PERL_CONTEXT_OVERRIDE(perl)
+#define MP_PERL_CONTEXT_STORE_OVERRIDE(new_perl)
+#define MP_PERL_CONTEXT_RESTORE
+
+#endif /* end of #ifdef USE_ITHREADS */
+
 #endif /*  MOD_PERL_H */

Modified: perl/modperl/trunk/src/modules/perl/modperl_cmd.c
Url: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/src/modules/perl/modperl_cmd.c?view=diff&rev=123020&p1=perl/modperl/trunk/src/modules/perl/modperl_cmd.c&r1=123019&p2=perl/modperl/trunk/src/modules/perl/modperl_cmd.c&r2=123020
==============================================================================
--- perl/modperl/trunk/src/modules/perl/modperl_cmd.c   (original)
+++ perl/modperl/trunk/src/modules/perl/modperl_cmd.c   Tue Dec 21 16:03:35 2004
@@ -15,42 +15,6 @@
 
 #include "mod_perl.h"
 
-#ifdef USE_ITHREADS
-
-/*
- * perl context overriding and restoration is required when
- * PerlOptions +Parent/+Clone is used in vhosts, and perl is used to
- * at the server startup. So that <Perl> sections, PerlLoadModule,
- * PerlModule and PerlRequire are all run using the right perl context
- * and restore to the original context when they are done.
- *
- * As of perl-5.8.3 it's unfortunate that it uses PERL_GET_CONTEXT and
- * doesn't rely on the passed pTHX internally. When and if perl is
- * fixed to always use pTHX if available, this context switching mess
- * can be removed.
- */
-
-#define MP_PERL_DECLARE_CONTEXT \
-    PerlInterpreter *orig_perl; \
-    pTHX;
-
-/* XXX: .htaccess support cannot use this perl with threaded MPMs */
-#define MP_PERL_OVERRIDE_CONTEXT    \
-    orig_perl = PERL_GET_CONTEXT;   \
-    aTHX = scfg->mip->parent->perl; \
-    PERL_SET_CONTEXT(aTHX);
-
-#define MP_PERL_RESTORE_CONTEXT     \
-    PERL_SET_CONTEXT(orig_perl);
-
-#else
-
-#define MP_PERL_DECLARE_CONTEXT
-#define MP_PERL_OVERRIDE_CONTEXT
-#define MP_PERL_RESTORE_CONTEXT
-
-#endif
-
 /* This ensures that a given directive is either in Server context
  * or in a .htaccess file, usefull for things like PerlRequire
  */
@@ -203,7 +167,7 @@
 MP_CMD_SRV_DECLARE(modules)
 {
     MP_dSCFG(parms->server);
-    MP_PERL_DECLARE_CONTEXT;
+    MP_PERL_CONTEXT_DECLARE;
 
     MP_CHECK_SERVER_OR_HTACCESS_CONTEXT;
 
@@ -218,11 +182,11 @@
 
         MP_TRACE_d(MP_FUNC, "load PerlModule %s\n", arg);
 
-        MP_PERL_OVERRIDE_CONTEXT;
+        MP_PERL_CONTEXT_STORE_OVERRIDE(scfg->mip->parent->perl);
         if (!modperl_require_module(aTHX_ arg, FALSE)) {
             error = SvPVX(ERRSV);
         }
-        MP_PERL_RESTORE_CONTEXT;
+        MP_PERL_CONTEXT_RESTORE;
 
         return error;
     }
@@ -236,7 +200,7 @@
 MP_CMD_SRV_DECLARE(requires)
 {
     MP_dSCFG(parms->server);
-    MP_PERL_DECLARE_CONTEXT;
+    MP_PERL_CONTEXT_DECLARE;
 
     MP_CHECK_SERVER_OR_HTACCESS_CONTEXT;
 
@@ -251,11 +215,11 @@
 
         MP_TRACE_d(MP_FUNC, "load PerlRequire %s\n", arg);
 
-        MP_PERL_OVERRIDE_CONTEXT;
+        MP_PERL_CONTEXT_STORE_OVERRIDE(scfg->mip->parent->perl);
         if (!modperl_require_file(aTHX_ arg, FALSE)) {
             error = SvPVX(ERRSV);
         }
-        MP_PERL_RESTORE_CONTEXT;
+        MP_PERL_CONTEXT_RESTORE;
 
         return error;
     }
@@ -525,7 +489,7 @@
     ap_directive_t *directive = parms->directive;
 #ifdef USE_ITHREADS
     MP_dSCFG(s);
-    MP_PERL_DECLARE_CONTEXT;
+    MP_PERL_CONTEXT_DECLARE;
 #endif
 
     if (!(arg && *arg)) {
@@ -541,7 +505,7 @@
         return "init mod_perl vhost failed";
     }
 
-    MP_PERL_OVERRIDE_CONTEXT;
+    MP_PERL_CONTEXT_STORE_OVERRIDE(scfg->mip->parent->perl);
 
     /* data will be set by a <Perl> section */
     if ((options = directive->data)) {
@@ -589,7 +553,7 @@
     }
 
     if (SvTRUE(ERRSV)) {
-        MP_PERL_RESTORE_CONTEXT;
+        MP_PERL_CONTEXT_RESTORE;
         return SvPVX(ERRSV);
     }
 
@@ -615,12 +579,12 @@
             char *error = SvTRUE(ERRSV) ? SvPVX(ERRSV) :
                 apr_psprintf(p, "<Perl> handler %s failed with status=%d",
                              handler->name, status);
-            MP_PERL_RESTORE_CONTEXT;
+            MP_PERL_CONTEXT_RESTORE;
             return error;
         }
     }
 
-    MP_PERL_RESTORE_CONTEXT;
+    MP_PERL_CONTEXT_RESTORE;
     return NULL;
 }
 

Modified: perl/modperl/trunk/src/modules/perl/modperl_config.c
Url: 
http://svn.apache.org/viewcvs/perl/modperl/trunk/src/modules/perl/modperl_config.c?view=diff&rev=123020&p1=perl/modperl/trunk/src/modules/perl/modperl_config.c&r1=123019&p2=perl/modperl/trunk/src/modules/perl/modperl_config.c&r2=123020
==============================================================================
--- perl/modperl/trunk/src/modules/perl/modperl_config.c        (original)
+++ perl/modperl/trunk/src/modules/perl/modperl_config.c        Tue Dec 21 
16:03:35 2004
@@ -446,10 +446,9 @@
 {
     modperl_require_file_t **requires;
     int i;
-#ifdef USE_ITHREADS
-    PerlInterpreter *orig_perl = PERL_GET_CONTEXT;
-    pTHX;
-#endif
+    MP_PERL_CONTEXT_DECLARE;
+
+    MP_PERL_CONTEXT_STORE;
     
     requires = (modperl_require_file_t **)scfg->PerlPostConfigRequire->elts;
     for (i = 0; i < scfg->PerlPostConfigRequire->nelts; i++){
@@ -464,15 +463,11 @@
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                          "Can't load Perl file: %s for server %s, exiting...",
                          requires[i]->file, modperl_server_desc(s, p));
-#ifdef USE_ITHREADS
-            PERL_SET_CONTEXT(orig_perl);
-#endif
+            MP_PERL_CONTEXT_RESTORE;
             return FALSE;
         }
     }
-#ifdef USE_ITHREADS
-    PERL_SET_CONTEXT(orig_perl);
-#endif
+    MP_PERL_CONTEXT_RESTORE;
 
     return TRUE;
 }

Reply via email to