Commit 1a8c2eb93b3116a3057e8009b8cbd7510abaf138
1 parent
76c4f78b
QPDFJob: use std::shared_ptr over PointerHolder where possible
Also fix QPDFArgParser
Showing
5 changed files
with
75 additions
and
83 deletions
include/qpdf/QPDFArgParser.hh
| @@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
| 23 | #define QPDFARGPARSER_HH | 23 | #define QPDFARGPARSER_HH |
| 24 | 24 | ||
| 25 | #include <qpdf/DLL.h> | 25 | #include <qpdf/DLL.h> |
| 26 | -#include <qpdf/PointerHolder.hh> | 26 | +#include <memory> |
| 27 | #include <string> | 27 | #include <string> |
| 28 | #include <set> | 28 | #include <set> |
| 29 | #include <map> | 29 | #include <map> |
| @@ -325,15 +325,15 @@ class QPDFArgParser | @@ -325,15 +325,15 @@ class QPDFArgParser | ||
| 325 | option_table_t* option_table; | 325 | option_table_t* option_table; |
| 326 | std::string option_table_name; | 326 | std::string option_table_name; |
| 327 | bare_arg_handler_t final_check_handler; | 327 | bare_arg_handler_t final_check_handler; |
| 328 | - std::vector<PointerHolder<char>> new_argv; | ||
| 329 | - std::vector<PointerHolder<char>> bash_argv; | ||
| 330 | - PointerHolder<char*> argv_ph; | ||
| 331 | - PointerHolder<char*> bash_argv_ph; | 328 | + std::vector<std::shared_ptr<char>> new_argv; |
| 329 | + std::vector<std::shared_ptr<char>> bash_argv; | ||
| 330 | + std::shared_ptr<char*> argv_ph; | ||
| 331 | + std::shared_ptr<char*> bash_argv_ph; | ||
| 332 | std::map<std::string, HelpTopic> help_topics; | 332 | std::map<std::string, HelpTopic> help_topics; |
| 333 | std::map<std::string, HelpTopic> option_help; | 333 | std::map<std::string, HelpTopic> option_help; |
| 334 | std::string help_footer; | 334 | std::string help_footer; |
| 335 | }; | 335 | }; |
| 336 | - PointerHolder<Members> m; | 336 | + std::shared_ptr<Members> m; |
| 337 | }; | 337 | }; |
| 338 | 338 | ||
| 339 | #endif // QPDFARGPARSER_HH | 339 | #endif // QPDFARGPARSER_HH |
include/qpdf/QPDFJob.hh
| @@ -24,11 +24,11 @@ | @@ -24,11 +24,11 @@ | ||
| 24 | 24 | ||
| 25 | #include <qpdf/DLL.h> | 25 | #include <qpdf/DLL.h> |
| 26 | #include <qpdf/Constants.h> | 26 | #include <qpdf/Constants.h> |
| 27 | -#include <qpdf/PointerHolder.hh> | ||
| 28 | #include <qpdf/QPDF.hh> | 27 | #include <qpdf/QPDF.hh> |
| 29 | #include <qpdf/QPDFPageObjectHelper.hh> | 28 | #include <qpdf/QPDFPageObjectHelper.hh> |
| 30 | #include <qpdf/QPDFArgParser.hh> | 29 | #include <qpdf/QPDFArgParser.hh> |
| 31 | 30 | ||
| 31 | +#include <memory> | ||
| 32 | #include <string> | 32 | #include <string> |
| 33 | #include <list> | 33 | #include <list> |
| 34 | #include <vector> | 34 | #include <vector> |
| @@ -167,7 +167,7 @@ class QPDFJob | @@ -167,7 +167,7 @@ class QPDFJob | ||
| 167 | char const* to_nr; | 167 | char const* to_nr; |
| 168 | char const* from_nr; | 168 | char const* from_nr; |
| 169 | char const* repeat_nr; | 169 | char const* repeat_nr; |
| 170 | - PointerHolder<QPDF> pdf; | 170 | + std::shared_ptr<QPDF> pdf; |
| 171 | std::vector<int> to_pagenos; | 171 | std::vector<int> to_pagenos; |
| 172 | std::vector<int> from_pagenos; | 172 | std::vector<int> from_pagenos; |
| 173 | std::vector<int> repeat_pagenos; | 173 | std::vector<int> repeat_pagenos; |
| @@ -316,14 +316,14 @@ class QPDFJob | @@ -316,14 +316,14 @@ class QPDFJob | ||
| 316 | 316 | ||
| 317 | private: | 317 | private: |
| 318 | // Basic file processing | 318 | // Basic file processing |
| 319 | - PointerHolder<QPDF> processFile( | 319 | + std::shared_ptr<QPDF> processFile( |
| 320 | char const* filename, char const* password); | 320 | char const* filename, char const* password); |
| 321 | - PointerHolder<QPDF> processInputSource( | 321 | + std::shared_ptr<QPDF> processInputSource( |
| 322 | PointerHolder<InputSource> is, char const* password); | 322 | PointerHolder<InputSource> is, char const* password); |
| 323 | - PointerHolder<QPDF> doProcess( | 323 | + std::shared_ptr<QPDF> doProcess( |
| 324 | std::function<void(QPDF*, char const*)> fn, | 324 | std::function<void(QPDF*, char const*)> fn, |
| 325 | char const* password, bool empty); | 325 | char const* password, bool empty); |
| 326 | - PointerHolder<QPDF> doProcessOnce( | 326 | + std::shared_ptr<QPDF> doProcessOnce( |
| 327 | std::function<void(QPDF*, char const*)> fn, | 327 | std::function<void(QPDF*, char const*)> fn, |
| 328 | char const* password, bool empty); | 328 | char const* password, bool empty); |
| 329 | 329 | ||
| @@ -331,7 +331,7 @@ class QPDFJob | @@ -331,7 +331,7 @@ class QPDFJob | ||
| 331 | void setQPDFOptions(QPDF& pdf); | 331 | void setQPDFOptions(QPDF& pdf); |
| 332 | void handlePageSpecs( | 332 | void handlePageSpecs( |
| 333 | QPDF& pdf, bool& warnings, | 333 | QPDF& pdf, bool& warnings, |
| 334 | - std::vector<PointerHolder<QPDF>>& page_heap); | 334 | + std::vector<std::shared_ptr<QPDF>>& page_heap); |
| 335 | bool shouldRemoveUnreferencedResources(QPDF& pdf); | 335 | bool shouldRemoveUnreferencedResources(QPDF& pdf); |
| 336 | void handleRotations(QPDF& pdf); | 336 | void handleRotations(QPDF& pdf); |
| 337 | void handleUnderOverlay(QPDF& pdf); | 337 | void handleUnderOverlay(QPDF& pdf); |
| @@ -395,9 +395,9 @@ class QPDFJob | @@ -395,9 +395,9 @@ class QPDFJob | ||
| 395 | std::ostream* cout; | 395 | std::ostream* cout; |
| 396 | std::ostream* cerr; | 396 | std::ostream* cerr; |
| 397 | unsigned long encryption_status; | 397 | unsigned long encryption_status; |
| 398 | - PointerHolder<QPDFArgParser> ap; | 398 | + std::shared_ptr<QPDFArgParser> ap; |
| 399 | }; | 399 | }; |
| 400 | - PointerHolder<Members> m; | 400 | + std::shared_ptr<Members> m; |
| 401 | }; | 401 | }; |
| 402 | 402 | ||
| 403 | #endif // QPDFOBJECT_HH | 403 | #endif // QPDFOBJECT_HH |
libqpdf/QPDFArgParser.cc
| @@ -295,10 +295,8 @@ QPDFArgParser::handleArgFileArguments() | @@ -295,10 +295,8 @@ QPDFArgParser::handleArgFileArguments() | ||
| 295 | { | 295 | { |
| 296 | // Support reading arguments from files. Create a new argv. Ensure | 296 | // Support reading arguments from files. Create a new argv. Ensure |
| 297 | // that argv itself as well as all its contents are automatically | 297 | // that argv itself as well as all its contents are automatically |
| 298 | - // deleted by using PointerHolder objects to back the pointers in | ||
| 299 | - // argv. | ||
| 300 | - this->m->new_argv.push_back( | ||
| 301 | - PointerHolder<char>(true, QUtil::copy_string(this->m->argv[0]))); | 298 | + // deleted by using shared pointers to back the pointers in argv. |
| 299 | + this->m->new_argv.push_back(QUtil::make_shared_cstr(this->m->argv[0])); | ||
| 302 | for (int i = 1; i < this->m->argc; ++i) | 300 | for (int i = 1; i < this->m->argc; ++i) |
| 303 | { | 301 | { |
| 304 | char* argfile = 0; | 302 | char* argfile = 0; |
| @@ -321,16 +319,16 @@ QPDFArgParser::handleArgFileArguments() | @@ -321,16 +319,16 @@ QPDFArgParser::handleArgFileArguments() | ||
| 321 | else | 319 | else |
| 322 | { | 320 | { |
| 323 | this->m->new_argv.push_back( | 321 | this->m->new_argv.push_back( |
| 324 | - PointerHolder<char>( | ||
| 325 | - true, QUtil::copy_string(this->m->argv[i]))); | 322 | + QUtil::make_shared_cstr(this->m->argv[i])); |
| 326 | } | 323 | } |
| 327 | } | 324 | } |
| 328 | - this->m->argv_ph = | ||
| 329 | - PointerHolder<char*>(true, new char*[1 + this->m->new_argv.size()]); | ||
| 330 | - this->m->argv = this->m->argv_ph.getPointer(); | 325 | + this->m->argv_ph = std::shared_ptr<char*>( |
| 326 | + new char*[1 + this->m->new_argv.size()], | ||
| 327 | + std::default_delete<char*[]>()); | ||
| 328 | + this->m->argv = this->m->argv_ph.get(); | ||
| 331 | for (size_t i = 0; i < this->m->new_argv.size(); ++i) | 329 | for (size_t i = 0; i < this->m->new_argv.size(); ++i) |
| 332 | { | 330 | { |
| 333 | - this->m->argv[i] = this->m->new_argv.at(i).getPointer(); | 331 | + this->m->argv[i] = this->m->new_argv.at(i).get(); |
| 334 | } | 332 | } |
| 335 | this->m->argc = QIntC::to_int(this->m->new_argv.size()); | 333 | this->m->argc = QIntC::to_int(this->m->new_argv.size()); |
| 336 | this->m->argv[this->m->argc] = 0; | 334 | this->m->argv[this->m->argc] = 0; |
| @@ -374,8 +372,7 @@ QPDFArgParser::handleBashArguments() | @@ -374,8 +372,7 @@ QPDFArgParser::handleBashArguments() | ||
| 374 | if (! arg.empty()) | 372 | if (! arg.empty()) |
| 375 | { | 373 | { |
| 376 | this->m->bash_argv.push_back( | 374 | this->m->bash_argv.push_back( |
| 377 | - PointerHolder<char>( | ||
| 378 | - true, QUtil::copy_string(arg.c_str()))); | 375 | + QUtil::make_shared_cstr(arg)); |
| 379 | arg.clear(); | 376 | arg.clear(); |
| 380 | } | 377 | } |
| 381 | } | 378 | } |
| @@ -426,17 +423,17 @@ QPDFArgParser::handleBashArguments() | @@ -426,17 +423,17 @@ QPDFArgParser::handleBashArguments() | ||
| 426 | // This can't happen if properly invoked by bash, but ensure | 423 | // This can't happen if properly invoked by bash, but ensure |
| 427 | // we have a valid argv[0] regardless. | 424 | // we have a valid argv[0] regardless. |
| 428 | this->m->bash_argv.push_back( | 425 | this->m->bash_argv.push_back( |
| 429 | - PointerHolder<char>( | ||
| 430 | - true, QUtil::copy_string(this->m->argv[0]))); | 426 | + QUtil::make_shared_cstr(this->m->argv[0])); |
| 431 | } | 427 | } |
| 432 | // Explicitly discard any non-space-terminated word. The "current | 428 | // Explicitly discard any non-space-terminated word. The "current |
| 433 | // word" is handled specially. | 429 | // word" is handled specially. |
| 434 | - this->m->bash_argv_ph = | ||
| 435 | - PointerHolder<char*>(true, new char*[1 + this->m->bash_argv.size()]); | ||
| 436 | - this->m->argv = this->m->bash_argv_ph.getPointer(); | 430 | + this->m->bash_argv_ph = std::shared_ptr<char*>( |
| 431 | + new char*[1 + this->m->bash_argv.size()], | ||
| 432 | + std::default_delete<char*[]>()); | ||
| 433 | + this->m->argv = this->m->bash_argv_ph.get(); | ||
| 437 | for (size_t i = 0; i < this->m->bash_argv.size(); ++i) | 434 | for (size_t i = 0; i < this->m->bash_argv.size(); ++i) |
| 438 | { | 435 | { |
| 439 | - this->m->argv[i] = this->m->bash_argv.at(i).getPointer(); | 436 | + this->m->argv[i] = this->m->bash_argv.at(i).get(); |
| 440 | } | 437 | } |
| 441 | this->m->argc = QIntC::to_int(this->m->bash_argv.size()); | 438 | this->m->argc = QIntC::to_int(this->m->bash_argv.size()); |
| 442 | this->m->argv[this->m->argc] = 0; | 439 | this->m->argv[this->m->argc] = 0; |
| @@ -467,11 +464,9 @@ QPDFArgParser::readArgsFromFile(char const* filename) | @@ -467,11 +464,9 @@ QPDFArgParser::readArgsFromFile(char const* filename) | ||
| 467 | QTC::TC("libtests", "QPDFArgParser read args from file"); | 464 | QTC::TC("libtests", "QPDFArgParser read args from file"); |
| 468 | lines = QUtil::read_lines_from_file(filename); | 465 | lines = QUtil::read_lines_from_file(filename); |
| 469 | } | 466 | } |
| 470 | - for (std::list<std::string>::iterator iter = lines.begin(); | ||
| 471 | - iter != lines.end(); ++iter) | 467 | + for (auto const& line: lines) |
| 472 | { | 468 | { |
| 473 | - this->m->new_argv.push_back( | ||
| 474 | - PointerHolder<char>(true, QUtil::copy_string((*iter).c_str()))); | 469 | + this->m->new_argv.push_back(QUtil::make_shared_cstr(line)); |
| 475 | } | 470 | } |
| 476 | } | 471 | } |
| 477 | 472 |
libqpdf/QPDFJob.cc
| @@ -17,7 +17,6 @@ | @@ -17,7 +17,6 @@ | ||
| 17 | #include <qpdf/Pl_DCT.hh> | 17 | #include <qpdf/Pl_DCT.hh> |
| 18 | #include <qpdf/Pl_Count.hh> | 18 | #include <qpdf/Pl_Count.hh> |
| 19 | #include <qpdf/Pl_Flate.hh> | 19 | #include <qpdf/Pl_Flate.hh> |
| 20 | -#include <qpdf/PointerHolder.hh> | ||
| 21 | 20 | ||
| 22 | #include <qpdf/QPDF.hh> | 21 | #include <qpdf/QPDF.hh> |
| 23 | #include <qpdf/QPDFPageDocumentHelper.hh> | 22 | #include <qpdf/QPDFPageDocumentHelper.hh> |
| @@ -45,7 +44,7 @@ namespace | @@ -45,7 +44,7 @@ namespace | ||
| 45 | } | 44 | } |
| 46 | virtual void provideStreamData(int objid, int generation, | 45 | virtual void provideStreamData(int objid, int generation, |
| 47 | Pipeline* pipeline); | 46 | Pipeline* pipeline); |
| 48 | - PointerHolder<Pipeline> makePipeline( | 47 | + std::shared_ptr<Pipeline> makePipeline( |
| 49 | std::string const& description, Pipeline* next); | 48 | std::string const& description, Pipeline* next); |
| 50 | bool evaluate(std::string const& description); | 49 | bool evaluate(std::string const& description); |
| 51 | 50 | ||
| @@ -103,10 +102,10 @@ ImageOptimizer::ImageOptimizer(QPDFJob& o, QPDFObjectHandle& image) : | @@ -103,10 +102,10 @@ ImageOptimizer::ImageOptimizer(QPDFJob& o, QPDFObjectHandle& image) : | ||
| 103 | { | 102 | { |
| 104 | } | 103 | } |
| 105 | 104 | ||
| 106 | -PointerHolder<Pipeline> | 105 | +std::shared_ptr<Pipeline> |
| 107 | ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | 106 | ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) |
| 108 | { | 107 | { |
| 109 | - PointerHolder<Pipeline> result; | 108 | + std::shared_ptr<Pipeline> result; |
| 110 | QPDFObjectHandle dict = image.getDict(); | 109 | QPDFObjectHandle dict = image.getDict(); |
| 111 | QPDFObjectHandle w_obj = dict.getKey("/Width"); | 110 | QPDFObjectHandle w_obj = dict.getKey("/Width"); |
| 112 | QPDFObjectHandle h_obj = dict.getKey("/Height"); | 111 | QPDFObjectHandle h_obj = dict.getKey("/Height"); |
| @@ -207,7 +206,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | @@ -207,7 +206,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | ||
| 207 | return result; | 206 | return result; |
| 208 | } | 207 | } |
| 209 | 208 | ||
| 210 | - result = new Pl_DCT("jpg", next, w, h, components, cs); | 209 | + result = std::make_shared<Pl_DCT>("jpg", next, w, h, components, cs); |
| 211 | return result; | 210 | return result; |
| 212 | } | 211 | } |
| 213 | 212 | ||
| @@ -227,13 +226,13 @@ ImageOptimizer::evaluate(std::string const& description) | @@ -227,13 +226,13 @@ ImageOptimizer::evaluate(std::string const& description) | ||
| 227 | } | 226 | } |
| 228 | Pl_Discard d; | 227 | Pl_Discard d; |
| 229 | Pl_Count c("count", &d); | 228 | Pl_Count c("count", &d); |
| 230 | - PointerHolder<Pipeline> p = makePipeline(description, &c); | ||
| 231 | - if (p.getPointer() == 0) | 229 | + std::shared_ptr<Pipeline> p = makePipeline(description, &c); |
| 230 | + if (p.get() == nullptr) | ||
| 232 | { | 231 | { |
| 233 | // message issued by makePipeline | 232 | // message issued by makePipeline |
| 234 | return false; | 233 | return false; |
| 235 | } | 234 | } |
| 236 | - if (! image.pipeStreamData(p.getPointer(), 0, qpdf_dl_specialized)) | 235 | + if (! image.pipeStreamData(p.get(), 0, qpdf_dl_specialized)) |
| 237 | { | 236 | { |
| 238 | return false; | 237 | return false; |
| 239 | } | 238 | } |
| @@ -260,8 +259,8 @@ ImageOptimizer::evaluate(std::string const& description) | @@ -260,8 +259,8 @@ ImageOptimizer::evaluate(std::string const& description) | ||
| 260 | void | 259 | void |
| 261 | ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) | 260 | ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) |
| 262 | { | 261 | { |
| 263 | - PointerHolder<Pipeline> p = makePipeline("", pipeline); | ||
| 264 | - if (p.getPointer() == 0) | 262 | + std::shared_ptr<Pipeline> p = makePipeline("", pipeline); |
| 263 | + if (p.get() == nullptr) | ||
| 265 | { | 264 | { |
| 266 | // Should not be possible | 265 | // Should not be possible |
| 267 | image.warnIfPossible("unable to create pipeline after previous" | 266 | image.warnIfPossible("unable to create pipeline after previous" |
| @@ -269,7 +268,7 @@ ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) | @@ -269,7 +268,7 @@ ImageOptimizer::provideStreamData(int, int, Pipeline* pipeline) | ||
| 269 | pipeline->finish(); | 268 | pipeline->finish(); |
| 270 | return; | 269 | return; |
| 271 | } | 270 | } |
| 272 | - image.pipeStreamData(p.getPointer(), 0, qpdf_dl_specialized, | 271 | + image.pipeStreamData(p.get(), 0, qpdf_dl_specialized, |
| 273 | false, false); | 272 | false, false); |
| 274 | } | 273 | } |
| 275 | 274 | ||
| @@ -450,7 +449,7 @@ void | @@ -450,7 +449,7 @@ void | ||
| 450 | QPDFJob::run() | 449 | QPDFJob::run() |
| 451 | { | 450 | { |
| 452 | QPDFJob& o = *this; // QXXXQ | 451 | QPDFJob& o = *this; // QXXXQ |
| 453 | - PointerHolder<QPDF> pdf_ph; | 452 | + std::shared_ptr<QPDF> pdf_ph; |
| 454 | try | 453 | try |
| 455 | { | 454 | { |
| 456 | pdf_ph = processFile(o.infilename, o.password); | 455 | pdf_ph = processFile(o.infilename, o.password); |
| @@ -480,7 +479,7 @@ QPDFJob::run() | @@ -480,7 +479,7 @@ QPDFJob::run() | ||
| 480 | return; | 479 | return; |
| 481 | } | 480 | } |
| 482 | bool other_warnings = false; | 481 | bool other_warnings = false; |
| 483 | - std::vector<PointerHolder<QPDF>> page_heap; | 482 | + std::vector<std::shared_ptr<QPDF>> page_heap; |
| 484 | if (! o.page_specs.empty()) | 483 | if (! o.page_specs.empty()) |
| 485 | { | 484 | { |
| 486 | handlePageSpecs(pdf, other_warnings, page_heap); | 485 | handlePageSpecs(pdf, other_warnings, page_heap); |
| @@ -1793,12 +1792,12 @@ QPDFJob::doInspection(QPDF& pdf) | @@ -1793,12 +1792,12 @@ QPDFJob::doInspection(QPDF& pdf) | ||
| 1793 | } | 1792 | } |
| 1794 | } | 1793 | } |
| 1795 | 1794 | ||
| 1796 | -PointerHolder<QPDF> | 1795 | +std::shared_ptr<QPDF> |
| 1797 | QPDFJob::doProcessOnce( | 1796 | QPDFJob::doProcessOnce( |
| 1798 | std::function<void(QPDF*, char const*)> fn, | 1797 | std::function<void(QPDF*, char const*)> fn, |
| 1799 | char const* password, bool empty) | 1798 | char const* password, bool empty) |
| 1800 | { | 1799 | { |
| 1801 | - PointerHolder<QPDF> pdf = new QPDF; | 1800 | + auto pdf = std::make_shared<QPDF>(); |
| 1802 | setQPDFOptions(*pdf); | 1801 | setQPDFOptions(*pdf); |
| 1803 | if (empty) | 1802 | if (empty) |
| 1804 | { | 1803 | { |
| @@ -1806,12 +1805,12 @@ QPDFJob::doProcessOnce( | @@ -1806,12 +1805,12 @@ QPDFJob::doProcessOnce( | ||
| 1806 | } | 1805 | } |
| 1807 | else | 1806 | else |
| 1808 | { | 1807 | { |
| 1809 | - fn(pdf.getPointer(), password); | 1808 | + fn(pdf.get(), password); |
| 1810 | } | 1809 | } |
| 1811 | return pdf; | 1810 | return pdf; |
| 1812 | } | 1811 | } |
| 1813 | 1812 | ||
| 1814 | -PointerHolder<QPDF> | 1813 | +std::shared_ptr<QPDF> |
| 1815 | QPDFJob::doProcess( | 1814 | QPDFJob::doProcess( |
| 1816 | std::function<void(QPDF*, char const*)> fn, | 1815 | std::function<void(QPDF*, char const*)> fn, |
| 1817 | char const* password, bool empty) | 1816 | char const* password, bool empty) |
| @@ -1904,7 +1903,7 @@ QPDFJob::doProcess( | @@ -1904,7 +1903,7 @@ QPDFJob::doProcess( | ||
| 1904 | throw std::logic_error("do_process returned"); | 1903 | throw std::logic_error("do_process returned"); |
| 1905 | } | 1904 | } |
| 1906 | 1905 | ||
| 1907 | -PointerHolder<QPDF> | 1906 | +std::shared_ptr<QPDF> |
| 1908 | QPDFJob::processFile(char const* filename, char const* password) | 1907 | QPDFJob::processFile(char const* filename, char const* password) |
| 1909 | { | 1908 | { |
| 1910 | auto f1 = std::mem_fn<void(char const*, char const*)>(&QPDF::processFile); | 1909 | auto f1 = std::mem_fn<void(char const*, char const*)>(&QPDF::processFile); |
| @@ -1913,7 +1912,7 @@ QPDFJob::processFile(char const* filename, char const* password) | @@ -1913,7 +1912,7 @@ QPDFJob::processFile(char const* filename, char const* password) | ||
| 1913 | return doProcess(fn, password, strcmp(filename, "") == 0); | 1912 | return doProcess(fn, password, strcmp(filename, "") == 0); |
| 1914 | } | 1913 | } |
| 1915 | 1914 | ||
| 1916 | -PointerHolder<QPDF> | 1915 | +std::shared_ptr<QPDF> |
| 1917 | QPDFJob::processInputSource( | 1916 | QPDFJob::processInputSource( |
| 1918 | PointerHolder<InputSource> is, char const* password) | 1917 | PointerHolder<InputSource> is, char const* password) |
| 1919 | { | 1918 | { |
| @@ -1969,15 +1968,15 @@ QPDFJob::validateUnderOverlay(QPDF& pdf, QPDFJob::UnderOverlay* uo) | @@ -1969,15 +1968,15 @@ QPDFJob::validateUnderOverlay(QPDF& pdf, QPDFJob::UnderOverlay* uo) | ||
| 1969 | 1968 | ||
| 1970 | static QPDFAcroFormDocumentHelper* get_afdh_for_qpdf( | 1969 | static QPDFAcroFormDocumentHelper* get_afdh_for_qpdf( |
| 1971 | std::map<unsigned long long, | 1970 | std::map<unsigned long long, |
| 1972 | - PointerHolder<QPDFAcroFormDocumentHelper>>& afdh_map, | 1971 | + std::shared_ptr<QPDFAcroFormDocumentHelper>>& afdh_map, |
| 1973 | QPDF* q) | 1972 | QPDF* q) |
| 1974 | { | 1973 | { |
| 1975 | auto uid = q->getUniqueId(); | 1974 | auto uid = q->getUniqueId(); |
| 1976 | if (! afdh_map.count(uid)) | 1975 | if (! afdh_map.count(uid)) |
| 1977 | { | 1976 | { |
| 1978 | - afdh_map[uid] = new QPDFAcroFormDocumentHelper(*q); | 1977 | + afdh_map[uid] = std::make_shared<QPDFAcroFormDocumentHelper>(*q); |
| 1979 | } | 1978 | } |
| 1980 | - return afdh_map[uid].getPointer(); | 1979 | + return afdh_map[uid].get(); |
| 1981 | } | 1980 | } |
| 1982 | 1981 | ||
| 1983 | void | 1982 | void |
| @@ -1999,7 +1998,7 @@ QPDFJob::doUnderOverlayForPage( | @@ -1999,7 +1998,7 @@ QPDFJob::doUnderOverlayForPage( | ||
| 1999 | } | 1998 | } |
| 2000 | 1999 | ||
| 2001 | std::map<unsigned long long, | 2000 | std::map<unsigned long long, |
| 2002 | - PointerHolder<QPDFAcroFormDocumentHelper>> afdh; | 2001 | + std::shared_ptr<QPDFAcroFormDocumentHelper>> afdh; |
| 2003 | auto make_afdh = [&](QPDFPageObjectHelper& ph) { | 2002 | auto make_afdh = [&](QPDFPageObjectHelper& ph) { |
| 2004 | QPDF* q = ph.getObjectHandle().getOwningQPDF(); | 2003 | QPDF* q = ph.getObjectHandle().getOwningQPDF(); |
| 2005 | return get_afdh_for_qpdf(afdh, q); | 2004 | return get_afdh_for_qpdf(afdh, q); |
| @@ -2098,8 +2097,8 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | @@ -2098,8 +2097,8 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | ||
| 2098 | QPDFJob& o = *this; // QXXXQ | 2097 | QPDFJob& o = *this; // QXXXQ |
| 2099 | validateUnderOverlay(pdf, &o.underlay); | 2098 | validateUnderOverlay(pdf, &o.underlay); |
| 2100 | validateUnderOverlay(pdf, &o.overlay); | 2099 | validateUnderOverlay(pdf, &o.overlay); |
| 2101 | - if ((0 == o.underlay.pdf.getPointer()) && | ||
| 2102 | - (0 == o.overlay.pdf.getPointer())) | 2100 | + if ((nullptr == o.underlay.pdf.get()) && |
| 2101 | + (nullptr == o.overlay.pdf.get())) | ||
| 2103 | { | 2102 | { |
| 2104 | return; | 2103 | return; |
| 2105 | } | 2104 | } |
| @@ -2110,12 +2109,12 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | @@ -2110,12 +2109,12 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | ||
| 2110 | std::map<int, QPDFObjectHandle> underlay_fo; | 2109 | std::map<int, QPDFObjectHandle> underlay_fo; |
| 2111 | std::map<int, QPDFObjectHandle> overlay_fo; | 2110 | std::map<int, QPDFObjectHandle> overlay_fo; |
| 2112 | std::vector<QPDFPageObjectHelper> upages; | 2111 | std::vector<QPDFPageObjectHelper> upages; |
| 2113 | - if (o.underlay.pdf.getPointer()) | 2112 | + if (o.underlay.pdf.get()) |
| 2114 | { | 2113 | { |
| 2115 | upages = QPDFPageDocumentHelper(*(o.underlay.pdf)).getAllPages(); | 2114 | upages = QPDFPageDocumentHelper(*(o.underlay.pdf)).getAllPages(); |
| 2116 | } | 2115 | } |
| 2117 | std::vector<QPDFPageObjectHelper> opages; | 2116 | std::vector<QPDFPageObjectHelper> opages; |
| 2118 | - if (o.overlay.pdf.getPointer()) | 2117 | + if (o.overlay.pdf.get()) |
| 2119 | { | 2118 | { |
| 2120 | opages = QPDFPageDocumentHelper(*(o.overlay.pdf)).getAllPages(); | 2119 | opages = QPDFPageDocumentHelper(*(o.overlay.pdf)).getAllPages(); |
| 2121 | } | 2120 | } |
| @@ -2275,11 +2274,11 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2275,11 +2274,11 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2275 | { | 2274 | { |
| 2276 | QPDFJob& o = *this; // QXXXQ | 2275 | QPDFJob& o = *this; // QXXXQ |
| 2277 | QPDFPageDocumentHelper dh(pdf); | 2276 | QPDFPageDocumentHelper dh(pdf); |
| 2278 | - PointerHolder<QPDFAcroFormDocumentHelper> afdh; | 2277 | + std::shared_ptr<QPDFAcroFormDocumentHelper> afdh; |
| 2279 | auto make_afdh = [&]() { | 2278 | auto make_afdh = [&]() { |
| 2280 | - if (! afdh.getPointer()) | 2279 | + if (! afdh.get()) |
| 2281 | { | 2280 | { |
| 2282 | - afdh = new QPDFAcroFormDocumentHelper(pdf); | 2281 | + afdh = std::make_shared<QPDFAcroFormDocumentHelper>(pdf); |
| 2283 | } | 2282 | } |
| 2284 | }; | 2283 | }; |
| 2285 | if (o.externalize_inline_images || | 2284 | if (o.externalize_inline_images || |
| @@ -2351,7 +2350,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2351,7 +2350,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2351 | make_afdh(); | 2350 | make_afdh(); |
| 2352 | for (auto& page: dh.getAllPages()) | 2351 | for (auto& page: dh.getAllPages()) |
| 2353 | { | 2352 | { |
| 2354 | - page.flattenRotation(afdh.getPointer()); | 2353 | + page.flattenRotation(afdh.get()); |
| 2355 | } | 2354 | } |
| 2356 | } | 2355 | } |
| 2357 | if (o.remove_page_labels) | 2356 | if (o.remove_page_labels) |
| @@ -2543,7 +2542,7 @@ static QPDFObjectHandle added_page(QPDF& pdf, QPDFPageObjectHelper page) | @@ -2543,7 +2542,7 @@ static QPDFObjectHandle added_page(QPDF& pdf, QPDFPageObjectHelper page) | ||
| 2543 | void | 2542 | void |
| 2544 | QPDFJob::handlePageSpecs( | 2543 | QPDFJob::handlePageSpecs( |
| 2545 | QPDF& pdf, bool& warnings, | 2544 | QPDF& pdf, bool& warnings, |
| 2546 | - std::vector<PointerHolder<QPDF>>& page_heap) | 2545 | + std::vector<std::shared_ptr<QPDF>>& page_heap) |
| 2547 | { | 2546 | { |
| 2548 | QPDFJob& o = *this; // QXXXQ | 2547 | QPDFJob& o = *this; // QXXXQ |
| 2549 | // Parse all page specifications and translate them into lists of | 2548 | // Parse all page specifications and translate them into lists of |
| @@ -2594,7 +2593,7 @@ QPDFJob::handlePageSpecs( | @@ -2594,7 +2593,7 @@ QPDFJob::handlePageSpecs( | ||
| 2594 | if (page_spec_qpdfs.count(page_spec.filename) == 0) | 2593 | if (page_spec_qpdfs.count(page_spec.filename) == 0) |
| 2595 | { | 2594 | { |
| 2596 | // Open the PDF file and store the QPDF object. Throw a | 2595 | // Open the PDF file and store the QPDF object. Throw a |
| 2597 | - // PointerHolder to the qpdf into a heap so that it | 2596 | + // std::shared_ptr to the qpdf into a heap so that it |
| 2598 | // survives through copying to the output but gets cleaned up | 2597 | // survives through copying to the output but gets cleaned up |
| 2599 | // automatically at the end. Do not canonicalize the file | 2598 | // automatically at the end. Do not canonicalize the file |
| 2600 | // name. Using two different paths to refer to the same | 2599 | // name. Using two different paths to refer to the same |
| @@ -2630,9 +2629,9 @@ QPDFJob::handlePageSpecs( | @@ -2630,9 +2629,9 @@ QPDFJob::handlePageSpecs( | ||
| 2630 | is = fis; | 2629 | is = fis; |
| 2631 | fis->setFilename(page_spec.filename.c_str()); | 2630 | fis->setFilename(page_spec.filename.c_str()); |
| 2632 | } | 2631 | } |
| 2633 | - PointerHolder<QPDF> qpdf_ph = processInputSource(is, password); | 2632 | + std::shared_ptr<QPDF> qpdf_ph = processInputSource(is, password); |
| 2634 | page_heap.push_back(qpdf_ph); | 2633 | page_heap.push_back(qpdf_ph); |
| 2635 | - page_spec_qpdfs[page_spec.filename] = qpdf_ph.getPointer(); | 2634 | + page_spec_qpdfs[page_spec.filename] = qpdf_ph.get(); |
| 2636 | if (cis) | 2635 | if (cis) |
| 2637 | { | 2636 | { |
| 2638 | cis->stayOpen(false); | 2637 | cis->stayOpen(false); |
| @@ -2735,7 +2734,7 @@ QPDFJob::handlePageSpecs( | @@ -2735,7 +2734,7 @@ QPDFJob::handlePageSpecs( | ||
| 2735 | bool any_page_labels = false; | 2734 | bool any_page_labels = false; |
| 2736 | int out_pageno = 0; | 2735 | int out_pageno = 0; |
| 2737 | std::map<unsigned long long, | 2736 | std::map<unsigned long long, |
| 2738 | - PointerHolder<QPDFAcroFormDocumentHelper>> afdh_map; | 2737 | + std::shared_ptr<QPDFAcroFormDocumentHelper>> afdh_map; |
| 2739 | auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf); | 2738 | auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf); |
| 2740 | std::set<QPDFObjGen> referenced_fields; | 2739 | std::set<QPDFObjGen> referenced_fields; |
| 2741 | for (std::vector<QPDFPageData>::iterator iter = | 2740 | for (std::vector<QPDFPageData>::iterator iter = |
| @@ -3147,8 +3146,8 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | @@ -3147,8 +3146,8 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | ||
| 3147 | static void parse_version(std::string const& full_version_string, | 3146 | static void parse_version(std::string const& full_version_string, |
| 3148 | std::string& version, int& extension_level) | 3147 | std::string& version, int& extension_level) |
| 3149 | { | 3148 | { |
| 3150 | - PointerHolder<char> vp(true, QUtil::copy_string(full_version_string)); | ||
| 3151 | - char* v = vp.getPointer(); | 3149 | + auto vp = QUtil::make_shared_cstr(full_version_string); |
| 3150 | + char* v = vp.get(); | ||
| 3152 | char* p1 = strchr(v, '.'); | 3151 | char* p1 = strchr(v, '.'); |
| 3153 | char* p2 = (p1 ? strchr(1 + p1, '.') : 0); | 3152 | char* p2 = (p1 ? strchr(1 + p1, '.') : 0); |
| 3154 | if (p2 && *(p2 + 1)) | 3153 | if (p2 && *(p2 + 1)) |
| @@ -3221,7 +3220,7 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | @@ -3221,7 +3220,7 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | ||
| 3221 | } | 3220 | } |
| 3222 | if (o.copy_encryption) | 3221 | if (o.copy_encryption) |
| 3223 | { | 3222 | { |
| 3224 | - PointerHolder<QPDF> encryption_pdf = | 3223 | + std::shared_ptr<QPDF> encryption_pdf = |
| 3225 | processFile(o.encryption_file, o.encryption_file_password); | 3224 | processFile(o.encryption_file, o.encryption_file_password); |
| 3226 | w.copyEncryptionParameters(*encryption_pdf); | 3225 | w.copyEncryptionParameters(*encryption_pdf); |
| 3227 | } | 3226 | } |
| @@ -3313,10 +3312,10 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) | @@ -3313,10 +3312,10 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) | ||
| 3313 | } | 3312 | } |
| 3314 | QPDF outpdf; | 3313 | QPDF outpdf; |
| 3315 | outpdf.emptyPDF(); | 3314 | outpdf.emptyPDF(); |
| 3316 | - PointerHolder<QPDFAcroFormDocumentHelper> out_afdh; | 3315 | + std::shared_ptr<QPDFAcroFormDocumentHelper> out_afdh; |
| 3317 | if (afdh.hasAcroForm()) | 3316 | if (afdh.hasAcroForm()) |
| 3318 | { | 3317 | { |
| 3319 | - out_afdh = new QPDFAcroFormDocumentHelper(outpdf); | 3318 | + out_afdh = std::make_shared<QPDFAcroFormDocumentHelper>(outpdf); |
| 3320 | } | 3319 | } |
| 3321 | if (o.suppress_warnings) | 3320 | if (o.suppress_warnings) |
| 3322 | { | 3321 | { |
| @@ -3327,7 +3326,7 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) | @@ -3327,7 +3326,7 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) | ||
| 3327 | QPDFObjectHandle page = pages.at(pageno - 1); | 3326 | QPDFObjectHandle page = pages.at(pageno - 1); |
| 3328 | outpdf.addPage(page, false); | 3327 | outpdf.addPage(page, false); |
| 3329 | auto new_page = added_page(outpdf, page); | 3328 | auto new_page = added_page(outpdf, page); |
| 3330 | - if (out_afdh.getPointer()) | 3329 | + if (out_afdh.get()) |
| 3331 | { | 3330 | { |
| 3332 | QTC::TC("qpdf", "qpdf copy form fields in split_pages"); | 3331 | QTC::TC("qpdf", "qpdf copy form fields in split_pages"); |
| 3333 | try | 3332 | try |
libqpdf/QPDFJob_argv.cc
| @@ -198,9 +198,7 @@ ArgParser::argPasswordFile(char* parameter) | @@ -198,9 +198,7 @@ ArgParser::argPasswordFile(char* parameter) | ||
| 198 | if (lines.size() >= 1) | 198 | if (lines.size() >= 1) |
| 199 | { | 199 | { |
| 200 | // Make sure the memory for this stays in scope. | 200 | // Make sure the memory for this stays in scope. |
| 201 | - o.password_alloc = std::shared_ptr<char>( | ||
| 202 | - QUtil::copy_string(lines.front().c_str()), | ||
| 203 | - std::default_delete<char[]>()); | 201 | + o.password_alloc = QUtil::make_shared_cstr(lines.front()); |
| 204 | o.password = o.password_alloc.get(); | 202 | o.password = o.password_alloc.get(); |
| 205 | 203 | ||
| 206 | if (lines.size() > 1) | 204 | if (lines.size() > 1) |
| @@ -1535,7 +1533,7 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | @@ -1535,7 +1533,7 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | ||
| 1535 | // QPDFArgParser must stay in scope for the life of the QPDFJob | 1533 | // QPDFArgParser must stay in scope for the life of the QPDFJob |
| 1536 | // object since it holds dynamic memory used for argv, which is | 1534 | // object since it holds dynamic memory used for argv, which is |
| 1537 | // pointed to by other member variables. | 1535 | // pointed to by other member variables. |
| 1538 | - this->m->ap = new QPDFArgParser(argc, argv, progname_env); | 1536 | + this->m->ap = std::make_shared<QPDFArgParser>(argc, argv, progname_env); |
| 1539 | setMessagePrefix(this->m->ap->getProgname()); | 1537 | setMessagePrefix(this->m->ap->getProgname()); |
| 1540 | ArgParser ap(*this->m->ap, *this); | 1538 | ArgParser ap(*this->m->ap, *this); |
| 1541 | ap.parseOptions(); | 1539 | ap.parseOptions(); |