diff options
author | Jukka Jylanki <jjylanki@imvu.com> | 2013-04-16 21:12:39 +0300 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:32 +0300 |
commit | 2afab7b6f9f890e2ba55e6273cb46db0f52c74d2 (patch) | |
tree | 326136b599930dcb9b2ad311ded47d4a1fd002cb | |
parent | f10fe0cc393eaf1a457872487eac31a128b496e8 (diff) |
Fix use of destructors in crafted destructors.
-rwxr-xr-x | src/embind/embind.js | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index 0a40c36d..2a484dea 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -384,9 +384,12 @@ function __embind_register_std_string(rawType, name) { } HEAPU8[ptr + 4 + i] = charCode; } - destructors.push(_free, ptr); + if (destructors !== null) { + destructors.push(_free, ptr); + } return ptr; }, + destructorFunction: function(ptr) { _free(ptr); }, }); } @@ -426,7 +429,7 @@ function __embind_register_std_wstring(rawType, charSize, name) { } return ptr; }, - destructorFunction: _free, + destructorFunction: function(ptr) { _free(ptr); }, }); } @@ -512,8 +515,10 @@ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cp // } var argsList = ""; + var argsListWired = ""; for(var i = 0; i < argCount-2; ++i) { argsList += (i!==0?", ":"")+"arg"+i; + argsListWired += (i!==0?", ":"")+"arg"+i+"Wired"; } var invokerFnBody = @@ -547,26 +552,25 @@ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cp } for(var i = 0; i < argCount-2; ++i) { - invokerFnBody += "var arg"+i+" = argType"+i+".toWireType("+dtorStack+", arg"+i+"); // "+argTypes[i+2].name+"\n"; - // argsList += ", arg"+i; + invokerFnBody += "var arg"+i+"Wired = argType"+i+".toWireType("+dtorStack+", arg"+i+"); // "+argTypes[i+2].name+"\n"; args1.push("argType"+i); args2.push(argTypes[i+2]); } if (isClassMethodFunc) { - argsList = "thisWired" + (argsList.length > 0 ? ", " : "") + argsList; + argsListWired = "thisWired" + (argsListWired.length > 0 ? ", " : "") + argsListWired; } var returns = (argTypes[0].name !== "void"); invokerFnBody += - (returns?"var rv = ":"") + "invoker(fn"+(argsList.length>0?", ":"")+argsList+");\n"; + (returns?"var rv = ":"") + "invoker(fn"+(argsListWired.length>0?", ":"")+argsListWired+");\n"; if (needsDestructorStack) { invokerFnBody += "runDestructors(destructors);\n"; } else { for(var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method. - var paramName = (i === 1 ? "thisWired" : ("argType"+(i-2))); + var paramName = (i === 1 ? "thisWired" : ("arg"+(i-2)+"Wired")); if (argTypes[i].destructorFunction !== null) { invokerFnBody += paramName+"_dtor("+paramName+"); // "+argTypes[i].name+"\n"; args1.push(paramName+"_dtor"); |