Commit 18b26a2b84289f56762ee5e655f4e8a73ce27ef1
1 parent
2f232e8e
Refactor `assert_debug.h` to add new debug assertion aliases and update include …
…directives across modules to improve clarity and enforce better assertion practices.
Showing
10 changed files
with
29 additions
and
19 deletions
README-maintainer.md
| @@ -200,7 +200,15 @@ Building docs from pull requests is also enabled. | @@ -200,7 +200,15 @@ Building docs from pull requests is also enabled. | ||
| 200 | 200 | ||
| 201 | * Test code: #include <qpdf/assert_test.h> first. | 201 | * Test code: #include <qpdf/assert_test.h> first. |
| 202 | * Debug code: #include <qpdf/assert_debug.h> first and use | 202 | * Debug code: #include <qpdf/assert_debug.h> first and use |
| 203 | - qpdf_assert_debug instead of assert. | 203 | + qpdf_assert_debug instead of assert. Note that <qpdf/Util.hh> |
| 204 | + includes assert_debug.h. Include this instead if 'At most one | ||
| 205 | + qpdf/assert header ...' errors are encounted, especially when | ||
| 206 | + using assert in private header files. | ||
| 207 | + * Use 'qpdf_expect', 'qpdf_static_expect', 'qpdf_ensures' and | ||
| 208 | + 'qpdf_ionvariant' to document pre/post-conditions and ivariants. | ||
| 209 | + This requires inclusion of 'assert_debug.h' or 'Util.hh'. Remember | ||
| 210 | + that these (except for 'qpdf_static_expect') are only checked in | ||
| 211 | + debug builds. | ||
| 204 | 212 | ||
| 205 | These rules are enforced by the check-assert test. This practices | 213 | These rules are enforced by the check-assert test. This practices |
| 206 | serves to | 214 | serves to |
libqpdf/Pl_Base64.cc
libqpdf/QPDFObjectHandle.cc
libqpdf/QPDFWriter.cc
libqpdf/QPDF_encryption.cc
libqpdf/QPDF_optimization.cc
libqpdf/qpdf/InputSource_private.hh
libqpdf/qpdf/Pipeline_private.hh
| 1 | #ifndef PIPELINE_PRIVATE_HH | 1 | #ifndef PIPELINE_PRIVATE_HH |
| 2 | #define PIPELINE_PRIVATE_HH | 2 | #define PIPELINE_PRIVATE_HH |
| 3 | 3 | ||
| 4 | +#include <qpdf/Types.h> | ||
| 5 | + | ||
| 4 | #include <qpdf/Pipeline.hh> | 6 | #include <qpdf/Pipeline.hh> |
| 5 | 7 | ||
| 6 | #include <qpdf/Pl_Flate.hh> | 8 | #include <qpdf/Pl_Flate.hh> |
| 7 | -#include <qpdf/Types.h> | 9 | +#include <qpdf/Util.hh> |
| 8 | 10 | ||
| 9 | namespace qpdf::pl | 11 | namespace qpdf::pl |
| 10 | { | 12 | { |
libqpdf/qpdf/Util.hh
| 1 | #ifndef UTIL_HH | 1 | #ifndef UTIL_HH |
| 2 | #define UTIL_HH | 2 | #define UTIL_HH |
| 3 | 3 | ||
| 4 | +#include <qpdf/assert_debug.h> | ||
| 5 | + | ||
| 4 | #include <string> | 6 | #include <string> |
| 7 | +#include <utility> | ||
| 5 | 8 | ||
| 6 | namespace qpdf::util | 9 | namespace qpdf::util |
| 7 | { | 10 | { |
| 8 | - // This is a collection of useful utility functions for qpdf internal use. They include inline | ||
| 9 | - // functions, some of which are exposed as regular functions in QUtil. Implementations are in | ||
| 10 | - // QUtil.cc. | 11 | + // qpdf::util is a collection of useful utility functions for qpdf internal use. It includes |
| 12 | + // inline functions, some of which are exposed as regular functions in QUtil. Implementations | ||
| 13 | + // are in QUtil.cc. | ||
| 11 | 14 | ||
| 12 | inline constexpr char | 15 | inline constexpr char |
| 13 | hex_decode_char(char digit) | 16 | hex_decode_char(char digit) |
libqpdf/qpdf/assert_debug.h
| @@ -12,7 +12,15 @@ | @@ -12,7 +12,15 @@ | ||
| 12 | #else | 12 | #else |
| 13 | # define QPDF_ASSERT_H | 13 | # define QPDF_ASSERT_H |
| 14 | 14 | ||
| 15 | -# include <assert.h> | 15 | +# include <cassert> |
| 16 | # define qpdf_assert_debug assert | 16 | # define qpdf_assert_debug assert |
| 17 | +// Alias for assert. Pre-condition is only enforced in debug builds. | ||
| 18 | +# define qpdf_expect assert | ||
| 19 | +// Alias for assert. Post-condition is only enforced in debug builds. | ||
| 20 | +# define qpdf_ensures assert | ||
| 21 | +// Alias for assert. Invariant is only enforced in debug builds. | ||
| 22 | +# define qpdf_invariant assert | ||
| 23 | +// Alias for static_assert. | ||
| 24 | +# define qpdf_static_expect static_assert | ||
| 17 | 25 | ||
| 18 | #endif /* QPDF_ASSERT_H */ | 26 | #endif /* QPDF_ASSERT_H */ |