Commit 18b26a2b84289f56762ee5e655f4e8a73ce27ef1

Authored by m-holger
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.
README-maintainer.md
... ... @@ -200,7 +200,15 @@ Building docs from pull requests is also enabled.
200 200  
201 201 * Test code: #include <qpdf/assert_test.h> first.
202 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 213 These rules are enforced by the check-assert test. This practices
206 214 serves to
... ...
libqpdf/Pl_Base64.cc
1   -#include <qpdf/assert_debug.h>
2   -
3 1 #include <qpdf/Pl_Base64.hh>
4 2  
5 3 #include <qpdf/QIntC.hh>
6   -#include <qpdf/QUtil.hh>
7 4 #include <qpdf/Util.hh>
8 5  
9 6 #include <cstring>
... ...
libqpdf/QPDFObjectHandle.cc
1   -#include <qpdf/assert_debug.h>
2   -
3 1 #include <qpdf/QPDFObjectHandle_private.hh>
4 2  
5 3 #include <qpdf/JSON_writer.hh>
... ...
libqpdf/QPDFWriter.cc
1   -#include <qpdf/assert_debug.h>
2   -
3 1 #include <qpdf/qpdf-config.h> // include early for large file support
4 2  
5 3 #include <qpdf/QPDFWriter_private.hh>
... ...
libqpdf/QPDF_encryption.cc
1   -// This file implements methods from the QPDF class that involve
2   -// encryption.
3   -
4   -#include <qpdf/assert_debug.h>
  1 +// This file implements methods from the QPDF class that involve encryption.
5 2  
6 3 #include <qpdf/QPDF_private.hh>
7 4  
... ...
libqpdf/QPDF_optimization.cc
1 1 // See the "Optimization" section of the manual.
2 2  
3   -#include <qpdf/assert_debug.h>
4   -
5 3 #include <qpdf/QPDF_private.hh>
6 4  
7 5 #include <qpdf/QPDFExc.hh>
... ...
libqpdf/qpdf/InputSource_private.hh
... ... @@ -3,6 +3,7 @@
3 3  
4 4 #include <qpdf/Buffer.hh>
5 5 #include <qpdf/InputSource.hh>
  6 +#include <qpdf/Util.hh>
6 7  
7 8 #include <limits>
8 9 #include <sstream>
... ...
libqpdf/qpdf/Pipeline_private.hh
1 1 #ifndef PIPELINE_PRIVATE_HH
2 2 #define PIPELINE_PRIVATE_HH
3 3  
  4 +#include <qpdf/Types.h>
  5 +
4 6 #include <qpdf/Pipeline.hh>
5 7  
6 8 #include <qpdf/Pl_Flate.hh>
7   -#include <qpdf/Types.h>
  9 +#include <qpdf/Util.hh>
8 10  
9 11 namespace qpdf::pl
10 12 {
... ...
libqpdf/qpdf/Util.hh
1 1 #ifndef UTIL_HH
2 2 #define UTIL_HH
3 3  
  4 +#include <qpdf/assert_debug.h>
  5 +
4 6 #include <string>
  7 +#include <utility>
5 8  
6 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 15 inline constexpr char
13 16 hex_decode_char(char digit)
... ...
libqpdf/qpdf/assert_debug.h
... ... @@ -12,7 +12,15 @@
12 12 #else
13 13 # define QPDF_ASSERT_H
14 14  
15   -# include <assert.h>
  15 +# include <cassert>
16 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 26 #endif /* QPDF_ASSERT_H */
... ...