forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
embind: Fix method pointers for AOT JS generation.
Previously, AOT JS glue code for method pointers used the address of the method pointer as a unique ID to match JS glue with the binding. However, sometimes static initializers are run in different orders when running the AOT generation code versus when the code is run normally. This caused the method pointer address to be different and the binding didn't match up. Instead of using the function pointer or the method pointer address we now use a generated signature for the invoker to match up the glue code. This works for both types of pointers and also has the advantage that many of the glue code functions are nearly identical and can be reusued (closure arguments make them behave differently). Fixes emscripten-core#20994
- Loading branch information
1 parent
c4d76b8
commit 4d2c647
Showing
5 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdio.h> | ||
#include <fstream> | ||
#include <emscripten.h> | ||
#include <emscripten/bind.h> | ||
|
||
using namespace emscripten; | ||
|
||
class Foo { | ||
public: | ||
void go(const std::string& filename) { | ||
// Using std::ifstream causes allocations to happen in a different order | ||
// during AOT JS generation versus normal execution. | ||
std::ifstream ifs(filename, std::ifstream::binary); | ||
ifs.close(); | ||
} | ||
}; | ||
|
||
int main() { | ||
printf("done\n"); | ||
} | ||
|
||
EMSCRIPTEN_BINDINGS(xxx) { | ||
class_<Foo>("Foo") | ||
.function("go", &Foo::go); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters