diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-09-10 15:03:56 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-09-10 15:03:56 -0700 |
commit | bb7546d9f4b694b96a971e39f4d81fec0bb0610b (patch) | |
tree | 699683c8c49edf02caba8eb298c53c28eb9b713b | |
parent | c33af789cb9d37ccea5cfb7cc3eef87c2eb8d2fd (diff) |
handle flexible arrays at the end of structs, whose elements are themselves structs; fixes #1602
-rw-r--r-- | src/runtime.js | 6 | ||||
-rw-r--r-- | tests/test_core.py | 28 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/runtime.js b/src/runtime.js index 33088ad9..6b1afd80 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -214,7 +214,11 @@ var Runtime = { // and it adds no size // XXX this happens in java-nbody for example... assert(index === type.fields.length, 'zero-length in the middle!'); size = 0; - alignSize = type.alignSize || QUANTUM_SIZE; + if (Types.types[field]) { + alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize); + } else { + alignSize = type.alignSize || QUANTUM_SIZE; + } } else { size = Types.types[field].flatSize; alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize); diff --git a/tests/test_core.py b/tests/test_core.py index 1dd07307..54fbdcd1 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -5432,6 +5432,34 @@ The current type of b is: 9 ''' self.do_run(src, 'memmove can be very useful....!') + def test_flexarray_struct(self): + src = r''' +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> + +typedef struct +{ + uint16_t length; + struct + { + int32_t int32; + } value[]; +} Tuple; + +int main() { + Tuple T[10]; + Tuple *t = &T[0]; + + t->length = 4; + t->value->int32 = 100; + + printf("(%d, %d)\n", t->length, t->value->int32); + return 0; +} +''' + self.do_run(src, '(4, 100)') + def test_bsearch(self): if Settings.QUANTUM_SIZE == 1: return self.skip('Test cannot work with q1') |