mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 04:56:14 +01:00
glib: Port to the private invalid parameter handler APIs
Use the newly-added private APIs added in the previous commit so that we can clean up the code a bit.
This commit is contained in:
parent
08e0fef632
commit
9bcc9405d7
@ -192,6 +192,7 @@
|
|||||||
#include "gcharset.h"
|
#include "gcharset.h"
|
||||||
#include "gconvert.h"
|
#include "gconvert.h"
|
||||||
#include "genviron.h"
|
#include "genviron.h"
|
||||||
|
#include "glib-private.h"
|
||||||
#include "gmain.h"
|
#include "gmain.h"
|
||||||
#include "gmem.h"
|
#include "gmem.h"
|
||||||
#include "gprintfint.h"
|
#include "gprintfint.h"
|
||||||
@ -219,22 +220,6 @@
|
|||||||
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
|
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (_MSC_VER) && (_MSC_VER >=1400)
|
|
||||||
/* This is ugly, but we need it for isatty() in case we have bad fd's,
|
|
||||||
* otherwise Windows will abort() the program on msvcrt80.dll and later
|
|
||||||
*/
|
|
||||||
#include <crtdbg.h>
|
|
||||||
|
|
||||||
_GLIB_EXTERN void
|
|
||||||
myInvalidParameterHandler(const wchar_t *expression,
|
|
||||||
const wchar_t *function,
|
|
||||||
const wchar_t *file,
|
|
||||||
unsigned int line,
|
|
||||||
uintptr_t pReserved)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "gwin32.h"
|
#include "gwin32.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2111,12 +2096,7 @@ g_log_writer_supports_color (gint output_fd)
|
|||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
GWin32InvalidParameterHandler handler;
|
||||||
#ifdef USE_INVALID_PARAMETER_HANDLER
|
|
||||||
_invalid_parameter_handler oldHandler, newHandler;
|
|
||||||
int prev_report_mode = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_return_val_if_fail (output_fd >= 0, FALSE);
|
g_return_val_if_fail (output_fd >= 0, FALSE);
|
||||||
@ -2143,17 +2123,7 @@ g_log_writer_supports_color (gint output_fd)
|
|||||||
*/
|
*/
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
|
|
||||||
#ifdef USE_INVALID_PARAMETER_HANDLER
|
g_win32_push_empty_invalid_parameter_handler (&handler);
|
||||||
/* Set up our empty invalid parameter handler, for isatty(),
|
|
||||||
* in case of bad fd's passed in for isatty(), so that
|
|
||||||
* msvcrt80.dll+ won't abort the program
|
|
||||||
*/
|
|
||||||
newHandler = myInvalidParameterHandler;
|
|
||||||
oldHandler = _set_invalid_parameter_handler (newHandler);
|
|
||||||
|
|
||||||
/* Disable the message box for assertions. */
|
|
||||||
prev_report_mode = _CrtSetReportMode(_CRT_ASSERT, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (g_win32_check_windows_version (10, 0, 0, G_WIN32_OS_ANY))
|
if (g_win32_check_windows_version (10, 0, 0, G_WIN32_OS_ANY))
|
||||||
{
|
{
|
||||||
@ -2185,10 +2155,7 @@ g_log_writer_supports_color (gint output_fd)
|
|||||||
result = win32_is_pipe_tty (output_fd);
|
result = win32_is_pipe_tty (output_fd);
|
||||||
|
|
||||||
reset_invalid_param_handler:
|
reset_invalid_param_handler:
|
||||||
#ifdef USE_INVALID_PARAMETER_HANDLER
|
g_win32_pop_invalid_parameter_handler (&handler);
|
||||||
_CrtSetReportMode(_CRT_ASSERT, prev_report_mode);
|
|
||||||
_set_invalid_parameter_handler (oldHandler);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
|
@ -23,20 +23,6 @@
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
/* For _CrtSetReportMode, we don't want Windows CRT (2005 and later)
|
|
||||||
* to terminate the process if a bad file descriptor is passed into
|
|
||||||
* _get_osfhandle(). This is necessary because we use _get_osfhandle()
|
|
||||||
* to check the validity of the fd before we try to call close() on
|
|
||||||
* it as attempting to close an invalid fd will cause the Windows CRT
|
|
||||||
* to abort() this program internally.
|
|
||||||
*
|
|
||||||
* Please see http://msdn.microsoft.com/zh-tw/library/ks2530z6%28v=vs.80%29.aspx
|
|
||||||
* for an explanation on this.
|
|
||||||
*/
|
|
||||||
#ifdef USE_INVALID_PARAMETER_HANDLER
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef G_LOG_DOMAIN
|
#undef G_LOG_DOMAIN
|
||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
#define GSPAWN_HELPER
|
#define GSPAWN_HELPER
|
||||||
@ -168,30 +154,6 @@ checked_dup2 (int oldfd, int newfd, int report_fd)
|
|||||||
return newfd;
|
return newfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_INVALID_PARAMETER_HANDLER
|
|
||||||
/*
|
|
||||||
* This is the (empty) invalid parameter handler
|
|
||||||
* that is used for Visual C++ 2005 (and later) builds
|
|
||||||
* so that we can use this instead of the system automatically
|
|
||||||
* aborting the process.
|
|
||||||
*
|
|
||||||
* This is necessary as we use _get_oshandle() to check the validity
|
|
||||||
* of the file descriptors as we close them, so when an invalid file
|
|
||||||
* descriptor is passed into that function as we check on it, we get
|
|
||||||
* -1 as the result, instead of the gspawn helper program aborting.
|
|
||||||
*
|
|
||||||
* Please see http://msdn.microsoft.com/zh-tw/library/ks2530z6%28v=vs.80%29.aspx
|
|
||||||
* for an explanation on this.
|
|
||||||
*/
|
|
||||||
extern void
|
|
||||||
myInvalidParameterHandler(const wchar_t *expression,
|
|
||||||
const wchar_t *function,
|
|
||||||
const wchar_t *file,
|
|
||||||
unsigned int line,
|
|
||||||
uintptr_t pReserved);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef HELPER_CONSOLE
|
#ifndef HELPER_CONSOLE
|
||||||
int _stdcall
|
int _stdcall
|
||||||
WinMain (struct HINSTANCE__ *hInstance,
|
WinMain (struct HINSTANCE__ *hInstance,
|
||||||
@ -220,16 +182,7 @@ main (int ignored_argc, char **ignored_argv)
|
|||||||
char **argv;
|
char **argv;
|
||||||
wchar_t **wargv;
|
wchar_t **wargv;
|
||||||
char c;
|
char c;
|
||||||
|
GWin32InvalidParameterHandler handler;
|
||||||
#ifdef USE_INVALID_PARAMETER_HANDLER
|
|
||||||
/* set up our empty invalid parameter handler */
|
|
||||||
_invalid_parameter_handler oldHandler, newHandler;
|
|
||||||
newHandler = myInvalidParameterHandler;
|
|
||||||
oldHandler = _set_invalid_parameter_handler(newHandler);
|
|
||||||
|
|
||||||
/* Disable the message box for assertions. */
|
|
||||||
_CrtSetReportMode(_CRT_ASSERT, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Fetch the wide-char argument vector */
|
/* Fetch the wide-char argument vector */
|
||||||
wargv = CommandLineToArgvW (GetCommandLineW(), &argc);
|
wargv = CommandLineToArgvW (GetCommandLineW(), &argc);
|
||||||
@ -398,11 +351,13 @@ main (int ignored_argc, char **ignored_argv)
|
|||||||
/* argv[ARG_CLOSE_DESCRIPTORS] is "y" if file descriptors from 3
|
/* argv[ARG_CLOSE_DESCRIPTORS] is "y" if file descriptors from 3
|
||||||
* upwards should be closed
|
* upwards should be closed
|
||||||
*/
|
*/
|
||||||
|
GLIB_PRIVATE_CALL (g_win32_push_empty_invalid_parameter_handler) (&handler);
|
||||||
if (argv[ARG_CLOSE_DESCRIPTORS][0] == 'y')
|
if (argv[ARG_CLOSE_DESCRIPTORS][0] == 'y')
|
||||||
for (i = 3; i < 1000; i++) /* FIXME real limit? */
|
for (i = 3; i < 1000; i++) /* FIXME real limit? */
|
||||||
if (!g_hash_table_contains (fds, GINT_TO_POINTER (i)))
|
if (!g_hash_table_contains (fds, GINT_TO_POINTER (i)))
|
||||||
if (_get_osfhandle (i) != -1)
|
if (_get_osfhandle (i) != -1)
|
||||||
close (i);
|
close (i);
|
||||||
|
GLIB_PRIVATE_CALL (g_win32_pop_invalid_parameter_handler) (&handler);
|
||||||
|
|
||||||
/* We don't want our child to inherit the error report and
|
/* We don't want our child to inherit the error report and
|
||||||
* helper sync fds.
|
* helper sync fds.
|
||||||
|
Loading…
Reference in New Issue
Block a user