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/30 12:24:32 UTC

svn commit: r398308 - in /httpd/mod_python/trunk: Doc/ lib/python/mod_python/ src/ src/include/

Author: grahamd
Date: Sun Apr 30 03:24:28 2006
New Revision: 398308

URL: http://svn.apache.org/viewcvs?rev=398308&view=rev
Log:
When in a sub request, when a request is the result of an internal
redirect, or when when returning from such a request, the req.main,
req.prev and req.next members now correctly return a reference to the
original Python request object wrapper first created for the specific
request_rec instance rather than creating a new distinct Python request
object. This means that any data added explicitly to a request object can
be passed between such requests. (MODPYTHON-152)

Modified:
    httpd/mod_python/trunk/Doc/appendixc.tex
    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/include/requestobject.h
    httpd/mod_python/trunk/src/mod_python.c
    httpd/mod_python/trunk/src/requestobject.c
    httpd/mod_python/trunk/src/serverobject.c

Modified: httpd/mod_python/trunk/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/appendixc.tex?rev=398308&r1=398307&r2=398308&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Sun Apr 30 03:24:28 2006
@@ -155,6 +155,16 @@
       Force an exception when handler evaluates to something other than
       \code{None} but is otherwise not callable. Previously an exception
       would not be generated if the handler evaluated to \code{False}.
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-152]{MODPYTHON-152})
+      When in a sub request, when a request is the result of an internal
+      redirect, or when when returning from such a request, the
+      \code{req.main}, \code{req.prev} and \code{req.next} members now
+      correctly return a reference to the original Python request object
+      wrapper first created for the specific \code{request_rec} instance
+      rather than creating a new distinct Python request object. This means
+      that any data added explicitly to a request object can be passed
+      between such requests.
   \end{itemize}
 
   Bug Fixes

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=398308&r1=398307&r2=398308&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 30 03:24:28 2006
@@ -20,5 +20,5 @@
 __all__ = ["apache", "cgihandler", "psp",
            "publisher", "util", "python22"]
 
-version = "3.3.0-dev-20060429"
+version = "3.3.0-dev-20060430"
 

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=398308&r1=398307&r2=398308&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h Sun Apr 30 03:24:28 2006
@@ -201,6 +201,8 @@
 } py_handler;
 
 apr_status_t python_cleanup(void *data);
+PyObject* python_interpreter_name(void);
+requestobject *python_get_request_object(request_rec *req, const char *phase);
 
 #endif /* !Mp_MOD_PYTHON_H */
 

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=398308&r1=398307&r2=398308&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 30 03:24:28 2006
@@ -201,6 +201,8 @@
 } py_handler;
 
 apr_status_t python_cleanup(void *data);
+PyObject* python_interpreter_name(void);
+requestobject *python_get_request_object(request_rec *req, const char *phase);
 
 #endif /* !Mp_MOD_PYTHON_H */
 

Modified: httpd/mod_python/trunk/src/include/mpversion.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mpversion.h?rev=398308&r1=398307&r2=398308&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mpversion.h (original)
+++ httpd/mod_python/trunk/src/include/mpversion.h Sun Apr 30 03:24:28 2006
@@ -1,5 +1,5 @@
 #define MPV_MAJOR 3
 #define MPV_MINOR 3
 #define MPV_PATCH 0
-#define MPV_BUILD 20060429
-#define MPV_STRING "3.3.0-dev-20060429"
+#define MPV_BUILD 20060430
+#define MPV_STRING "3.3.0-dev-20060430"

Modified: httpd/mod_python/trunk/src/include/requestobject.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/requestobject.h?rev=398308&r1=398307&r2=398308&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/requestobject.h (original)
+++ httpd/mod_python/trunk/src/include/requestobject.h Sun Apr 30 03:24:28 2006
@@ -34,9 +34,6 @@
         request_rec    * request_rec;
         PyObject       * connection;
         PyObject       * server;
-        PyObject       * next;
-        PyObject       * prev;
-        PyObject       * main;
         PyObject       * headers_in;
         PyObject       * headers_out;
         PyObject       * err_headers_out;
@@ -44,7 +41,6 @@
         PyObject       * notes;
         PyObject       * phase;
         char           * extension;   /* for | .ext syntax */
-        char           * interpreter; 
         int              content_type_set;
         hlistobject    * hlo;
         char           * rbuff;       /* read bufer */

Modified: httpd/mod_python/trunk/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/mod_python.c?rev=398308&r1=398307&r2=398308&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Sun Apr 30 03:24:28 2006
@@ -192,6 +192,34 @@
     return idata;
 }
 
