Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 062b6f8

Browse files
committed
[[ Bug 19873 ]] Ensure MCForeignValue content is 64-bit aligned
This patch forces the content portion of MCForeignValue structs to be 64-bit aligned. This ensures that emscripten does not have to generate 'special' code to access a double which has been packed into the struct as when it does use the non-aligned code path, the numbers gain error which cause repeat loops to behave unexpectedly.
1 parent 03b363a commit 062b6f8

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

docs/lcb/notes/19873.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure doubles don't get munged in repeat loops in HTML5

libfoundation/src/foundation-private.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,11 @@ struct __MCCustomValue: public __MCValue
425425

426426
struct __MCForeignValue: public __MCValue
427427
{
428-
MCTypeInfoRef typeinfo;
428+
union
429+
{
430+
MCTypeInfoRef typeinfo;
431+
uint64_t _dummy;
432+
};
429433
};
430434

431435
////////

tests/lcb/vm/repeat-loops.lcb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
module __VMTEST.repeat_loops
2+
3+
public handler TestRepeatForUpTo()
4+
-- This test ensures that repeat up to loops perform the correct number of
5+
-- iterations, motivated by a 'double' issue on emscripten. Rather than
6+
-- use numbers to test, we use a string which accumulates a new char for
7+
-- each iteration ensuring that the method of testing is entirely distinct
8+
-- from what is being tested.
9+
10+
variable tLoopCount as String
11+
variable tCount as Number
12+
13+
put the empty string into tLoopCount
14+
repeat with tCount from 1 up to 12
15+
put "X" after tLoopCount
16+
end repeat
17+
test "from 1 up to 12 gives 12 iterations" when tLoopCount is "XXXXXXXXXXXX"
18+
19+
put the empty string into tLoopCount
20+
repeat with tCount from 1 up to 12 by 2
21+
put "X" after tLoopCount
22+
end repeat
23+
test "from 1 up to 12 by 2 gives 6 iterations" when tLoopCount is "XXXXXX"
24+
25+
put the empty string into tLoopCount
26+
repeat with tCount from 1 up to 12 by 0.5
27+
put "X" after tLoopCount
28+
end repeat
29+
test "from 1 up to 12 by 0.5 gives 24 iterations" when tLoopCount is "XXXXXXXXXXXXXXXXXXXXXXX"
30+
end handler
31+
32+
public handler TestRepeatForDownTo()
33+
-- This test ensures that repeat down to loops perform the correct number of
34+
-- iterations, motivated by a 'double' issue on emscripten. Rather than
35+
-- use numbers to test, we use a string which accumulates a new char for
36+
-- each iteration ensuring that the method of testing is entirely distinct
37+
-- from what is being tested.
38+
39+
variable tLoopCount as String
40+
variable tCount as Number
41+
42+
put the empty string into tLoopCount
43+
repeat with tCount from 12 down to 1
44+
put "X" after tLoopCount
45+
end repeat
46+
test "from 12 down to 1 gives 12 iterations" when tLoopCount is "XXXXXXXXXXXX"
47+
48+
put the empty string into tLoopCount
49+
repeat with tCount from 12 down to 1 by -2
50+
put "X" after tLoopCount
51+
end repeat
52+
test "from 12 down to 1 by 2 gives 6 iterations" when tLoopCount is "XXXXXX"
53+
54+
put the empty string into tLoopCount
55+
repeat with tCount from 12 down to 1 by -0.5
56+
put "X" after tLoopCount
57+
end repeat
58+
test "from 12 down to 1 by 0.5 gives 24 iterations" when tLoopCount is "XXXXXXXXXXXXXXXXXXXXXXX"
59+
end handler
60+
61+
end module

0 commit comments

Comments
 (0)