Skip to content

Commit

Permalink
Adding multiple directories to Python module search path failing unde…
Browse files Browse the repository at this point in the history
…r Python 3. #92
  • Loading branch information
GrahamDumpleton committed Oct 3, 2015
1 parent 8119b1f commit 1abae88
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
8 changes: 8 additions & 0 deletions docs/release-notes/version-4.4.15.rst
Expand Up @@ -9,3 +9,11 @@ Version 4.4.15 of mod_wsgi can be obtained from:
For details on the availability of Windows binaries see:

https://github.com/GrahamDumpleton/mod_wsgi/tree/master/win32

Bugs Fixed
----------

1. When specifying multiple directories for the Python module search path
using the ``WSGIPythonPath`` directive, or the ``python-path`` option to
``WSGIDaemonProcess``, it was failing under Python 3 due to incorrect
logging. It was therefore only possible to add a single directory.
30 changes: 18 additions & 12 deletions src/server/wsgi_interp.c
Expand Up @@ -843,16 +843,14 @@ InterpreterObject *newInterpreterObject(const char *name)

if (end) {
#if PY_MAJOR_VERSION >= 3
item = PyUnicode_Decode(start, end-start,
Py_FileSystemDefaultEncoding,
"surrogateescape");
item = PyUnicode_DecodeFSDefaultAndSize(start, end-start);
value = PyUnicode_AsUTF8(item);
#else
item = PyString_FromStringAndSize(start, end-start);
value = PyString_AsString(item);
#endif
start = end+1;

value = PyString_AsString(item);

Py_BEGIN_ALLOW_THREADS
ap_log_error(APLOG_MARK, APLOG_INFO, 0, wsgi_server,
"mod_wsgi (pid=%d): Adding '%s' to "
Expand All @@ -879,16 +877,15 @@ InterpreterObject *newInterpreterObject(const char *name)

while (result && end) {
#if PY_MAJOR_VERSION >= 3
item = PyUnicode_Decode(start, end-start,
Py_FileSystemDefaultEncoding,
"surrogateescape");
item = PyUnicode_DecodeFSDefaultAndSize(start,
end-start);
value = PyUnicode_AsUTF8(item);
#else
item = PyString_FromStringAndSize(start, end-start);
value = PyString_AsString(item);
#endif
start = end+1;

value = PyString_AsString(item);

Py_BEGIN_ALLOW_THREADS
ap_log_error(APLOG_MARK, APLOG_INFO, 0, wsgi_server,
"mod_wsgi (pid=%d): Adding '%s' to "
Expand Down Expand Up @@ -916,13 +913,21 @@ InterpreterObject *newInterpreterObject(const char *name)
}
}

#if PY_MAJOR_VERSION >= 3
item = PyUnicode_DecodeFSDefault(start);
value = PyUnicode_AsUTF8(item);
#else
item = PyString_FromString(start);
value = PyString_AsString(item);
#endif

Py_BEGIN_ALLOW_THREADS
ap_log_error(APLOG_MARK, APLOG_INFO, 0, wsgi_server,
"mod_wsgi (pid=%d): Adding '%s' to "
"path.", getpid(), start);
"path.", getpid(), value);
Py_END_ALLOW_THREADS

args = Py_BuildValue("(s)", start);
args = Py_BuildValue("(O)", item);
result = PyEval_CallObject(object, args);

if (!result) {
Expand All @@ -935,6 +940,7 @@ InterpreterObject *newInterpreterObject(const char *name)
}

Py_XDECREF(result);
Py_XDECREF(item);
Py_DECREF(args);

Py_DECREF(object);
Expand Down

0 comments on commit 1abae88

Please sign in to comment.