Skip to content

Commit ab8f4bf

Browse files
author
awen
committed
Update code
1 parent 5b2bf96 commit ab8f4bf

11 files changed

+41
-30
lines changed

_example/addon/goaddon.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ Value _EmptyString(const CallbackInfo& wg_info) {
360360
char *s = new char[wg_s.length() + 1];
361361
strcpy(s, wg_s.c_str());
362362
bool wg_res_ = EmptyString(s);
363+
delete [] s;
363364
return Boolean::New(wg_env, wg_res_);
364365
}
365366
// ---------- GenCode ----------
@@ -396,6 +397,7 @@ Value _CountMap(const CallbackInfo& wg_info) {
396397
char *obj = new char[wg_obj.length() + 1];
397398
strcpy(obj, wg_obj.c_str());
398399
int wg_res_ = CountMap(obj);
400+
delete [] obj;
399401
return Number::New(wg_env, wg_res_);
400402
}
401403
// ---------- GenCode ----------
@@ -413,6 +415,7 @@ Value _IsMapType(const CallbackInfo& wg_info) {
413415
char *obj = new char[wg_obj.length() + 1];
414416
strcpy(obj, wg_obj.c_str());
415417
bool wg_res_ = IsMapType(obj);
418+
delete [] obj;
416419
return Boolean::New(wg_env, wg_res_);
417420
}
418421
// ---------- GenCode ----------
@@ -449,6 +452,7 @@ Value _CountSlice(const CallbackInfo& wg_info) {
449452
char *s = new char[wg_s.length() + 1];
450453
strcpy(s, wg_s.c_str());
451454
int wg_res_ = CountSlice(s);
455+
delete [] s;
452456
return Number::New(wg_env, wg_res_);
453457
}
454458
// ---------- GenCode ----------
@@ -466,6 +470,7 @@ Value _IsSliceType(const CallbackInfo& wg_info) {
466470
char *s = new char[wg_s.length() + 1];
467471
strcpy(s, wg_s.c_str());
468472
bool wg_res_ = IsSliceType(s);
473+
delete [] s;
469474
return Boolean::New(wg_env, wg_res_);
470475
}
471476
// ---------- GenCode ----------
@@ -673,7 +678,7 @@ static void wg_work_complete_asynccallbackreuintsum32(napi_env wg_env, napi_stat
673678
static napi_value wg_work_asynccallbackreuintsum32(napi_env wg_env, napi_callback_info wg_info) {
674679
size_t wg_argc = 3;
675680
size_t wg_cb_arg_index = 2;
676-
napi_value wg_args[wg_argc];
681+
napi_value wg_args[3];
677682
napi_value wg_work_name;
678683
napi_status wg_sts;
679684
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_
810815
static napi_value wg_work_asynccallbackrearr(napi_env wg_env, napi_callback_info wg_info) {
811816
size_t wg_argc = 2;
812817
size_t wg_cb_arg_index = 1;
813-
napi_value wg_args[wg_argc];
818+
napi_value wg_args[2];
814819
napi_value wg_work_name;
815820
napi_status wg_sts;
816821
WgAddonDataASyncCallbackReArr* wg_addon = (WgAddonDataASyncCallbackReArr*)malloc(sizeof(*wg_addon));
@@ -936,7 +941,7 @@ static void wg_work_complete_asynccallbackreobject(napi_env wg_env, napi_status
936941
static napi_value wg_work_asynccallbackreobject(napi_env wg_env, napi_callback_info wg_info) {
937942
size_t wg_argc = 2;
938943
size_t wg_cb_arg_index = 1;
939-
napi_value wg_args[wg_argc];
944+
napi_value wg_args[2];
940945
napi_value wg_work_name;
941946
napi_status wg_sts;
942947
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
10661071
static napi_value wg_work_asynccallbackrecount(napi_env wg_env, napi_callback_info wg_info) {
10671072
size_t wg_argc = 2;
10681073
size_t wg_cb_arg_index = 1;
1069-
napi_value wg_args[wg_argc];
1074+
napi_value wg_args[2];
10701075
napi_value wg_work_name;
10711076
napi_status wg_sts;
10721077
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
11941199
static napi_value wg_work_asynccallbackrebool(napi_env wg_env, napi_callback_info wg_info) {
11951200
size_t wg_argc = 2;
11961201
size_t wg_cb_arg_index = 1;
1197-
napi_value wg_args[wg_argc];
1202+
napi_value wg_args[2];
11981203
napi_value wg_work_name;
11991204
napi_status wg_sts;
12001205
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
13281333
static napi_value wg_work_asynccallbackmarg(napi_env wg_env, napi_callback_info wg_info) {
13291334
size_t wg_argc = 3;
13301335
size_t wg_cb_arg_index = 1;
1331-
napi_value wg_args[wg_argc];
1336+
napi_value wg_args[3];
13321337
napi_value wg_work_name;
13331338
napi_status wg_sts;
13341339
WgAddonDataASyncCallbackMArg* wg_addon = (WgAddonDataASyncCallbackMArg*)malloc(sizeof(*wg_addon));

_example/addon/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const goaddon = require('bindings')('goaddon');
2+
// JS call API
23
module.exports = {
34
intSum32 : goaddon.int_sum32,
45
intSum64 : goaddon.int_sum64,

buildtask/dep_install.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func installDep(cfgs config.Config) bool {
1111
path := tools.FormatDirPath(cfgs.OutPut)
1212

13-
clog.Info("Staring install npm dependencies ...")
13+
clog.Info("Staring install dependencies ...")
1414
// "bindings" "node-addon-api"
1515
msg, err := cmd.RunCommand(
1616
"./",
@@ -22,6 +22,6 @@ func installDep(cfgs config.Config) bool {
2222
return false
2323
}
2424
clog.Info(msg)
25-
clog.Info("Install npm dependencies done ~")
25+
clog.Info("Install dependencies done ~")
2626
return true
2727
}

content/args/argsync/gen_arg_object_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func GenObjectArgTypeCode(name string, index string) (string, string) {
1313
string wg_` + name + ` = wg_object_to_string(wg__` + name + `);
1414
char *` + name + ` = new char[wg_` + name + `.length() + 1];
1515
strcpy(` + name + `, wg_` + name + `.c_str());`
16+
1617
endCode := tools.FormatCodeIndentLn(`delete [] `+name+`;`, 2)
1718
return code, endCode
1819
}

content/returns/resync/gen_return_array_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package resync
22

33
import (
44
"github.com/wenlng/gonacli/config"
5-
args2 "github.com/wenlng/gonacli/content/args/argsync"
5+
"github.com/wenlng/gonacli/content/args/argsync"
66
"github.com/wenlng/gonacli/tools"
77
"strings"
88
)
@@ -29,7 +29,7 @@ func GenReturnArrayTypeCode(export config.Export) string {
2929
Value _` + methodName + `(const CallbackInfo& wg_info) {`
3030
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)
3131

32-
c, argNames, endCode := args2.GenArgCode(args)
32+
c, argNames, endCode := argsync.GenArgCode(args)
3333
code += c
3434

3535
code += GenHandleReturnArrayCode(methodName, argNames, endCode)

content/returns/resync/gen_return_boolean_type.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package resync
22

33
import (
44
"github.com/wenlng/gonacli/config"
5-
args2 "github.com/wenlng/gonacli/content/args/argsync"
5+
"github.com/wenlng/gonacli/content/args/argsync"
66
"github.com/wenlng/gonacli/tools"
77
"strings"
88
)
99

1010
// 生成处理体
11-
func GenHandleReturnBooleanCode(method string, args []string) string {
11+
func GenHandleReturnBooleanCode(method string, args []string, endCode string) string {
1212
code := tools.FormatCodeIndentLn(`bool wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
13+
code += endCode
1314
code += tools.FormatCodeIndentLn(`return Boolean::New(wg_env, wg_res_);`, 2)
1415
return code
1516
}
@@ -24,10 +25,10 @@ func GenReturnBooleanTypeCode(export config.Export) string {
2425
Value _` + methodName + `(const CallbackInfo& wg_info) {`
2526
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)
2627

27-
c, argNames, _ := args2.GenArgCode(args)
28+
c, argNames, endCode := argsync.GenArgCode(args)
2829
code += c
2930

30-
code += GenHandleReturnBooleanCode(methodName, argNames)
31+
code += GenHandleReturnBooleanCode(methodName, argNames, endCode)
3132

3233
code += tools.FormatCodeIndentLn(`}`, 0)
3334
return code

content/returns/resync/gen_return_double_type.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package resync
22

33
import (
44
"github.com/wenlng/gonacli/config"
5-
args2 "github.com/wenlng/gonacli/content/args/argsync"
5+
"github.com/wenlng/gonacli/content/args/argsync"
66
"github.com/wenlng/gonacli/tools"
77
"strings"
88
)
99

1010
// 生成处理体
11-
func GenHandleReturnDoubleCode(method string, args []string) string {
11+
func GenHandleReturnDoubleCode(method string, args []string, endCode string) string {
1212
code := tools.FormatCodeIndentLn(`double wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
13+
code += endCode
1314
code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2)
1415
return code
1516
}
@@ -24,10 +25,10 @@ func GenReturnDoubleTypeCode(export config.Export) string {
2425
Value _` + methodName + `(const CallbackInfo& wg_info) {`
2526
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)
2627

27-
c, argNames, _ := args2.GenArgCode(args)
28+
c, argNames, endCode := argsync.GenArgCode(args)
2829
code += c
2930

30-
code += GenHandleReturnDoubleCode(methodName, argNames)
31+
code += GenHandleReturnDoubleCode(methodName, argNames, endCode)
3132

3233
code += tools.FormatCodeIndentLn(`}`, 0)
3334
return code

content/returns/resync/gen_return_float_type.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package resync
22

33
import (
44
"github.com/wenlng/gonacli/config"
5-
args2 "github.com/wenlng/gonacli/content/args/argsync"
5+
"github.com/wenlng/gonacli/content/args/argsync"
66
"github.com/wenlng/gonacli/tools"
77
"strings"
88
)
99

1010
// 生成处理体
11-
func GenHandleReturnFloatCode(method string, args []string) string {
11+
func GenHandleReturnFloatCode(method string, args []string, endCode string) string {
1212
code := tools.FormatCodeIndentLn(`float wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
13+
code += endCode
1314
code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2)
1415
return code
1516
}
@@ -24,10 +25,10 @@ func GenReturnFloatTypeCode(export config.Export) string {
2425
Value _` + methodName + `(const CallbackInfo& wg_info) {`
2526
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)
2627

27-
c, argNames, _ := args2.GenArgCode(args)
28+
c, argNames, endCode := argsync.GenArgCode(args)
2829
code += c
2930

30-
code += GenHandleReturnFloatCode(methodName, argNames)
31+
code += GenHandleReturnFloatCode(methodName, argNames, endCode)
3132

3233
code += tools.FormatCodeIndentLn(`}`, 0)
3334
return code

content/returns/resync/gen_return_int_type.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package resync
22

33
import (
44
"github.com/wenlng/gonacli/config"
5-
args2 "github.com/wenlng/gonacli/content/args/argsync"
5+
"github.com/wenlng/gonacli/content/args/argsync"
66
"github.com/wenlng/gonacli/tools"
77
"strings"
88
)
99

1010
// 生成处理体
11-
func GenHandleReturnIntCode(method string, args []string, varType string) string {
11+
func GenHandleReturnIntCode(method string, args []string, varType string, endCode string) string {
1212
code := ""
1313

1414
// int32 int64 uint32
@@ -20,6 +20,7 @@ func GenHandleReturnIntCode(method string, args []string, varType string) string
2020
code = tools.FormatCodeIndentLn(`int wg_res_ = `+method+`(`+strings.Join(args, ",")+`);`, 2)
2121
}
2222

23+
code += endCode
2324
code += tools.FormatCodeIndentLn(`return Number::New(wg_env, wg_res_);`, 2)
2425
return code
2526
}
@@ -34,10 +35,10 @@ func GenReturnIntTypeCode(export config.Export, varType string) string {
3435
Value _` + methodName + `(const CallbackInfo& wg_info) {`
3536
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)
3637

37-
c, argNames, _ := args2.GenArgCode(args)
38+
c, argNames, endCode := argsync.GenArgCode(args)
3839
code += c
3940

40-
code += GenHandleReturnIntCode(methodName, argNames, varType)
41+
code += GenHandleReturnIntCode(methodName, argNames, varType, endCode)
4142

4243
code += tools.FormatCodeIndentLn(`}`, 0)
4344
return code

content/returns/resync/gen_return_object_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package resync
22

33
import (
44
"github.com/wenlng/gonacli/config"
5-
args2 "github.com/wenlng/gonacli/content/args/argsync"
5+
"github.com/wenlng/gonacli/content/args/argsync"
66
"github.com/wenlng/gonacli/tools"
77
"strings"
88
)
@@ -27,7 +27,7 @@ func GenReturnObjectTypeCode(export config.Export) string {
2727
Value _` + methodName + `(const CallbackInfo& wg_info) {`
2828
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)
2929

30-
c, argNames, endCode := args2.GenArgCode(args)
30+
c, argNames, endCode := argsync.GenArgCode(args)
3131
code += c
3232

3333
code += GenHandleReturnObjectCode(methodName, argNames, endCode)

content/returns/resync/gen_return_string_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package resync
22

33
import (
44
"github.com/wenlng/gonacli/config"
5-
args2 "github.com/wenlng/gonacli/content/args/argsync"
5+
"github.com/wenlng/gonacli/content/args/argsync"
66
"github.com/wenlng/gonacli/tools"
77
"strings"
88
)
@@ -26,7 +26,7 @@ func GenReturnStringTypeCode(export config.Export) string {
2626
Value _` + methodName + `(const CallbackInfo& wg_info) {`
2727
code += tools.FormatCodeIndentLn(`Env wg_env = wg_info.Env();`, 2)
2828

29-
c, argNames, preCode := args2.GenArgCode(args)
29+
c, argNames, preCode := argsync.GenArgCode(args)
3030
code += c
3131

3232
code += GenHandleReturnStringCode(methodName, argNames, preCode)

0 commit comments

Comments
 (0)