aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-10-19 23:40:08 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-10-26 14:42:45 +0100
commitdb63b6316586873ae1fd13318787dca586026645 (patch)
treeef02fd0cab6a5532b50fc6ba24f90ce84150ad9f
parentb1be61a1f449360187a6d9ff0b49f837177ffe9a (diff)
downloadscintilla-mirror-sciteco-rel-5-5-7.tar.gz
support ptrdiff_t if it has the same storage size as int, but does *not* alias itHEADsciteco-rel-5-5-7
* 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. This is impossible to test for in a constant expression that can be used with the preprocessor. Also, it's not possible to conditionally instantiate templates. We tried to instantiate RunStyles for all scalar types that could be behind ptrdiff_t, but it was causing warnings on MSVC. Implicitly instantiating RunStyles would be possible, but is not desired. Therefore as a workaround, you can now define the PTRDIFF_DOESNT_ALIAS_INT macro when invoking the build system, to force instantiating RunStyles<ptrdiff_t>. When writing portable applications, you may have to use a compile-time check for checking aliasability of ptrdiff_t and int in order to define PTRDIFF_DOESNT_ALIAS_INT.
-rw-r--r--doc/ScintillaDoc.html7
-rw-r--r--src/CellBuffer.cxx3
-rw-r--r--src/RunStyles.cxx2
3 files changed, 10 insertions, 2 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 5c92043cc..82829a947 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -10529,6 +10529,13 @@ EM_SETTARGETDEVICE
<td align="left"><code>DISABLE_D2D</code></td>
<td>(Win32) Build Scintilla without Direct2D/DirectWrite.</td>
</tr>
+
+ <tr>
+ <td align="left"><code>PTRDIFF_DOESNT_ALIAS_INT</code></td>
+ <td>Define if <code>ptrdiff_t*</code> does not alias <code>int*</code>.
+ This is detected automatically, but the check may be unreliable.
+ Try to define this symbol in case of errors about undefined symbols.</td>
+ </tr>
</tbody>
</table>
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..bca45c889 100644
--- a/src/RunStyles.cxx
+++ b/src/RunStyles.cxx
@@ -321,7 +321,7 @@ void RunStyles<DISTANCE, STYLE>::Check() const {
template class Scintilla::Internal::RunStyles<int, int>;
template class Scintilla::Internal::RunStyles<int, char>;
-#if (PTRDIFF_MAX != INT_MAX) || defined(__HAIKU__)
+#if (PTRDIFF_MAX != INT_MAX) || defined(__HAIKU__) || defined(PTRDIFF_DOESNT_ALIAS_INT)
template class Scintilla::Internal::RunStyles<ptrdiff_t, int>;
template class Scintilla::Internal::RunStyles<ptrdiff_t, char>;
#endif