Abzac / python-on-a-chip

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

Fix lost module function after GC when imported via "from foo import *" #147

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Reported by Oscar Lindberg on the maillist on 2010/10/01:

- - main.py - -
from sys import gc
from foo import *

print _bar()
print bar()
gc()
print 'did gc'
print _bar()
print bar()

- - foo.py - -
# Shows an error

def _bar():
   """__NATIVE__
   PmReturn_t retval = PM_RET_OK;

   /* If wrong number of args, raise TypeError */
   if (NATIVE_GET_NUM_ARGS() != 0)
   {
       PM_RAISE(retval, PM_RET_EX_TYPE);
       return retval;
   }

   NATIVE_SET_TOS(PM_NONE);
   return retval;
   """
   pass

def bar():
   return _bar()

This is the output (don't forget to add foo.py to the Makefile):

$ ./main.out
None
None
did gc
None
Traceback (most recent call first):
 File "foo.py", line 20, in bar
 File "main.py", line 9, in main
TypeError detected by dict.c:176

Original issue reported on code.google.com by dwhall...@gmail.com on 3 Oct 2010 at 2:13

GoogleCodeExporter commented 9 years ago

Original comment by dwhall...@gmail.com on 3 Oct 2010 at 2:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Problem found:  The C type pPmFunc_t which is the structure for both Python 
Funcs and Modules was not having its f_globals field marked by the GC.  The 
assumption was that the globals namespace would be marked someplace else and 
didn't need to be marked for every module & func.

Solution: having the GC mark the f_globals field allows the new unit test, 
t347, to pass.

Original comment by dwhall...@gmail.com on 3 Oct 2010 at 4:31

GoogleCodeExporter commented 9 years ago
r623
- src/vm/heap.c edited to mark the f_globals field of a PmFunc_t.
- Added unit test t347

Tests pass.  Mainlined directly.

Original comment by dwhall...@gmail.com on 3 Oct 2010 at 4:39

GoogleCodeExporter commented 9 years ago
r624

Applied same changes to branch for release 09

Original comment by dwhall...@gmail.com on 3 Oct 2010 at 4:42