From 440e9a9993d5113f6b8923ce10ea9acf04cdfd61 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 6 Sep 2021 14:18:07 +0300 Subject: [PATCH] ensure qt_error_string() uses XSI/POSIX.1 version of strerror_r() fixes QProcess test failures Signed-off-by: Ivailo Monev --- src/core/CMakeLists.txt | 5 +++ src/core/global/qglobal.cpp | 19 ----------- src/core/global/qt_error_string.cpp | 51 +++++++++++++++++++++++++++++ src/tools/moc/CMakeLists.txt | 1 + 4 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 src/core/global/qt_error_string.cpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b28cadf84..5e19eae21 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -298,6 +298,7 @@ set(CORE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/concurrent/qthreadpool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/global/qglobal.cpp ${CMAKE_CURRENT_SOURCE_DIR}/global/qlibraryinfo.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/global/qt_error_string.cpp ${CMAKE_CURRENT_SOURCE_DIR}/io/qabstractfileengine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/io/qbuffer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/io/qdatastream.cpp @@ -422,6 +423,10 @@ if(WITH_EXECINFO AND EXECINFO_FOUND) include_directories(${EXECINFO_INCLUDES}) endif() +katie_unity_exclude( + ${CMAKE_CURRENT_SOURCE_DIR}/global/qt_error_string.cpp +) + katie_generate_misc("${CORE_HEADERS}" QtCore) katie_generate_public("${CORE_PUBLIC_HEADERS}" QtCore) katie_generate_package(KtCore "") diff --git a/src/core/global/qglobal.cpp b/src/core/global/qglobal.cpp index 20b7bd974..a4aa6d012 100644 --- a/src/core/global/qglobal.cpp +++ b/src/core/global/qglobal.cpp @@ -1106,25 +1106,6 @@ void qt_check_pointer(const char *file, int line) static QtMsgHandler handler = 0; // pointer to debug handler -QString qt_error_string(int errorCode) -{ - // There are two incompatible versions of strerror_r: - // a) the XSI/POSIX.1 version, which returns an int, - // indicating success or not - // b) the GNU version, which returns a char*, which may or may not - // be the beginning of the buffer we used - // The GNU libc manpage for strerror_r says you should use the the XSI - // version in portable code. -#if !defined(QT_NO_THREAD) - QSTACKARRAY(char, errbuf, 1024); - ::strerror_r(errorCode, errbuf, sizeof(errbuf)); - return QString::fromLocal8Bit(errbuf); -#else - return QString::fromLocal8Bit(::strerror(errorCode)); -#endif -} - - /*! \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler) \relates diff --git a/src/core/global/qt_error_string.cpp b/src/core/global/qt_error_string.cpp new file mode 100644 index 000000000..5637f3f97 --- /dev/null +++ b/src/core/global/qt_error_string.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 Ivailo Monev +** +** This file is part of the QtCore module of the Katie Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// There are two incompatible versions of strerror_r: +// a) the XSI/POSIX.1 version, which returns an int, +// indicating success or not +// b) the GNU version, which returns a char*, which may or may not +// be the beginning of the buffer we used +// The GNU libc manpage for strerror_r says you should use the the XSI +// version in portable code. +// +// to get the XSI/POSIX.1 version _GNU_SOURCE must not be defined +#undef _GNU_SOURCE + +#include "qcorecommon_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +QString qt_error_string(int errorCode) +{ +#if !defined(QT_NO_THREAD) + QSTACKARRAY(char, errbuf, 1024); + strerror_r(errorCode, errbuf, sizeof(errbuf)); + return QString::fromLocal8Bit(errbuf); +#else + return QString::fromLocal8Bit(::strerror(errorCode)); +#endif +} + +QT_END_NAMESPACE diff --git a/src/tools/moc/CMakeLists.txt b/src/tools/moc/CMakeLists.txt index 8382f7309..022c507a1 100644 --- a/src/tools/moc/CMakeLists.txt +++ b/src/tools/moc/CMakeLists.txt @@ -51,6 +51,7 @@ endif() set(BOOTSTRAP_SOURCES ${CMAKE_SOURCE_DIR}/src/core/codecs/qicucodec.cpp ${CMAKE_SOURCE_DIR}/src/core/global/qglobal.cpp + ${CMAKE_SOURCE_DIR}/src/core/global/qt_error_string.cpp ${CMAKE_SOURCE_DIR}/src/core/io/qabstractfileengine.cpp ${CMAKE_SOURCE_DIR}/src/core/io/qbuffer.cpp ${CMAKE_SOURCE_DIR}/src/core/io/qdir.cpp