sprhawk / python-on-a-chip

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

Fix iterator losing its object #129

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
# Apply the patch to put iter() in builtns, then run ipm:

ipm> ch = iter("abcd")
ipm> def i():
....  print ch.next()
....  sys.gc()
.... 
ipm> import sys
ipm> i()
a
ipm> i()
Traceback (most recent call first):
  File "../lib/__bi.py", line 307, in iter
  File "../lib/__bi.py", line 787, in next
  File "<ipm>", line 2, in i
  File "<ipm>", line 1, in <ipm>
  File "../lib/ipm.py", line 99, in ipm
  File "main.py", line 19, in main
Error code 0xFC detected by seq.c:210

Original issue reported on code.google.com by dwhall...@gmail.com on 25 Aug 2010 at 2:41

Attachments:

GoogleCodeExporter commented 9 years ago
Problem description: Inside the iter() function, the for-loop caused the VM to 
create a sequence-iterator structure.  This structure was being swept by the GC 
despite being properly linked to the roots.

The blame was because the Generator's frame's fo_back was referring to a frame 
that was already freed and when heap_gcMarkObj() tried to follow fo_back to the 
freed frame, it encountered a C_ASSERT.  HOWEVER!  The retval from the C_ASSERT 
was being ignored when the thread list was being marked!!

Lesson: Make sure the C_ASSERT statements return their error codes!

Solution: In heap_gcMarkObj() do not follow a frame's fo_back reference if that 
frame is for a generator function.

Original comment by dwhall...@gmail.com on 26 Aug 2010 at 6:36

GoogleCodeExporter commented 9 years ago
r585
- Made src/tools/pmOdDecoder.py able to accept hex input.
- Added system regression test t329
- Added condition in src/vm/heap.c heap_gcMarkObj() to frame's fo_back is not 
followed if the frame is for a generator.
- Added/removed PM_RETURN_IF_ERROR() in heap.c so C_ASSERT() error codes are 
returned.
- Leaving iter() in src/lib/__bi.py commented out in case someone finds it 
useful

All tests pass.  Tested interactively and the test in comment 0 passed.
Mainlined directly.

Original comment by dwhall...@gmail.com on 26 Aug 2010 at 7:43