From 0953ffeee80abdd8e79ddacc7066eb02c78968e7 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 21 Aug 2025 23:04:57 +0000 Subject: support ptrdiff_t if it has the same storage size as int, but does *not* alias it * This is the case e.g. on NetBSD 10 for ARMv6 where Sci::Position == ptrdiff_t == long int, but obviously for other platforms as well, where it causes "invalid conversion" and "undefined symbol" errors. Scintilla was testing for aliasability by comparing the storage size with sizeof() or PTRDIFF_MAX == INT_MAX at the preprocessor level. This was fundamentally flawed. * In LineVector::InsertLines() we are now using the C++17 construct std::is_convertible_v instead. * We need RunStyles as well on the affected platforms. AFAIK this is impossible to test for in a constant expression that can be used with the preprocessor. A workaround has been added previously for Haiku: https://groups.google.com/g/scintilla-interest/c/xPXquJUIXo8/m/BLXBpTTgBwAJ The workaround is not very robust, as probably nobody guarantees that ptrdiff_t never aliases on Haiku. If it does, you will suddenly get errors about duplicate template instantiations. Instead we now instantiate RunStyles for all scalar types that could possibly be behind ptrdiff_t. This will always be more than what is required on any particular platform, but the linker should eliminate unused symbols. --- src/CellBuffer.cxx | 3 ++- src/RunStyles.cxx | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 04486d4c6..3e9deb934 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include "ScintillaTypes.h" @@ -215,7 +216,7 @@ public: } void InsertLines(Sci::Line line, const Sci::Position *positions, size_t lines, bool lineStart) override { const POS lineAsPos = pos_cast(line); - if constexpr (sizeof(Sci::Position) == sizeof(POS)) { + if constexpr (std::is_convertible_v) { starts.InsertPartitions(lineAsPos, positions, lines); } else { starts.InsertPartitionsWithCast(lineAsPos, positions, lines); diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx index 848670ba9..4fac2c2b3 100644 --- a/src/RunStyles.cxx +++ b/src/RunStyles.cxx @@ -319,9 +319,10 @@ void RunStyles::Check() const { } } +// should also cover all possible types underlying ptrdiff_t (Sci::Position) template class Scintilla::Internal::RunStyles; template class Scintilla::Internal::RunStyles; -#if (PTRDIFF_MAX != INT_MAX) || defined(__HAIKU__) -template class Scintilla::Internal::RunStyles; -template class Scintilla::Internal::RunStyles; -#endif +template class Scintilla::Internal::RunStyles; +template class Scintilla::Internal::RunStyles; +template class Scintilla::Internal::RunStyles; +template class Scintilla::Internal::RunStyles; -- cgit v1.2.3