Commit 8cf7f2bfb542b1583aa525611179d1a545f945d5

Authored by Jay Berkenbilt
1 parent 5f3f7882

API contract: qpdf_get_qpdf_version() returns a static

ChangeLog
1 2022-02-05 Jay Berkenbilt <ejb@ql.org> 1 2022-02-05 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Add comments letting people know that the version string
  4 + returned by QPDF::QPDFVersion and qpdf_get_qpdf_version is static.
  5 +
3 * Add QUtil::make_unique_cstr to return a std::unique_ptr<char[]> 6 * Add QUtil::make_unique_cstr to return a std::unique_ptr<char[]>
4 as an alternative to QUtil::copy_string and 7 as an alternative to QUtil::copy_string and
5 QUtil::make_shared_cstr. 8 QUtil::make_shared_cstr.
include/qpdf/QPDF.hh
@@ -773,7 +773,7 @@ class QPDF @@ -773,7 +773,7 @@ class QPDF
773 friend class Pipe; 773 friend class Pipe;
774 774
775 private: 775 private:
776 - static std::string qpdf_version; 776 + static std::string const qpdf_version;
777 777
778 class ObjCache 778 class ObjCache
779 { 779 {
include/qpdf/qpdf-c.h
@@ -171,7 +171,9 @@ extern &quot;C&quot; { @@ -171,7 +171,9 @@ extern &quot;C&quot; {
171 QPDF_DLL 171 QPDF_DLL
172 void qpdf_silence_errors(qpdf_data qpdf); 172 void qpdf_silence_errors(qpdf_data qpdf);
173 173
174 - /* Returns the version of the qpdf software */ 174 + /* Returns the version of the qpdf software. This is guaranteed to
  175 + * be a static value.
  176 + */
175 QPDF_DLL 177 QPDF_DLL
176 char const* qpdf_get_qpdf_version(); 178 char const* qpdf_get_qpdf_version();
177 179
libqpdf/QPDF.cc
@@ -26,7 +26,9 @@ @@ -26,7 +26,9 @@
26 #include <qpdf/QPDF_Stream.hh> 26 #include <qpdf/QPDF_Stream.hh>
27 #include <qpdf/QPDF_Array.hh> 27 #include <qpdf/QPDF_Array.hh>
28 28
29 -std::string QPDF::qpdf_version(QPDF_VERSION); 29 +// This must be a fixed value. This API returns a const reference to
  30 +// it, and the C API relies on its being static as well.
  31 +std::string const QPDF::qpdf_version(QPDF_VERSION);
30 32
31 static char const* EMPTY_PDF = 33 static char const* EMPTY_PDF =
32 "%PDF-1.3\n" 34 "%PDF-1.3\n"
@@ -178,6 +180,7 @@ QPDF::StringDecrypter::decryptString(std::string&amp; val) @@ -178,6 +180,7 @@ QPDF::StringDecrypter::decryptString(std::string&amp; val)
178 std::string const& 180 std::string const&
179 QPDF::QPDFVersion() 181 QPDF::QPDFVersion()
180 { 182 {
  183 + // The C API relies on this being a static value.
181 return QPDF::qpdf_version; 184 return QPDF::qpdf_version;
182 } 185 }
183 186
libqpdf/qpdf-c.cc
@@ -161,6 +161,7 @@ static QPDF_ERROR_CODE trap_errors( @@ -161,6 +161,7 @@ static QPDF_ERROR_CODE trap_errors(
161 char const* qpdf_get_qpdf_version() 161 char const* qpdf_get_qpdf_version()
162 { 162 {
163 QTC::TC("qpdf", "qpdf-c called qpdf_get_qpdf_version"); 163 QTC::TC("qpdf", "qpdf-c called qpdf_get_qpdf_version");
  164 + // The API guarantees that this is a static value.
164 return QPDF::QPDFVersion().c_str(); 165 return QPDF::QPDFVersion().c_str();
165 } 166 }
166 167