Moved mhd_panic() and helpers to separate .c/.h files

This commit is contained in:
Evgeny Grin (Karlson2k)
2022-01-25 19:45:53 +03:00
parent 89b4a7fb2d
commit fc66711ad5
8 changed files with 196 additions and 112 deletions
+1 -1
View File
@@ -3150,7 +3150,7 @@ MHD_set_connection_value_n (struct MHD_Connection *connection,
* simply prints an error message and calls `abort()`. Alternative
* implementations might call `exit()` or other similar functions.
*
* @param cb new error handler
* @param cb new error handler or NULL to use default handler
* @param cls passed to @a cb
* @ingroup logging
*/
+1
View File
@@ -88,6 +88,7 @@ libmicrohttpd_la_SOURCES = \
mhd_sockets.c mhd_sockets.h \
mhd_itc.c mhd_itc.h mhd_itc_types.h \
mhd_compat.c mhd_compat.h \
mhd_panic.c mhd_panic.h \
response.c response.h
if USE_POSIX_THREADS
+1 -68
View File
@@ -116,47 +116,6 @@ MHD_epoll (struct MHD_Daemon *daemon,
#endif /* EPOLL_SUPPORT */
/**
* Default implementation of the panic function,
* prints an error message and aborts.
*
* @param cls unused
* @param file name of the file with the problem
* @param line line number with the problem
* @param reason error message with details
*/
_MHD_NORETURN static void
mhd_panic_std (void *cls,
const char *file,
unsigned int line,
const char *reason)
{
(void) cls; /* Mute compiler warning. */
#ifdef HAVE_MESSAGES
fprintf (stderr,
_ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"),
file,
line,
reason);
#else /* ! HAVE_MESSAGES */
(void) file; /* Mute compiler warning. */
(void) line; /* Mute compiler warning. */
(void) reason; /* Mute compiler warning. */
#endif
abort ();
}
/**
* Handler for fatal errors.
*/
MHD_PanicCallback mhd_panic = (MHD_PanicCallback) NULL;
/**
* Closure argument for #mhd_panic.
*/
void *mhd_panic_cls = NULL;
/**
* Globally initialise library.
*/
@@ -7888,31 +7847,6 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
}
/**
* Sets the global error handler to a different implementation. @a cb
* will only be called in the case of typically fatal, serious
* internal consistency issues. These issues should only arise in the
* case of serious memory corruption or similar problems with the
* architecture. While @a cb is allowed to return and MHD will then
* try to continue, this is never safe.
*
* The default implementation that is used if no panic function is set
* simply prints an error message and calls `abort()`. Alternative
* implementations might call `exit()` or other similar functions.
*
* @param cb new error handler
* @param cls passed to @a cb
* @ingroup logging
*/
void
MHD_set_panic_func (MHD_PanicCallback cb,
void *cls)
{
mhd_panic = cb;
mhd_panic_cls = cls;
}
/**
* Obtain the version of this library
*
@@ -8175,8 +8109,7 @@ MHD_init (void)
WSADATA wsd;
#endif /* MHD_WINSOCK_SOCKETS */
if (NULL == mhd_panic)
mhd_panic = &mhd_panic_std;
MHD_set_panic_func (NULL, NULL);
#if defined(MHD_WINSOCK_SOCKETS)
if (0 != WSAStartup (MAKEWORD (2, 2), &wsd))
+2 -43
View File
@@ -53,28 +53,8 @@
#define PRIu64 "llu"
#endif /* ! PRIu64 */
#ifdef MHD_PANIC
/* Override any defined MHD_PANIC macro with proper one */
#undef MHD_PANIC
#endif /* MHD_PANIC */
#ifdef HAVE_MESSAGES
/**
* Trigger 'panic' action based on fatal errors.
*
* @param msg error message (const char *)
*/
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
BUILTIN_NOT_REACHED; } while (0)
#else
/**
* Trigger 'panic' action based on fatal errors.
*
* @param msg error message (const char *)
*/
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
BUILTIN_NOT_REACHED; } while (0)
#endif
/* Must be included before other internal headers! */
#include "mhd_panic.h"
#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
#include "mhd_threads.h"
@@ -147,27 +127,6 @@
*/
#define MHD_BUF_INC_SIZE 1024
/**
* Handler for fatal errors.
*/
extern MHD_PanicCallback mhd_panic;
/**
* Closure argument for "mhd_panic".
*/
extern void *mhd_panic_cls;
/* If we have Clang or gcc >= 4.5, use __builtin_unreachable() */
#if defined(__clang__) || (__GNUC__ > 4) || \
(__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define BUILTIN_NOT_REACHED __builtin_unreachable ()
#elif defined(_MSC_FULL_VER)
#define BUILTIN_NOT_REACHED __assume (0)
#else
#define BUILTIN_NOT_REACHED
#endif
#ifndef MHD_STATICSTR_LEN_
/**
* Determine length of static string / macro strings at compile time.
+101
View File
@@ -0,0 +1,101 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file microhttpd/mhd_panic.h
* @brief MHD_panic() function and helpers
* @author Daniel Pittman
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*/
#include "mhd_panic.h"
#include "platform.h"
#include "microhttpd.h"
/**
* Handler for fatal errors.
*/
MHD_PanicCallback mhd_panic = (MHD_PanicCallback) NULL;
/**
* Closure argument for #mhd_panic.
*/
void *mhd_panic_cls = NULL;
/**
* Default implementation of the panic function,
* prints an error message and aborts.
*
* @param cls unused
* @param file name of the file with the problem
* @param line line number with the problem
* @param reason error message with details
*/
_MHD_NORETURN static void
mhd_panic_std (void *cls,
const char *file,
unsigned int line,
const char *reason)
{
(void) cls; /* Mute compiler warning. */
#ifdef HAVE_MESSAGES
fprintf (stderr,
_ ("Fatal error in GNU libmicrohttpd %s:%u: %s\n"),
file,
line,
reason);
#else /* ! HAVE_MESSAGES */
(void) file; /* Mute compiler warning. */
(void) line; /* Mute compiler warning. */
(void) reason; /* Mute compiler warning. */
#endif
abort ();
}
/**
* Sets the global error handler to a different implementation. @a cb
* will only be called in the case of typically fatal, serious
* internal consistency issues. These issues should only arise in the
* case of serious memory corruption or similar problems with the
* architecture. While @a cb is allowed to return and MHD will then
* try to continue, this is never safe.
*
* The default implementation that is used if no panic function is set
* simply prints an error message and calls `abort()`. Alternative
* implementations might call `exit()` or other similar functions.
*
* @param cb new error handler or NULL to use default handler
* @param cls passed to @a cb
* @ingroup logging
*/
void
MHD_set_panic_func (MHD_PanicCallback cb,
void *cls)
{
if ((MHD_PanicCallback) NULL != cb)
mhd_panic = cb;
else
mhd_panic = &mhd_panic_std;
mhd_panic_cls = cls;
}
+82
View File
@@ -0,0 +1,82 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file microhttpd/mhd_panic.h
* @brief Declaration and macros for MHD_panic()
* @author Daniel Pittman
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*/
#ifndef MHD_PANIC_H
#define MHD_PANIC_H 1
#include "mhd_options.h"
#ifdef MHD_PANIC
/* Override any possible defined MHD_PANIC macro with proper one */
#undef MHD_PANIC
#endif /* MHD_PANIC */
/* If we have Clang or gcc >= 4.5, use __builtin_unreachable() */
#if defined(__clang__) || (__GNUC__ > 4) || \
(__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define BUILTIN_NOT_REACHED __builtin_unreachable ()
#elif defined(_MSC_FULL_VER)
#define BUILTIN_NOT_REACHED __assume (0)
#else
#define BUILTIN_NOT_REACHED
#endif
/* The MHD_PanicCallback type, but without main header. */
/**
* Handler for fatal errors.
*/
extern void
(*mhd_panic) (void *cls,
const char *file,
unsigned int line,
const char *reason);
/**
* Closure argument for "mhd_panic".
*/
extern void *mhd_panic_cls;
#ifdef HAVE_MESSAGES
/**
* Trigger 'panic' action based on fatal errors.
*
* @param msg error message (const char *)
*/
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
BUILTIN_NOT_REACHED; } while (0)
#else
/**
* Trigger 'panic' action based on fatal errors.
*
* @param msg error message (const char *)
*/
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
BUILTIN_NOT_REACHED; } while (0)
#endif
#endif /* MHD_PANIC_H */
+2
View File
@@ -24,6 +24,7 @@
<ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c">
<ExcludedFromBuild Condition="'$(PlatformToolsetVersion)'&gt;='140'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="$(MhdSrc)microhttpd\mhd_panic.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MhdSrc)include\autoinit_funcs.h" />
@@ -53,6 +54,7 @@
<ClInclude Include="$(MhdSrc)microhttpd\mhd_itc.h" />
<ClInclude Include="$(MhdSrc)microhttpd\mhd_itc_types.h" />
<ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h" />
<ClInclude Include="$(MhdSrc)microhttpd\mhd_panic.h" />
<ClInclude Include="$(MhdW32Common)MHD_config.h" />
</ItemGroup>
<ItemGroup>
+6
View File
@@ -109,6 +109,9 @@
<ClInclude Include="$(MhdSrc)microhttpd\mhd_compat.h">
<Filter>Internal Headers</Filter>
</ClInclude>
<ClInclude Include="$(MhdSrc)microhttpd\mhd_panic.h">
<Filter>Internal Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MhdSrc)microhttpd\base64.c">
@@ -174,6 +177,9 @@
<ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MhdSrc)microhttpd\mhd_panic.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="$(MhdW32Common)microhttpd_dll_res_vc.rc">