+/*
+ * python_interpreter_name
+ *
+ *      Get name of current interpreter. Must be called while lock is held.
+ *      This is effectively a shortcut for accessing "apache.interpreter".
+ */
+
+PyObject *python_interpreter_name()
+{
+    PyObject *m = NULL;
+    PyObject *d = NULL;
+    PyObject *o = NULL;
+
+    m = PyImport_ImportModule("mod_python.apache");
+    if (m) {
+        d = PyModule_GetDict(m);
+        o = PyDict_GetItemString(d, "interpreter");
+
+        if (o) {
+            Py_INCREF(o);
+            Py_DECREF(m);
+            return o;
+        }
+    }
+
+    return 0;
+}
+
 /**
  ** get_interpreter
  **
@@ -325,6 +353,7 @@
     if (!idata) {
         Py_DECREF(ci->handler);
         Py_XDECREF(ci->data);
+        free((void *)ci->interpreter);
         free(ci);
         return APR_SUCCESS; /* this is ignored anyway */
     }
@@ -377,6 +406,7 @@
 
     Py_DECREF(ci->handler);
     Py_DECREF(ci->data);
+    free((void *)ci->interpreter);
     free(ci);
 
     release_interpreter();
@@ -1096,13 +1126,13 @@
 static apr_status_t python_cleanup_handler(void *data);
 
 /**
- ** get_request_object
+ ** python_get_request_object
  **
  *      This creates or retrieves a previously created request object.
  *      The pointer to request object is stored in req->request_config.
  */
 
-static requestobject *get_request_object(request_rec *req, const char *interp_name, char *phase)
+requestobject *python_get_request_object(request_rec *req, const char *phase)
 {
     py_req_config *req_config;
     requestobject *request_obj = NULL;
@@ -1160,11 +1190,6 @@
                                   python_cleanup_handler, 
                                   apr_pool_cleanup_null);
     }
-    /* make a note of which subinterpreter we're running under */
-    if (interp_name)
-        request_obj->interpreter = apr_pstrdup(req->pool, interp_name);
-    else
-        request_obj->interpreter = apr_pstrdup(req->pool, MAIN_INTERPRETER);
 
     /* make a note of which phase we are in right now */
     if (phase)
@@ -1348,7 +1373,7 @@
     }
     
     /* create/acquire request object */
-    request_obj = get_request_object(req, interp_name, phase);
+    request_obj = python_get_request_object(req, phase);
 
     /* remember the extension if any. used by publisher */
     if (ext) 
@@ -1646,7 +1671,7 @@
     }
 
     /* create/acquire request object */
-    request_obj = get_request_object(req, interp_name, 0);
+    request_obj = python_get_request_object(req, 0);
 
     req_config = (py_req_config *) ap_get_module_config(req->request_config,
                                                         &python_module);
@@ -1846,7 +1871,7 @@
     }
 
     /* create/acquire request object */
-    request_obj = get_request_object(req, interp_name, 0);
+    request_obj = python_get_request_object(req, 0);
 
     /* create filter */
     filter = (filterobject *)MpFilter_FromFilter(f, bb, 0, 0, 0, 0, 0);
@@ -1987,7 +2012,7 @@
     }
 
     /* create/acquire request object */
-    request_obj = get_request_object(req, interp_name, 0);
+    request_obj = python_get_request_object(req, 0);
 
     /* create filter */
     filter = (filterobject *)MpFilter_FromFilter(f, *bb, 0, 0, 0, 0, 0);

Modified: httpd/mod_python/trunk/src/requestobject.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/requestobject.c?rev=398308&r1=398307&r2=398308&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/requestobject.c (original)
+++ httpd/mod_python/trunk/src/requestobject.c Sun Apr 30 03:24:28 2006
@@ -59,9 +59,6 @@
     result->request_rec = req;
     result->connection = NULL;
     result->server = NULL;
-    result->next = NULL;
-    result->prev = NULL;
-    result->main = NULL;
     result->headers_in = MpTable_FromTable(req->headers_in);
     result->headers_out = MpTable_FromTable(req->headers_out);
     result->err_headers_out = MpTable_FromTable(req->err_headers_out);
@@ -69,7 +66,6 @@
     result->notes = MpTable_FromTable(req->notes);
     result->phase = NULL;
     result->extension = NULL;
-    result->interpreter = NULL;
     result->content_type_set = 0;
     result->hlo = NULL;
     result->rbuff = NULL;
@@ -1108,6 +1104,8 @@
     cleanup_info *ci;
     PyObject *handler = NULL;
     PyObject *data = NULL;
+    PyObject *name_obj = NULL;
+    char *name = NULL;
 
     if (! PyArg_ParseTuple(args, "O|O", &handler, &data))
         return NULL;  /* bad args */
