Move qAbort from qglobal.cpp to qassert.cpp

It makes more sense there, as all the other functions in that file are
about early termination. This allows us to remove qglobal.cpp from the
bootstrap library, because qglobal.cpp now only has the callback tables.

Amends 8f13af5d7b9b659208a8a93e6581d30b434dae1f.

Change-Id: I01ec3c774d9943adb903fffd17b7ea92404bdbd3
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Thiago Macieira 2024-02-27 19:54:57 -08:00
parent 1560e0161a
commit 907e9a8b29
3 changed files with 67 additions and 75 deletions

View File

@ -5,14 +5,51 @@
#include <QtCore/qlogging.h>
#include <cstdlib>
#include <cstdio>
#include <exception>
#ifndef QT_NO_EXCEPTIONS
#include <new>
#endif
#if defined(Q_CC_MSVC)
# include <crtdbg.h>
#endif
#ifdef Q_OS_WIN
# include <qt_windows.h>
#endif
QT_BEGIN_NAMESPACE
void qAbort()
{
#ifdef Q_OS_WIN
// std::abort() in the MSVC runtime will call _exit(3) if the abort
// behavior is _WRITE_ABORT_MSG - see also _set_abort_behavior(). This is
// the default for a debug-mode build of the runtime. Worse, MinGW's
// std::abort() implementation (in msvcrt.dll) is basically a call to
// _exit(3) too. Unfortunately, _exit() and _Exit() *do* run the static
// destructors of objects in DLLs, a violation of the C++ standard (see
// [support.start.term]). So we bypass std::abort() and directly
// terminate the application.
# if defined(Q_CC_MSVC)
if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
__fastfail(FAST_FAIL_FATAL_APP_EXIT);
# else
RaiseFailFastException(nullptr, nullptr, 0);
# endif
// Fallback
TerminateProcess(GetCurrentProcess(), STATUS_FATAL_APP_EXIT);
// Tell the compiler the application has stopped.
Q_UNREACHABLE_IMPL();
#else // !Q_OS_WIN
std::abort();
#endif
}
/*!
\macro void Q_ASSERT(bool test)
\relates <QtAssert>
@ -157,6 +194,36 @@ void qBadAlloc()
\sa Q_ASSERT(), Q_UNREACHABLE(), Q_LIKELY()
*/
/*!
\macro QT_TERMINATE_ON_EXCEPTION(expr)
\relates <QtGlobal>
\internal
In general, use of the Q_DECL_NOEXCEPT macro is preferred over
Q_DECL_NOTHROW, because it exhibits well-defined behavior and
supports the more powerful Q_DECL_NOEXCEPT_EXPR variant. However,
use of Q_DECL_NOTHROW has the advantage that Windows builds
benefit on a wide range or compiler versions that do not yet
support the C++11 noexcept feature.
It may therefore be beneficial to use Q_DECL_NOTHROW and emulate
the C++11 behavior manually with an embedded try/catch.
Qt provides the QT_TERMINATE_ON_EXCEPTION(expr) macro for this
purpose. It either expands to \c expr (if Qt is compiled without
exception support or the compiler supports C++11 noexcept
semantics) or to
\snippet code/src_corelib_global_qglobal.cpp qterminate
otherwise.
Since this macro expands to just \c expr if the compiler supports
C++11 noexcept, expecting the compiler to take over responsibility
of calling std::terminate() in that case, it should not be used
outside Q_DECL_NOTHROW functions.
\sa Q_DECL_NOEXCEPT, Q_DECL_NOTHROW, qTerminate()
*/
/*!
\macro void Q_UNREACHABLE()
\relates <QtAssert>

View File

@ -12,15 +12,6 @@
#include "qnativeinterface.h"
#include "qnativeinterface_p.h"
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#if defined(Q_CC_MSVC)
# include <crtdbg.h>
#endif
#ifdef Q_OS_WIN
# include <qt_windows.h>
#endif
@ -42,12 +33,6 @@ extern "C" {
}
#endif
#ifdef qFatal
// the qFatal in this file are just redirections from elsewhere, so
// don't capture any context again
# undef qFatal
#endif
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
@ -133,35 +118,6 @@ Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n)
return p;
}
void qAbort()
{
#ifdef Q_OS_WIN
// std::abort() in the MSVC runtime will call _exit(3) if the abort
// behavior is _WRITE_ABORT_MSG - see also _set_abort_behavior(). This is
// the default for a debug-mode build of the runtime. Worse, MinGW's
// std::abort() implementation (in msvcrt.dll) is basically a call to
// _exit(3) too. Unfortunately, _exit() and _Exit() *do* run the static
// destructors of objects in DLLs, a violation of the C++ standard (see
// [support.start.term]). So we bypass std::abort() and directly
// terminate the application.
# if defined(Q_CC_MSVC)
if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
__fastfail(FAST_FAIL_FATAL_APP_EXIT);
# else
RaiseFailFastException(nullptr, nullptr, 0);
# endif
// Fallback
TerminateProcess(GetCurrentProcess(), STATUS_FATAL_APP_EXIT);
// Tell the compiler the application has stopped.
Q_UNREACHABLE_IMPL();
#else // !Q_OS_WIN
std::abort();
#endif
}
// Also specified to behave as if they call tzset():
// localtime() -- but not localtime_r(), which we use when threaded
// strftime() -- not used (except in tests)
@ -354,36 +310,6 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
qMove takes an rvalue reference to its parameter \a x, and converts it to an xvalue.
*/
/*!
\macro QT_TERMINATE_ON_EXCEPTION(expr)
\relates <QtGlobal>
\internal
In general, use of the Q_DECL_NOEXCEPT macro is preferred over
Q_DECL_NOTHROW, because it exhibits well-defined behavior and
supports the more powerful Q_DECL_NOEXCEPT_EXPR variant. However,
use of Q_DECL_NOTHROW has the advantage that Windows builds
benefit on a wide range or compiler versions that do not yet
support the C++11 noexcept feature.
It may therefore be beneficial to use Q_DECL_NOTHROW and emulate
the C++11 behavior manually with an embedded try/catch.
Qt provides the QT_TERMINATE_ON_EXCEPTION(expr) macro for this
purpose. It either expands to \c expr (if Qt is compiled without
exception support or the compiler supports C++11 noexcept
semantics) or to
\snippet code/src_corelib_global_qglobal.cpp qterminate
otherwise.
Since this macro expands to just \c expr if the compiler supports
C++11 noexcept, expecting the compiler to take over responsibility
of calling std::terminate() in that case, it should not be used
outside Q_DECL_NOTHROW functions.
\sa Q_DECL_NOEXCEPT, Q_DECL_NOTHROW, qTerminate()
*/
namespace QtPrivate {
Q_LOGGING_CATEGORY(lcNativeInterface, "qt.nativeinterface")
}

View File

@ -16,7 +16,6 @@ qt_internal_extend_target(Bootstrap
../../corelib/global/qassert.cpp
../../corelib/global/qendian.cpp
../../corelib/global/qfloat16.cpp
../../corelib/global/qglobal.cpp
../../corelib/global/qlogging.cpp
../../corelib/global/qmalloc.cpp
../../corelib/global/qnumeric.cpp