You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2006/04/09 10:58:37 UTC

svn commit: r392692 - in /httpd/mod_python/trunk: lib/python/mod_python/__init__.py src/include/mod_python.h src/include/mod_python.h.in src/include/mpversion.h src/mod_python.c

Author: grahamd
Date: Sun Apr  9 01:58:35 2006
New Revision: 392692

URL: http://svn.apache.org/viewcvs?rev=392692&view=rev
Log:
The PythonImport directive makes use of the handler list data structure
even though it specifically is for a different purpose. The handler list
data structure needs to be changed a bit in order to support changes
required to address MODPYTHON-63 and MODPYTHON-126. These changes may
make it unusable in the way that the PythonImport directive was using it,
or at least it will not be a good match. The PythonImport directive has
therefore been modified to use a standard Apache table object thereby
allowing arbitrary changes to the handler list data structure to be made as
necessary.

Note that although the current Apache table implementation probably results
in module imports occuring in the order they appear in the Apache
configuration file, if how it is implemented is changed, this may no longer
be the case. This is not seen as an issue as the documentation for the
PythonImport directive does not give any guarantees about ordering of
imports within the context of a specific interpreter and it would be bad
practice for modules to rely on mod_python importing them in a specific
order. If there are ordering requirements, it should be dealt with internal
to the module being imported so that it is self contained.

Modified:
    httpd/mod_python/trunk/lib/python/mod_python/__init__.py
    httpd/mod_python/trunk/src/include/mod_python.h
    httpd/mod_python/trunk/src/include/mod_python.h.in
    httpd/mod_python/trunk/src/include/mpversion.h
    httpd/mod_python/trunk/src/mod_python.c

Modified: httpd/mod_python/trunk/lib/python/mod_python/__init__.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/__init__.py?rev=392692&r1=392691&r2=392692&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/__init__.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/__init__.py Sun Apr  9 01:58:35 2006
@@ -20,5 +20,5 @@
 __all__ = ["apache", "cgihandler", "psp",
            "publisher", "util", "python22"]
 
-version = "3.3.0-dev-20060402"
+version = "3.3.0-dev-20060409"
 

Modified: httpd/mod_python/trunk/src/include/mod_python.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mod_python.h?rev=392692&r1=392691&r2=392692&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h Sun Apr  9 01:58:35 2006
@@ -147,7 +147,7 @@
     apr_hash_t   *hlists; /* hlists for every phase */
     apr_hash_t   *in_filters;
     apr_hash_t   *out_filters;
-    hl_entry     *imports;  /* for PythonImport */
+    apr_table_t  *imports;  /* for PythonImport */
 } py_config;
 
 /* register_cleanup info */

Modified: httpd/mod_python/trunk/src/include/mod_python.h.in
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mod_python.h.in?rev=392692&r1=392691&r2=392692&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h.in (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h.in Sun Apr  9 01:58:35 2006
@@ -147,7 +147,7 @@
     apr_hash_t   *hlists; /* hlists for every phase */
     apr_hash_t   *in_filters;
     apr_hash_t   *out_filters;
-    hl_entry     *imports;  /* for PythonImport */
+    apr_table_t  *imports;  /* for PythonImport */
 } py_config;
 
 /* register_cleanup info */

Modified: httpd/mod_python/trunk/src/include/mpversion.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mpversion.h?rev=392692&r1=392691&r2=392692&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mpversion.h (original)
+++ httpd/mod_python/trunk/src/include/mpversion.h Sun Apr  9 01:58:35 2006
@@ -1,5 +1,5 @@
 #define MPV_MAJOR 3
 #define MPV_MINOR 3
 #define MPV_PATCH 0
-#define MPV_BUILD 20060402
-#define MPV_STRING "3.3.0-dev-20060402"
+#define MPV_BUILD 20060409
+#define MPV_STRING "3.3.0-dev-20060409"

Modified: httpd/mod_python/trunk/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/mod_python.c?rev=392692&r1=392691&r2=392692&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Sun Apr  9 01:58:35 2006
@@ -1861,9 +1861,9 @@
                                            &python_module);
 
     if (!conf->imports)
-        conf->imports = hlist_new(cmd->pool, module, interp_name, 0);
-    else 
-        hlist_append(cmd->pool, conf->imports, module, interp_name, 0);
+        conf->imports = apr_table_make(cmd->pool, 4);
+
+    apr_table_add(conf->imports, interp_name, module);
 
     return NULL;
 
@@ -2236,7 +2236,10 @@
 {
 
 
-    hl_entry *hle;
+    const apr_array_header_t *ah;
+    apr_table_entry_t *elts;
+    int i;
+
     py_config *conf = ap_get_module_config(s->module_config, &python_module);
     py_global_config *glb;
     PyObject *resultobject = NULL;
@@ -2307,45 +2310,50 @@
      * Now run PythonImports
      */
 
-    hle = conf->imports;
-    while(hle) {
+    if (conf->imports) {
+        ah = apr_table_elts (conf->imports);
+        elts = (apr_table_entry_t *) ah->elts;
+
+        i = ah->nelts;
+
+        while (i--) {
+            if (elts[i].key) {
+
+                interpreterdata *idata;
+                const char *interp_name = elts[i].key;
+                const char *module_name = elts[i].val;
+                const char *ppath;
+
+                /* get interpreter */
+                idata = get_interpreter(interp_name, s);
+                if (!idata)
+                    return;
+
+                /* 
+                 * Call into Python to do import.
+                 * This is the C equivalent of
+                 * >>> resultobject = obCallBack.ImportDispatch(module_name)
+                 */
+                resultobject = PyObject_CallMethod(idata->obcallback,
+                                                   "ImportDispatch", "s", module_name);
+
+                if (!resultobject) {
+                    if (PyErr_Occurred()) {
+                        PyErr_Print();
+                        fflush(stderr); 
+                    }
+                    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+                                 "directive_PythonImport: error importing %s",
+                                 (!module_name) ? "<null>" : module_name);
+                }
+
+                /* clean up */
+                Py_XDECREF(resultobject);
 
-        interpreterdata *idata;
-        const char *module_name = hle->handler;
-        const char *interp_name = hle->directory;
-        const char *ppath;
-
-        /* get interpreter */
-        idata = get_interpreter(interp_name, s);
-        if (!idata)
-            return;
-
-        /* 
-         * Call into Python to do import.
-         * This is the C equivalent of
-         * >>> resultobject = obCallBack.ImportDispatch(module_name)
-         */
-        resultobject = PyObject_CallMethod(idata->obcallback,
-                                           "ImportDispatch", "s", module_name);
-
-        if (!resultobject) {
-            if (PyErr_Occurred()) {
-                PyErr_Print();
-                fflush(stderr); 
+                /* release interpreter */
+                release_interpreter();
             }
-            ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
-                         "directive_PythonImport: error importing %s",
-                         (!module_name) ? "<null>" : module_name);
         }
-
-        /* clean up */
-        Py_XDECREF(resultobject);
-
-        /* release interpreter */
-        release_interpreter();
-
-        /* next module */
-        hle = hle->next;
     }
 }