@@ -1118,7 +1116,10 @@
     if (PyCallable_Check(handler)) {
         Py_INCREF(handler);
         ci->handler = handler;
-        ci->interpreter = self->interpreter;
+        name_obj = python_interpreter_name();
+        name = (char *)malloc(strlen(PyString_AsString(name_obj))+1);
+        strcpy(name, PyString_AsString(name_obj));
+        ci->interpreter = name;
         if (data) {
             Py_INCREF(data);
             ci->data = data;
@@ -1490,7 +1491,10 @@
      * replaced in between handlers and we're left with a stale.
      */
 
-    if (strcmp(name, "headers_in") == 0) {
+    if (strcmp(name, "interpreter") == 0) {
+        return python_interpreter_name();
+    }
+    else if (strcmp(name, "headers_in") == 0) {
         if (((tableobject*)self->headers_in)->table != self->request_rec->headers_in) 
             ((tableobject*)self->headers_in)->table = self->request_rec->headers_in;
         Py_INCREF(self->headers_in);
@@ -1740,24 +1744,22 @@
         result = self->server;
     }
     else if (strcmp(name, "next") == 0) {
-        if (!self->next && self->request_rec->next) {
-            self->next = MpRequest_FromRequest(self->request_rec->next);
-            ((requestobject*)self->next)->prev = (PyObject *) self;
+        if (self->request_rec->next) {
+            result = (PyObject*)python_get_request_object(
+                self->request_rec->next, 0);
         }
-        result = self->next;
     }
     else if (strcmp(name, "prev") == 0) {
-        if (!self->prev && self->request_rec->prev) {
-            self->prev = MpRequest_FromRequest(self->request_rec->prev);
-            ((requestobject*)self->prev)->next = (PyObject *) self;
+        if (self->request_rec->prev) {
+            result = (PyObject*)python_get_request_object(
+                self->request_rec->prev, 0);
         }
-        result = self->prev;
     }
     else if (strcmp(name, "main") == 0) {
-        if (!self->main && self->request_rec->main) {
-            self->main = MpRequest_FromRequest(self->request_rec->main);
+        if (self->request_rec->main) {
+            result = (PyObject*)python_get_request_object(
+                self->request_rec->main, 0);
         }
-        result = self->main;
     }
 
     if (!result)
@@ -1769,6 +1771,7 @@
 }
 
 static PyGetSetDef request_getsets[] = {
+    {"interpreter", (getter)getreq_recmbr, NULL, "Python interpreter name", "interpreter"},
     {"connection", (getter)getmakeobj, NULL, "Connection object", "connection"},
     {"server",     (getter)getmakeobj, NULL, "Server object", "server"},
     {"next",       (getter)getmakeobj, NULL, "If redirected, pointer to the to request", "next"},
@@ -1838,7 +1841,6 @@
     {"_content_type_set",  T_INT,       OFF(content_type_set),  RO},
     {"phase",              T_OBJECT,    OFF(phase),             RO},
     {"extension",          T_STRING,    OFF(extension),         RO},
-    {"interpreter",        T_STRING,    OFF(interpreter),       RO},
     {"hlist",              T_OBJECT,    OFF(hlo),               RO},
     {NULL}  /* Sentinel */
 };
@@ -1863,9 +1865,6 @@
     CLEAR_REQUEST_MEMBER(self->dict);
     CLEAR_REQUEST_MEMBER(self->connection);
     CLEAR_REQUEST_MEMBER(self->server);
-    CLEAR_REQUEST_MEMBER(self->next);
-    CLEAR_REQUEST_MEMBER(self->prev);
-    CLEAR_REQUEST_MEMBER(self->main);
     CLEAR_REQUEST_MEMBER(self->headers_in);
     CLEAR_REQUEST_MEMBER(self->headers_out);
     CLEAR_REQUEST_MEMBER(self->err_headers_out);
@@ -1917,9 +1916,6 @@
     VISIT_REQUEST_MEMBER(self->dict, visit, arg);
     VISIT_REQUEST_MEMBER(self->connection, visit, arg);
     VISIT_REQUEST_MEMBER(self->server, visit, arg);
-    VISIT_REQUEST_MEMBER(self->next, visit, arg);
-    VISIT_REQUEST_MEMBER(self->prev, visit, arg);
-    VISIT_REQUEST_MEMBER(self->main, visit, arg);
     VISIT_REQUEST_MEMBER(self->headers_in, visit, arg);
     VISIT_REQUEST_MEMBER(self->headers_out, visit, arg);
     VISIT_REQUEST_MEMBER(self->err_headers_out, visit, arg);

Modified: httpd/mod_python/trunk/src/serverobject.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/serverobject.c?rev=398308&r1=398307&r2=398308&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/serverobject.c (original)
+++ httpd/mod_python/trunk/src/serverobject.c Sun Apr 30 03:24:28 2006
@@ -96,6 +96,8 @@
     PyObject *handler = NULL;
     PyObject *data = NULL;
     requestobject *req = NULL;
+    PyObject *name_obj = NULL;
+    char *name = NULL;
 
     if (! PyArg_ParseTuple(args, "OO|O", &req, &handler, &data))
         return NULL; 
@@ -116,7 +118,10 @@
     ci->server_rec = self->server;
     Py_INCREF(handler);
     ci->handler = handler;
-    ci->interpreter = strdup(req->interpreter);
+    name_obj = python_interpreter_name();
+    name = (char *)malloc(strlen(PyString_AsString(name_obj))+1);
+    strcpy(name, PyString_AsString(name_obj));
+    ci->interpreter = name;
     if (data) {
         Py_INCREF(data);
         ci->data = data;