Skip to content

Commit

Permalink
the CallBack.req bug is really fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
gtrubetskoy committed May 23, 2001
1 parent e9732ec commit 99f14a5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
May 22 2000 - The bug that was supposedly fixed below was a bit more
complicated than it seemed at first. The fix below caused
a circular reference, and some further fixing had to be done,
and now it's really fixed, thanks to Chris's dilligence.

May 17 2000 - Fixed a threading bug reported by Chris Trengove where
the callback object could have the reference to self.req
overwritten by other threads. The reference to the Request
Expand Down
15 changes: 12 additions & 3 deletions lib/python/mod_python/apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# OF THE POSSIBILITY OF SUCH DAMAGE.
# ====================================================================
#
# $Id: apache.py,v 1.31 2001/05/19 05:22:10 gtrubetskoy Exp $
# $Id: apache.py,v 1.32 2001/05/23 02:49:43 gtrubetskoy Exp $

import sys
import string
Expand All @@ -58,6 +58,10 @@
# variable stores the last PythonPath in raw (unevaled) form.
_path = None

# this is used in Request.__init__
def _cleanup_request(_req):
_req._Request = None

class Request:
""" This is a normal Python Class that can be subclassed.
However, most of its functionality comes from a built-in
Expand All @@ -68,6 +72,11 @@ class Request:
def __init__(self, _req):
# look at __setattr__ if changing this line!
self._req = _req

# this will decrement the reference to the _req
# object at cleanup time. If we don't do this, we
# get a cirular reference and _req never gets destroyed.
_req.register_cleanup(_cleanup_request, _req)

def __getattr__(self, attr):
try:
Expand Down Expand Up @@ -121,7 +130,7 @@ def Dispatch(self, _req, htype):
# is there a Request object for this request?
if not _req._Request:
_req._Request = Request(_req)

req = _req._Request

# config
Expand Down Expand Up @@ -565,7 +574,7 @@ def tell(self): return self.pos

def setup_cgi(req):
"""
Replace sys.stdin and stdout with an objects that reead/write to
Replace sys.stdin and stdout with an objects that read/write to
the socket, as well as substitute the os.environ.
Returns (environ, stdin, stdout) which you must save and then use
with restore_nocgi().
Expand Down
8 changes: 4 additions & 4 deletions src/mod_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*
* mod_python.c
*
* $Id: mod_python.c,v 1.48 2001/04/11 02:29:48 gtrubetskoy Exp $
* $Id: mod_python.c,v 1.49 2001/05/23 02:49:43 gtrubetskoy Exp $
*
* See accompanying documentation and source code comments
* for details.
Expand Down Expand Up @@ -204,9 +204,9 @@ void python_cleanup(void *data)
stype = PyObject_Str(ptype);
svalue = PyObject_Str(pvalue);

Py_DECREF(ptype);
Py_DECREF(pvalue);
Py_DECREF(ptb);
Py_XDECREF(ptype);
Py_XDECREF(pvalue);
Py_XDECREF(ptb);

if (ci->request_rec) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, ci->request_rec,
Expand Down
9 changes: 8 additions & 1 deletion src/requestobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*
* requestobject.c
*
* $Id: requestobject.c,v 1.10 2001/05/19 05:22:11 gtrubetskoy Exp $
* $Id: requestobject.c,v 1.11 2001/05/23 02:49:43 gtrubetskoy Exp $
*
*/

Expand Down Expand Up @@ -1063,6 +1063,13 @@ static int request_setattr(requestobject *self, char *name, PyObject *value)
return 0;
}
else if (strcmp(name, "_Request") == 0) {
/* it's ok to assign None */
if (value == Py_None) {
Py_XDECREF(self->Request);
self->Request = NULL;
return 0;
}
/* but anything else has to be an instance */
if (! PyInstance_Check(value)) {
PyErr_SetString(PyExc_AttributeError,
"special attribute _Request must be an instance");
Expand Down

0 comments on commit 99f14a5

Please sign in to comment.