Commit 5d25aac6c7c0363be213124211b7c93eee9c1630
1 parent
258343fc
In QPDFParser constructor change input parameter to InputSource&
Showing
4 changed files
with
20 additions
and
20 deletions
libqpdf/QPDF.cc
| ... | ... | @@ -1465,7 +1465,7 @@ QPDF::readTrailer() |
| 1465 | 1465 | qpdf_offset_t offset = m->file->tell(); |
| 1466 | 1466 | bool empty = false; |
| 1467 | 1467 | auto object = |
| 1468 | - QPDFParser(m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false); | |
| 1468 | + QPDFParser(*m->file, "trailer", m->tokenizer, nullptr, this, true).parse(empty, false); | |
| 1469 | 1469 | if (empty) { |
| 1470 | 1470 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in |
| 1471 | 1471 | // actual PDF files and Adobe Reader appears to ignore them. |
| ... | ... | @@ -1488,7 +1488,7 @@ QPDF::readObject(std::string const& description, QPDFObjGen og) |
| 1488 | 1488 | StringDecrypter decrypter{this, og}; |
| 1489 | 1489 | StringDecrypter* decrypter_ptr = m->encp->encrypted ? &decrypter : nullptr; |
| 1490 | 1490 | auto object = |
| 1491 | - QPDFParser(m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true) | |
| 1491 | + QPDFParser(*m->file, m->last_object_description, m->tokenizer, decrypter_ptr, this, true) | |
| 1492 | 1492 | .parse(empty, false); |
| 1493 | 1493 | if (empty) { |
| 1494 | 1494 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in |
| ... | ... | @@ -1608,7 +1608,7 @@ QPDF::readObjectInStream(std::shared_ptr<InputSource>& input, int obj) |
| 1608 | 1608 | m->last_object_description += " 0"; |
| 1609 | 1609 | |
| 1610 | 1610 | bool empty = false; |
| 1611 | - auto object = QPDFParser(input, m->last_object_description, m->tokenizer, nullptr, this, true) | |
| 1611 | + auto object = QPDFParser(*input, m->last_object_description, m->tokenizer, nullptr, this, true) | |
| 1612 | 1612 | .parse(empty, false); |
| 1613 | 1613 | if (empty) { |
| 1614 | 1614 | // Nothing in the PDF spec appears to allow empty objects, but they have been encountered in | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -2164,7 +2164,7 @@ QPDFObjectHandle::parseContentStream_data( |
| 2164 | 2164 | qpdf_offset_t offset = input->getLastOffset(); |
| 2165 | 2165 | input->seek(offset, SEEK_SET); |
| 2166 | 2166 | auto obj = |
| 2167 | - QPDFParser(input, "content", tokenizer, nullptr, context, false).parse(empty, true); | |
| 2167 | + QPDFParser(*input, "content", tokenizer, nullptr, context, false).parse(empty, true); | |
| 2168 | 2168 | if (!obj.isInitialized()) { |
| 2169 | 2169 | // EOF |
| 2170 | 2170 | break; |
| ... | ... | @@ -2223,7 +2223,7 @@ QPDFObjectHandle::parse( |
| 2223 | 2223 | StringDecrypter* decrypter, |
| 2224 | 2224 | QPDF* context) |
| 2225 | 2225 | { |
| 2226 | - return QPDFParser(input, object_description, tokenizer, decrypter, context, false) | |
| 2226 | + return QPDFParser(*input, object_description, tokenizer, decrypter, context, false) | |
| 2227 | 2227 | .parse(empty, false); |
| 2228 | 2228 | } |
| 2229 | 2229 | ... | ... |
libqpdf/QPDFParser.cc
| ... | ... | @@ -33,9 +33,9 @@ QPDFParser::parse(bool& empty, bool content_stream) |
| 33 | 33 | |
| 34 | 34 | QPDF::ParseGuard pg(context); |
| 35 | 35 | empty = false; |
| 36 | - start = input->tell(); | |
| 36 | + start = input.tell(); | |
| 37 | 37 | |
| 38 | - if (!tokenizer.nextToken(*input, object_description)) { | |
| 38 | + if (!tokenizer.nextToken(input, object_description)) { | |
| 39 | 39 | warn(tokenizer.getErrorMessage()); |
| 40 | 40 | } |
| 41 | 41 | |
| ... | ... | @@ -101,7 +101,7 @@ QPDFParser::parse(bool& empty, bool content_stream) |
| 101 | 101 | } else if (value == "endobj") { |
| 102 | 102 | // We just saw endobj without having read anything. Treat this as a null and do |
| 103 | 103 | // not move the input source's offset. |
| 104 | - input->seek(input->getLastOffset(), SEEK_SET); | |
| 104 | + input.seek(input.getLastOffset(), SEEK_SET); | |
| 105 | 105 | empty = true; |
| 106 | 106 | return {QPDF_Null::create()}; |
| 107 | 107 | } else { |
| ... | ... | @@ -138,7 +138,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 138 | 138 | bool b_contents = false; |
| 139 | 139 | |
| 140 | 140 | while (true) { |
| 141 | - if (!tokenizer.nextToken(*input, object_description)) { | |
| 141 | + if (!tokenizer.nextToken(input, object_description)) { | |
| 142 | 142 | warn(tokenizer.getErrorMessage()); |
| 143 | 143 | } |
| 144 | 144 | ++good_count; // optimistically |
| ... | ... | @@ -151,7 +151,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 151 | 151 | // Process the oldest buffered integer. |
| 152 | 152 | addInt(int_count); |
| 153 | 153 | } |
| 154 | - last_offset_buffer[int_count % 2] = input->getLastOffset(); | |
| 154 | + last_offset_buffer[int_count % 2] = input.getLastOffset(); | |
| 155 | 155 | int_buffer[int_count % 2] = QUtil::string_to_ll(tokenizer.getValue().c_str()); |
| 156 | 156 | continue; |
| 157 | 157 | |
| ... | ... | @@ -309,7 +309,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 309 | 309 | case QPDFTokenizer::tt_integer: |
| 310 | 310 | if (!content_stream) { |
| 311 | 311 | // Buffer token in case it is part of an indirect reference. |
| 312 | - last_offset_buffer[1] = input->getLastOffset(); | |
| 312 | + last_offset_buffer[1] = input.getLastOffset(); | |
| 313 | 313 | int_buffer[1] = QUtil::string_to_ll(tokenizer.getValue().c_str()); |
| 314 | 314 | int_count = 1; |
| 315 | 315 | } else { |
| ... | ... | @@ -351,7 +351,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 351 | 351 | if (decrypter) { |
| 352 | 352 | if (b_contents) { |
| 353 | 353 | frame->contents_string = val; |
| 354 | - frame->contents_offset = input->getLastOffset(); | |
| 354 | + frame->contents_offset = input.getLastOffset(); | |
| 355 | 355 | b_contents = false; |
| 356 | 356 | } |
| 357 | 357 | std::string s{val}; |
| ... | ... | @@ -419,7 +419,7 @@ void |
| 419 | 419 | QPDFParser::addScalar(Args&&... args) |
| 420 | 420 | { |
| 421 | 421 | auto obj = T::create(args...); |
| 422 | - obj->setDescription(context, description, input->getLastOffset()); | |
| 422 | + obj->setDescription(context, description, input.getLastOffset()); | |
| 423 | 423 | add(std::move(obj)); |
| 424 | 424 | } |
| 425 | 425 | |
| ... | ... | @@ -506,11 +506,11 @@ QPDFParser::warnDuplicateKey() |
| 506 | 506 | void |
| 507 | 507 | QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const |
| 508 | 508 | { |
| 509 | - warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg)); | |
| 509 | + warn(QPDFExc(qpdf_e_damaged_pdf, input.getName(), object_description, offset, msg)); | |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | void |
| 513 | 513 | QPDFParser::warn(std::string const& msg) const |
| 514 | 514 | { |
| 515 | - warn(input->getLastOffset(), msg); | |
| 515 | + warn(input.getLastOffset(), msg); | |
| 516 | 516 | } | ... | ... |
libqpdf/qpdf/QPDFParser.hh
| ... | ... | @@ -12,7 +12,7 @@ class QPDFParser |
| 12 | 12 | public: |
| 13 | 13 | QPDFParser() = delete; |
| 14 | 14 | QPDFParser( |
| 15 | - std::shared_ptr<InputSource> input, | |
| 15 | + InputSource& input, | |
| 16 | 16 | std::string const& object_description, |
| 17 | 17 | QPDFTokenizer& tokenizer, |
| 18 | 18 | QPDFObjectHandle::StringDecrypter* decrypter, |
| ... | ... | @@ -24,7 +24,7 @@ class QPDFParser |
| 24 | 24 | decrypter(decrypter), |
| 25 | 25 | context(context), |
| 26 | 26 | description(std::make_shared<QPDFValue::Description>( |
| 27 | - std::string(input->getName() + ", " + object_description + " at offset $PO"))), | |
| 27 | + std::string(input.getName() + ", " + object_description + " at offset $PO"))), | |
| 28 | 28 | parse_pdf(parse_pdf) |
| 29 | 29 | { |
| 30 | 30 | } |
| ... | ... | @@ -39,9 +39,9 @@ class QPDFParser |
| 39 | 39 | |
| 40 | 40 | struct StackFrame |
| 41 | 41 | { |
| 42 | - StackFrame(std::shared_ptr<InputSource> const& input, parser_state_e state) : | |
| 42 | + StackFrame(InputSource& input, parser_state_e state) : | |
| 43 | 43 | state(state), |
| 44 | - offset(input->tell()) | |
| 44 | + offset(input.tell()) | |
| 45 | 45 | { |
| 46 | 46 | } |
| 47 | 47 | |
| ... | ... | @@ -72,7 +72,7 @@ class QPDFParser |
| 72 | 72 | // NB the offset includes any leading whitespace. |
| 73 | 73 | QPDFObjectHandle withDescription(Args&&... args); |
| 74 | 74 | void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset); |
| 75 | - std::shared_ptr<InputSource> input; | |
| 75 | + InputSource& input; | |
| 76 | 76 | std::string const& object_description; |
| 77 | 77 | QPDFTokenizer& tokenizer; |
| 78 | 78 | QPDFObjectHandle::StringDecrypter* decrypter; | ... | ... |