summaryrefslogtreecommitdiff
path: root/src/binaryen-c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r--src/binaryen-c.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index 80f8d8276..9ed6ad314 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -306,7 +306,7 @@ void BinaryenModuleDispose(BinaryenModuleRef module) {
BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const char* name, BinaryenType result, BinaryenType* paramTypes, BinaryenIndex numParams) {
auto* wasm = (Module*)module;
- auto* ret = new FunctionType;
+ auto ret = make_unique<FunctionType>();
if (name) ret->name = name;
else ret->name = Name::fromInt(wasm->functionTypes.size());
ret->result = Type(result);
@@ -314,13 +314,6 @@ BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const
ret->params.push_back(Type(paramTypes[i]));
}
- // Lock. This can be called from multiple threads at once, and is a
- // point where they all access and modify the module.
- {
- std::lock_guard<std::mutex> lock(BinaryenFunctionTypeMutex);
- wasm->addFunctionType(ret);
- }
-
if (tracing) {
std::cout << " {\n";
std::cout << " BinaryenType paramTypes[] = { ";
@@ -332,13 +325,16 @@ BinaryenFunctionTypeRef BinaryenAddFunctionType(BinaryenModuleRef module, const
std::cout << " };\n";
size_t id = functionTypes.size();
std::cout << " functionTypes[" << id << "] = BinaryenAddFunctionType(the_module, ";
- functionTypes[ret] = id;
+ functionTypes[ret.get()] = id;
traceNameOrNULL(name);
std::cout << ", " << result << ", paramTypes, " << numParams << ");\n";
std::cout << " }\n";
}
- return ret;
+ // Lock. This can be called from multiple threads at once, and is a
+ // point where they all access and modify the module.
+ std::lock_guard<std::mutex> lock(BinaryenFunctionTypeMutex);
+ return wasm->addFunctionType(std::move(ret));
}
void BinaryenRemoveFunctionType(BinaryenModuleRef module, const char* name) {
if (tracing) {