Commit b9cd693a5b36b8b0246822cb97386792045179ec

Authored by Jay Berkenbilt
1 parent d526d4c1

QPDFJob: allocate QPDFArgParser on stack

The previous commits have removed all references to memory from
QPDFArgParser from QPDFJob. This commit removes the constraint that
QPDFArgParser remain in scope. This is a prerequisite to allowing JSON
as an alternative way to initialize QPDFJob and to initialize it
directly using a public API.
include/qpdf/QPDFJob.hh
... ... @@ -26,7 +26,6 @@
26 26 #include <qpdf/Constants.h>
27 27 #include <qpdf/QPDF.hh>
28 28 #include <qpdf/QPDFPageObjectHelper.hh>
29   -#include <qpdf/QPDFArgParser.hh>
30 29  
31 30 #include <memory>
32 31 #include <string>
... ... @@ -387,7 +386,6 @@ class QPDFJob
387 386 std::ostream* cout;
388 387 std::ostream* cerr;
389 388 unsigned long encryption_status;
390   - std::shared_ptr<QPDFArgParser> ap;
391 389 };
392 390 std::shared_ptr<Members> m;
393 391 };
... ...
libqpdf/QPDFJob_argv.cc
... ... @@ -1529,11 +1529,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
1529 1529 {
1530 1530 progname_env = "QPDF_EXECUTABLE";
1531 1531 }
1532   - // QPDFArgParser must stay in scope for the life of the QPDFJob
1533   - // object since it holds dynamic memory used for argv, which is
1534   - // pointed to by other member variables.
1535   - this->m->ap = std::make_shared<QPDFArgParser>(argc, argv, progname_env);
1536   - setMessagePrefix(this->m->ap->getProgname());
1537   - ArgParser ap(*this->m->ap, *this);
  1532 + QPDFArgParser qap(argc, argv, progname_env);
  1533 + setMessagePrefix(qap.getProgname());
  1534 + ArgParser ap(qap, *this);
1538 1535 ap.parseOptions();
1539 1536 }
... ...
qpdf/qpdf.cc
1 1 #include <qpdf/QPDFJob.hh>
2 2 #include <qpdf/QTC.hh>
3 3 #include <qpdf/QUtil.hh>
  4 +#include <qpdf/QPDFArgParser.hh>
4 5  
5 6 #include <cstdio>
6 7 #include <cstdlib>
... ...