aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-08-21 23:04:57 +0000
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-08-26 17:36:33 +0300
commit0953ffeee80abdd8e79ddacc7066eb02c78968e7 (patch)
tree2efc33f98d60261d3e0cefb30273786f3c9a18b0
parentb1be61a1f449360187a6d9ff0b49f837177ffe9a (diff)
downloadscintilla-mirror-0953ffeee80abdd8e79ddacc7066eb02c78968e7.tar.gz
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<T>::InsertLines() we are now using the C++17 construct std::is_convertible_v<From*,To*> instead. * We need RunStyles<ptrdiff_t> 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.
-rw-r--r--src/CellBuffer.cxx3
-rw-r--r--src/RunStyles.cxx9
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 <optional>
#include <algorithm>
#include <memory>
+#include <type_traits>
#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<Sci::Position *, POS *>) {
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<DISTANCE, STYLE>::Check() const {
}
}
+// should also cover all possible types underlying ptrdiff_t (Sci::Position)
template class Scintilla::Internal::RunStyles<int, int>;
template class Scintilla::Internal::RunStyles<int, char>;
-#if (PTRDIFF_MAX != INT_MAX) || defined(__HAIKU__)
-template class Scintilla::Internal::RunStyles<ptrdiff_t, int>;
-template class Scintilla::Internal::RunStyles<ptrdiff_t, char>;
-#endif
+template class Scintilla::Internal::RunStyles<long, int>;
+template class Scintilla::Internal::RunStyles<long, char>;
+template class Scintilla::Internal::RunStyles<long long, int>;
+template class Scintilla::Internal::RunStyles<long long, char>;