Commit 5033e3b215c36457106cc2dd0150f2322655360c
1 parent
4a851591
Add method QPDFObject::getQPDF and remove QPDFObjectHandle::qpdf
Showing
3 changed files
with
16 additions
and
13 deletions
include/qpdf/QPDFObject.hh
| ... | ... | @@ -97,6 +97,12 @@ class QPDFObject |
| 97 | 97 | { |
| 98 | 98 | return value->type_name; |
| 99 | 99 | } |
| 100 | + // Returns nullptr for direct objects | |
| 101 | + QPDF* | |
| 102 | + getQPDF() const | |
| 103 | + { | |
| 104 | + return value->qpdf; | |
| 105 | + } | |
| 100 | 106 | void |
| 101 | 107 | setDescription(QPDF* qpdf, std::string const& description) |
| 102 | 108 | { | ... | ... |
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -973,8 +973,8 @@ class QPDFObjectHandle |
| 973 | 973 | // null for a direct object if allow_nullptr is set to true or |
| 974 | 974 | // throws a runtime error otherwise. |
| 975 | 975 | QPDF_DLL |
| 976 | - inline QPDF* | |
| 977 | - getOwningQPDF(bool allow_nullptr = true, std::string const& error_msg = ""); | |
| 976 | + inline QPDF* getOwningQPDF( | |
| 977 | + bool allow_nullptr = true, std::string const& error_msg = "") const; | |
| 978 | 978 | |
| 979 | 979 | // Create a shallow copy of an object as a direct object, but do not |
| 980 | 980 | // traverse across indirect object boundaries. That means that, |
| ... | ... | @@ -1584,7 +1584,6 @@ class QPDFObjectHandle |
| 1584 | 1584 | QPDF* qpdf, |
| 1585 | 1585 | QPDFObjGen const& og, |
| 1586 | 1586 | std::shared_ptr<QPDFObject> const& obj) : |
| 1587 | - qpdf(qpdf), | |
| 1588 | 1587 | og(og), |
| 1589 | 1588 | obj(obj) |
| 1590 | 1589 | { |
| ... | ... | @@ -1641,7 +1640,6 @@ class QPDFObjectHandle |
| 1641 | 1640 | // Moving members of QPDFObjectHandle into a smart pointer incurs |
| 1642 | 1641 | // a substantial performance penalty since QPDFObjectHandle |
| 1643 | 1642 | // objects are copied around so frequently. |
| 1644 | - QPDF* qpdf; | |
| 1645 | 1643 | QPDFObjGen og; |
| 1646 | 1644 | std::shared_ptr<QPDFObject> obj; |
| 1647 | 1645 | }; |
| ... | ... | @@ -1896,14 +1894,15 @@ QPDFObjectHandle::isInitialized() const |
| 1896 | 1894 | // Indirect object accessors |
| 1897 | 1895 | inline QPDF* |
| 1898 | 1896 | QPDFObjectHandle::getOwningQPDF( |
| 1899 | - bool allow_nullptr, std::string const& error_msg) | |
| 1897 | + bool allow_nullptr, std::string const& error_msg) const | |
| 1900 | 1898 | { |
| 1901 | 1899 | // Will be null for direct objects |
| 1902 | - if (!allow_nullptr && (this->qpdf == nullptr)) { | |
| 1900 | + auto result = isInitialized() ? this->obj->getQPDF() : nullptr; | |
| 1901 | + if (!allow_nullptr && (result == nullptr)) { | |
| 1903 | 1902 | throw std::runtime_error( |
| 1904 | 1903 | error_msg == "" ? "attempt to use a null qpdf object" : error_msg); |
| 1905 | 1904 | } |
| 1906 | - return this->qpdf; | |
| 1905 | + return result; | |
| 1907 | 1906 | } |
| 1908 | 1907 | |
| 1909 | 1908 | inline void | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -235,13 +235,11 @@ LastChar::getLastChar() |
| 235 | 235 | return this->last_char; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | -QPDFObjectHandle::QPDFObjectHandle() : | |
| 239 | - qpdf(nullptr) | |
| 238 | +QPDFObjectHandle::QPDFObjectHandle() | |
| 240 | 239 | { |
| 241 | 240 | } |
| 242 | 241 | |
| 243 | 242 | QPDFObjectHandle::QPDFObjectHandle(std::shared_ptr<QPDFObject> const& data) : |
| 244 | - qpdf(nullptr), | |
| 245 | 243 | obj(data) |
| 246 | 244 | { |
| 247 | 245 | } |
| ... | ... | @@ -2284,7 +2282,6 @@ QPDFObjectHandle::copyObject( |
| 2284 | 2282 | " reserved object handle direct"); |
| 2285 | 2283 | } |
| 2286 | 2284 | |
| 2287 | - qpdf = nullptr; | |
| 2288 | 2285 | og = QPDFObjGen(); |
| 2289 | 2286 | |
| 2290 | 2287 | std::shared_ptr<QPDFObject> new_obj; |
| ... | ... | @@ -2572,8 +2569,9 @@ QPDFObjectHandle::isImage(bool exclude_imagemask) |
| 2572 | 2569 | void |
| 2573 | 2570 | QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const |
| 2574 | 2571 | { |
| 2575 | - if ((this->qpdf != nullptr) && (item.qpdf != nullptr) && | |
| 2576 | - (this->qpdf != item.qpdf)) { | |
| 2572 | + auto qpdf = getOwningQPDF(); | |
| 2573 | + auto item_qpdf = item.getOwningQPDF(); | |
| 2574 | + if ((qpdf != nullptr) && (item_qpdf != nullptr) && (qpdf != item_qpdf)) { | |
| 2577 | 2575 | QTC::TC("qpdf", "QPDFObjectHandle check ownership"); |
| 2578 | 2576 | throw std::logic_error( |
| 2579 | 2577 | "Attempting to add an object from a different QPDF." | ... | ... |