Commit e684d8169bc866c413b269005c7645fd28146d10

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 218f069a

Make QPDFValue::object_description a shared pointer

libqpdf/QPDFObjectHandle.cc
@@ -2176,7 +2176,8 @@ QPDFObjectHandle::setObjectDescription( @@ -2176,7 +2176,8 @@ QPDFObjectHandle::setObjectDescription(
2176 // This is called during parsing on newly created direct objects, 2176 // This is called during parsing on newly created direct objects,
2177 // so we can't call dereference() here. 2177 // so we can't call dereference() here.
2178 if (isInitialized() && obj.get()) { 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,11 +419,10 @@ QPDFParser::setDescription(
419 qpdf_offset_t parsed_offset) const 419 qpdf_offset_t parsed_offset) const
420 { 420 {
421 if (auto& obj = oh.obj) { 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,10 +123,9 @@ QPDF_Stream::QPDF_Stream(
123 throw std::logic_error("stream object instantiated with non-dictionary " 123 throw std::logic_error("stream object instantiated with non-dictionary "
124 "object for dictionary"); 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 std::shared_ptr<QPDFObject> 131 std::shared_ptr<QPDFObject>
@@ -284,7 +283,7 @@ QPDF_Stream::getStreamJSON( @@ -284,7 +283,7 @@ QPDF_Stream::getStreamJSON(
284 283
285 void 284 void
286 QPDF_Stream::setDescription( 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 this->QPDFValue::setDescription(qpdf, description, offset); 288 this->QPDFValue::setDescription(qpdf, description, offset);
290 setDictDescription(); 289 setDictDescription();
libqpdf/qpdf/QPDFObject_private.hh
@@ -70,7 +70,9 @@ class QPDFObject @@ -70,7 +70,9 @@ class QPDFObject
70 } 70 }
71 void 71 void
72 setDescription( 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 return value->setDescription(qpdf, description, offset); 77 return value->setDescription(qpdf, description, offset);
76 } 78 }
libqpdf/qpdf/QPDFParser.hh
@@ -40,7 +40,6 @@ class QPDFParser @@ -40,7 +40,6 @@ class QPDFParser
40 void warn(qpdf_offset_t offset, std::string const& msg) const; 40 void warn(qpdf_offset_t offset, std::string const& msg) const;
41 void warn(std::string const& msg) const; 41 void warn(std::string const& msg) const;
42 static void warn(QPDF*, QPDFExc const&); 42 static void warn(QPDF*, QPDFExc const&);
43 -  
44 void setDescription( 43 void setDescription(
45 QPDFObjectHandle oh, 44 QPDFObjectHandle oh,
46 qpdf_offset_t descr_offset, 45 qpdf_offset_t descr_offset,
libqpdf/qpdf/QPDFValue.hh
@@ -25,7 +25,9 @@ class QPDFValue @@ -25,7 +25,9 @@ class QPDFValue
25 virtual JSON getJSON(int json_version) = 0; 25 virtual JSON getJSON(int json_version) = 0;
26 virtual void 26 virtual void
27 setDescription( 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 qpdf = qpdf_p; 32 qpdf = qpdf_p;
31 object_description = description; 33 object_description = description;
@@ -34,8 +36,9 @@ class QPDFValue @@ -34,8 +36,9 @@ class QPDFValue
34 void 36 void
35 setDefaultDescription(QPDF* a_qpdf, QPDFObjGen const& a_og) 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 qpdf = a_qpdf; 43 qpdf = a_qpdf;
41 og = a_og; 44 og = a_og;
@@ -44,13 +47,14 @@ class QPDFValue @@ -44,13 +47,14 @@ class QPDFValue
44 getDescription(QPDF*& qpdf_p, std::string& description) 47 getDescription(QPDF*& qpdf_p, std::string& description)
45 { 48 {
46 qpdf_p = qpdf; 49 qpdf_p = qpdf;
47 - description = object_description; 50 + description = object_description ? *object_description : "";
48 return qpdf != nullptr; 51 return qpdf != nullptr;
49 } 52 }
50 bool 53 bool
51 hasDescription() 54 hasDescription()
52 { 55 {
53 - return qpdf != nullptr && !object_description.empty(); 56 + return qpdf != nullptr && object_description &&
  57 + !object_description->empty();
54 } 58 }
55 void 59 void
56 setParsedOffset(qpdf_offset_t offset) 60 setParsedOffset(qpdf_offset_t offset)
@@ -109,7 +113,7 @@ class QPDFValue @@ -109,7 +113,7 @@ class QPDFValue
109 private: 113 private:
110 QPDFValue(QPDFValue const&) = delete; 114 QPDFValue(QPDFValue const&) = delete;
111 QPDFValue& operator=(QPDFValue const&) = delete; 115 QPDFValue& operator=(QPDFValue const&) = delete;
112 - std::string object_description; 116 + std::shared_ptr<std::string> object_description;
113 117
114 const qpdf_object_type_e type_code{::ot_uninitialized}; 118 const qpdf_object_type_e type_code{::ot_uninitialized};
115 char const* type_name{"uninitialized"}; 119 char const* type_name{"uninitialized"};
libqpdf/qpdf/QPDF_Stream.hh
@@ -26,8 +26,8 @@ class QPDF_Stream: public QPDFValue @@ -26,8 +26,8 @@ class QPDF_Stream: public QPDFValue
26 virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); 26 virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
27 virtual std::string unparse(); 27 virtual std::string unparse();
28 virtual JSON getJSON(int json_version); 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 virtual void disconnect(); 31 virtual void disconnect();
32 QPDFObjectHandle getDict() const; 32 QPDFObjectHandle getDict() const;
33 bool isDataModified() const; 33 bool isDataModified() const;