Skip to content

Commit

Permalink
fix errors and warnings in VS 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoroz committed Dec 16, 2022
1 parent ad7ff92 commit 5b26376
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion test/addon_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Addon {

static void DeleteAddon(Napi::Env, Addon* addon, uint32_t* hint) {
delete addon;
fprintf(stderr, "hint: %d\n", *hint);
fprintf(stderr, "hint: %u\n", *hint);
delete hint;
}

Expand Down
4 changes: 2 additions & 2 deletions test/async_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class FailCancelWorker : public AsyncWorker {
#ifdef NAPI_CPP_EXCEPTIONS
try {
cancelWorker->Cancel();
} catch (Napi::Error& e) {
} catch (Napi::Error&) {
Napi::Error::New(info.Env(), "Unable to cancel async worker tasks")
.ThrowAsJavaScriptException();
}
Expand Down Expand Up @@ -193,7 +193,7 @@ class CancelWorker : public AsyncWorker {
#ifdef NAPI_CPP_EXCEPTIONS
try {
cancelWorker->Cancel();
} catch (Napi::Error& e) {
} catch (Napi::Error&) {
Napi::Error::New(info.Env(), "Unable to cancel async worker tasks")
.ThrowAsJavaScriptException();
}
Expand Down
2 changes: 1 addition & 1 deletion test/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'object/subscript_operator.cc',
'promise.cc',
'run_script.cc',
"symbol.cc",
'symbol.cc',
'threadsafe_function/threadsafe_function_ctx.cc',
'threadsafe_function/threadsafe_function_existing_tsfn.cc',
'threadsafe_function/threadsafe_function_ptr.cc',
Expand Down
28 changes: 15 additions & 13 deletions test/function_reference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ Value CallWithRecvVector(const CallbackInfo& info) {
Value CallWithRecvArgc(const CallbackInfo& info) {
HandleScope scope(info.Env());
FunctionReference ref;
int argLength = info.Length() - 2;
napi_value* args = new napi_value[argLength];
ref.Reset(info[0].As<Function>());

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

return MaybeUnwrap(ref.Call(info[1], argLength, args));
return MaybeUnwrap(ref.Call(info[1], argLength, args.get()));
}

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

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

Napi::AsyncContext context(info.Env(), "func_ref_resources", {});
return MaybeUnwrap(ref.MakeCallback(
Napi::Object::New(info.Env()), argLength, args, context));
return MaybeUnwrap(ref.MakeCallback(Napi::Object::New(info.Env()),
argLength,
argLength > 0 ? args.get() : nullptr,
context));
}

Value CreateFunctionReferenceUsingNew(const Napi::CallbackInfo& info) {
Expand Down
38 changes: 19 additions & 19 deletions test/threadsafe_function/threadsafe_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ constexpr size_t ARRAY_LENGTH = 10;
constexpr size_t MAX_QUEUE_SIZE = 2;

static std::thread threads[2];
static ThreadSafeFunction tsfn;
static ThreadSafeFunction s_tsfn;

struct ThreadSafeFunctionInfo {
enum CallType { DEFAULT, BLOCKING, NON_BLOCKING } type;
Expand All @@ -29,17 +29,17 @@ struct ThreadSafeFunctionInfo {
static int ints[ARRAY_LENGTH];

static void SecondaryThread() {
if (tsfn.Release() != napi_ok) {
if (s_tsfn.Release() != napi_ok) {
Error::Fatal("SecondaryThread", "ThreadSafeFunction.Release() failed");
}
}

// Source thread producing the data
static void DataSourceThread() {
ThreadSafeFunctionInfo* info = tsfn.GetContext();
ThreadSafeFunctionInfo* info = s_tsfn.GetContext();

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

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

switch (info->type) {
case ThreadSafeFunctionInfo::DEFAULT:
status = tsfn.BlockingCall();
status = s_tsfn.BlockingCall();
break;
case ThreadSafeFunctionInfo::BLOCKING:
status = tsfn.BlockingCall(&ints[index], callback);
status = s_tsfn.BlockingCall(&ints[index], callback);
break;
case ThreadSafeFunctionInfo::NON_BLOCKING:
status = tsfn.NonBlockingCall(&ints[index], callback);
status = s_tsfn.NonBlockingCall(&ints[index], callback);
break;
}

Expand Down Expand Up @@ -101,7 +101,7 @@ static void DataSourceThread() {
Error::Fatal("DataSourceThread", "Queue was never closing");
}

if (!queueWasClosing && tsfn.Release() != napi_ok) {
if (!queueWasClosing && s_tsfn.Release() != napi_ok) {
Error::Fatal("DataSourceThread", "ThreadSafeFunction.Release() failed");
}
}
Expand All @@ -110,9 +110,9 @@ static Value StopThread(const CallbackInfo& info) {
tsfnInfo.jsFinalizeCallback = Napi::Persistent(info[0].As<Function>());
bool abort = info[1].As<Boolean>();
if (abort) {
tsfn.Abort();
s_tsfn.Abort();
} else {
tsfn.Release();
s_tsfn.Release();
}
{
std::lock_guard<std::mutex> _(tsfnInfo.protect);
Expand Down Expand Up @@ -143,22 +143,22 @@ static Value StartThreadInternal(const CallbackInfo& info,
tsfnInfo.maxQueueSize = info[3].As<Number>().Uint32Value();
tsfnInfo.closeCalledFromJs = false;

tsfn = ThreadSafeFunction::New(info.Env(),
info[0].As<Function>(),
"Test",
tsfnInfo.maxQueueSize,
2,
&tsfnInfo,
JoinTheThreads,
threads);
s_tsfn = ThreadSafeFunction::New(info.Env(),
info[0].As<Function>(),
"Test",
tsfnInfo.maxQueueSize,
2,
&tsfnInfo,
JoinTheThreads,
threads);

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

return Value();
}

static Value Release(const CallbackInfo& /* info */) {
if (tsfn.Release() != napi_ok) {
if (s_tsfn.Release() != napi_ok) {
Error::Fatal("Release", "ThreadSafeFunction.Release() failed");
}
return Value();
Expand Down
40 changes: 20 additions & 20 deletions test/typed_threadsafe_function/typed_threadsafe_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ static void TSFNCallJS(Env env,
}

using TSFN = TypedThreadSafeFunction<ThreadSafeFunctionInfo, int, TSFNCallJS>;
static TSFN tsfn;
static TSFN s_tsfn;

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

static void SecondaryThread() {
if (tsfn.Release() != napi_ok) {
if (s_tsfn.Release() != napi_ok) {
Error::Fatal("TypedSecondaryThread", "ThreadSafeFunction.Release() failed");
}
}

// Source thread producing the data
static void DataSourceThread() {
ThreadSafeFunctionInfo* info = tsfn.GetContext();
ThreadSafeFunctionInfo* info = s_tsfn.GetContext();

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

switch (info->type) {
case ThreadSafeFunctionInfo::DEFAULT:
status = tsfn.BlockingCall();
status = s_tsfn.BlockingCall();
break;
case ThreadSafeFunctionInfo::BLOCKING:
status = tsfn.BlockingCall(&ints[index]);
status = s_tsfn.BlockingCall(&ints[index]);
break;
case ThreadSafeFunctionInfo::NON_BLOCKING:
status = tsfn.NonBlockingCall(&ints[index]);
status = s_tsfn.NonBlockingCall(&ints[index]);
break;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ static void DataSourceThread() {
Error::Fatal("TypedDataSourceThread", "Queue was never closing");
}

if (!queueWasClosing && tsfn.Release() != napi_ok) {
if (!queueWasClosing && s_tsfn.Release() != napi_ok) {
Error::Fatal("TypedDataSourceThread",
"ThreadSafeFunction.Release() failed");
}
Expand All @@ -127,9 +127,9 @@ static Value StopThread(const CallbackInfo& info) {
tsfnInfo.jsFinalizeCallback = Napi::Persistent(info[0].As<Function>());
bool abort = info[1].As<Boolean>();
if (abort) {
tsfn.Abort();
s_tsfn.Abort();
} else {
tsfn.Release();
s_tsfn.Release();
}
{
std::lock_guard<std::mutex> _(tsfnInfo.protect);
Expand Down Expand Up @@ -160,23 +160,23 @@ static Value StartThreadInternal(const CallbackInfo& info,
tsfnInfo.maxQueueSize = info[3].As<Number>().Uint32Value();
tsfnInfo.closeCalledFromJs = false;

tsfn = TSFN::New(info.Env(),
info[0].As<Function>(),
Object::New(info.Env()),
"Test",
tsfnInfo.maxQueueSize,
2,
&tsfnInfo,
JoinTheThreads,
threads);
s_tsfn = TSFN::New(info.Env(),
info[0].As<Function>(),
Object::New(info.Env()),
"Test",
tsfnInfo.maxQueueSize,
2,
&tsfnInfo,
JoinTheThreads,
threads);

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

return Value();
}

static Value Release(const CallbackInfo& /* info */) {
if (tsfn.Release() != napi_ok) {
if (s_tsfn.Release() != napi_ok) {
Error::Fatal("Release", "TypedThreadSafeFunction.Release() failed");
}
return Value();
Expand Down

0 comments on commit 5b26376

Please sign in to comment.