From 8cf7f2bfb542b1583aa525611179d1a545f945d5 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 5 Feb 2022 08:26:32 -0500 Subject: [PATCH] API contract: qpdf_get_qpdf_version() returns a static --- ChangeLog | 3 +++ include/qpdf/QPDF.hh | 2 +- include/qpdf/qpdf-c.h | 4 +++- libqpdf/QPDF.cc | 5 ++++- libqpdf/qpdf-c.cc | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index db2faa7f..3bc733e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2022-02-05 Jay Berkenbilt + * Add comments letting people know that the version string + returned by QPDF::QPDFVersion and qpdf_get_qpdf_version is static. + * Add QUtil::make_unique_cstr to return a std::unique_ptr as an alternative to QUtil::copy_string and QUtil::make_shared_cstr. diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index b26fc805..5d3fd651 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -773,7 +773,7 @@ class QPDF friend class Pipe; private: - static std::string qpdf_version; + static std::string const qpdf_version; class ObjCache { diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index a6fc82ae..5a0595b2 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -171,7 +171,9 @@ extern "C" { QPDF_DLL void qpdf_silence_errors(qpdf_data qpdf); - /* Returns the version of the qpdf software */ + /* Returns the version of the qpdf software. This is guaranteed to + * be a static value. + */ QPDF_DLL char const* qpdf_get_qpdf_version(); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index ce534d6e..565c73f6 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -26,7 +26,9 @@ #include #include -std::string QPDF::qpdf_version(QPDF_VERSION); +// This must be a fixed value. This API returns a const reference to +// it, and the C API relies on its being static as well. +std::string const QPDF::qpdf_version(QPDF_VERSION); static char const* EMPTY_PDF = "%PDF-1.3\n" @@ -178,6 +180,7 @@ QPDF::StringDecrypter::decryptString(std::string& val) std::string const& QPDF::QPDFVersion() { + // The C API relies on this being a static value. return QPDF::qpdf_version; } diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc index 6f03a315..f03ed845 100644 --- a/libqpdf/qpdf-c.cc +++ b/libqpdf/qpdf-c.cc @@ -161,6 +161,7 @@ static QPDF_ERROR_CODE trap_errors( char const* qpdf_get_qpdf_version() { QTC::TC("qpdf", "qpdf-c called qpdf_get_qpdf_version"); + // The API guarantees that this is a static value. return QPDF::QPDFVersion().c_str(); }