From 2678d761bad4c6c2ee1b737bb95200b0bd8252c3 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sat, 14 Nov 2015 13:58:05 +0000 Subject: [PATCH] Use FreeCallback to support mixed Windows runtime libs #152 --- binding.js | 6 +++--- src/common.cc | 9 +++++++++ src/common.h | 5 +++++ src/metadata.cc | 11 +++++++++-- src/pipeline.cc | 5 ++++- test/leak/sharp.supp | 7 +++++++ 6 files changed, 37 insertions(+), 6 deletions(-) mode change 100755 => 100644 src/common.cc mode change 100755 => 100644 src/common.h mode change 100755 => 100644 src/metadata.cc mode change 100755 => 100644 src/pipeline.cc diff --git a/binding.js b/binding.js index 45b3d4e3..6593218d 100644 --- a/binding.js +++ b/binding.js @@ -54,9 +54,9 @@ var error = function(msg) { module.exports.download_vips = function() { // Has vips been installed locally? if (!isFile(vipsHeaderPath)) { - // 32-bit - if (process.arch === 'ia32') { - error('32-bit systems require manual installation - please see http://sharp.dimens.io/en/stable/install/'); + // Ensure 64-bit + if (process.arch !== 'x64') { + error('ARM and 32-bit systems require manual installation - please see http://sharp.dimens.io/en/stable/install/'); } // Ensure libc >= 2.15 var lddVersion = process.env.LDD_VERSION; diff --git a/src/common.cc b/src/common.cc old mode 100755 new mode 100644 index 9533df02..9e4205bc --- a/src/common.cc +++ b/src/common.cc @@ -177,4 +177,13 @@ namespace sharp { return window_size; } + /* + Called when a Buffer undergoes GC, required to support mixed runtime libraries in Windows + */ + void FreeCallback(char* data, void* hint) { + if (data != NULL) { + g_free(data); + } + } + } // namespace sharp diff --git a/src/common.h b/src/common.h old mode 100755 new mode 100644 index 09296a54..88e081d2 --- a/src/common.h +++ b/src/common.h @@ -80,6 +80,11 @@ namespace sharp { */ int InterpolatorWindowSize(char const *name); + /* + Called when a Buffer undergoes GC, required to support mixed runtime libraries in Windows + */ + void FreeCallback(char* data, void* hint); + } // namespace sharp #endif // SRC_COMMON_H_ diff --git a/src/metadata.cc b/src/metadata.cc old mode 100755 new mode 100644 index a3acb902..795b3c0a --- a/src/metadata.cc +++ b/src/metadata.cc @@ -35,6 +35,7 @@ using sharp::InitImage; using sharp::HasProfile; using sharp::HasAlpha; using sharp::ExifOrientation; +using sharp::FreeCallback; using sharp::counterQueue; struct MetadataBaton { @@ -175,10 +176,16 @@ class MetadataWorker : public AsyncWorker { Set(info, New("orientation").ToLocalChecked(), New(baton->orientation)); } if (baton->exifLength > 0) { - Set(info, New("exif").ToLocalChecked(), NewBuffer(baton->exif, baton->exifLength).ToLocalChecked()); + Set(info, + New("exif").ToLocalChecked(), + NewBuffer(baton->exif, baton->exifLength, FreeCallback, nullptr).ToLocalChecked() + ); } if (baton->iccLength > 0) { - Set(info, New("icc").ToLocalChecked(), NewBuffer(baton->icc, baton->iccLength).ToLocalChecked()); + Set(info, + New("icc").ToLocalChecked(), + NewBuffer(baton->icc, baton->iccLength, FreeCallback, nullptr).ToLocalChecked() + ); } argv[1] = info; } diff --git a/src/pipeline.cc b/src/pipeline.cc old mode 100755 new mode 100644 index 10f2e4b4..c0ae7c8a --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -55,6 +55,7 @@ using sharp::IsPng; using sharp::IsWebp; using sharp::IsTiff; using sharp::IsDz; +using sharp::FreeCallback; using sharp::counterProcess; using sharp::counterQueue; @@ -959,7 +960,9 @@ class PipelineWorker : public AsyncWorker { if (baton->bufferOutLength > 0) { // Pass ownership of output data to Buffer instance - argv[1] = NewBuffer(static_cast(baton->bufferOut), baton->bufferOutLength).ToLocalChecked(); + argv[1] = NewBuffer( + static_cast(baton->bufferOut), baton->bufferOutLength, FreeCallback, nullptr + ).ToLocalChecked(); // Add buffer size to info Set(info, New("size").ToLocalChecked(), New(static_cast(baton->bufferOutLength))); argv[2] = info; diff --git a/test/leak/sharp.supp b/test/leak/sharp.supp index 9efe0062..bf224789 100644 --- a/test/leak/sharp.supp +++ b/test/leak/sharp.supp @@ -285,6 +285,13 @@ ... fun:get_bands } +{ + value_magick_is_palette_image + Memcheck:Value8 + fun:IsPaletteImage + ... + fun:get_bands +} # glib g_file_read_link # https://github.com/GNOME/glib/commit/49a5d0f6f2aed99cd78f25655f137f4448e47d92