Skip to content

Commit 3c9e841

Browse files
committed
BinaryenSetFunctionTable now accepts array of func names not funcs. Fixes #1645
1 parent 235e30b commit 3c9e841

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This document describes changes between tagged Binaryen versions.
2+
3+
To browse or download snapshots of old tagged versions, visit
4+
https://github.com/WebAssembly/binaryen/releases.
5+
6+
Not all changes are documented here. In particular, new features, user-oriented
7+
fixes, options, command-line parameters, usage changes, deprecations,
8+
significant internal modifications and optimizations etc. generally deserve a
9+
mention. To examine the full set of changes between versions, visit the link to
10+
full changeset diff at the end of each section.
11+
12+
Current Trunk
13+
-------------
14+
15+
### BREAKING CHANGES
16+
17+
- `BinaryenSetFunctionTable` no longer accepts an array of functions, instead it accepts an array of function names, `const char **funcNames`. Previously, you could not include imported functions because they are of type `BinaryenImportRef` instead of `BinaryenFunctionRef`. [#1650](https://github.com/WebAssembly/binaryen/pull/1650)

src/binaryen-c.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,28 +1882,27 @@ void BinaryenRemoveExport(BinaryenModuleRef module, const char* externalName) {
18821882

18831883
// Function table. One per module
18841884

1885-
void BinaryenSetFunctionTable(BinaryenModuleRef module, BinaryenFunctionRef* funcs, BinaryenIndex numFuncs) {
1885+
void BinaryenSetFunctionTable(BinaryenModuleRef module, const char **funcNames, BinaryenIndex numFuncNames) {
18861886
if (tracing) {
18871887
std::cout << " {\n";
1888-
std::cout << " BinaryenFunctionRef funcs[] = { ";
1889-
for (BinaryenIndex i = 0; i < numFuncs; i++) {
1888+
std::cout << " const char* funcNames[] = { ";
1889+
for (BinaryenIndex i = 0; i < numFuncNames; i++) {
18901890
if (i > 0) std::cout << ", ";
1891-
std::cout << "functions[" << functions[funcs[i]] << "]";
1891+
std::cout << "\"" << funcNames[i] << "\"";
18921892
}
1893-
if (numFuncs == 0) std::cout << "0"; // ensure the array is not empty, otherwise a compiler error on VS
18941893
std::cout << " };\n";
1895-
std::cout << " BinaryenSetFunctionTable(the_module, funcs, " << numFuncs << ");\n";
1894+
std::cout << " BinaryenSetFunctionTable(the_module, funcNames, " << numFuncNames << ");\n";
18961895
std::cout << " }\n";
18971896
}
18981897

18991898
auto* wasm = (Module*)module;
19001899
wasm->table.exists = true;
19011900
Table::Segment segment(wasm->allocator.alloc<Const>()->set(Literal(int32_t(0))));
1902-
for (BinaryenIndex i = 0; i < numFuncs; i++) {
1903-
segment.data.push_back(((Function*)funcs[i])->name);
1901+
for (BinaryenIndex i = 0; i < numFuncNames; i++) {
1902+
segment.data.push_back(funcNames[i]);
19041903
}
19051904
wasm->table.segments.push_back(segment);
1906-
wasm->table.initial = wasm->table.max = numFuncs;
1905+
wasm->table.initial = wasm->table.max = numFuncNames;
19071906
}
19081907

19091908
// Memory. One per module

src/binaryen-c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name,
634634

635635
// Function table. One per module
636636

637-
void BinaryenSetFunctionTable(BinaryenModuleRef module, BinaryenFunctionRef* funcs, BinaryenIndex numFuncs);
637+
void BinaryenSetFunctionTable(BinaryenModuleRef module, const char **funcNames, BinaryenIndex numFuncNames);
638638

639639
// Memory. One per module
640640

test/binaryen.js/kitchen-sink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function test_core() {
250250

251251
// Function table. One per module
252252

253-
module.setFunctionTable([ sinker ]);
253+
module.setFunctionTable([ getFunctionInfo(sinker).name ]);
254254

255255
// Memory. One per module
256256

test/example/c-api-kitchen-sink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ void test_core() {
253253
BinaryenAddFunctionExport(module, "kitchen()sinker", "kitchen_sinker");
254254

255255
// Function table. One per module
256-
BinaryenFunctionRef functions[] = { sinker };
257-
BinaryenSetFunctionTable(module, functions, 1);
256+
const char **funcNames[] = { BinaryenFunctionGetName(sinker) };
257+
BinaryenSetFunctionTable(module, funcNames, 1);
258258

259259
// Memory. One per module
260260

test/example/c-api-kitchen-sink.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,10 @@ int main() {
14001400
}
14011401
imports[0] = BinaryenAddFunctionImport(the_module, "an-imported", "module", "base", functionTypes[1]);
14021402
exports[0] = BinaryenAddFunctionExport(the_module, "kitchen()sinker", "kitchen_sinker");
1403+
BinaryenFunctionGetName(functions[0]);
14031404
{
1404-
BinaryenFunctionRef funcs[] = { functions[0] };
1405-
BinaryenSetFunctionTable(the_module, funcs, 1);
1405+
const char* funcNames[] = { "kitchen()sinker" };
1406+
BinaryenSetFunctionTable(the_module, funcNames, 1);
14061407
}
14071408
expressions[254] = BinaryenConst(the_module, BinaryenLiteralInt32(10));
14081409
{

0 commit comments

Comments
 (0)