Support info.size on wide-char systems via upgrade to C++17 #3943

This commit is contained in:
Lovell Fuller
2024-11-04 18:16:29 +00:00
parent 7bdf419eb1
commit 06b08bf10f
8 changed files with 43 additions and 48 deletions

View File

@@ -45,6 +45,9 @@
'Release': {
'msvs_settings': {
'VCCLCompilerTool': {
"AdditionalOptions": [
"/std:c++17"
],
'ExceptionHandling': 1,
'Optimization': 1,
'WholeProgramOptimization': 'true'
@@ -172,6 +175,7 @@
'-l:libvips-cpp.so.<(vips_version)'
],
'ldflags': [
'-lstdc++fs',
'-Wl,-s',
'-Wl,--disable-new-dtags',
'-Wl,-z,nodelete',
@@ -207,13 +211,13 @@
}]
],
'cflags_cc': [
'-std=c++0x',
'-std=c++17',
'-fexceptions',
'-Wall',
'-Os'
],
'xcode_settings': {
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
'MACOSX_DEPLOYMENT_TARGET': '10.15',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES',
@@ -234,6 +238,9 @@
['OS == "win"', {
'msvs_settings': {
'VCCLCompilerTool': {
"AdditionalOptions": [
"/std:c++17"
],
'ExceptionHandling': 1,
'Optimization': 1,
'WholeProgramOptimization': 'true'

View File

@@ -20,13 +20,9 @@
#error "libvips version 8.16.0+ is required - please see https://sharp.pixelplumbing.com/install"
#endif
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
#error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
#endif
#if (defined(__clang__) && defined(__has_feature))
#if (!__has_feature(cxx_range_for))
#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
#if defined(__has_include)
#if !__has_include(<filesystem>)
#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"
#endif
#endif

View File

@@ -3,6 +3,7 @@
#include <algorithm>
#include <cmath>
#include <filesystem>
#include <map>
#include <memory>
#include <numeric>
@@ -20,17 +21,6 @@
#include "operations.h"
#include "pipeline.h"
#ifdef _WIN32
#define STAT64_STRUCT __stat64
#define STAT64_FUNCTION _stat64
#elif defined(_LARGEFILE64_SOURCE)
#define STAT64_STRUCT stat64
#define STAT64_FUNCTION stat64
#else
#define STAT64_STRUCT stat
#define STAT64_FUNCTION stat
#endif
class PipelineWorker : public Napi::AsyncWorker {
public:
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
@@ -1306,9 +1296,11 @@ class PipelineWorker : public Napi::AsyncWorker {
Callback().Call(Receiver().Value(), { env.Null(), data, info });
} else {
// Add file size to info
struct STAT64_STRUCT st;
if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
info.Set("size", static_cast<uint32_t>(st.st_size));
if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) {
try {
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut));
info.Set("size", size);
} catch (...) {}
}
Callback().Call(Receiver().Value(), { env.Null(), info });
}