[Python-bugs-list] [ python-Bugs-698282 ] __file__ attribute missing from dynamicly loaded module

SourceForge.net noreply@sourceforge.net
Wed, 05 Mar 2003 12:52:30 -0800


Bugs item #698282, was opened at 2003-03-05 15:52
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=698282&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: David C. Sweeton (dsweeton)
Assigned to: Nobody/Anonymous (nobody)
Summary: __file__ attribute missing from dynamicly loaded module

Initial Comment:
Only the first instanceof a dynamically loaded module 
gets the __file__ attribute. It is missing from all later 
instances.

The problem is in importdl.c in the function 
_PyImport_LoadDynamicModule. The first time a 
module is loaded a copy of its module dictionary is 
made by a call to _PyImport_FixupExtension. After that 
copy was made, _PyImport_LoadDynamicModule adds 
the _file__ attribute to the original module dictionary. 
Thus the first instance of the module has the 
__file__attribute.

Later when another instance of the module loads, its 
module dictionary is duplicated from the copy of the 
dictionary from the first instance. The problem is that 
when that copy was made, the __file__ attribute was not 
yet there. Thus the later instance of the module does 
not have the __file__ attribute.

The required fix is in importdl.c and consists of simply 
moving the call of _PyImport_FixupExtension to a point 
just after the __file__ attribute is added, instead of just 
before it. I have tested this fix and it solves the problem.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=698282&group_id=5470