Commit e684d8169bc866c413b269005c7645fd28146d10
Committed by
Jay Berkenbilt
1 parent
218f069a
Make QPDFValue::object_description a shared pointer
Showing
7 changed files
with
25 additions
and
21 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -2176,7 +2176,8 @@ QPDFObjectHandle::setObjectDescription( |
| 2176 | 2176 | // This is called during parsing on newly created direct objects, |
| 2177 | 2177 | // so we can't call dereference() here. |
| 2178 | 2178 | if (isInitialized() && obj.get()) { |
| 2179 | - obj->setDescription(owning_qpdf, object_description); | |
| 2179 | + auto descr = std::make_shared<std::string>(object_description); | |
| 2180 | + obj->setDescription(owning_qpdf, descr); | |
| 2180 | 2181 | } |
| 2181 | 2182 | } |
| 2182 | 2183 | ... | ... |
libqpdf/QPDFParser.cc
| ... | ... | @@ -419,11 +419,10 @@ QPDFParser::setDescription( |
| 419 | 419 | qpdf_offset_t parsed_offset) const |
| 420 | 420 | { |
| 421 | 421 | if (auto& obj = oh.obj) { |
| 422 | - obj->setDescription( | |
| 423 | - context, | |
| 424 | - (input->getName() + ", " + object_description + " at offset " + | |
| 425 | - std::to_string(descr_offset)), | |
| 426 | - parsed_offset); | |
| 422 | + auto descr = std::make_shared<std::string>( | |
| 423 | + input->getName() + ", " + object_description + " at offset " + | |
| 424 | + std::to_string(descr_offset)); | |
| 425 | + obj->setDescription(context, descr, parsed_offset); | |
| 427 | 426 | } |
| 428 | 427 | } |
| 429 | 428 | ... | ... |
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -123,10 +123,9 @@ QPDF_Stream::QPDF_Stream( |
| 123 | 123 | throw std::logic_error("stream object instantiated with non-dictionary " |
| 124 | 124 | "object for dictionary"); |
| 125 | 125 | } |
| 126 | - setDescription( | |
| 127 | - qpdf, | |
| 128 | - qpdf->getFilename() + ", stream object " + og.unparse(' '), | |
| 129 | - offset); | |
| 126 | + auto descr = std::make_shared<std::string>( | |
| 127 | + qpdf->getFilename() + ", stream object " + og.unparse(' ')); | |
| 128 | + setDescription(qpdf, descr, offset); | |
| 130 | 129 | } |
| 131 | 130 | |
| 132 | 131 | std::shared_ptr<QPDFObject> |
| ... | ... | @@ -284,7 +283,7 @@ QPDF_Stream::getStreamJSON( |
| 284 | 283 | |
| 285 | 284 | void |
| 286 | 285 | QPDF_Stream::setDescription( |
| 287 | - QPDF* qpdf, std::string const& description, qpdf_offset_t offset) | |
| 286 | + QPDF* qpdf, std::shared_ptr<std::string>& description, qpdf_offset_t offset) | |
| 288 | 287 | { |
| 289 | 288 | this->QPDFValue::setDescription(qpdf, description, offset); |
| 290 | 289 | setDictDescription(); | ... | ... |
libqpdf/qpdf/QPDFObject_private.hh
| ... | ... | @@ -70,7 +70,9 @@ class QPDFObject |
| 70 | 70 | } |
| 71 | 71 | void |
| 72 | 72 | setDescription( |
| 73 | - QPDF* qpdf, std::string const& description, qpdf_offset_t offset = -1) | |
| 73 | + QPDF* qpdf, | |
| 74 | + std::shared_ptr<std::string>& description, | |
| 75 | + qpdf_offset_t offset = -1) | |
| 74 | 76 | { |
| 75 | 77 | return value->setDescription(qpdf, description, offset); |
| 76 | 78 | } | ... | ... |
libqpdf/qpdf/QPDFParser.hh
| ... | ... | @@ -40,7 +40,6 @@ class QPDFParser |
| 40 | 40 | void warn(qpdf_offset_t offset, std::string const& msg) const; |
| 41 | 41 | void warn(std::string const& msg) const; |
| 42 | 42 | static void warn(QPDF*, QPDFExc const&); |
| 43 | - | |
| 44 | 43 | void setDescription( |
| 45 | 44 | QPDFObjectHandle oh, |
| 46 | 45 | qpdf_offset_t descr_offset, | ... | ... |
libqpdf/qpdf/QPDFValue.hh
| ... | ... | @@ -25,7 +25,9 @@ class QPDFValue |
| 25 | 25 | virtual JSON getJSON(int json_version) = 0; |
| 26 | 26 | virtual void |
| 27 | 27 | setDescription( |
| 28 | - QPDF* qpdf_p, std::string const& description, qpdf_offset_t offset) | |
| 28 | + QPDF* qpdf_p, | |
| 29 | + std::shared_ptr<std::string>& description, | |
| 30 | + qpdf_offset_t offset) | |
| 29 | 31 | { |
| 30 | 32 | qpdf = qpdf_p; |
| 31 | 33 | object_description = description; |
| ... | ... | @@ -34,8 +36,9 @@ class QPDFValue |
| 34 | 36 | void |
| 35 | 37 | setDefaultDescription(QPDF* a_qpdf, QPDFObjGen const& a_og) |
| 36 | 38 | { |
| 37 | - if (object_description.empty()) { | |
| 38 | - object_description = "object " + a_og.unparse(' '); | |
| 39 | + if (!object_description) { | |
| 40 | + object_description = | |
| 41 | + std::make_shared<std::string>("object " + a_og.unparse(' ')); | |
| 39 | 42 | } |
| 40 | 43 | qpdf = a_qpdf; |
| 41 | 44 | og = a_og; |
| ... | ... | @@ -44,13 +47,14 @@ class QPDFValue |
| 44 | 47 | getDescription(QPDF*& qpdf_p, std::string& description) |
| 45 | 48 | { |
| 46 | 49 | qpdf_p = qpdf; |
| 47 | - description = object_description; | |
| 50 | + description = object_description ? *object_description : ""; | |
| 48 | 51 | return qpdf != nullptr; |
| 49 | 52 | } |
| 50 | 53 | bool |
| 51 | 54 | hasDescription() |
| 52 | 55 | { |
| 53 | - return qpdf != nullptr && !object_description.empty(); | |
| 56 | + return qpdf != nullptr && object_description && | |
| 57 | + !object_description->empty(); | |
| 54 | 58 | } |
| 55 | 59 | void |
| 56 | 60 | setParsedOffset(qpdf_offset_t offset) |
| ... | ... | @@ -109,7 +113,7 @@ class QPDFValue |
| 109 | 113 | private: |
| 110 | 114 | QPDFValue(QPDFValue const&) = delete; |
| 111 | 115 | QPDFValue& operator=(QPDFValue const&) = delete; |
| 112 | - std::string object_description; | |
| 116 | + std::shared_ptr<std::string> object_description; | |
| 113 | 117 | |
| 114 | 118 | const qpdf_object_type_e type_code{::ot_uninitialized}; |
| 115 | 119 | char const* type_name{"uninitialized"}; | ... | ... |
libqpdf/qpdf/QPDF_Stream.hh
| ... | ... | @@ -26,8 +26,8 @@ class QPDF_Stream: public QPDFValue |
| 26 | 26 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 27 | 27 | virtual std::string unparse(); |
| 28 | 28 | virtual JSON getJSON(int json_version); |
| 29 | - virtual void | |
| 30 | - setDescription(QPDF*, std::string const&, qpdf_offset_t offset); | |
| 29 | + virtual void setDescription( | |
| 30 | + QPDF*, std::shared_ptr<std::string>& description, qpdf_offset_t offset); | |
| 31 | 31 | virtual void disconnect(); |
| 32 | 32 | QPDFObjectHandle getDict() const; |
| 33 | 33 | bool isDataModified() const; | ... | ... |