Skip to content

Commit

Permalink
Unpin node-addon-api, cast CallbackInfo access to size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jan 16, 2023
1 parent a9bd0e7 commit bdc50e1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"dependencies": {
"color": "^4.2.3",
"detect-libc": "^2.0.1",
"node-addon-api": "5.0.0",
"node-addon-api": "^5.1.0",
"prebuild-install": "^7.1.1",
"semver": "^7.3.8",
"simple-get": "^4.0.1",
Expand Down
4 changes: 3 additions & 1 deletion src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ namespace sharp {
Napi::Buffer<char> NewOrCopyBuffer(Napi::Env env, char* data, size_t len) {
try {
return Napi::Buffer<char>::New(env, data, len, FreeCallback);
} catch (Napi::Error const &err) {}
} catch (Napi::Error const &err) {
static_cast<void>(err);
}
Napi::Buffer<char> buf = Napi::Buffer<char>::Copy(env, data, len);
FreeCallback(nullptr, data);
return buf;
Expand Down
4 changes: 2 additions & 2 deletions src/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class MetadataWorker : public Napi::AsyncWorker {
Napi::Value metadata(const Napi::CallbackInfo& info) {
// V8 objects are converted to non-V8 types held in the baton struct
MetadataBaton *baton = new MetadataBaton;
Napi::Object options = info[0].As<Napi::Object>();
Napi::Object options = info[size_t(0)].As<Napi::Object>();

// Input
baton->input = sharp::CreateInputDescriptor(options.Get("input").As<Napi::Object>());
Expand All @@ -285,7 +285,7 @@ Napi::Value metadata(const Napi::CallbackInfo& info) {
Napi::Function debuglog = options.Get("debuglog").As<Napi::Function>();

// Join queue for worker thread
Napi::Function callback = info[1].As<Napi::Function>();
Napi::Function callback = info[size_t(1)].As<Napi::Function>();
MetadataWorker *worker = new MetadataWorker(callback, baton, debuglog);
worker->Receiver().Set("options", options);
worker->Queue();
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ class PipelineWorker : public Napi::AsyncWorker {
Napi::Value pipeline(const Napi::CallbackInfo& info) {
// V8 objects are converted to non-V8 types held in the baton struct
PipelineBaton *baton = new PipelineBaton;
Napi::Object options = info[0].As<Napi::Object>();
Napi::Object options = info[size_t(0)].As<Napi::Object>();

// Input
baton->input = sharp::CreateInputDescriptor(options.Get("input").As<Napi::Object>());
Expand Down Expand Up @@ -1661,7 +1661,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
Napi::Function queueListener = options.Get("queueListener").As<Napi::Function>();

// Join queue for worker thread
Napi::Function callback = info[1].As<Napi::Function>();
Napi::Function callback = info[size_t(1)].As<Napi::Function>();
PipelineWorker *worker = new PipelineWorker(callback, baton, debuglog, queueListener);
worker->Receiver().Set("options", options);
worker->Queue();
Expand Down
4 changes: 2 additions & 2 deletions src/stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class StatsWorker : public Napi::AsyncWorker {
Napi::Value stats(const Napi::CallbackInfo& info) {
// V8 objects are converted to non-V8 types held in the baton struct
StatsBaton *baton = new StatsBaton;
Napi::Object options = info[0].As<Napi::Object>();
Napi::Object options = info[size_t(0)].As<Napi::Object>();

// Input
baton->input = sharp::CreateInputDescriptor(options.Get("input").As<Napi::Object>());
Expand All @@ -182,7 +182,7 @@ Napi::Value stats(const Napi::CallbackInfo& info) {
Napi::Function debuglog = options.Get("debuglog").As<Napi::Function>();

// Join queue for worker thread
Napi::Function callback = info[1].As<Napi::Function>();
Napi::Function callback = info[size_t(1)].As<Napi::Function>();
StatsWorker *worker = new StatsWorker(callback, baton, debuglog);
worker->Receiver().Set("options", options);
worker->Queue();
Expand Down
28 changes: 14 additions & 14 deletions src/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ Napi::Value cache(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();

// Set memory limit
if (info[0].IsNumber()) {
vips_cache_set_max_mem(info[0].As<Napi::Number>().Int32Value() * 1048576);
if (info[size_t(0)].IsNumber()) {
vips_cache_set_max_mem(info[size_t(0)].As<Napi::Number>().Int32Value() * 1048576);
}
// Set file limit
if (info[1].IsNumber()) {
vips_cache_set_max_files(info[1].As<Napi::Number>().Int32Value());
if (info[size_t(1)].IsNumber()) {
vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Int32Value());
}
// Set items limit
if (info[2].IsNumber()) {
vips_cache_set_max(info[2].As<Napi::Number>().Int32Value());
if (info[size_t(2)].IsNumber()) {
vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Int32Value());
}

// Get memory stats
Expand Down Expand Up @@ -69,8 +69,8 @@ Napi::Value cache(const Napi::CallbackInfo& info) {
*/
Napi::Value concurrency(const Napi::CallbackInfo& info) {
// Set concurrency
if (info[0].IsNumber()) {
vips_concurrency_set(info[0].As<Napi::Number>().Int32Value());
if (info[size_t(0)].IsNumber()) {
vips_concurrency_set(info[size_t(0)].As<Napi::Number>().Int32Value());
}
// Get concurrency
return Napi::Number::New(info.Env(), vips_concurrency_get());
Expand All @@ -91,8 +91,8 @@ Napi::Value counters(const Napi::CallbackInfo& info) {
*/
Napi::Value simd(const Napi::CallbackInfo& info) {
// Set state
if (info[0].IsBoolean()) {
vips_vector_set_enabled(info[0].As<Napi::Boolean>().Value());
if (info[size_t(0)].IsBoolean()) {
vips_vector_set_enabled(info[size_t(0)].As<Napi::Boolean>().Value());
}
// Get state
return Napi::Boolean::New(info.Env(), vips_vector_isenabled());
Expand Down Expand Up @@ -185,21 +185,21 @@ Napi::Value _maxColourDistance(const Napi::CallbackInfo& info) {

// Open input files
VImage image1;
sharp::ImageType imageType1 = sharp::DetermineImageType(info[0].As<Napi::String>().Utf8Value().data());
sharp::ImageType imageType1 = sharp::DetermineImageType(info[size_t(0)].As<Napi::String>().Utf8Value().data());
if (imageType1 != sharp::ImageType::UNKNOWN) {
try {
image1 = VImage::new_from_file(info[0].As<Napi::String>().Utf8Value().c_str());
image1 = VImage::new_from_file(info[size_t(0)].As<Napi::String>().Utf8Value().c_str());
} catch (...) {
throw Napi::Error::New(env, "Input file 1 has corrupt header");
}
} else {
throw Napi::Error::New(env, "Input file 1 is of an unsupported image format");
}
VImage image2;
sharp::ImageType imageType2 = sharp::DetermineImageType(info[1].As<Napi::String>().Utf8Value().data());
sharp::ImageType imageType2 = sharp::DetermineImageType(info[size_t(1)].As<Napi::String>().Utf8Value().data());
if (imageType2 != sharp::ImageType::UNKNOWN) {
try {
image2 = VImage::new_from_file(info[1].As<Napi::String>().Utf8Value().c_str());
image2 = VImage::new_from_file(info[size_t(1)].As<Napi::String>().Utf8Value().c_str());
} catch (...) {
throw Napi::Error::New(env, "Input file 2 has corrupt header");
}
Expand Down

0 comments on commit bdc50e1

Please sign in to comment.