This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyImport_ExecCodeModuleObject not setting module attributes
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.snow Nosy List: Arfrever, benjamin.peterson, brett.cannon, eric.snow, ncoghlan, python-dev, trevor3
Priority: normal Keywords: patch

Created on 2014-04-14 21:04 by trevor3, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix-PyImport_ExecCodeModuleObject.diff eric.snow, 2014-04-19 07:49
fix-PyImport_ExecCodeModuleObject.diff eric.snow, 2014-04-20 00:13
Messages (7)
msg216217 - (view) Author: Trevor Caira (trevor3) Date: 2014-04-14 21:04
In Python/import.c, PyImport_ExecCodeModuleObject creates a new module object but doesn't set all of the attributes required for modules, such as __spec__ or __loader__.

This breaks mod_wsgi from 3.3 and up, which depends on PyImport_ExecCodeModuleEx, which delegates to PyImport_ExecCodeModuleObject for its module creation logic. See https://code.google.com/p/modwsgi/source/browse/mod_wsgi/mod_wsgi.c#6289
msg216850 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-04-19 07:49
Here's a (currently segfaulting) patch that demonstrates how I'd like to solve this.  Feedback on the approach is welcome. :)  When I get a chance I'll debug the segfault.
msg216864 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-04-19 16:53
The last argument to _PyObject_CallMethodIdObjArgs needs to be NULL...
msg216886 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-04-20 00:13
Thanks, Benjamin.  Here's an updated patch that passes all tests.  It should be good to go.  And yet again our zipimport implementation was a pain point. :(
msg218161 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-05-09 12:41
LGTM although you forgot to use a loader instance instead of the class.
msg218391 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-05-13 00:27
New changeset 7d20e30bd540 by Eric Snow in branch '3.4':
Issue #21226: Set all attrs in PyImport_ExecCodeModuleObject.
http://hg.python.org/cpython/rev/7d20e30bd540

New changeset bc324a49d0fc by Eric Snow in branch 'default':
Merge from 3.4 (for #21226).
http://hg.python.org/cpython/rev/bc324a49d0fc
msg219356 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-05-29 18:44
New changeset baa7b5555656 by Eric Snow in branch '3.4':
Issue #21226: fix a ref leak.
http://hg.python.org/cpython/rev/baa7b5555656

New changeset 57130574d1e8 by Eric Snow in branch 'default':
Issue #21226: Merge from 3.4.
http://hg.python.org/cpython/rev/57130574d1e8
History
Date User Action Args
2022-04-11 14:58:01adminsetgithub: 65425
2014-05-29 18:44:15python-devsetmessages: + msg219356
2014-05-13 00:31:35eric.snowsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-05-13 00:27:34python-devsetnosy: + python-dev
messages: + msg218391
2014-05-11 11:57:02Arfreversetnosy: + Arfrever
2014-05-09 12:41:29brett.cannonsetmessages: + msg218161
2014-04-20 00:13:19eric.snowsetfiles: + fix-PyImport_ExecCodeModuleObject.diff

messages: + msg216886
2014-04-19 16:53:09benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg216864
2014-04-19 07:49:57eric.snowsetfiles: + fix-PyImport_ExecCodeModuleObject.diff
messages: + msg216850

assignee: eric.snow
keywords: + patch
stage: patch review
2014-04-14 21:04:27trevor3create