diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-06-12 23:24:15 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-06-12 23:24:15 +0300 |
commit | 279a9ad2ab9f504264f3e1a671fc427a18079205 (patch) | |
tree | 416912756d18a33dc4f27a4a0d857e7677d87c6c | |
parent | 5c988da5164458e15eeae4f6bae930a500795dbf (diff) | |
download | libmicrohttpd-279a9ad2ab9f504264f3e1a671fc427a18079205.tar.gz libmicrohttpd-279a9ad2ab9f504264f3e1a671fc427a18079205.zip |
Added support for detection of 'assert()' and replacement if 'assert()' is not available
-rw-r--r-- | configure.ac | 51 | ||||
-rw-r--r-- | src/microhttpd/Makefile.am | 2 | ||||
-rw-r--r-- | src/microhttpd/mhd_assert.h | 49 |
3 files changed, 99 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 0fd671aa..b6d5cbc0 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1417,8 +1417,6 @@ AC_LINK_IFELSE( | |||
1417 | 1417 | ||
1418 | AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"]) | 1418 | AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"]) |
1419 | 1419 | ||
1420 | MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS -export-dynamic -no-undefined" | ||
1421 | |||
1422 | # gcov compilation | 1420 | # gcov compilation |
1423 | AC_MSG_CHECKING(whether to compile with support for code coverage analysis) | 1421 | AC_MSG_CHECKING(whether to compile with support for code coverage analysis) |
1424 | AC_ARG_ENABLE([coverage], | 1422 | AC_ARG_ENABLE([coverage], |
@@ -1432,6 +1430,54 @@ AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"]) | |||
1432 | AX_COUNT_CPUS | 1430 | AX_COUNT_CPUS |
1433 | AC_SUBST([CPU_COUNT]) | 1431 | AC_SUBST([CPU_COUNT]) |
1434 | 1432 | ||
1433 | AC_MSG_CHECKING([[whether to enable debug asserts]]) | ||
1434 | AC_ARG_ENABLE([[asserts]], | ||
1435 | AS_HELP_STRING([[--enable-asserts]], | ||
1436 | [enable test build with debug asserts]), | ||
1437 | [], [[enable_asserts='no']]) | ||
1438 | AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']]) | ||
1439 | AC_MSG_RESULT([[$enable_asserts]]) | ||
1440 | |||
1441 | AS_VAR_IF([[enable_asserts]], [["yes"]], | ||
1442 | [ | ||
1443 | AC_DEFINE([[_DEBUG]], [[1]], [Define to use debug asserts.]) | ||
1444 | [mhd_assert_test_prg="#include <assert.h> | ||
1445 | int pos_val(void) {return 5;} | ||
1446 | int neg_val(void) {return -5;} | ||
1447 | int main(void) | ||
1448 | { int pos_var = pos_val(), neg_var = neg_val(); | ||
1449 | assert(neg_var > pos_var); /* Must trigger assert. */ | ||
1450 | (void)pos_var; (void)neg_var; | ||
1451 | return 0; } | ||
1452 | "] | ||
1453 | AC_CACHE_CHECK([[whether system assert() is available]], [mhd_cv_sys_assert_avail], | ||
1454 | [ | ||
1455 | AC_LINK_IFELSE([AC_LANG_SOURCE([[$mhd_assert_test_prg]])], | ||
1456 | [[mhd_cv_sys_assert_avail='yes']], | ||
1457 | [[mhd_cv_sys_assert_avail='no']]) | ||
1458 | ] | ||
1459 | ) | ||
1460 | AS_VAR_IF([[mhd_cv_sys_assert_avail]], [["yes"]], | ||
1461 | [ | ||
1462 | AC_CACHE_CHECK([[whether system assert() is usable]], [mhd_cv_sys_assert_use], | ||
1463 | [ | ||
1464 | AC_RUN_IFELSE([AC_LANG_SOURCE([[$mhd_assert_test_prg]])], | ||
1465 | [[mhd_cv_sys_assert_use='no']], | ||
1466 | [[mhd_cv_sys_assert_use='yes']], | ||
1467 | [[mhd_cv_sys_assert_use='assuming yes']]) | ||
1468 | ] | ||
1469 | ) | ||
1470 | AS_VAR_IF([[mhd_cv_sys_assert_use]], [["no"]], [], | ||
1471 | [AC_DEFINE([[HAVE_ASSERT]], [[1]], [Define if you have usable assert() and assert.h])]) | ||
1472 | ] | ||
1473 | ) | ||
1474 | AS_UNSET([mhd_assert_test_prg]) | ||
1475 | ], | ||
1476 | [AC_DEFINE([[NDEBUG]], [[1]], [Define to disable usage of debug asserts.])] | ||
1477 | ) | ||
1478 | |||
1479 | MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS -export-dynamic -no-undefined" | ||
1480 | |||
1435 | AC_SUBST(MHD_LIB_CPPFLAGS) | 1481 | AC_SUBST(MHD_LIB_CPPFLAGS) |
1436 | AC_SUBST(MHD_LIB_CFLAGS) | 1482 | AC_SUBST(MHD_LIB_CFLAGS) |
1437 | AC_SUBST(MHD_LIB_LDFLAGS) | 1483 | AC_SUBST(MHD_LIB_LDFLAGS) |
@@ -1485,6 +1531,7 @@ AC_MSG_NOTICE([libmicrohttpd ${PACKAGE_VERSION} Configuration Summary: | |||
1485 | Target directory: ${prefix} | 1531 | Target directory: ${prefix} |
1486 | Shutdown of listening socket | 1532 | Shutdown of listening socket |
1487 | trigger select: ${mhd_cv_host_shtdwn_trgr_select} | 1533 | trigger select: ${mhd_cv_host_shtdwn_trgr_select} |
1534 | Use debug asserts: ${enable_asserts} | ||
1488 | Messages: ${enable_messages} | 1535 | Messages: ${enable_messages} |
1489 | Basic auth.: ${enable_bauth} | 1536 | Basic auth.: ${enable_bauth} |
1490 | Digest auth.: ${enable_dauth} | 1537 | Digest auth.: ${enable_dauth} |
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am index 36121539..5ae900ac 100644 --- a/src/microhttpd/Makefile.am +++ b/src/microhttpd/Makefile.am | |||
@@ -63,7 +63,7 @@ libmicrohttpd_la_SOURCES = \ | |||
63 | sysfdsetsize.c sysfdsetsize.h \ | 63 | sysfdsetsize.c sysfdsetsize.h \ |
64 | mhd_str.c mhd_str.h \ | 64 | mhd_str.c mhd_str.h \ |
65 | mhd_threads.c mhd_threads.h \ | 65 | mhd_threads.c mhd_threads.h \ |
66 | mhd_locks.h \ | 66 | mhd_locks.h mhd_assert.h \ |
67 | mhd_sockets.c mhd_sockets.h \ | 67 | mhd_sockets.c mhd_sockets.h \ |
68 | mhd_itc.c mhd_itc.h mhd_itc_types.h \ | 68 | mhd_itc.c mhd_itc.h mhd_itc_types.h \ |
69 | mhd_compat.c mhd_compat.h \ | 69 | mhd_compat.c mhd_compat.h \ |
diff --git a/src/microhttpd/mhd_assert.h b/src/microhttpd/mhd_assert.h new file mode 100644 index 00000000..c720ce5c --- /dev/null +++ b/src/microhttpd/mhd_assert.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2017 Karlson2k (Evgeny Grin) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library. | ||
17 | If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file microhttpd/mhd_assert.h | ||
22 | * @brief macros for mhd_assert() | ||
23 | * @author Karlson2k (Evgeny Grin) | ||
24 | */ | ||
25 | |||
26 | #ifndef MHD_ASSERT_H | ||
27 | #define MHD_ASSERT_H 1 | ||
28 | |||
29 | #include "mhd_options.h" | ||
30 | #ifdef NDEBUG | ||
31 | # define mhd_assert(ignore) ((void)0) | ||
32 | #else /* _DEBUG */ | ||
33 | # ifdef HAVE_ASSERT | ||
34 | # include <assert.h> | ||
35 | # define mhd_assert(CHK) assert(CHK) | ||
36 | # else /* ! HAVE_ASSERT */ | ||
37 | # include <stdio.h> | ||
38 | # include <stdlib.h> | ||
39 | # define mhd_assert(CHK) \ | ||
40 | do { \ | ||
41 | if (!(CHK)) { \ | ||
42 | fprintf(stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \ | ||
43 | __FILE__, (unsigned)__LINE__, #CHK); \ | ||
44 | fflush(stderr); abort(); } \ | ||
45 | } while(0) | ||
46 | # endif /* ! HAVE_ASSERT */ | ||
47 | #endif /* _DEBUG */ | ||
48 | |||
49 | #endif /* ! MHD_ASSERT_H */ | ||