From 5f3a9ffd0e69c2d00e90261c69d9cd2ec8bfa2f9 Mon Sep 17 00:00:00 2001 From: "alon@honor" Date: Fri, 10 Sep 2010 21:38:19 -0700 Subject: [PATCH] fix some print() corners --- src/preamble.js | 12 ++++++++---- tests/runner.py | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index 38d73dd83..1ed1b6eb2 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -8,8 +8,8 @@ var __THREW__ = false; // Used in checking for thrown exceptions. var __ATEXIT__ = []; -var HEAP = []; -var HEAPTOP = 0; +var HEAP = [0]; +var HEAPTOP = 1; // Leave 0 as an invalid address, 'NULL' #if SAFE_HEAP // Semi-manual memory corruption debugging @@ -147,8 +147,12 @@ function __formatString() { } function _printf() { - var text = __formatString.apply(null, arguments); - print(Pointer_stringify(text)); + var text = Pointer_stringify(__formatString.apply(null, arguments)); + // Our print() will print a \n anyhow... remove dupes + if (text[text.length-1] == '\n') { + text = text.substr(0, text.length-1); + } + print(text); } function _puts(p) { diff --git a/tests/runner.py b/tests/runner.py index d81c1b574..4bb20c0a5 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -234,10 +234,11 @@ class T(unittest.TestCase): printf("%d", atoi(argv[3])+2); const char *foolingthecompiler = "\\rabcd"; printf("%d", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D! + printf("%s*", NULL); // Should print nothing, not the string at address 0, which is a real address for us! return 0; } ''' - self.do_test(src, '*4*wowie*too*76*5*', ['wowie', 'too', '74'], lambda x: x.replace('\n', '*')) + self.do_test(src, '*4*wowie*too*76*5**', ['wowie', 'too', '74'], lambda x: x.replace('\n', '*')) def test_funcs(self): src = ''' @@ -570,7 +571,7 @@ class T(unittest.TestCase): return 0; } ''' - self.do_test(src, '*2,2,5,8,8****8,8,5,8,8****7,2,6,990,7,2*', [], lambda x: x.replace('\n', '*')) + self.do_test(src, '*2,2,5,8,8***8,8,5,8,8***7,2,6,990,7,2*', [], lambda x: x.replace('\n', '*')) def test_llvmswitch(self): src = ''' @@ -664,8 +665,8 @@ class T(unittest.TestCase): self.do_test(src, 'Pfannkuchen(%d) = %d.' % (i,j), [str(i)], no_build=i>1) def test_fasta(self): - results = [ (1,'''GG*ctt**tgagc**'''), (20,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tacgtgtagcctagtgtttgtgttgcgttatagtctatttgtggacacagtatggtcaaa**tgacgtcttttgatctgacggcgttaacaaagatactctg**'''), -(50,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA*TCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACAT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tactDtDagcctatttSVHtHttKtgtHMaSattgWaHKHttttagacatWatgtRgaaa**NtactMcSMtYtcMgRtacttctWBacgaa**agatactctgggcaacacacatacttctctcatgttgtttcttcggacctttcataacct**ttcctggcacatggttagctgcacatcacaggattgtaagggtctagtggttcagtgagc**ggaatatcattcgtcggtggtgttaatctatctcggtgtagcttataaatgcatccgtaa**gaatattatgtttatttgtcggtacgttcatggtagtggtgtcgccgatttagacgtaaa**ggcatgtatg**''') ] + results = [ (1,'''GG*ctt*tgagc*'''), (20,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg*tacgtgtagcctagtgtttgtgttgcgttatagtctatttgtggacacagtatggtcaaa*tgacgtcttttgatctgacggcgttaacaaagatactctg*'''), +(50,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA*TCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACAT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg*tactDtDagcctatttSVHtHttKtgtHMaSattgWaHKHttttagacatWatgtRgaaa*NtactMcSMtYtcMgRtacttctWBacgaa*agatactctgggcaacacacatacttctctcatgttgtttcttcggacctttcataacct*ttcctggcacatggttagctgcacatcacaggattgtaagggtctagtggttcagtgagc*ggaatatcattcgtcggtggtgttaatctatctcggtgtagcttataaatgcatccgtaa*gaatattatgtttatttgtcggtacgttcatggtagtggtgtcgccgatttagacgtaaa*ggcatgtatg*''') ] for i, j in results: src = open(path_from_root(['tests', 'fasta.cpp']), 'r').read() self.do_test(src, j, [str(i)], lambda x: x.replace('\n', '*'), no_python=True, no_build=i>1)