From 9f7207d3be4adce435a17a820de14b362af6437e Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 17 Jan 2026 11:21:48 +0000 Subject: [PATCH] Refactor QPDFJob::Input methods to pass QPDFJob reference --- libqpdf/QPDFJob.cc | 20 ++++++++++---------- libqpdf/qpdf/QPDFJob_private.hh | 18 +++++------------- manual/release-notes.rst | 7 +++++++ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 08cae10..db6718a 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -261,7 +261,7 @@ struct QPDFJob::PageNo }; QPDFJob::QPDFJob() : - m(std::make_shared(*this)) + m(std::make_shared()) { } @@ -2331,7 +2331,7 @@ added_page(QPDF& pdf, QPDFPageObjectHelper page) // Initialize all members that depend on the QPDF object. If both qpdf and qpdf_p are null do // nothing. void -QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) +QPDFJob::Input::initialize(QPDFJob& job, Inputs& in, QPDF* a_qpdf) { qpdf = a_qpdf ? a_qpdf : qpdf_p.get(); if (qpdf) { @@ -2340,8 +2340,8 @@ QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) n_pages = static_cast(orig_pages.size()); copied_pages = std::vector(orig_pages.size(), false); - if (in.job.m->remove_unreferenced_page_resources != QPDFJob::re_no) { - remove_unreferenced = in.job.shouldRemoveUnreferencedResources(*qpdf); + if (job.m->remove_unreferenced_page_resources != QPDFJob::re_no) { + remove_unreferenced = job.shouldRemoveUnreferencedResources(*qpdf); } if (doc.page_labels().hasPageLabels()) { in.any_page_labels = true; @@ -2372,7 +2372,7 @@ QPDFJob::Inputs::infile_name(std::string const& name) } void -QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) +QPDFJob::Inputs::process(QPDFJob& job, std::string const& filename, QPDFJob::Input& input) { // Open the PDF file and store the QPDF object. Do not canonicalize the file name. Using two // different paths to refer to the same file is a documented workaround for duplicating a page. @@ -2398,7 +2398,7 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) password.data(), true); } - input.initialize(*this); + input.initialize(job, *this); if (input.cfis) { input.cfis->stayOpen(false); @@ -2406,7 +2406,7 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) } void -QPDFJob::Inputs::process_all() +QPDFJob::Inputs::process_all(QPDFJob& job) { if (!infile_name().empty()) { files.erase(""); @@ -2425,7 +2425,7 @@ QPDFJob::Inputs::process_all() for (auto& [filename, input]: files) { if (!input.qpdf) { - process(filename, input); + process(job, filename, input); } for (auto& selection: selections) { @@ -2519,10 +2519,10 @@ QPDFJob::handlePageSpecs(QPDF& pdf) return; } auto& main_input = m->inputs.files[m->infile_name()]; - main_input.initialize(m->inputs, &pdf); + main_input.initialize(*this, m->inputs, &pdf); // Parse all section and translate them into lists of actual pages. - m->inputs.process_all(); + m->inputs.process_all(*this); // Clear all pages out of the primary QPDF's pages tree but leave the objects in place in the // file so they can be re-added without changing their object numbers. This enables other things diff --git a/libqpdf/qpdf/QPDFJob_private.hh b/libqpdf/qpdf/QPDFJob_private.hh index bdb91d4..86e4007 100644 --- a/libqpdf/qpdf/QPDFJob_private.hh +++ b/libqpdf/qpdf/QPDFJob_private.hh @@ -37,7 +37,7 @@ struct QPDFJob::Selection // filename. This is a documented work-around. struct QPDFJob::Input { - void initialize(Inputs& in, QPDF* qpdf = nullptr); + void initialize(QPDFJob& job, Inputs& in, QPDF* qpdf = nullptr); std::string password; std::unique_ptr qpdf_p; @@ -56,12 +56,8 @@ struct QPDFJob::Inputs // These default values are duplicated in help and docs. static int constexpr DEFAULT_KEEP_FILES_OPEN_THRESHOLD = 200; - Inputs(QPDFJob& job) : - job(job) - { - } - void process(std::string const& filename, QPDFJob::Input& file_spec); - void process_all(); + void process(QPDFJob& job, std::string const& filename, QPDFJob::Input& file_spec); + void process_all(QPDFJob& job); // Destroy all owned QPDF objects. Return false if any of the QPDF objects recorded warnings. bool clear(); @@ -90,9 +86,6 @@ struct QPDFJob::Inputs std::vector selections; bool any_page_labels{false}; - - private: - QPDFJob& job; }; struct QPDFJob::RotationSpec @@ -150,9 +143,8 @@ class QPDFJob::Members friend class QPDFJob; public: - Members(QPDFJob& job) : - log(d_cfg.log()), - inputs(job) + Members() : + log(d_cfg.log()) { } Members(Members const&) = delete; diff --git a/manual/release-notes.rst b/manual/release-notes.rst index a7527af..4aa56c5 100644 --- a/manual/release-notes.rst +++ b/manual/release-notes.rst @@ -13,6 +13,13 @@ more detail. .. x.y.z: not yet released + +12.3.1: not yet released + - Bug fixes + + - Fix a bug causing ``QPDFJob::createQPDF`` to fail if called + from pikepdf. + 12.3.0: January 10, 2026 - Release changes -- libgit2 0.21.4