Commit 8a971af1cfc8189ea58d3f8f66d4536f275bdc4c

Authored by m-holger
Committed by GitHub
2 parents 3a9ec47d 9e8bd681

Merge pull request #1597 from m-holger/assert

Update header guards for `assert_test.h` and `assert_debug.h`
README-maintainer.md
@@ -219,13 +219,19 @@ Building docs from pull requests is also enabled. @@ -219,13 +219,19 @@ Building docs from pull requests is also enabled.
219 serves to 219 serves to
220 220
221 * remind us that assert in release code disappears and so should only 221 * remind us that assert in release code disappears and so should only
222 - be used for debugging; when doing so use a Debug build  
223 - configuration 222 + be used to document pre/post conditions and invariants, and for
  223 + sanity checks during development and testing; when doing so use
  224 + a Debug build configuration.
224 225
225 * protect us from using assert in test code without explicitly 226 * protect us from using assert in test code without explicitly
226 removing the NDEBUG definition, since that would cause the assert 227 removing the NDEBUG definition, since that would cause the assert
227 not to actually be testing anything in non-Debug build 228 not to actually be testing anything in non-Debug build
228 configurations. 229 configurations.
  230 +
  231 + Prior to 12.3 assert_test.h and assert_debug.h shared the same header
  232 + guard, which prevented the simultaneous inclusion of both headers.
  233 + This was changed to permit the CI testing of private-API methods
  234 + without loosing the use of assertions in private header files.
229 235
230 * In a source file, include the header file that declares the source 236 * In a source file, include the header file that declares the source
231 class first followed by a blank line. If a config file is needed 237 class first followed by a blank line. If a config file is needed
libqpdf/qpdf/assert_debug.h
@@ -4,23 +4,18 @@ @@ -4,23 +4,18 @@
4 * disabled in release code. Use qpdf_assert_debug in the code. 4 * disabled in release code. Use qpdf_assert_debug in the code.
5 */ 5 */
6 6
7 -/* assert_debug and assert_test intentionally use the same  
8 - * guard. Search for assert in README-MAINTAINER.  
9 - */  
10 -#ifdef QPDF_ASSERT_H  
11 -# error "At most one qpdf/assert header may be included at most one time"  
12 -#else  
13 -# define QPDF_ASSERT_H 7 +#ifndef QPDF_ASSERT_DEBUG_H
  8 +#define QPDF_ASSERT_DEBUG_H
14 9
15 -# include <cassert>  
16 -# define qpdf_assert_debug assert 10 +#include <cassert>
  11 +#define qpdf_assert_debug assert
17 // Alias for assert. Pre-condition is only enforced in debug builds. 12 // Alias for assert. Pre-condition is only enforced in debug builds.
18 -# define qpdf_expect assert 13 +#define qpdf_expect assert
19 // Alias for assert. Post-condition is only enforced in debug builds. 14 // Alias for assert. Post-condition is only enforced in debug builds.
20 -# define qpdf_ensures assert 15 +#define qpdf_ensures assert
21 // Alias for assert. Invariant is only enforced in debug builds. 16 // Alias for assert. Invariant is only enforced in debug builds.
22 -# define qpdf_invariant assert 17 +#define qpdf_invariant assert
23 // Alias for static_assert. 18 // Alias for static_assert.
24 -# define qpdf_static_expect static_assert 19 +#define qpdf_static_expect static_assert
25 20
26 -#endif /* QPDF_ASSERT_H */ 21 +#endif /* QPDF_ASSERT_DEBUG_H */
libqpdf/qpdf/assert_test.h
1 /* 1 /*
2 - * Include this file to use assert in regular code for  
3 - * debugging/strong sanity checking, knowing that the assert will be  
4 - * disabled in release code. Use qpdf_debug_assert in the code. 2 + * Include this file to use assert in CI code for. This will allow
  3 + * the use of assert and ensure that NDEBUG is undefined (which
  4 + * would cause spurious CI passes).
5 */ 5 */
6 6
7 -/* assert_debug and assert_test intentionally use the same  
8 - * guard. Search for assert in README-MAINTAINER.  
9 - */  
10 -#ifdef QPDF_ASSERT_H  
11 -# error "At most one qpdf/assert header may be included at most one time"  
12 -#else  
13 -# define QPDF_ASSERT_H 7 +#ifndef QPDF_ASSERT_TEST_H
  8 +#define QPDF_ASSERT_TEST_H
14 9
15 -# ifdef NDEBUG  
16 -# undef NDEBUG  
17 -# endif  
18 -# include <assert.h> 10 +#ifdef NDEBUG
  11 +# undef NDEBUG
  12 +#endif
  13 +#include <assert.h>
19 14
20 #endif /* QPDF_ASSERT_H */ 15 #endif /* QPDF_ASSERT_H */