Skip to content

Commit 5b26376

Browse files
committed
fix errors and warnings in VS 2017
1 parent ad7ff92 commit 5b26376

File tree

6 files changed

+58
-56
lines changed

6 files changed

+58
-56
lines changed

test/addon_data.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Addon {
5959

6060
static void DeleteAddon(Napi::Env, Addon* addon, uint32_t* hint) {
6161
delete addon;
62-
fprintf(stderr, "hint: %d\n", *hint);
62+
fprintf(stderr, "hint: %u\n", *hint);
6363
delete hint;
6464
}
6565

test/async_worker.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class FailCancelWorker : public AsyncWorker {
152152
#ifdef NAPI_CPP_EXCEPTIONS
153153
try {
154154
cancelWorker->Cancel();
155-
} catch (Napi::Error& e) {
155+
} catch (Napi::Error&) {
156156
Napi::Error::New(info.Env(), "Unable to cancel async worker tasks")
157157
.ThrowAsJavaScriptException();
158158
}
@@ -193,7 +193,7 @@ class CancelWorker : public AsyncWorker {
193193
#ifdef NAPI_CPP_EXCEPTIONS
194194
try {
195195
cancelWorker->Cancel();
196-
} catch (Napi::Error& e) {
196+
} catch (Napi::Error&) {
197197
Napi::Error::New(info.Env(), "Unable to cancel async worker tasks")
198198
.ThrowAsJavaScriptException();
199199
}

test/binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'object/subscript_operator.cc',
5151
'promise.cc',
5252
'run_script.cc',
53-
"symbol.cc",
53+
'symbol.cc',
5454
'threadsafe_function/threadsafe_function_ctx.cc',
5555
'threadsafe_function/threadsafe_function_existing_tsfn.cc',
5656
'threadsafe_function/threadsafe_function_ptr.cc',

test/function_reference.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ Value CallWithRecvVector(const CallbackInfo& info) {
8282
Value CallWithRecvArgc(const CallbackInfo& info) {
8383
HandleScope scope(info.Env());
8484
FunctionReference ref;
85-
int argLength = info.Length() - 2;
86-
napi_value* args = new napi_value[argLength];
8785
ref.Reset(info[0].As<Function>());
8886

89-
int argIdx = 0;
90-
for (int i = 2; i < (int)info.Length(); i++, argIdx++) {
91-
args[argIdx] = info[i];
87+
size_t argLength = info.Length() > 2 ? info.Length() - 2 : 0;
88+
std::unique_ptr<napi_value[]> args{argLength > 0 ? new napi_value[argLength]
89+
: nullptr};
90+
for (size_t i = 0; i < argLength; ++i) {
91+
args[i] = info[i + 2];
9292
}
9393

94-
return MaybeUnwrap(ref.Call(info[1], argLength, args));
94+
return MaybeUnwrap(ref.Call(info[1], argLength, args.get()));
9595
}
9696

9797
Value MakeAsyncCallbackWithInitList(const Napi::CallbackInfo& info) {
@@ -121,17 +121,19 @@ Value MakeAsyncCallbackWithVector(const Napi::CallbackInfo& info) {
121121
Value MakeAsyncCallbackWithArgv(const Napi::CallbackInfo& info) {
122122
Napi::FunctionReference ref;
123123
ref.Reset(info[0].As<Function>());
124-
int argLength = info.Length() - 1;
125-
napi_value* args = new napi_value[argLength];
126124

127-
int argIdx = 0;
128-
for (int i = 1; i < (int)info.Length(); i++, argIdx++) {
129-
args[argIdx] = info[i];
125+
size_t argLength = info.Length() > 1 ? info.Length() - 1 : 0;
126+
std::unique_ptr<napi_value[]> args{argLength > 0 ? new napi_value[argLength]
127+
: nullptr};
128+
for (size_t i = 0; i < argLength; ++i) {
129+
args[i] = info[i + 1];
130130
}
131131

132132
Napi::AsyncContext context(info.Env(), "func_ref_resources", {});
133-
return MaybeUnwrap(ref.MakeCallback(
134-
Napi::Object::New(info.Env()), argLength, args, context));
133+
return MaybeUnwrap(ref.MakeCallback(Napi::Object::New(info.Env()),
134+
argLength,
135+
argLength > 0 ? args.get() : nullptr,
136+
context));
135137
}
136138

137139
Value CreateFunctionReferenceUsingNew(const Napi::CallbackInfo& info) {

test/threadsafe_function/threadsafe_function.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ constexpr size_t ARRAY_LENGTH = 10;
1212
constexpr size_t MAX_QUEUE_SIZE = 2;
1313

1414
static std::thread threads[2];
15-
static ThreadSafeFunction tsfn;
15+
static ThreadSafeFunction s_tsfn;
1616

1717
struct ThreadSafeFunctionInfo {
1818
enum CallType { DEFAULT, BLOCKING, NON_BLOCKING } type;
@@ -29,17 +29,17 @@ struct ThreadSafeFunctionInfo {
2929
static int ints[ARRAY_LENGTH];
3030

3131
static void SecondaryThread() {
32-
if (tsfn.Release() != napi_ok) {
32+
if (s_tsfn.Release() != napi_ok) {
3333
Error::Fatal("SecondaryThread", "ThreadSafeFunction.Release() failed");
3434
}
3535
}
3636

3737
// Source thread producing the data
3838
static void DataSourceThread() {
39-
ThreadSafeFunctionInfo* info = tsfn.GetContext();
39+
ThreadSafeFunctionInfo* info = s_tsfn.GetContext();
4040

4141
if (info->startSecondary) {
42-
if (tsfn.Acquire() != napi_ok) {
42+
if (s_tsfn.Acquire() != napi_ok) {
4343
Error::Fatal("DataSourceThread", "ThreadSafeFunction.Acquire() failed");
4444
}
4545

@@ -56,13 +56,13 @@ static void DataSourceThread() {
5656

5757
switch (info->type) {
5858
case ThreadSafeFunctionInfo::DEFAULT:
59-
status = tsfn.BlockingCall();
59+
status = s_tsfn.BlockingCall();
6060
break;
6161
case ThreadSafeFunctionInfo::BLOCKING:
62-
status = tsfn.BlockingCall(&ints[index], callback);
62+
status = s_tsfn.BlockingCall(&ints[index], callback);
6363
break;
6464
case ThreadSafeFunctionInfo::NON_BLOCKING:
65-
status = tsfn.NonBlockingCall(&ints[index], callback);
65+
status = s_tsfn.NonBlockingCall(&ints[index], callback);
6666
break;
6767
}
6868

@@ -101,7 +101,7 @@ static void DataSourceThread() {
101101
Error::Fatal("DataSourceThread", "Queue was never closing");
102102
}
103103

104-
if (!queueWasClosing && tsfn.Release() != napi_ok) {
104+
if (!queueWasClosing && s_tsfn.Release() != napi_ok) {
105105
Error::Fatal("DataSourceThread", "ThreadSafeFunction.Release() failed");
106106
}
107107
}
@@ -110,9 +110,9 @@ static Value StopThread(const CallbackInfo& info) {
110110
tsfnInfo.jsFinalizeCallback = Napi::Persistent(info[0].As<Function>());
111111
bool abort = info[1].As<Boolean>();
112112
if (abort) {
113-
tsfn.Abort();
113+
s_tsfn.Abort();
114114
} else {
115-
tsfn.Release();
115+
s_tsfn.Release();
116116
}
117117
{
118118
std::lock_guard<std::mutex> _(tsfnInfo.protect);
@@ -143,22 +143,22 @@ static Value StartThreadInternal(const CallbackInfo& info,
143143
tsfnInfo.maxQueueSize = info[3].As<Number>().Uint32Value();
144144
tsfnInfo.closeCalledFromJs = false;
145145

146-
tsfn = ThreadSafeFunction::New(info.Env(),
147-
info[0].As<Function>(),
148-
"Test",
149-
tsfnInfo.maxQueueSize,
150-
2,
151-
&tsfnInfo,
152-
JoinTheThreads,
153-
threads);
146+
s_tsfn = ThreadSafeFunction::New(info.Env(),
147+
info[0].As<Function>(),
148+
"Test",
149+
tsfnInfo.maxQueueSize,
150+
2,
151+
&tsfnInfo,
152+
JoinTheThreads,
153+
threads);
154154

155155
threads[0] = std::thread(DataSourceThread);
156156

157157
return Value();
158158
}
159159

160160
static Value Release(const CallbackInfo& /* info */) {
161-
if (tsfn.Release() != napi_ok) {
161+
if (s_tsfn.Release() != napi_ok) {
162162
Error::Fatal("Release", "ThreadSafeFunction.Release() failed");
163163
}
164164
return Value();

test/typed_threadsafe_function/typed_threadsafe_function.cc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ static void TSFNCallJS(Env env,
4040
}
4141

4242
using TSFN = TypedThreadSafeFunction<ThreadSafeFunctionInfo, int, TSFNCallJS>;
43-
static TSFN tsfn;
43+
static TSFN s_tsfn;
4444

4545
// Thread data to transmit to JS
4646
static int ints[ARRAY_LENGTH];
4747

4848
static void SecondaryThread() {
49-
if (tsfn.Release() != napi_ok) {
49+
if (s_tsfn.Release() != napi_ok) {
5050
Error::Fatal("TypedSecondaryThread", "ThreadSafeFunction.Release() failed");
5151
}
5252
}
5353

5454
// Source thread producing the data
5555
static void DataSourceThread() {
56-
ThreadSafeFunctionInfo* info = tsfn.GetContext();
56+
ThreadSafeFunctionInfo* info = s_tsfn.GetContext();
5757

5858
if (info->startSecondary) {
59-
if (tsfn.Acquire() != napi_ok) {
59+
if (s_tsfn.Acquire() != napi_ok) {
6060
Error::Fatal("TypedDataSourceThread",
6161
"ThreadSafeFunction.Acquire() failed");
6262
}
@@ -71,13 +71,13 @@ static void DataSourceThread() {
7171

7272
switch (info->type) {
7373
case ThreadSafeFunctionInfo::DEFAULT:
74-
status = tsfn.BlockingCall();
74+
status = s_tsfn.BlockingCall();
7575
break;
7676
case ThreadSafeFunctionInfo::BLOCKING:
77-
status = tsfn.BlockingCall(&ints[index]);
77+
status = s_tsfn.BlockingCall(&ints[index]);
7878
break;
7979
case ThreadSafeFunctionInfo::NON_BLOCKING:
80-
status = tsfn.NonBlockingCall(&ints[index]);
80+
status = s_tsfn.NonBlockingCall(&ints[index]);
8181
break;
8282
}
8383

@@ -117,7 +117,7 @@ static void DataSourceThread() {
117117
Error::Fatal("TypedDataSourceThread", "Queue was never closing");
118118
}
119119

120-
if (!queueWasClosing && tsfn.Release() != napi_ok) {
120+
if (!queueWasClosing && s_tsfn.Release() != napi_ok) {
121121
Error::Fatal("TypedDataSourceThread",
122122
"ThreadSafeFunction.Release() failed");
123123
}
@@ -127,9 +127,9 @@ static Value StopThread(const CallbackInfo& info) {
127127
tsfnInfo.jsFinalizeCallback = Napi::Persistent(info[0].As<Function>());
128128
bool abort = info[1].As<Boolean>();
129129
if (abort) {
130-
tsfn.Abort();
130+
s_tsfn.Abort();
131131
} else {
132-
tsfn.Release();
132+
s_tsfn.Release();
133133
}
134134
{
135135
std::lock_guard<std::mutex> _(tsfnInfo.protect);
@@ -160,23 +160,23 @@ static Value StartThreadInternal(const CallbackInfo& info,
160160
tsfnInfo.maxQueueSize = info[3].As<Number>().Uint32Value();
161161
tsfnInfo.closeCalledFromJs = false;
162162

163-
tsfn = TSFN::New(info.Env(),
164-
info[0].As<Function>(),
165-
Object::New(info.Env()),
166-
"Test",
167-
tsfnInfo.maxQueueSize,
168-
2,
169-
&tsfnInfo,
170-
JoinTheThreads,
171-
threads);
163+
s_tsfn = TSFN::New(info.Env(),
164+
info[0].As<Function>(),
165+
Object::New(info.Env()),
166+
"Test",
167+
tsfnInfo.maxQueueSize,
168+
2,
169+
&tsfnInfo,
170+
JoinTheThreads,
171+
threads);
172172

173173
threads[0] = std::thread(DataSourceThread);
174174

175175
return Value();
176176
}
177177

178178
static Value Release(const CallbackInfo& /* info */) {
179-
if (tsfn.Release() != napi_ok) {
179+
if (s_tsfn.Release() != napi_ok) {
180180
Error::Fatal("Release", "TypedThreadSafeFunction.Release() failed");
181181
}
182182
return Value();

0 commit comments

Comments
 (0)