From ef2cdbe1e7f7ccb2cdf74fa5a1eeb70cd14673e9 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Wed, 30 Dec 2015 20:24:10 +0000 Subject: [PATCH] Correctly detect _set_invalid_parameter_handler There is still at least one Microsoft-supported version of the CRT which does not include the secure versions of various functions, and consequently does not include `_set_invalid_parameter_handler`. Tests for the definition and inclusion of caml_install_invalid_parameter_handler refined to detect `__STDC_SECURE_LIB__` defined in `crtdefs.h`. This is a badly documented, but standardised, define. Although `__STDC_SECURE_LIB__` is compatible with MinGW, I have retained the test for `_MSC_VER` and so kept this as an MSVC-only patch. --- asmrun/startup.c | 4 ++-- byterun/startup.c | 6 +++--- byterun/win32.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/asmrun/startup.c b/asmrun/startup.c index da61ffcde..385ef25ac 100644 --- a/asmrun/startup.c +++ b/asmrun/startup.c @@ -88,7 +88,7 @@ extern value caml_start_program (void); extern void caml_init_ieee_floats (void); extern void caml_init_signals (void); -#ifdef _MSC_VER +#if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L /* PR 4887: avoid crash box of windows runtime on some system calls */ extern void caml_install_invalid_parameter_handler(); @@ -105,7 +105,7 @@ void caml_main(char **argv) caml_init_frame_descriptors(); caml_init_ieee_floats(); -#ifdef _MSC_VER +#if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L caml_install_invalid_parameter_handler(); #endif caml_init_custom_operations(); diff --git a/byterun/startup.c b/byterun/startup.c index 0d2c19451..c4a13d2c8 100644 --- a/byterun/startup.c +++ b/byterun/startup.c @@ -259,7 +259,7 @@ extern void caml_init_ieee_floats (void); extern void caml_signal_thread(void * lpParam); #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L /* PR 4887: avoid crash box of windows runtime on some system calls */ extern void caml_install_invalid_parameter_handler(); @@ -281,7 +281,7 @@ CAMLexport void caml_main(char **argv) /* Machine-dependent initialization of the floating-point hardware so that it behaves as much as possible as specified in IEEE */ caml_init_ieee_floats(); -#ifdef _MSC_VER +#if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L caml_install_invalid_parameter_handler(); #endif caml_init_custom_operations(); @@ -397,7 +397,7 @@ CAMLexport void caml_startup_code( static char proc_self_exe[256]; caml_init_ieee_floats(); -#ifdef _MSC_VER +#if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L caml_install_invalid_parameter_handler(); #endif caml_init_custom_operations(); diff --git a/byterun/win32.c b/byterun/win32.c index c7865e66d..4a9cecc4c 100644 --- a/byterun/win32.c +++ b/byterun/win32.c @@ -579,7 +579,7 @@ int caml_win32_random_seed (intnat data[16]) } -#ifdef _MSC_VER +#if defined(_MSC_VER) && __STDC_SECURE_LIB__ >= 200411L static void invalid_parameter_handler(const wchar_t* expression, const wchar_t* function,