ReactOS 0.4.16-dev-822-gbcedb53
matherr.cpp
Go to the documentation of this file.
1//
2// matherr.cpp
3//
4// Copyright (c) 2024 Timo Kreuzer
5//
6// User math error support.
7//
8// SPDX-License-Identifier: MIT
9//
10
11#include <math.h>
12#include <corecrt_startup.h>
13#include <corecrt_internal.h>
14
15static __crt_state_management::dual_state_global<_UserMathErrorFunctionPointer> __acrt_global_user_matherr;
16
17//
18// Declared in corecrt_internal.h
19// Called from initialize_pointers()
20//
21extern "C"
23{
25 reinterpret_cast<_UserMathErrorFunctionPointer>(encoded_null));
26}
27
28//
29// Declared in corecrt_internal.h
30//
31extern "C"
33{
35 __crt_fast_decode_pointer(__acrt_global_user_matherr.value());
36 return user_matherr != nullptr;
37}
38
39//
40// Declared in corecrt_internal.h
41//
42extern "C"
44{
46 __crt_fast_decode_pointer(__acrt_global_user_matherr.value());
47 if (user_matherr != nullptr)
48 {
49 return user_matherr(_Exp);
50 }
51
52 return 0;
53}
54
55//
56// Declared in corecrt_startup.h
57//
58extern "C"
59void
62 _UserMathErrorFunctionPointer _UserMathErrorFunction)
63{
65 __crt_fast_encode_pointer(_UserMathErrorFunction);
66
67 __acrt_global_user_matherr.value() = encodedPtr;
68}
69
70//
71// Used by libm
72//
73extern "C"
74int
77 int type,
78 char* name,
79 double arg1,
80 double arg2,
81 double retval)
82{
83 struct _exception excpt;
84 excpt.type = type;
85 excpt.name = name;
86 excpt.arg1 = arg1;
87 excpt.arg2 = arg2;
88 excpt.retval = retval;
89 return __acrt_invoke_user_matherr(&excpt);
90}
static _UserMathErrorFunctionPointer user_matherr
#define __cdecl
Definition: accygwin.h:79
int(__cdecl * _UserMathErrorFunctionPointer)(struct _exception *)
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
void __cdecl __setusermatherr(_UserMathErrorFunctionPointer _UserMathErrorFunction)
Definition: matherr.cpp:61
int __cdecl _invoke_matherr(int type, char *name, double arg1, double arg2, double retval)
Definition: matherr.cpp:76
void __cdecl __acrt_initialize_user_matherr(void *encoded_null)
Definition: matherr.cpp:22
static __crt_state_management::dual_state_global< _UserMathErrorFunctionPointer > __acrt_global_user_matherr
Definition: matherr.cpp:15
bool __cdecl __acrt_has_user_matherr(void)
Definition: matherr.cpp:32
int __cdecl __acrt_invoke_user_matherr(struct _exception *_Exp)
Definition: matherr.cpp:43
double retval
Definition: math.h:25
char * name
Definition: math.h:22
double arg2
Definition: math.h:24
int type
Definition: math.h:21
double arg1
Definition: math.h:23
Definition: name.c:39
int retval
Definition: wcstombs.cpp:91
_CRTIMP short __cdecl _Exp(double *, double, short)