From 4ac941a003acadfa027eb883700dff3018414267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Mon, 5 Oct 2026 19:13:43 +0200 Subject: [PATCH] Add aare::ssize_t alias for MSVC (#398) - MSVC has no ssize_t, which made every translation unit fail on Windows. - Define aare::ssize_t in defs.hpp: the platform ssize_t on POSIX (so nothing changes there) and std::ptrdiff_t on MSVC. - Code inside the namespace picks it up unchanged; the few files that use ssize_t outside the namespace get a using-declaration. FilePtr.hpp now includes defs.hpp since it had no aare include. Closing #393 Co-authored-by: Claude Fable 5.1 --- benchmarks/fit_benchmark.cpp | 2 ++ benchmarks/ndarray_benchmark.cpp | 1 + include/aare/FilePtr.hpp | 1 + include/aare/defs.hpp | 17 +++++++++++++++++ python/src/bind_MultiThreadedFileReader.hpp | 1 + python/src/bind_calibration.hpp | 1 + python/src/fit.hpp | 1 + src/ClusterVector.test.cpp | 1 + src/MultiThreadedFileReader.test.cpp | 1 + src/NDArray.test.cpp | 1 + src/NDView.test.cpp | 1 + src/algorithm.test.cpp | 2 ++ src/decode.test.cpp | 1 + src/fit/Fit.test.cpp | 1 + .../PedestalTrackingPixelHistogram.test.cpp | 1 + src/hist/PixelHistogram.test.cpp | 1 + 16 files changed, 34 insertions(+) diff --git a/benchmarks/fit_benchmark.cpp b/benchmarks/fit_benchmark.cpp index 8e522f80..2a307002 100644 --- a/benchmarks/fit_benchmark.cpp +++ b/benchmarks/fit_benchmark.cpp @@ -10,6 +10,8 @@ #include #include +using aare::ssize_t; + struct TestCase { std::string name; double true_A; diff --git a/benchmarks/ndarray_benchmark.cpp b/benchmarks/ndarray_benchmark.cpp index b3a3f610..46e7138e 100644 --- a/benchmarks/ndarray_benchmark.cpp +++ b/benchmarks/ndarray_benchmark.cpp @@ -3,6 +3,7 @@ #include using aare::NDArray; +using aare::ssize_t; constexpr ssize_t size = 1024; class TwoArrays : public benchmark::Fixture { diff --git a/include/aare/FilePtr.hpp b/include/aare/FilePtr.hpp index 2e84b87c..d9753006 100644 --- a/include/aare/FilePtr.hpp +++ b/include/aare/FilePtr.hpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 #pragma once +#include "aare/defs.hpp" #include #include diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index 174bfb6b..43cae3cb 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -13,6 +14,10 @@ #include #include +#if !defined(_MSC_VER) +#include // ::ssize_t +#endif + /** * @brief LOCATION macro to get the current location in the code */ @@ -54,6 +59,18 @@ namespace aare { +/** + * Signed size and index type used throughout the library (shapes, strides, + * frame indices, ROI coordinates). On POSIX this is the platform's ssize_t, + * so nothing changes for existing code. MSVC has no ssize_t, so there it is + * std::ptrdiff_t, which is the same type as Py_ssize_t and NumPy's npy_intp. + */ +#if defined(_MSC_VER) +using ssize_t = std::ptrdiff_t; +#else +using ssize_t = ::ssize_t; +#endif + inline constexpr size_t bits_per_byte = 8; void assert_failed(const std::string &msg); diff --git a/python/src/bind_MultiThreadedFileReader.hpp b/python/src/bind_MultiThreadedFileReader.hpp index f63f79c8..0f39cb6c 100644 --- a/python/src/bind_MultiThreadedFileReader.hpp +++ b/python/src/bind_MultiThreadedFileReader.hpp @@ -16,6 +16,7 @@ #include namespace py = pybind11; +using aare::ssize_t; inline py::dtype multi_threaded_reader_numpy_dtype(const aare::Dtype &dtype) { using aare::Dtype; diff --git a/python/src/bind_calibration.hpp b/python/src/bind_calibration.hpp index 6efa87bc..cdb16b86 100644 --- a/python/src/bind_calibration.hpp +++ b/python/src/bind_calibration.hpp @@ -9,6 +9,7 @@ #include namespace py = pybind11; +using aare::ssize_t; template py::array_t diff --git a/python/src/fit.hpp b/python/src/fit.hpp index f26cc20c..b41b1596 100644 --- a/python/src/fit.hpp +++ b/python/src/fit.hpp @@ -11,6 +11,7 @@ namespace py = pybind11; using namespace pybind11::literals; +using aare::ssize_t; template py::object diff --git a/src/ClusterVector.test.cpp b/src/ClusterVector.test.cpp index 135719c1..7d5b3910 100644 --- a/src/ClusterVector.test.cpp +++ b/src/ClusterVector.test.cpp @@ -12,6 +12,7 @@ using aare::Cluster; using aare::ClusterVector; +using aare::ssize_t; using C1 = Cluster; TEST_CASE("A newly created ClusterVector is empty") { diff --git a/src/MultiThreadedFileReader.test.cpp b/src/MultiThreadedFileReader.test.cpp index 4896d788..c6fdcd90 100644 --- a/src/MultiThreadedFileReader.test.cpp +++ b/src/MultiThreadedFileReader.test.cpp @@ -22,6 +22,7 @@ using aare::File; using aare::FileConfig; using aare::Frame; using aare::NumpyFile; +using aare::ssize_t; using aare::experimental::MultiThreadedFileReader; namespace { diff --git a/src/NDArray.test.cpp b/src/NDArray.test.cpp index 872f22cd..56514102 100644 --- a/src/NDArray.test.cpp +++ b/src/NDArray.test.cpp @@ -9,6 +9,7 @@ using aare::NDArray; using aare::NDView; using aare::Shape; +using aare::ssize_t; TEST_CASE("Initial size is zero if no size is specified") { NDArray a; diff --git a/src/NDView.test.cpp b/src/NDView.test.cpp index 1a8c6a2b..59d231b3 100644 --- a/src/NDView.test.cpp +++ b/src/NDView.test.cpp @@ -11,6 +11,7 @@ using aare::NDView; using aare::num_elements; using aare::Shape; +using aare::ssize_t; static_assert(std::is_convertible_v, NDView>); static_assert(!std::is_convertible_v, NDView>); diff --git a/src/algorithm.test.cpp b/src/algorithm.test.cpp index e498c3b2..026fcacb 100644 --- a/src/algorithm.test.cpp +++ b/src/algorithm.test.cpp @@ -3,6 +3,8 @@ #include #include +using aare::ssize_t; + TEST_CASE("Find the closed index in a 1D array", "[algorithm]") { aare::NDArray arr({5}); for (ssize_t i = 0; i < arr.size(); i++) { diff --git a/src/decode.test.cpp b/src/decode.test.cpp index 09d6c61c..dec59e08 100644 --- a/src/decode.test.cpp +++ b/src/decode.test.cpp @@ -10,6 +10,7 @@ using Catch::Matchers::WithinAbs; #include using aare::BitOffset; +using aare::ssize_t; TEST_CASE("test_adc_sar_05_decode64to16") { uint64_t input = 0; diff --git a/src/fit/Fit.test.cpp b/src/fit/Fit.test.cpp index 992500e8..9c1c7311 100644 --- a/src/fit/Fit.test.cpp +++ b/src/fit/Fit.test.cpp @@ -17,6 +17,7 @@ using aare::Minimizer; using aare::NDArray; using aare::NDView; +using aare::ssize_t; using Catch::Approx; namespace { diff --git a/src/hist/PedestalTrackingPixelHistogram.test.cpp b/src/hist/PedestalTrackingPixelHistogram.test.cpp index 2c9f1590..b8d81df4 100644 --- a/src/hist/PedestalTrackingPixelHistogram.test.cpp +++ b/src/hist/PedestalTrackingPixelHistogram.test.cpp @@ -20,6 +20,7 @@ using aare::FileConfig; using aare::Frame; using aare::NumpyFile; using aare::PedestalTrackingPixelHistogram; +using aare::ssize_t; namespace { diff --git a/src/hist/PixelHistogram.test.cpp b/src/hist/PixelHistogram.test.cpp index 50b1fcec..25767257 100644 --- a/src/hist/PixelHistogram.test.cpp +++ b/src/hist/PixelHistogram.test.cpp @@ -18,6 +18,7 @@ using aare::NDArray; using aare::NDView; using aare::PixelHistogram; +using aare::ssize_t; namespace { // The synchronous fill() has been removed; fill_async() is the only entry