corelib/io: use qUtf16Printable(), %ls, qErrnoWarning()

... instead of qPrintable(), %s, explicit qt_error_string().

Saves temporary QByteArray creation, and 540b in text size on
optimized Linux AMD64 GCC 9.1 builds.

Change-Id: Id4e861683cf05a92faf51e4a9de9eb1dec4fc84a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
 
 
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2019-05-29 17:54:38 +02:00
parent b5e0bb9152
commit 9322ee7ace
6 changed files with 35 additions and 34 deletions

View File

@ -169,7 +169,7 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys()
if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) { if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) {
qt_safe_close(fd); qt_safe_close(fd);
if (!QFile::remove(fileName)) if (!QFile::remove(fileName))
qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName)); qWarning("QLockFile: Could not remove our own lock file %ls.", qUtf16Printable(fileName));
return QLockFile::UnknownError; // partition full return QLockFile::UnknownError; // partition full
} }

View File

@ -202,8 +202,7 @@ static int qt_create_pipe(int *pipe)
qt_safe_close(pipe[1]); qt_safe_close(pipe[1]);
int pipe_ret = qt_safe_pipe(pipe); int pipe_ret = qt_safe_pipe(pipe);
if (pipe_ret != 0) { if (pipe_ret != 0) {
qWarning("QProcessPrivate::createPipe: Cannot create pipe %p: %s", qErrnoWarning("QProcessPrivate::createPipe: Cannot create pipe %p", pipe);
pipe, qPrintable(qt_error_string(errno)));
} }
return pipe_ret; return pipe_ret;
} }
@ -473,7 +472,7 @@ void QProcessPrivate::startProcess()
if (forkfd == -1) { if (forkfd == -1) {
// Cleanup, report error and return // Cleanup, report error and return
#if defined (QPROCESS_DEBUG) #if defined (QPROCESS_DEBUG)
qDebug("fork failed: %s", qPrintable(qt_error_string(lastForkErrno))); qDebug("fork failed: %ls", qUtf16Printable(qt_error_string(lastForkErrno)));
#endif #endif
q->setProcessState(QProcess::NotRunning); q->setProcessState(QProcess::NotRunning);
setErrorAndEmit(QProcess::FailedToStart, setErrorAndEmit(QProcess::FailedToStart,
@ -652,7 +651,7 @@ bool QProcessPrivate::writeToStdin()
qDebug("QProcessPrivate::writeToStdin(), write(%p \"%s\", %lld) == %lld", qDebug("QProcessPrivate::writeToStdin(), write(%p \"%s\", %lld) == %lld",
data, qt_prettyDebug(data, bytesToWrite, 16).constData(), bytesToWrite, written); data, qt_prettyDebug(data, bytesToWrite, 16).constData(), bytesToWrite, written);
if (written == -1) if (written == -1)
qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qPrintable(qt_error_string(errno))); qDebug("QProcessPrivate::writeToStdin(), failed to write (%ls)", qUtf16Printable(qt_error_string(errno)));
#endif #endif
if (written == -1) { if (written == -1) {
// If the O_NONBLOCK flag is set and If some data can be written without blocking // If the O_NONBLOCK flag is set and If some data can be written without blocking

View File

@ -193,7 +193,7 @@ bool QSaveFile::open(OpenMode mode)
{ {
Q_D(QSaveFile); Q_D(QSaveFile);
if (isOpen()) { if (isOpen()) {
qWarning("QSaveFile::open: File (%s) already open", qPrintable(fileName())); qWarning("QSaveFile::open: File (%ls) already open", qUtf16Printable(fileName()));
return false; return false;
} }
unsetError(); unsetError();
@ -326,7 +326,7 @@ bool QSaveFile::commit()
return false; return false;
if (!isOpen()) { if (!isOpen()) {
qWarning("QSaveFile::commit: File (%s) is not open", qPrintable(fileName())); qWarning("QSaveFile::commit: File (%ls) is not open", qUtf16Printable(fileName()));
return false; return false;
} }
QFileDevice::close(); // calls flush() QFileDevice::close(); // calls flush()

View File

@ -166,8 +166,8 @@ static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSub
if (res == ERROR_SUCCESS) if (res == ERROR_SUCCESS)
return resultHandle; return resultHandle;
//qWarning("QSettings: Failed to create subkey \"%s\": %s", //qErrnoWarning(int(res), "QSettings: Failed to create subkey \"%ls\"",
// qPrintable(rSubKey), qPrintable(qt_error_string(int(res)))); // qUtf16Printable(rSubKey));
return 0; return 0;
} }
@ -207,7 +207,7 @@ static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildS
&numKeys, &maxKeySize, 0, 0, 0); &numKeys, &maxKeySize, 0, 0, 0);
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegQueryInfoKey() failed: %s", qPrintable(qt_error_string(int(res)))); qErrnoWarning(int(res), "QSettings: RegQueryInfoKey() failed");
return result; return result;
} }
@ -241,7 +241,7 @@ static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildS
item = QString::fromWCharArray((const wchar_t *)buff.constData(), l); item = QString::fromWCharArray((const wchar_t *)buff.constData(), l);
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegEnumValue failed: %s", qPrintable(qt_error_string(int(res)))); qErrnoWarning(int(res), "QSettings: RegEnumValue failed");
continue; continue;
} }
if (item.isEmpty()) if (item.isEmpty())
@ -295,8 +295,8 @@ static void deleteChildGroups(HKEY parentHandle, REGSAM access = 0)
// delete group itself // delete group itself
LONG res = RegDeleteKey(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16())); LONG res = RegDeleteKey(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16()));
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegDeleteKey failed on subkey \"%s\": %s", qErrnoWarning(int(res), "QSettings: RegDeleteKey failed on subkey \"%ls\"",
qPrintable(group), qPrintable(qt_error_string(int(res)))); qUtf16Printable(group));
return; return;
} }
} }
@ -596,8 +596,8 @@ QWinSettingsPrivate::~QWinSettingsPrivate()
QString emptyKey; QString emptyKey;
DWORD res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16())); DWORD res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
qWarning("QSettings: Failed to delete key \"%s\": %s", qErrnoWarning(int(res), "QSettings: Failed to delete key \"%ls\"",
qPrintable(regList.at(0).key()), qPrintable(qt_error_string(int(res)))); qUtf16Printable(regList.constFirst().key()));
} }
} }
@ -633,16 +633,16 @@ void QWinSettingsPrivate::remove(const QString &uKey)
for (const QString &group : childKeys) { for (const QString &group : childKeys) {
LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16())); LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s", qErrnoWarning(int(res), "QSettings: RegDeleteValue failed on subkey \"%ls\"",
qPrintable(group), qPrintable(qt_error_string(int(res)))); qUtf16Printable(group));
} }
} }
} else { } else {
res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16())); res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegDeleteKey failed on key \"%s\": %s", qErrnoWarning(int(res), "QSettings: RegDeleteKey failed on key \"%ls\"",
qPrintable(rKey), qPrintable(qt_error_string(int(res)))); qUtf16Printable(rKey));
} }
} }
RegCloseKey(handle); RegCloseKey(handle);
@ -739,8 +739,8 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value)
if (res == ERROR_SUCCESS) { if (res == ERROR_SUCCESS) {
deleteWriteHandleOnExit = false; deleteWriteHandleOnExit = false;
} else { } else {
qWarning("QSettings: failed to set subkey \"%s\": %s", qErrnoWarning(int(res), "QSettings: failed to set subkey \"%ls\"",
qPrintable(rKey), qPrintable(qt_error_string(int(res)))); qUtf16Printable(rKey));
setStatus(QSettings::AccessError); setStatus(QSettings::AccessError);
} }

