https://git.reactos.org/?p=reactos.git;a=commitdiff;h=da2a5673e79d222159d1b…
commit da2a5673e79d222159d1b2f17ba77f6ca187ec9a
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Jul 24 18:13:06 2021 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Tue Jul 27 22:08:58 2021 +0200
[CRT] Fix _matherror and _setusermatherror
We previously used 2 different versions: one from wine and one from mingw-w64.
The former was used in msvcrt, the latter was statically compiled into the executable.
When using MS libs, there is only one _matherr, which is statically linked into the
executable and does nothing (it's not really a function for users to be called).
_setusermatherror should only exist in msvcrt and not statically, which wouldn't
work at all.
---
sdk/lib/crt/except/except.cmake | 1 -
sdk/lib/crt/except/matherr.c | 49 -------------------------
sdk/lib/crt/math/math.cmake | 1 +
sdk/lib/crt/math/usermatherr.c | 36 +++++++++++++++++++
sdk/lib/crt/msvcrtex.cmake | 2 +-
sdk/lib/crt/startup/_matherr.c | 18 ++++++++++
sdk/lib/crt/startup/merr.c | 76 ---------------------------------------
sdk/lib/crt/startup/startup.cmake | 2 +-
8 files changed, 57 insertions(+), 128 deletions(-)
diff --git a/sdk/lib/crt/except/except.cmake b/sdk/lib/crt/except/except.cmake
index 7bc56b8078e..ad4345cc066 100644
--- a/sdk/lib/crt/except/except.cmake
+++ b/sdk/lib/crt/except/except.cmake
@@ -55,7 +55,6 @@ endif()
list(APPEND CRT_EXCEPT_SOURCE
${LIBCNTPR_EXCEPT_SOURCE}
- except/matherr.c
except/stack.c
)
diff --git a/sdk/lib/crt/except/matherr.c b/sdk/lib/crt/except/matherr.c
deleted file mode 100644
index d7e6c5bf35b..00000000000
--- a/sdk/lib/crt/except/matherr.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <precomp.h>
-
-#define __USE_ISOC9X 1
-#define __USE_ISOC99 1
-#include <math.h>
-
-#ifdef HAVE_IEEEFP_H
-#include <ieeefp.h>
-#endif
-
-#ifndef HAVE_FINITE
-#ifndef finite /* Could be a macro */
-#ifdef isfinite
-#define finite(x) isfinite(x)
-#else
-#define finite(x) (!isnan(x)) /* At least catch some cases */
-#endif
-#endif
-#endif
-
-#ifndef signbit
-#define signbit(x) 0
-#endif
-
-typedef int (*MSVCRT_matherr_func)(struct _exception *);
-
-static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
-
-int CDECL _matherr(struct _exception *e)
-{
- if (e)
- TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1,
e->arg2,
- e->retval);
- else
- TRACE("(null)\n");
- if (MSVCRT_default_matherr_func)
- return MSVCRT_default_matherr_func(e);
- ERR(":Unhandled math error!\n");
- return 0;
-}
-
-/*********************************************************************
- * __setusermatherr (MSVCRT.@)
- */
-void CDECL __setusermatherr(MSVCRT_matherr_func func)
-{
- MSVCRT_default_matherr_func = func;
- TRACE(":new matherr handler %p\n", func);
-}
diff --git a/sdk/lib/crt/math/math.cmake b/sdk/lib/crt/math/math.cmake
index a11c62ccb3f..e647201f53b 100644
--- a/sdk/lib/crt/math/math.cmake
+++ b/sdk/lib/crt/math/math.cmake
@@ -3,6 +3,7 @@ list(APPEND LIBCNTPR_MATH_SOURCE
math/abs.c
math/div.c
math/labs.c
+ math/usermatherr.c
)
if(ARCH STREQUAL "i386")
diff --git a/sdk/lib/crt/math/usermatherr.c b/sdk/lib/crt/math/usermatherr.c
new file mode 100644
index 00000000000..283a42cd5d0
--- /dev/null
+++ b/sdk/lib/crt/math/usermatherr.c
@@ -0,0 +1,36 @@
+/*
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __setusermatherr and _invoke_user_matherr
+ * COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer(a)reactos.org>
+ */
+
+// DO NOT SYNC WITH WINE OR MINGW32
+
+#include <math.h>
+
+/* MS headers have this in corecrt_startup.h */
+typedef int (*_UserMathErrorFunctionPointer)(struct _exception *);
+
+static _UserMathErrorFunctionPointer user_matherr = NULL;;
+
+void
+__cdecl
+__setusermatherr(_UserMathErrorFunctionPointer func)
+{
+ user_matherr = func;
+}
+
+int
+__cdecl
+_invoke_user_matherr(struct _exception *e)
+{
+ if (user_matherr != NULL)
+ {
+ return user_matherr(e);
+ }
+ else
+ {
+ return 0;
+ }
+}
diff --git a/sdk/lib/crt/msvcrtex.cmake b/sdk/lib/crt/msvcrtex.cmake
index d438a841d31..38ad8b04712 100644
--- a/sdk/lib/crt/msvcrtex.cmake
+++ b/sdk/lib/crt/msvcrtex.cmake
@@ -2,6 +2,7 @@
include_directories(include/internal/mingw-w64)
list(APPEND MSVCRTEX_SOURCE
+ startup/_matherr.c
startup/crtexe.c
startup/wcrtexe.c
startup/crt_handler.c
@@ -12,7 +13,6 @@ list(APPEND MSVCRTEX_SOURCE
startup/mingw_helpers.c
startup/natstart.c
startup/charmax.c
- startup/merr.c
startup/atonexit.c
startup/dllmain.c
startup/txtmode.c
diff --git a/sdk/lib/crt/startup/_matherr.c b/sdk/lib/crt/startup/_matherr.c
new file mode 100644
index 00000000000..0cde46ec56d
--- /dev/null
+++ b/sdk/lib/crt/startup/_matherr.c
@@ -0,0 +1,18 @@
+/*
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of _matherr dummy
+ * COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer(a)reactos.org>
+ */
+
+// DO NOT SYNC WITH WINE OR MINGW32
+
+#include <math.h>
+
+/* Dummy function, like in MS CRT */
+int
+__cdecl
+_matherr(struct _exception *pexcept)
+{
+ return 0;
+}
diff --git a/sdk/lib/crt/startup/merr.c b/sdk/lib/crt/startup/merr.c
deleted file mode 100644
index 464c211fed9..00000000000
--- a/sdk/lib/crt/startup/merr.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the w64 mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-
-#include <internal.h>
-#include <math.h>
-#include <stdio.h>
-
-typedef int (__cdecl *fUserMathErr)(struct _exception *);
-static fUserMathErr stUserMathErr;
-
-void __mingw_raise_matherr (int typ, const char *name, double a1, double a2,
- double rslt)
-{
- struct _exception ex;
- if (!stUserMathErr)
- return;
- ex.type = typ;
- ex.name = (char*)name;
- ex.arg1 = a1;
- ex.arg2 = a2;
- ex.retval = rslt;
- (*stUserMathErr)(&ex);
-}
-
-#undef __setusermatherr
-
-void __mingw_setusermatherr (int (__cdecl *f)(struct _exception *))
-{
- stUserMathErr = f;
- __setusermatherr (f);
-}
-
-int __CRTDECL
-_matherr (struct _exception *pexcept)
-{
- const char * type;
-
- switch(pexcept->type)
- {
- case _DOMAIN:
- type = "Argument domain error (DOMAIN)";
- break;
-
- case _SING:
- type = "Argument singularity (SIGN)";
- break;
-
- case _OVERFLOW:
- type = "Overflow range error (OVERFLOW)";
- break;
-
- case _PLOSS:
- type = "Partial loss of significance (PLOSS)";
- break;
-
- case _TLOSS:
- type = "Total loss of significance (TLOSS)";
- break;
-
- case _UNDERFLOW:
- type = "The result is too small to be represented (UNDERFLOW)";
- break;
-
- default:
- type = "Unknown error";
- break;
- }
-
- __mingw_fprintf (stderr, "_matherr(): %s in %s(%g, %g) (retval=%g)\n",
- type, pexcept->name, pexcept->arg1, pexcept->arg2, pexcept->retval);
- return 0;
-}
-
diff --git a/sdk/lib/crt/startup/startup.cmake b/sdk/lib/crt/startup/startup.cmake
index b2d3070c12d..1574d29e97b 100644
--- a/sdk/lib/crt/startup/startup.cmake
+++ b/sdk/lib/crt/startup/startup.cmake
@@ -1,5 +1,6 @@
list(APPEND CRT_STARTUP_SOURCE
+ startup/_matherr.c
startup/crtexe.c
startup/wcrtexe.c
startup/crt_handler.c
@@ -10,7 +11,6 @@ list(APPEND CRT_STARTUP_SOURCE
startup/mingw_helpers.c
startup/natstart.c
startup/charmax.c
- #startup/merr.c
startup/atonexit.c
#startup/txtmode.c
startup/pesect.c