diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2024-07-18 10:53:42 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2024-08-03 10:30:05 +0000 |
| commit | bd7d54249e3f2b6a9dd6b759c892d7c97d26c0aa (patch) | |
| tree | c3361d17c56843d837228c3340e87a3f2e904a38 /src/corelib/io/qdebug.cpp | |
| parent | afdc5ce1e0c006154b8c08124cabe40e91d7b3af (diff) | |
Introduce QT_NO_QSNPRINTF and mark QtCore as qsnprintf-free
... except, of course, the implementation file, which therefore has to
be excluded from PCH'ed builds.
Remove qvsnprintf.cpp from libbootstrap, as it's no longer needed
after porting all five uses of qsnprintf() in QtCore to C++11's
std::snprintf(), which even Windows implements with std behavior.
The reason we're removing the function is that std::snprintf() is the
better alternative: qsnprintf() just introduces even more platform
variance than any implementation-defined behavior of C or C++
snprintf().
To wit:
- On Windows, the return value is sometimes "wrong"
(cf. Windows-specific qsnprintf() tests in tst_qbytearray.cpp)
- On WASM and at least some Android configurations, it is incorrectly
implmented using the QString::asprintf().toLocal8Bit() work-around,
even though both platforms have a working snprintf().
QString::asprintf() is implemented in Qt itself, so has some
differences:
- the `a` format for hex floats is not supported
- %ls expects char16_t*, not wchar_t* (these are, in general, not
the same width)
We will deprecate these functions in 6.9, but before we do, we need to
get the Qt code in order, and that's where this macro comes in.
[ChangeLog][QtCore] Added the QT_NO_QSNPRINTF macro to disable
qsnprintf() and qvsnprintf(), which will also be deprecated in 6.9.
See the documentation for details why we take this step.
Task-number: QTBUG-127110
Pick-to: 6.8
Change-Id: I4e1c1f213bcfd615f83387f5f51e77fa1ff2062e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/io/qdebug.cpp')
| -rw-r--r-- | src/corelib/io/qdebug.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index cd835f548c0..42515be1187 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -11,6 +11,7 @@ #include <array> #include <q20chrono.h> +#include <cstdio> QT_BEGIN_NAMESPACE @@ -406,9 +407,9 @@ static QByteArray timeUnit(qint64 num, qint64 den) }; auto appendNumber = [&](qint64 value) { if (value >= 10'000 && (value % 1000) == 0) - len += qsnprintf(buf + len, sizeof(buf) - len, "%.6g", double(value)); // "1e+06" + len += std::snprintf(buf + len, sizeof(buf) - len, "%.6g", double(value)); // "1e+06" else - len += qsnprintf(buf + len, sizeof(buf) - len, "%lld", value); + len += std::snprintf(buf + len, sizeof(buf) - len, "%lld", value); }; appendChar('['); appendNumber(num); |
