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