View File

@ -130,29 +130,31 @@ QString QStandardPaths::writableLocation(StandardLocation type)
fileInfo.setFile(xdgRuntimeDir); fileInfo.setFile(xdgRuntimeDir);
if (!fileInfo.isDir()) { if (!fileInfo.isDir()) {
if (!QDir().mkdir(xdgRuntimeDir)) { if (!QDir().mkdir(xdgRuntimeDir)) {
qWarning("QStandardPaths: error creating runtime directory %s: %s", qPrintable(xdgRuntimeDir), qPrintable(qt_error_string(errno))); qErrnoWarning("QStandardPaths: error creating runtime directory %ls",
qUtf16Printable(xdgRuntimeDir));
return QString(); return QString();
} }
} }
#ifndef Q_OS_WASM #ifndef Q_OS_WASM
qWarning("QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '%s'", qPrintable(xdgRuntimeDir)); qWarning("QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '%ls'", qUtf16Printable(xdgRuntimeDir));
#endif #endif
} else { } else {
fileInfo.setFile(xdgRuntimeDir); fileInfo.setFile(xdgRuntimeDir);
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
qWarning("QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '%s', " qWarning("QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '%ls', "
"please create it with 0700 permissions.", qPrintable(xdgRuntimeDir)); "please create it with 0700 permissions.", qUtf16Printable(xdgRuntimeDir));
return QString(); return QString();
} }
if (!fileInfo.isDir()) { if (!fileInfo.isDir()) {
qWarning("QStandardPaths: XDG_RUNTIME_DIR points to '%s' which is not a directory", qWarning("QStandardPaths: XDG_RUNTIME_DIR points to '%ls' which is not a directory",
qPrintable(xdgRuntimeDir)); qUtf16Printable(xdgRuntimeDir));
return QString(); return QString();
} }
} }
// "The directory MUST be owned by the user" // "The directory MUST be owned by the user"
if (fileInfo.ownerId() != myUid) { if (fileInfo.ownerId() != myUid) {
qWarning("QStandardPaths: wrong ownership on runtime directory %s, %d instead of %d", qPrintable(xdgRuntimeDir), qWarning("QStandardPaths: wrong ownership on runtime directory %ls, %d instead of %d",
qUtf16Printable(xdgRuntimeDir),
fileInfo.ownerId(), myUid); fileInfo.ownerId(), myUid);
return QString(); return QString();
} }
@ -163,8 +165,8 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (fileInfo.permissions() != wantedPerms) { if (fileInfo.permissions() != wantedPerms) {
QFile file(xdgRuntimeDir); QFile file(xdgRuntimeDir);
if (!file.setPermissions(wantedPerms)) { if (!file.setPermissions(wantedPerms)) {
qWarning("QStandardPaths: could not set correct permissions on runtime directory %s: %s", qWarning("QStandardPaths: could not set correct permissions on runtime directory %ls: %ls",
qPrintable(xdgRuntimeDir), qPrintable(file.errorString())); qUtf16Printable(xdgRuntimeDir), qUtf16Printable(file.errorString()));
return QString(); return QString();
} }
} }

View File

@ -3266,10 +3266,10 @@ QUrl QUrl::resolved(const QUrl &relative) const
removeDotsFromPath(&t.d->path); removeDotsFromPath(&t.d->path);
#if defined(QURL_DEBUG) #if defined(QURL_DEBUG)
qDebug("QUrl(\"%s\").resolved(\"%s\") = \"%s\"", qDebug("QUrl(\"%ls\").resolved(\"%ls\") = \"%ls\"",
qPrintable(url()), qUtf16Printable(url()),
qPrintable(relative.url()), qUtf16Printable(relative.url()),
qPrintable(t.url())); qUtf16Printable(t.url()));
#endif #endif
return t; return t;
} }