Abzac / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

Fix import so modules are reused #178

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Report from Oscar on 2010/12/25 on the maillist:

A small project:

a.py:
the_list = [0]

b.py
from a import the_list
the_list[0] += 1

c.py
from a import the_list
the_list[0] += 2

main.py
from a import the_list
import b
import c

print the_list[0]

In cpython the output is:
3

In pymite (desktop platform) the output is:
0

Original issue reported on code.google.com by dwhall...@gmail.com on 26 Dec 2010 at 10:36

GoogleCodeExporter commented 9 years ago
r1c55952f624f
- Modified IMPORT_NAME bytecode so new module uses the current globals 
namespace.
- Added system test t378

Tests pass.

Original comment by dwhall...@gmail.com on 2 Jan 2011 at 8:25

GoogleCodeExporter commented 9 years ago
The committed changes broke ipm and compatibility with CPython.  Backing out 
this change and will attempt to fix this another way.

$ hg backout --merge -r 1c55952f62
r7f42525a071f

Tests pass.  ipm passes.

$ hg ci
rbaeccda61be8

Original comment by dwhall...@gmail.com on 8 Jan 2011 at 3:03

GoogleCodeExporter commented 9 years ago
The summary is changed to reflect the new approach to solving this problem.  
Instead of having modules share their global namespaces, the import system 
should re-use modules.  When a module is reused, its attributes (globals inside 
the module) will be reused and that should solve this issue.

Original comment by dwhall...@gmail.com on 9 Jan 2011 at 2:41

GoogleCodeExporter commented 9 years ago
I've implemented a dict in the builtins module (__bi) to cache modules.  The 
dict is named "__md" (for "modules dict").  And I changed IMPORT_NAME to use a 
module in __md if it exists and otherwise put a new module in __md.

I reinstated the same system test t378.  The test passes with these changes.  
However, because system heap was consumed with __md, t104 had to be modified 
because it depends on a certain heap size to cause a GC.

I also modified t114.c because IMPORT now behaves differently and the VM now 
properly raises an AttributeError for t114.py.  This matches CPython.

Original comment by dwhall...@gmail.com on 9 Jan 2011 at 2:51

GoogleCodeExporter commented 9 years ago
r76c20922f040

tests pass.  ipm passes.

Original comment by dwhall...@gmail.com on 9 Jan 2011 at 3:51

GoogleCodeExporter commented 9 years ago

Original comment by dwhall...@gmail.com on 9 Jan 2011 at 3:52