@@ -190,41 +190,40 @@ void BinaryenModuleDispose(BinaryenModuleRef module) {
190190
191191// Function types
192192
193- BinaryenFunctionTypeRef BinaryenAddFunctionType (BinaryenModuleRef module , const char * name, BinaryenType result, BinaryenType* paramTypes, BinaryenIndex numParams) {
193+ BinaryenFunctionTypeRef BinaryenAddFunctionType (BinaryenModuleRef module , const char * name,
194+ BinaryenType result, BinaryenType* paramTypes, BinaryenIndex numParams) {
194195 auto * wasm = (Module*)module ;
195- auto * ret = new FunctionType;
196+ auto ret = make_unique< FunctionType>() ;
196197 if (name) ret->name = name;
197198 else ret->name = Name::fromInt (wasm->functionTypes .size ());
198199 ret->result = Type (result);
199200 for (BinaryenIndex i = 0 ; i < numParams; i++) {
200201 ret->params .push_back (Type (paramTypes[i]));
201202 }
202203
203- // Lock. This can be called from multiple threads at once, and is a
204- // point where they all access and modify the module.
205- {
206- std::lock_guard<std::mutex> lock (BinaryenFunctionTypeMutex);
207- wasm->addFunctionType (ret);
208- }
209-
210204 if (tracing) {
211205 std::cout << " {\n " ;
212206 std::cout << " BinaryenType paramTypes[] = { " ;
213207 for (BinaryenIndex i = 0 ; i < numParams; i++) {
214- if (i > 0 ) std::cout << " , " ;
208+ if (i > 0 )
209+ std::cout << " , " ;
215210 std::cout << paramTypes[i];
216211 }
217- if (numParams == 0 ) std::cout << " 0" ; // ensure the array is not empty, otherwise a compiler error on VS
212+ if (numParams == 0 )
213+ std::cout << " 0" ; // ensure the array is not empty, otherwise a compiler error on VS
218214 std::cout << " };\n " ;
219215 size_t id = functionTypes.size ();
220216 std::cout << " functionTypes[" << id << " ] = BinaryenAddFunctionType(the_module, " ;
221- functionTypes[ret] = id;
217+ functionTypes[ret. get () ] = id;
222218 traceNameOrNULL (name);
223219 std::cout << " , " << result << " , paramTypes, " << numParams << " );\n " ;
224220 std::cout << " }\n " ;
225221 }
226222
227- return ret;
223+ // Lock. This can be called from multiple threads at once, and is a
224+ // point where they all access and modify the module.
225+ std::lock_guard<std::mutex> lock (BinaryenFunctionTypeMutex);
226+ return wasm->addFunctionType (std::move (ret));
228227}
229228void BinaryenRemoveFunctionType (BinaryenModuleRef module , const char * name) {
230229 if (tracing) {
0 commit comments