aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-11-03 20:06:45 +1100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-11-03 20:06:45 +1100
commit30ec0541d55d048467ad5de9a9718d89ad6c8c35 (patch)
treecef5b7eb7866b138e36739833fd25612d5394faa
parentb0552440af91e0e7647df415b92c5b3e75b5f654 (diff)
downloadscintilla-mirror-30ec0541d55d048467ad5de9a9718d89ad6c8c35.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. 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--doc/ScintillaHistory.html3
-rw-r--r--scripts/HeaderOrder.txt1
-rw-r--r--src/CellBuffer.cxx3
-rw-r--r--src/RunStyles.cxx2
5 files changed, 14 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/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 342a87d51..0e1394f7a 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -614,6 +614,9 @@
<a href="https://sourceforge.net/p/scintilla/feature-requests/1567/">Feature #1567</a>.
</li>
<li>
+ Add PTRDIFF_DOESNT_ALIAS_INT preprocessor choice.
+ </li>
+ <li>
On Win32, force autocompletion list colours to be opaque.
Enlarge bitmap to avoid visible blank background between items.
<a href="https://sourceforge.net/p/scintilla/bugs/2482/">Bug #2482</a>.
diff --git a/scripts/HeaderOrder.txt b/scripts/HeaderOrder.txt
index 12cd90726..5c6d2d58f 100644
--- a/scripts/HeaderOrder.txt
+++ b/scripts/HeaderOrder.txt
@@ -62,6 +62,7 @@
#include <mutex>
#include <thread>
#include <future>
+#include <type_traits>
// GTK headers
#include <glib.h>
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