[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 03/05: Moved mhd_panic() and helpers to separate .c/.h f
From: |
gnunet |
Subject: |
[libmicrohttpd] 03/05: Moved mhd_panic() and helpers to separate .c/.h files |
Date: |
Tue, 25 Jan 2022 17:46:36 +0100 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit fc66711ad5b92067c758c807ac6210f808050767
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Tue Jan 25 19:25:38 2022 +0300
Moved mhd_panic() and helpers to separate .c/.h files
---
src/include/microhttpd.h | 2 +-
src/microhttpd/Makefile.am | 1 +
src/microhttpd/daemon.c | 69 +--------------------
src/microhttpd/internal.h | 45 +-------------
src/microhttpd/mhd_panic.c | 101 +++++++++++++++++++++++++++++++
src/microhttpd/mhd_panic.h | 82 +++++++++++++++++++++++++
w32/common/libmicrohttpd-files.vcxproj | 2 +
w32/common/libmicrohttpd-filters.vcxproj | 6 ++
8 files changed, 196 insertions(+), 112 deletions(-)
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 87d2f86e..23ce06c7 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -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
*/
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am
index ba52b740..f5125ef3 100644
--- a/src/microhttpd/Makefile.am
+++ b/src/microhttpd/Makefile.am
@@ -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
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 1ddbd83e..e58a1caa 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -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))
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 3c1a889d..277510d8 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -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.
diff --git a/src/microhttpd/mhd_panic.c b/src/microhttpd/mhd_panic.c
new file mode 100644
index 00000000..1efba20d
--- /dev/null
+++ b/src/microhttpd/mhd_panic.c
@@ -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;
+}
diff --git a/src/microhttpd/mhd_panic.h b/src/microhttpd/mhd_panic.h
new file mode 100644
index 00000000..623639b4
--- /dev/null
+++ b/src/microhttpd/mhd_panic.h
@@ -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 */
diff --git a/w32/common/libmicrohttpd-files.vcxproj
b/w32/common/libmicrohttpd-files.vcxproj
index b6dfb363..e4b6eb14 100644
--- a/w32/common/libmicrohttpd-files.vcxproj
+++ b/w32/common/libmicrohttpd-files.vcxproj
@@ -24,6 +24,7 @@
<ClCompile Include="$(MhdSrc)microhttpd\mhd_compat.c">
<ExcludedFromBuild
Condition="'$(PlatformToolsetVersion)'>='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>
diff --git a/w32/common/libmicrohttpd-filters.vcxproj
b/w32/common/libmicrohttpd-filters.vcxproj
index ceea92fe..fd19a0b0 100644
--- a/w32/common/libmicrohttpd-filters.vcxproj
+++ b/w32/common/libmicrohttpd-filters.vcxproj
@@ -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">
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.