Skip to content

Conversation

COFFEETALES
Copy link
Contributor

and minor test fixes

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just a few small readability nits on the test.

@@ -1033,28 +1033,24 @@ void test_for_each() {
assert(BinaryenGetExportByIndex(module, i) == exps[i]);
}

BinaryenAddGlobal(module, "a-global", BinaryenTypeInt32(), 0, makeInt32(module, 125));
const int32_t expected_offsets[] = { 10, 125 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const int32_t expected_offsets[] = { 10, 125 };
const uint32_t expected_offsets[] = { 10, 125 };

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more readable to group all the static data about the segments here at the top instead of mixing it in with binaryen API calls.


const char* segments[] = { "hello, world", "segment data 2" };
int8_t segmentPassive[] = { 0, 0 };
BinaryenExpressionRef segmentOffsets[] = {
BinaryenConst(module, BinaryenLiteralInt32(10)),
BinaryenConst(module, BinaryenLiteralInt32(expected_offsets[0])),
BinaryenGlobalGet(module, "a-global", BinaryenTypeInt32())
};
BinaryenIndex segmentSizes[] = { 12, 14 };
BinaryenSetMemory(module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 0);

for (i = 0; i < BinaryenGetNumMemorySegments(module) ; i++) {
char out[15] = {0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
char out[15] = {0};
char out[15] = {};

BinaryenGlobalGet(module, "a-global", BinaryenTypeInt32())
};
BinaryenIndex segmentSizes[] = { 12, 14 };
BinaryenSetMemory(module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 0);

for (i = 0; i < BinaryenGetNumMemorySegments(module) ; i++) {
char out[15] = {0};
assert(BinaryenGetMemorySegmentByteOffset(module, i) == (0==i?10:125));
assert(BinaryenGetMemorySegmentByteOffset(module, i) == expected_offsets[i]);
assert(BinaryenGetMemorySegmentByteLength(module, i) == segmentSizes[i]);
BinaryenCopyMemorySegmentData(module, i, &out[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BinaryenCopyMemorySegmentData(module, i, &out[0]);
BinaryenCopyMemorySegmentData(module, i, out);

else {
assert(0 == strcmp("segment data 2", &out[0]));
}
assert(0 == strcmp(segments[i], &out[0]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert(0 == strcmp(segments[i], &out[0]));
assert(0 == strcmp(segments[i], out));

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants