mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
Reorganize the "don't dump core from test subprocesses" code.
g_test_init() was calling _g_messages_set_exit_on_fatal() from subprocesses, to make fatal log messages call _exit() rather than abort(), but the function name is sort of confusing, and we don't really need it anyway, since g_log() can just call g_test_subprocess() instead and decide for itself. Likewise, update g_assertion_message() to do the check itself, rather than calling into gmessages to do it, and fix g_assertion_message_expr() to also check whether it should exit or abort. (Previously it always called abort(), although this didn't actually matter since that was dead code until test_nonfatal_assertions was added.) https://bugzilla.gnome.org/show_bug.cgi?id=711800
This commit is contained in:
parent
97fac93670
commit
3d70db0750
@ -145,7 +145,6 @@ libglib_2_0_la_SOURCES = \
|
||||
gmarkup.c \
|
||||
gmem.c \
|
||||
gmessages.c \
|
||||
gmessages-private.h \
|
||||
gmirroringtable.h \
|
||||
gnode.c \
|
||||
goption.c \
|
||||
|
@ -1,35 +0,0 @@
|
||||
/* gmain.h - the GLib Main loop
|
||||
* Copyright (C) 1998-2000 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __G_MESSAGES_PRIVATE_H__
|
||||
#define __G_MESSAGES_PRIVATE_H__
|
||||
|
||||
#include <glib/gmessages.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
G_GNUC_INTERNAL void
|
||||
_g_log_set_exit_on_fatal (void);
|
||||
|
||||
G_GNUC_INTERNAL void
|
||||
_g_log_abort (void) G_GNUC_NORETURN;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_MESSAGES_PRIVATE_H__ */
|
@ -56,8 +56,6 @@
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "gmessages-private.h"
|
||||
|
||||
#include "glib-init.h"
|
||||
#include "gbacktrace.h"
|
||||
#include "gcharset.h"
|
||||
@ -285,7 +283,6 @@ static GLogDomain *g_log_domains = NULL;
|
||||
static GPrintFunc glib_print_func = NULL;
|
||||
static GPrintFunc glib_printerr_func = NULL;
|
||||
static GPrivate g_log_depth;
|
||||
static gboolean exit_on_fatal;
|
||||
static GLogFunc default_log_func = g_log_default_handler;
|
||||
static gpointer default_log_data = NULL;
|
||||
static GTestLogFatalFunc fatal_log_func = NULL;
|
||||
@ -293,11 +290,20 @@ static gpointer fatal_log_data;
|
||||
|
||||
/* --- functions --- */
|
||||
|
||||
void
|
||||
static void _g_log_abort (void) G_GNUC_NORETURN;
|
||||
|
||||
static void
|
||||
_g_log_abort (void)
|
||||
{
|
||||
if (exit_on_fatal)
|
||||
_exit (1);
|
||||
if (g_test_subprocess ())
|
||||
{
|
||||
/* If this is a test case subprocess then it probably caused
|
||||
* this error message on purpose, so just exit() rather than
|
||||
* abort()ing, to avoid triggering any system crash-reporting
|
||||
* daemon.
|
||||
*/
|
||||
_exit (1);
|
||||
}
|
||||
else
|
||||
abort ();
|
||||
}
|
||||
@ -1017,11 +1023,7 @@ g_logv (const gchar *log_domain,
|
||||
&& !fatal_log_func (log_domain, test_level, msg, fatal_log_data);
|
||||
}
|
||||
|
||||
if ((test_level & G_LOG_FLAG_FATAL) && exit_on_fatal && !masquerade_fatal)
|
||||
{
|
||||
_g_log_abort ();
|
||||
}
|
||||
else if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
|
||||
if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
|
||||
{
|
||||
#ifdef G_OS_WIN32
|
||||
if (win32_keep_fatal_message)
|
||||
@ -1034,12 +1036,12 @@ g_logv (const gchar *log_domain,
|
||||
if (IsDebuggerPresent () && !(test_level & G_LOG_FLAG_RECURSION))
|
||||
G_BREAKPOINT ();
|
||||
else
|
||||
abort ();
|
||||
_g_log_abort ();
|
||||
#else
|
||||
if (!(test_level & G_LOG_FLAG_RECURSION))
|
||||
G_BREAKPOINT ();
|
||||
else
|
||||
abort ();
|
||||
_g_log_abort ();
|
||||
#endif /* !G_OS_WIN32 */
|
||||
}
|
||||
|
||||
@ -1634,9 +1636,3 @@ g_printf_string_upper_bound (const gchar *format,
|
||||
gchar c;
|
||||
return _g_vsnprintf (&c, 1, format, args) + 1;
|
||||
}
|
||||
|
||||
void
|
||||
_g_log_set_exit_on_fatal (void)
|
||||
{
|
||||
exit_on_fatal = TRUE;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gtestutils.h"
|
||||
#include "gmessages-private.h"
|
||||
#include "gfileutils.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -56,7 +55,6 @@
|
||||
#include "gslice.h"
|
||||
#include "gspawn.h"
|
||||
#include "glib-private.h"
|
||||
#include "gmessages-private.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -892,7 +890,6 @@ parse_args (gint *argc_p,
|
||||
(void) setrlimit (RLIMIT_CORE, &limit);
|
||||
}
|
||||
#endif
|
||||
_g_log_set_exit_on_fatal ();
|
||||
argv[i] = NULL;
|
||||
}
|
||||
else if (strcmp ("-p", argv[i]) == 0 || strncmp ("-p=", argv[i], 3) == 0)
|
||||
@ -2307,7 +2304,17 @@ g_assertion_message (const char *domain,
|
||||
strcpy (__glib_assert_msg, s);
|
||||
|
||||
g_free (s);
|
||||
_g_log_abort ();
|
||||
|
||||
if (test_in_subprocess)
|
||||
{
|
||||
/* If this is a test case subprocess then it probably hit this
|
||||
* assertion on purpose, so just exit() rather than abort()ing,
|
||||
* to avoid triggering any system crash-reporting daemon.
|
||||
*/
|
||||
_exit (1);
|
||||
}
|
||||
else
|
||||
abort ();
|
||||
}
|
||||
|
||||
void
|
||||
@ -2324,7 +2331,15 @@ g_assertion_message_expr (const char *domain,
|
||||
s = g_strconcat ("assertion failed: (", expr, ")", NULL);
|
||||
g_assertion_message (domain, file, line, func, s);
|
||||
g_free (s);
|
||||
abort ();
|
||||
|
||||
/* Normally g_assertion_message() won't return, but we need this for
|
||||
* when test_nonfatal_assertions is set, since
|
||||
* g_assertion_message_expr() is used for always-fatal assertions.
|
||||
*/
|
||||
if (test_in_subprocess)
|
||||
_exit (1);
|
||||
else
|
||||
abort ();
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user