Commit e91e642cf35a704866f1dabd89d9a987a309bcc2

Authored by m-holger
Committed by Jay Berkenbilt
1 parent ec35156a

Change object variable in QPDFParser::parse to shared_ptr<QPDFObject>

Showing 1 changed file with 32 additions and 16 deletions
libqpdf/QPDFParser.cc
... ... @@ -4,9 +4,24 @@
4 4 #include <qpdf/QPDFObjGen.hh>
5 5 #include <qpdf/QPDFObjectHandle.hh>
6 6 #include <qpdf/QPDFObject_private.hh>
  7 +#include <qpdf/QPDF_Array.hh>
  8 +#include <qpdf/QPDF_Bool.hh>
  9 +#include <qpdf/QPDF_Dictionary.hh>
  10 +#include <qpdf/QPDF_InlineImage.hh>
  11 +#include <qpdf/QPDF_Integer.hh>
  12 +#include <qpdf/QPDF_Name.hh>
  13 +#include <qpdf/QPDF_Null.hh>
  14 +#include <qpdf/QPDF_Operator.hh>
  15 +#include <qpdf/QPDF_Real.hh>
  16 +#include <qpdf/QPDF_Reserved.hh>
  17 +#include <qpdf/QPDF_Stream.hh>
  18 +#include <qpdf/QPDF_String.hh>
  19 +#include <qpdf/QPDF_Unresolved.hh>
7 20 #include <qpdf/QTC.hh>
8 21 #include <qpdf/QUtil.hh>
9 22  
  23 +#include <memory>
  24 +
10 25 namespace
11 26 {
12 27 struct StackFrame
... ... @@ -39,7 +54,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
39 54  
40 55 empty = false;
41 56  
42   - QPDFObjectHandle object;
  57 + std::shared_ptr<QPDFObject> object;
43 58 bool set_offset = false;
44 59  
45 60 std::vector<StackFrame> stack;
... ... @@ -63,7 +78,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
63 78 parser_state_e state = state_stack.back();
64 79 offset = frame.offset;
65 80  
66   - object = QPDFObjectHandle();
  81 + object = nullptr;
67 82 set_offset = false;
68 83  
69 84 QPDFTokenizer::Token token =
... ... @@ -140,7 +155,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
140 155 break;
141 156  
142 157 case QPDFTokenizer::tt_bool:
143   - object = QPDFObjectHandle::newBool((token.getValue() == "true"));
  158 + object = QPDF_Bool::create((token.getValue() == "true"));
144 159 break;
145 160  
146 161 case QPDFTokenizer::tt_null:
... ... @@ -148,18 +163,18 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
148 163 break;
149 164  
150 165 case QPDFTokenizer::tt_integer:
151   - object = QPDFObjectHandle::newInteger(
  166 + object = QPDF_Integer::create(
152 167 QUtil::string_to_ll(token.getValue().c_str()));
153 168 break;
154 169  
155 170 case QPDFTokenizer::tt_real:
156   - object = QPDFObjectHandle::newReal(token.getValue());
  171 + object = QPDF_Real::create(token.getValue());
157 172 break;
158 173  
159 174 case QPDFTokenizer::tt_name:
160 175 {
161 176 std::string name = token.getValue();
162   - object = QPDFObjectHandle::newName(name);
  177 + object = QPDF_Name::create(name);
163 178  
164 179 if (name == "/Contents") {
165 180 b_contents = true;
... ... @@ -174,7 +189,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
174 189 std::string const& value = token.getValue();
175 190 auto size = olist.size();
176 191 if (content_stream) {
177   - object = QPDFObjectHandle::newOperator(value);
  192 + object = QPDF_Operator::create(value);
178 193 } else if (
179 194 (value == "R") && (state != st_top) && (size >= 2) &&
180 195 (!olist.back().isIndirect()) &&
... ... @@ -196,7 +211,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
196 211 // to indirect objects that don't appear in
197 212 // the PDF) in any parsed object to appear in
198 213 // the object cache.
199   - object = context->getObject(ref_og);
  214 + object = context->getObject(ref_og).obj;
200 215 indirect_ref = true;
201 216 } else {
202 217 QTC::TC("qpdf", "QPDFParser indirect with 0 objid");
... ... @@ -216,7 +231,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
216 231 warn("unknown token while reading object;"
217 232 " treating as string");
218 233 bad = true;
219   - object = QPDFObjectHandle::newString(value);
  234 + object = QPDF_String::create(value);
220 235 }
221 236 }
222 237 break;
... ... @@ -232,7 +247,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
232 247 }
233 248 decrypter->decryptString(val);
234 249 }
235   - object = QPDFObjectHandle::newString(val);
  250 + object = QPDF_String::create(val);
236 251 }
237 252  
238 253 break;
... ... @@ -245,7 +260,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
245 260 break;
246 261 }
247 262  
248   - if (!object.isInitialized() && !is_null &&
  263 + if (object == nullptr && !is_null &&
249 264 (!((state == st_start) || (state == st_stop) ||
250 265 (state == st_eof)))) {
251 266 throw std::logic_error("QPDFObjectHandle::parseInternal: "
... ... @@ -291,7 +306,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
291 306 setDescription(object, input->getLastOffset());
292 307 }
293 308 set_offset = true;
294   - olist.push_back(is_null ? null_oh : object);
  309 + olist.push_back(is_null ? null_oh : QPDFObjectHandle(object));
295 310 break;
296 311  
297 312 case st_top:
... ... @@ -310,7 +325,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
310 325 parser_state_e old_state = state_stack.back();
311 326 state_stack.pop_back();
312 327 if (old_state == st_array) {
313   - object = QPDFObjectHandle::newArray(olist);
  328 + object = QPDF_Array::create(olist);
314 329 setDescription(object, offset - 1);
315 330 // The `offset` points to the next of "[". Set the rewind
316 331 // offset to point to the beginning of "[". This has been
... ... @@ -384,7 +399,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
384 399 QPDFObjectHandle::newString(frame.contents_string);
385 400 dict["/Contents"].setParsedOffset(frame.contents_offset);
386 401 }
387   - object = QPDFObjectHandle::newDictionary(dict);
  402 + object = QPDF_Dictionary::create(dict);
388 403 setDescription(object, offset - 2);
389 404 // The `offset` points to the next of "<<". Set the rewind
390 405 // offset to point to the beginning of "<<". This has been
... ... @@ -397,13 +412,14 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
397 412 if (state_stack.back() == st_top) {
398 413 done = true;
399 414 } else {
400   - stack.back().olist.push_back(is_null ? null_oh : object);
  415 + stack.back().olist.push_back(
  416 + is_null ? null_oh : QPDFObjectHandle(object));
401 417 }
402 418 }
403 419 }
404 420  
405 421 if (is_null) {
406   - object = QPDFObjectHandle::newNull();
  422 + object = QPDF_Null::create();
407 423 }
408 424 if (!set_offset) {
409 425 setDescription(object, offset);
... ...