aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/CellBuffer.cxx
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 /src/CellBuffer.cxx
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.
Diffstat (limited to 'src/CellBuffer.cxx')
-rw-r--r--src/CellBuffer.cxx3
1 files changed, 2 insertions, 1 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);