diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-10-17 13:39:06 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-10-17 13:39:06 (GMT) |
commit | b8903fbf9b87c079be1438f7e7cdb6c06381ef55 (patch) | |
tree | a522ade60d07729d05f03cd1e7c7295e82dd9394 /Tools/compiler/stacktest.py | |
parent | 138d90eb73415e48a0e7f09a7c9603b1164bcaed (diff) | |
download | cpython-b8903fbf9b87c079be1438f7e7cdb6c06381ef55.zip cpython-b8903fbf9b87c079be1438f7e7cdb6c06381ef55.tar.gz cpython-b8903fbf9b87c079be1438f7e7cdb6c06381ef55.tar.bz2 |
Test utility to look for bad stacksize calculations.
Diffstat (limited to 'Tools/compiler/stacktest.py')
-rw-r--r-- | Tools/compiler/stacktest.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Tools/compiler/stacktest.py b/Tools/compiler/stacktest.py new file mode 100644 index 0000000..4f4b161 --- /dev/null +++ b/Tools/compiler/stacktest.py @@ -0,0 +1,43 @@ +import compiler +import dis +import types + +def extract_code_objects(co): + l = [co] + for const in co.co_consts: + if type(const) == types.CodeType: + l.append(const) + return l + +def compare(a, b): + if not (a.co_name == "?" or a.co_name.startswith('<lambda')): + assert a.co_name == b.co_name, (a, b) + if a.co_stacksize != b.co_stacksize: + print "stack mismatch %s: %d vs. %d" % (a.co_name, + a.co_stacksize, + b.co_stacksize) + if a.co_stacksize > b.co_stacksize: + print "good code" + dis.dis(a) + print "bad code" + dis.dis(b) + assert 0 + +def main(files): + for file in files: + print file + buf = open(file).read() + try: + co1 = compile(buf, file, "exec") + except SyntaxError: + print "skipped" + continue + co2 = compiler.compile(buf, file, "exec") + co1l = extract_code_objects(co1) + co2l = extract_code_objects(co2) + for a, b in zip(co1l, co2l): + compare(a, b) + +if __name__ == "__main__": + import sys + main(sys.argv[1:]) |