diff --git a/include/qpdf/QPDFValue.hh b/include/qpdf/QPDFValue.hh index 4ed3a0de..8b4f53b5 100644 --- a/include/qpdf/QPDFValue.hh +++ b/include/qpdf/QPDFValue.hh @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -73,11 +74,21 @@ class QPDFValue { return parsed_offset; } + QPDF* + getQPDF() + { + return qpdf; + } + QPDFObjGen + getObjGen() + { + return og; + } protected: QPDFValue() : type_code(::ot_uninitialized), - type_name("uninitilized") + type_name("uninitialized") { } QPDFValue(qpdf_object_type_e type_code, char const* type_name) : @@ -85,7 +96,17 @@ class QPDFValue type_name(type_name) { } - + QPDFValue( + qpdf_object_type_e type_code, + char const* type_name, + QPDF* qpdf, + QPDFObjGen const& og) : + type_code(type_code), + type_name(type_name), + qpdf(qpdf), + og(og) + { + } virtual void releaseResolved() { @@ -100,6 +121,10 @@ class QPDFValue qpdf_offset_t parsed_offset{-1}; const qpdf_object_type_e type_code; char const* type_name; + + protected: + QPDF* qpdf{nullptr}; + QPDFObjGen og; }; #endif // QPDFVALUE_HH diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 553c1a41..f33e2920 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2183,9 +2183,8 @@ QPDF::getObject(QPDFObjGen const& og) if (!og.isIndirect()) { return QPDFObjectHandle::newNull(); } - // auto obj = (og.getObj() != 0) ? resolve(og) : QPDF_Null::create(); - if (!m->obj_cache.count(og)) { - m->obj_cache[og] = ObjCache(QPDF_Unresolved::create(), -1, -1); + if (!isCached(og)) { + m->obj_cache[og] = ObjCache(QPDF_Unresolved::create(this, og), -1, -1); } return newIndirect(og, m->obj_cache[og].object); } diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc index 40d4874e..f824a9a6 100644 --- a/libqpdf/QPDF_Unresolved.cc +++ b/libqpdf/QPDF_Unresolved.cc @@ -2,21 +2,23 @@ #include -QPDF_Unresolved::QPDF_Unresolved() : - QPDFValue(::ot_unresolved, "unresolved") +QPDF_Unresolved::QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og) : + QPDFValue(::ot_unresolved, "unresolved", qpdf, og) { } std::shared_ptr -QPDF_Unresolved::create() +QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const& og) { - return do_create(new QPDF_Unresolved()); + return do_create(new QPDF_Unresolved(qpdf, og)); } std::shared_ptr QPDF_Unresolved::shallowCopy() { - return create(); + throw std::logic_error( + "attempted to shallow copy unresolved QPDFObjectHandle"); + return create(qpdf, og); } std::string diff --git a/libqpdf/qpdf/QPDF_Unresolved.hh b/libqpdf/qpdf/QPDF_Unresolved.hh index c1231590..efcf4e3d 100644 --- a/libqpdf/qpdf/QPDF_Unresolved.hh +++ b/libqpdf/qpdf/QPDF_Unresolved.hh @@ -7,13 +7,13 @@ class QPDF_Unresolved: public QPDFValue { public: virtual ~QPDF_Unresolved() = default; - static std::shared_ptr create(); + static std::shared_ptr create(QPDF* qpdf, QPDFObjGen const& og); virtual std::shared_ptr shallowCopy(); virtual std::string unparse(); virtual JSON getJSON(int json_version); private: - QPDF_Unresolved(); + QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og); }; #endif // QPDF_UNRESOLVED_HH