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

This commit is contained in:
Alon Zakai 2012-07-04 16:08:05 -07:00
Родитель 370128e8d9
Коммит b9e43e29b6
2 изменённых файлов: 31 добавлений и 2 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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>