aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-07-04 16:08:05 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-07-04 16:08:05 -0700
commitb9e43e29b6c9e251334b1de75dec1d04d2013853 (patch)
tree170578da349f189d92f5b30051e1c40f8c87ac3c
parent370128e8d9459cfe6469a38be8d0282d9d4f92cd (diff)
fix a bug with allocate not being told the right number of bytes with single double values, and fix one extra byte being needlessly allocated while we are at it
-rw-r--r--src/parseTools.js4
-rwxr-xr-xtests/runner.py29
2 files changed, 31 insertions, 2 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index e13d8807..4f2f7142 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -775,7 +775,7 @@ function generateStructTypes(type) {
if (USE_TYPED_ARRAYS == 2 && type == 'i64') {
return ['i64', 0, 0, 0, 'i32', 0, 0, 0];
}
- return [type].concat(zeros(Runtime.getNativeFieldSize(type)));
+ return [type].concat(zeros(Runtime.getNativeFieldSize(type)-1));
}
// Avoid multiple concats by finding the size first. This is much faster
@@ -1264,7 +1264,7 @@ function makePointer(slab, pos, allocator, type) {
var evaled = typeof slab === 'string' ? eval(slab) : slab;
de = dedup(evaled);
if (de.length === 1 && de[0] === 0) {
- slab = evaled.length;
+ slab = types.length;
}
// TODO: if not all zeros, at least filter out items with type === 0. requires cleverness to know how to skip at runtime though. also
// be careful of structure padding
diff --git a/tests/runner.py b/tests/runner.py
index 19ef538b..5b005bc4 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1210,6 +1210,35 @@ m_divisor is 1091269979
'''
self.do_run(src, '*1,10,10.5,1,1.2340,0.00*')
+ def test_globaldoubles(self):
+ src = r'''
+ #include <stdlib.h>
+ #include <stdio.h>
+
+ double testVu, testVv, testWu, testWv;
+
+ void Test(double _testVu, double _testVv, double _testWu, double _testWv)
+ {
+ testVu = _testVu;
+ testVv = _testVv;
+ testWu = _testWu;
+ testWv = _testWv;
+ printf("BUG?\n");
+ printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, testWv);
+ }
+
+ int main(void)
+ {
+ double v1 = 465.1;
+ double v2 = 465.2;
+ double v3 = 160.3;
+ double v4 = 111.4;
+ Test(v1, v2, v3, v4);
+ return 0;
+ }
+ '''
+ self.do_run(src, 'BUG?\nDisplay: Vu=465.100000 Vv=465.200000 Wu=160.300000 Wv=111.400000')
+
def test_math(self):
src = '''
#include <stdio.h>