t291.py

00001 # This file is Copyright 2003, 2006, 2007, 2009, 2010 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 #
00014 # System Test 291
00015 # Fix GC so base classes are not collected
00016 #
00017 
00018 import sys
00019 
00020 
00021 class Bar(object):
00022     def baz(self, ):
00023         return "baz"
00024 
00025 class Foo(Bar):
00026     def faz(self, ):
00027         return "faz"
00028 
00029 foo = Foo()
00030 print foo.faz()
00031 print foo.baz()
00032 
00033 # Cause a GC
00034 print "sys.heap() = ", sys.heap()
00035 a = range(120) 
00036 print "sys.heap() = ", sys.heap()
00037 
00038 # Overwrite a reclaimed chunk
00039 del a
00040 b = range(50)
00041 
00042 # Try to use a method from a base class
00043 print foo
00044 print foo.faz()
00045 print foo.baz()
00046 
00047 # A C assertion reveals regression: subclass is not of type class.
00048 # This occurs because the chunk was GC'd accidentally and then
00049 # was overwritten with another object:
00050 #
00051 #$ ./t291.out
00052 #faz 
00053 #baz 
00054 #sys.heap() =  (2668, 8192) 
00055 #sys.heap() =  (1200, 8192) 
00056 #Error:     0xFC
00057 #  Release: 0x08
00058 #  FileId:  0x18
00059 #  LineNum: 140
00060 #Traceback (top first):
00061 #  t291()
00062 #  <module>.
00063 #make: *** [t291.out] Error 252

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9