diff --git a/_example/addon/goaddon.cc b/_example/addon/goaddon.cc index 95696cb..f4bf5f5 100755 --- a/_example/addon/goaddon.cc +++ b/_example/addon/goaddon.cc @@ -360,6 +360,7 @@ Value _EmptyString(const CallbackInfo& wg_info) { char *s = new char[wg_s.length() + 1]; strcpy(s, wg_s.c_str()); bool wg_res_ = EmptyString(s); + delete [] s; return Boolean::New(wg_env, wg_res_); } // ---------- GenCode ---------- @@ -396,6 +397,7 @@ Value _CountMap(const CallbackInfo& wg_info) { char *obj = new char[wg_obj.length() + 1]; strcpy(obj, wg_obj.c_str()); int wg_res_ = CountMap(obj); + delete [] obj; return Number::New(wg_env, wg_res_); } // ---------- GenCode ---------- @@ -413,6 +415,7 @@ Value _IsMapType(const CallbackInfo& wg_info) { char *obj = new char[wg_obj.length() + 1]; strcpy(obj, wg_obj.c_str()); bool wg_res_ = IsMapType(obj); + delete [] obj; return Boolean::New(wg_env, wg_res_); } // ---------- GenCode ---------- @@ -449,6 +452,7 @@ Value _CountSlice(const CallbackInfo& wg_info) { char *s = new char[wg_s.length() + 1]; strcpy(s, wg_s.c_str()); int wg_res_ = CountSlice(s); + delete [] s; return Number::New(wg_env, wg_res_); } // ---------- GenCode ---------- @@ -466,6 +470,7 @@ Value _IsSliceType(const CallbackInfo& wg_info) { char *s = new char[wg_s.length() + 1]; strcpy(s, wg_s.c_str()); bool wg_res_ = IsSliceType(s); + delete [] s; return Boolean::New(wg_env, wg_res_); } // ---------- GenCode ---------- @@ -673,7 +678,7 @@ static void wg_work_complete_asynccallbackreuintsum32(napi_env wg_env, napi_stat static napi_value wg_work_asynccallbackreuintsum32(napi_env wg_env, napi_callback_info wg_info) { size_t wg_argc = 3; size_t wg_cb_arg_index = 2; - napi_value wg_args[wg_argc]; + napi_value wg_args[3]; napi_value wg_work_name; napi_status wg_sts; WgAddonDataASyncCallbackReUintSum32* wg_addon = (WgAddonDataASyncCallbackReUintSum32*)malloc(sizeof(*wg_addon)); @@ -810,7 +815,7 @@ static void wg_work_complete_asynccallbackrearr(napi_env wg_env, napi_status wg_ static napi_value wg_work_asynccallbackrearr(napi_env wg_env, napi_callback_info wg_info) { size_t wg_argc = 2; size_t wg_cb_arg_index = 1; - napi_value wg_args[wg_argc]; + napi_value wg_args[2]; napi_value wg_work_name; napi_status wg_sts; WgAddonDataASyncCallbackReArr* wg_addon = (WgAddonDataASyncCallbackReArr*)malloc(sizeof(*wg_addon)); @@ -936,7 +941,7 @@ static void wg_work_complete_asynccallbackreobject(napi_env wg_env, napi_status static napi_value wg_work_asynccallbackreobject(napi_env wg_env, napi_callback_info wg_info) { size_t wg_argc = 2; size_t wg_cb_arg_index = 1; - napi_value wg_args[wg_argc]; + napi_value wg_args[2]; napi_value wg_work_name; napi_status wg_sts; WgAddonDataASyncCallbackReObject* wg_addon = (WgAddonDataASyncCallbackReObject*)malloc(sizeof(*wg_addon)); @@ -1066,7 +1071,7 @@ static void wg_work_complete_asynccallbackrecount(napi_env wg_env, napi_status w static napi_value wg_work_asynccallbackrecount(napi_env wg_env, napi_callback_info wg_info) { size_t wg_argc = 2; size_t wg_cb_arg_index = 1; - napi_value wg_args[wg_argc]; + napi_value wg_args[2]; napi_value wg_work_name; napi_status wg_sts; WgAddonDataASyncCallbackReCount* wg_addon = (WgAddonDataASyncCallbackReCount*)malloc(sizeof(*wg_addon)); @@ -1194,7 +1199,7 @@ static void wg_work_complete_asynccallbackrebool(napi_env wg_env, napi_status wg static napi_value wg_work_asynccallbackrebool(napi_env wg_env, napi_callback_info wg_info) { size_t wg_argc = 2; size_t wg_cb_arg_index = 1; - napi_value wg_args[wg_argc]; + napi_value wg_args[2]; napi_value wg_work_name; napi_status wg_sts; WgAddonDataASyncCallbackReBool* wg_addon = (WgAddonDataASyncCallbackReBool*)malloc(sizeof(*wg_addon)); @@ -1328,7 +1333,7 @@ static void wg_work_complete_asynccallbackmarg(napi_env wg_env, napi_status wg_s static napi_value wg_work_asynccallbackmarg(napi_env wg_env, napi_callback_info wg_info) { size_t wg_argc = 3; size_t wg_cb_arg_index = 1; - napi_value wg_args[wg_argc]; + napi_value wg_args[3]; napi_value wg_work_name; napi_status wg_sts; WgAddonDataASyncCallbackMArg* wg_addon = (WgAddonDataASyncCallbackMArg*)malloc(sizeof(*wg_addon)); diff --git a/_example/addon/index.js b/_example/addon/index.js index f8c3155..08cd26e 100755 --- a/_example/addon/index.js +++ b/_example/addon/index.js @@ -1,4 +1,5 @@ const goaddon = require('bindings')('goaddon'); +// JS call API module.exports = { intSum32 : goaddon.int_sum32, intSum64 : goaddon.int_sum64, diff --git a/buildtask/dep_install.go b/buildtask/dep_install.go index 1bd56be..76dccb4 100644 --- a/buildtask/dep_install.go +++ b/buildtask/dep_install.go @@ -10,7 +10,7 @@ import ( func installDep(cfgs config.Config) bool { path := tools.FormatDirPath(cfgs.OutPut) - clog.Info("Staring install npm dependencies ...") + clog.Info("Staring install dependencies ...") // "bindings" "node-addon-api" msg, err := cmd.RunCommand( "./", @@ -22,6 +22,6 @@ func installDep(cfgs config.Config) bool { return false } clog.Info(msg) - clog.Info("Install npm dependencies done ~") + clog.Info("Install dependencies done ~") return true } diff --git a/content/args/argsync/gen_arg_object_type.go b/content/args/argsync/gen_arg_object_type.go index f747eb7..1c9e4ee 100644 --- a/content/args/argsync/gen_arg_object_type.go +++ b/content/args/argsync/gen_arg_object_type.go @@ -13,6 +13,7 @@ func GenObjectArgTypeCode(name string, index string) (string, string) { string wg_` + name + ` = wg_object_to_string(wg__` + name + `); char *` + name + ` = new char[wg_` + name + `.length() + 1]; strcpy(` + name + `, wg_` + name + `.c_str());` + endCode := tools.FormatCodeIndentLn(`delete [] `+name+`;`, 2) return code, endCode } diff --git a/content/returns/resync/gen_return_array_type.go b/content/returns/resync/gen_return_array_type.go index 86a11f2..c4992cc 100644 --- a/content/returns/resync/gen_return_array_type.go +++ b/content/returns/resync/gen_return_array_type.go @@ -2,7 +2,7 @@ package resync import ( "github.com/wenlng/gonacli/config" - args2 "github.com/wenlng/gonacli/content/args/argsync" + "github.com/wenlng/gonacli/content/args/argsync" "github.com/wenlng/gonacli/tools" "strings" ) @@ -29,7 +29,7 @@ func GenReturnArrayTypeCode(export config.Export) string { Value _` + methodName + `(const CallbackInfo& wg_info) {` code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2) - c, argNames, endCode := args2.GenArgCode(args) + c, argNames, endCode := argsync.GenArgCode(args) code += c code += GenHandleReturnArrayCode(methodName, argNames, endCode) diff --git a/content/returns/resync/gen_return_boolean_type.go b/content/returns/resync/gen_return_boolean_type.go index fba8517..535d259 100644 --- a/content/returns/resync/gen_return_boolean_type.go +++ b/content/returns/resync/gen_return_boolean_type.go @@ -2,14 +2,15 @@ package resync import ( "github.com/wenlng/gonacli/config" - args2 "github.com/wenlng/gonacli/content/args/argsync" + "github.com/wenlng/gonacli/content/args/argsync" "github.com/wenlng/gonacli/tools" "strings" ) // 生成处理体 -func GenHandleReturnBooleanCode(method string, args []string) string { +func GenHandleReturnBooleanCode(method string, args []string, endCode string) string { code := tools.FormatCodeIndentLn(`bool wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2) + code += endCode code += tools.FormatCodeIndentLn(`return Boolean::New(wg_env, wg_res_);`, 2) return code } @@ -24,10 +25,10 @@ func GenReturnBooleanTypeCode(export config.Export) string { Value _` + methodName + `(const CallbackInfo& wg_info) {` code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2) - c, argNames, _ := args2.GenArgCode(args) + c, argNames, endCode := argsync.GenArgCode(args) code += c - code += GenHandleReturnBooleanCode(methodName, argNames) + code += GenHandleReturnBooleanCode(methodName, argNames, endCode) code += tools.FormatCodeIndentLn(`}`, 0) return code diff --git a/content/returns/resync/gen_return_double_type.go b/content/returns/resync/gen_return_double_type.go index e42c61d..0971832 100644 --- a/content/returns/resync/gen_return_double_type.go +++ b/content/returns/resync/gen_return_double_type.go @@ -2,14 +2,15 @@ package resync import ( "github.com/wenlng/gonacli/config" - args2 "github.com/wenlng/gonacli/content/args/argsync" + "github.com/wenlng/gonacli/content/args/argsync" "github.com/wenlng/gonacli/tools" "strings" ) // 生成处理体 -func GenHandleReturnDoubleCode(method string, args []string) string { +func GenHandleReturnDoubleCode(method string, args []string, endCode string) string { code := tools.FormatCodeIndentLn(`double wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2) + code += endCode code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2) return code } @@ -24,10 +25,10 @@ func GenReturnDoubleTypeCode(export config.Export) string { Value _` + methodName + `(const CallbackInfo& wg_info) {` code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2) - c, argNames, _ := args2.GenArgCode(args) + c, argNames, endCode := argsync.GenArgCode(args) code += c - code += GenHandleReturnDoubleCode(methodName, argNames) + code += GenHandleReturnDoubleCode(methodName, argNames, endCode) code += tools.FormatCodeIndentLn(`}`, 0) return code diff --git a/content/returns/resync/gen_return_float_type.go b/content/returns/resync/gen_return_float_type.go index 720f2af..f8d93c8 100644 --- a/content/returns/resync/gen_return_float_type.go +++ b/content/returns/resync/gen_return_float_type.go @@ -2,14 +2,15 @@ package resync import ( "github.com/wenlng/gonacli/config" - args2 "github.com/wenlng/gonacli/content/args/argsync" + "github.com/wenlng/gonacli/content/args/argsync" "github.com/wenlng/gonacli/tools" "strings" ) // 生成处理体 -func GenHandleReturnFloatCode(method string, args []string) string { +func GenHandleReturnFloatCode(method string, args []string, endCode string) string { code := tools.FormatCodeIndentLn(`float wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2) + code += endCode code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2) return code } @@ -24,10 +25,10 @@ func GenReturnFloatTypeCode(export config.Export) string { Value _` + methodName + `(const CallbackInfo& wg_info) {` code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2) - c, argNames, _ := args2.GenArgCode(args) + c, argNames, endCode := argsync.GenArgCode(args) code += c - code += GenHandleReturnFloatCode(methodName, argNames) + code += GenHandleReturnFloatCode(methodName, argNames, endCode) code += tools.FormatCodeIndentLn(`}`, 0) return code diff --git a/content/returns/resync/gen_return_int_type.go b/content/returns/resync/gen_return_int_type.go index 1a4af68..32c1320 100644 --- a/content/returns/resync/gen_return_int_type.go +++ b/content/returns/resync/gen_return_int_type.go @@ -2,13 +2,13 @@ package resync import ( "github.com/wenlng/gonacli/config" - args2 "github.com/wenlng/gonacli/content/args/argsync" + "github.com/wenlng/gonacli/content/args/argsync" "github.com/wenlng/gonacli/tools" "strings" ) // 生成处理体 -func GenHandleReturnIntCode(method string, args []string, varType string) string { +func GenHandleReturnIntCode(method string, args []string, varType string, endCode string) string { code := "" // int32 int64 uint32 @@ -20,6 +20,7 @@ func GenHandleReturnIntCode(method string, args []string, varType string) string code = tools.FormatCodeIndentLn(`int wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2) } + code += endCode code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2) return code } @@ -34,10 +35,10 @@ func GenReturnIntTypeCode(export config.Export, varType string) string { Value _` + methodName + `(const CallbackInfo& wg_info) {` code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2) - c, argNames, _ := args2.GenArgCode(args) + c, argNames, endCode := argsync.GenArgCode(args) code += c - code += GenHandleReturnIntCode(methodName, argNames, varType) + code += GenHandleReturnIntCode(methodName, argNames, varType, endCode) code += tools.FormatCodeIndentLn(`}`, 0) return code diff --git a/content/returns/resync/gen_return_object_type.go b/content/returns/resync/gen_return_object_type.go index d7ed2d9..c92306c 100644 --- a/content/returns/resync/gen_return_object_type.go +++ b/content/returns/resync/gen_return_object_type.go @@ -2,7 +2,7 @@ package resync import ( "github.com/wenlng/gonacli/config" - args2 "github.com/wenlng/gonacli/content/args/argsync" + "github.com/wenlng/gonacli/content/args/argsync" "github.com/wenlng/gonacli/tools" "strings" ) @@ -27,7 +27,7 @@ func GenReturnObjectTypeCode(export config.Export) string { Value _` + methodName + `(const CallbackInfo& wg_info) {` code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2) - c, argNames, endCode := args2.GenArgCode(args) + c, argNames, endCode := argsync.GenArgCode(args) code += c code += GenHandleReturnObjectCode(methodName, argNames, endCode) diff --git a/content/returns/resync/gen_return_string_type.go b/content/returns/resync/gen_return_string_type.go index 4ee7302..ac4e341 100644 --- a/content/returns/resync/gen_return_string_type.go +++ b/content/returns/resync/gen_return_string_type.go @@ -2,7 +2,7 @@ package resync import ( "github.com/wenlng/gonacli/config" - args2 "github.com/wenlng/gonacli/content/args/argsync" + "github.com/wenlng/gonacli/content/args/argsync" "github.com/wenlng/gonacli/tools" "strings" ) @@ -26,7 +26,7 @@ func GenReturnStringTypeCode(export config.Export) string { Value _` + methodName + `(const CallbackInfo& wg_info) {` code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2) - c, argNames, preCode := args2.GenArgCode(args) + c, argNames, preCode := argsync.GenArgCode(args) code += c code += GenHandleReturnStringCode(methodName, argNames, preCode)