Issue Details (XML | Word | Printable)

Key: MODPYTHON-155
Type: Sub-task Sub-task
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python
MODPYTHON-143

req.add_handler() and inheritance of directory to be searched for module

Created: 09/Apr/06 02:57 PM   Updated: 11/Apr/07 11:41 AM
Return to search
Component/s: importer
Affects Version/s: None
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 03/Aug/06 10:57 AM


 Description  « Hide
The documentation for req.add_handler() says:

"""Optional dir is a string containing the name of the directory to be added to the pythonpath. If no directory is specified, then, if there is already a handler of the same type specified, its directory is inherited, otherwise the directory of the presently executing handler is used. I there is a PythonPath directive in effect, then sys.path will be set exactly according to it (no directories added, the dir argument is ignored)."""

This comment about the directory being inherited from the prior or currently executing handler is actually bogus as the code does not do anything specific at all to try and implement such behaviour. If it works this way at all it is partly by luck as what will actually dictate where the module specified to the req.add_handler() method is found is the current order of directories specified in sys.path. Since additional directories added into sys.path by the old importer can be performed in effectively random order, behaviour could actually be quite random if the same module name were used in multiple directories.

Because the new importer doesn't add directories into sys.path for Python*Handler directives, a problem will currently arise if no directory is supplied to req.add_handler(). Specifically, a module may not be able to be found. This is because it can no longer fall back on to fact that with old module importer, the directory corresponding to the Python*Handler directive would be listed in sys.path somewhere.

Thus, the documented behaviour for req.add_handler() when the directory hasn't been set needs to actually be implemented as described with an appropriate directory being calculated at the time that req.add_handler() is called with that directory being recorded as needing to be searched for the module. In changing the code though, if old and new importers are going to be supported during a transition phase, it must detect when the new module importer is being used and only do this when it is, as otherwise it will screw up how modules are found for the old importer.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #426882 Sun Jul 30 10:27:00 UTC 2006 grahamd (MODPYTHON-155) Modifications to handler and filter lists so that
references can be maintained back to parent handler of a handler/filter
which was registered dynamically. This is necessary within the scheme of
how the new module importer works. Specifically, where a directory isn't
specified when adding a handler or registering a filter, the directory
associated with the parent up the chain has to be used instead. In the old
importer it was relying on fact that directory of parent had already been
added to the Python sys.path, although this didn't actually work reliably.
The new module importer doesn't add directories to sys.path and so the need
to properly work out directory associated with a parent so that it can be
used when required.
Files Changed
MODIFY /httpd/mod_python/trunk/src/hlistobject.c
MODIFY /httpd/mod_python/trunk/src/hlist.c
MODIFY /httpd/mod_python/trunk/src/include/filterobject.h
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h
MODIFY /httpd/mod_python/trunk/src/filterobject.c
MODIFY /httpd/mod_python/trunk/src/mod_python.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/importer.py
MODIFY /httpd/mod_python/trunk/src/requestobject.c
MODIFY /httpd/mod_python/trunk/src/include/hlist.h
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h.in

Repository Revision Date User Message
ASF #428316 Thu Aug 03 10:54:37 UTC 2006 grahamd (MODPYTHON-155) Improve memory efficiency related to req.add_handler()
and construction of handler list objects.
(MODPYTHON-181) Fix problems with req.add_handler() introduced when memory
leaks were eliminated related to handler list object.
Files Changed
MODIFY /httpd/mod_python/trunk/src/hlistobject.c
MODIFY /httpd/mod_python/trunk/src/filterobject.c
MODIFY /httpd/mod_python/trunk/src/mod_python.c
MODIFY /httpd/mod_python/trunk/src/requestobject.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/src/include/hlistobject.h
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h