Commit dc5c8b82eb79d0ae5b92600a52162b9c0e352d6c
1 parent
7108cd7b
Remove FileInputSource::Members
Showing
2 changed files
with
36 additions
and
59 deletions
include/qpdf/FileInputSource.hh
| @@ -58,24 +58,9 @@ class QPDF_DLL_CLASS FileInputSource: public InputSource | @@ -58,24 +58,9 @@ class QPDF_DLL_CLASS FileInputSource: public InputSource | ||
| 58 | FileInputSource(FileInputSource const&) = delete; | 58 | FileInputSource(FileInputSource const&) = delete; |
| 59 | FileInputSource& operator=(FileInputSource const&) = delete; | 59 | FileInputSource& operator=(FileInputSource const&) = delete; |
| 60 | 60 | ||
| 61 | - class QPDF_DLL_PRIVATE Members | ||
| 62 | - { | ||
| 63 | - friend class FileInputSource; | ||
| 64 | - | ||
| 65 | - public: | ||
| 66 | - QPDF_DLL | ||
| 67 | - ~Members(); | ||
| 68 | - | ||
| 69 | - private: | ||
| 70 | - Members(bool close_file); | ||
| 71 | - Members(Members const&) = delete; | ||
| 72 | - | ||
| 73 | - bool close_file; | ||
| 74 | - std::string filename; | ||
| 75 | - FILE* file; | ||
| 76 | - }; | ||
| 77 | - | ||
| 78 | - std::shared_ptr<Members> m; | 61 | + bool close_file; |
| 62 | + std::string filename; | ||
| 63 | + FILE* file; | ||
| 79 | }; | 64 | }; |
| 80 | 65 | ||
| 81 | #endif // QPDF_FILEINPUTSOURCE_HH | 66 | #endif // QPDF_FILEINPUTSOURCE_HH |
libqpdf/FileInputSource.cc
| @@ -5,60 +5,52 @@ | @@ -5,60 +5,52 @@ | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <string.h> | 6 | #include <string.h> |
| 7 | 7 | ||
| 8 | -FileInputSource::Members::Members(bool close_file) : | ||
| 9 | - close_file(close_file), | ||
| 10 | - file(nullptr) | ||
| 11 | -{ | ||
| 12 | -} | ||
| 13 | - | ||
| 14 | -FileInputSource::Members::~Members() | ||
| 15 | -{ | ||
| 16 | - if (this->file && this->close_file) { | ||
| 17 | - fclose(this->file); | ||
| 18 | - } | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | FileInputSource::FileInputSource() : | 8 | FileInputSource::FileInputSource() : |
| 22 | - m(new Members(false)) | 9 | + close_file(false), |
| 10 | + file(nullptr) | ||
| 23 | { | 11 | { |
| 24 | } | 12 | } |
| 25 | 13 | ||
| 26 | FileInputSource::FileInputSource(char const* filename) : | 14 | FileInputSource::FileInputSource(char const* filename) : |
| 27 | - m(new Members(false)) | 15 | + close_file(true), |
| 16 | + filename(filename), | ||
| 17 | + file(QUtil::safe_fopen(filename, "rb")) | ||
| 28 | { | 18 | { |
| 29 | - setFilename(filename); | ||
| 30 | } | 19 | } |
| 31 | 20 | ||
| 32 | FileInputSource::FileInputSource( | 21 | FileInputSource::FileInputSource( |
| 33 | char const* description, FILE* filep, bool close_file) : | 22 | char const* description, FILE* filep, bool close_file) : |
| 34 | - m(new Members(false)) | 23 | + close_file(close_file), |
| 24 | + filename(description), | ||
| 25 | + file(filep) | ||
| 26 | +{ | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +FileInputSource::~FileInputSource() | ||
| 35 | { | 30 | { |
| 36 | - setFile(description, filep, close_file); | 31 | + // Must be explicit and not inline -- see QPDF_DLL_CLASS in |
| 32 | + // README-maintainer | ||
| 33 | + if (this->file && this->close_file) { | ||
| 34 | + fclose(this->file); | ||
| 35 | + } | ||
| 37 | } | 36 | } |
| 38 | 37 | ||
| 39 | void | 38 | void |
| 40 | FileInputSource::setFilename(char const* filename) | 39 | FileInputSource::setFilename(char const* filename) |
| 41 | { | 40 | { |
| 42 | - this->m = std::shared_ptr<Members>(new Members(true)); | ||
| 43 | - this->m->filename = filename; | ||
| 44 | - this->m->file = QUtil::safe_fopen(filename, "rb"); | 41 | + this->close_file = true; |
| 42 | + this->filename = filename; | ||
| 43 | + this->file = QUtil::safe_fopen(filename, "rb"); | ||
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | void | 46 | void |
| 48 | FileInputSource::setFile(char const* description, FILE* filep, bool close_file) | 47 | FileInputSource::setFile(char const* description, FILE* filep, bool close_file) |
| 49 | { | 48 | { |
| 50 | - this->m = std::shared_ptr<Members>(new Members(close_file)); | ||
| 51 | - this->m->filename = description; | ||
| 52 | - this->m->file = filep; | 49 | + this->filename = description; |
| 50 | + this->file = filep; | ||
| 53 | this->seek(0, SEEK_SET); | 51 | this->seek(0, SEEK_SET); |
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | -FileInputSource::~FileInputSource() | ||
| 57 | -{ | ||
| 58 | - // Must be explicit and not inline -- see QPDF_DLL_CLASS in | ||
| 59 | - // README-maintainer | ||
| 60 | -} | ||
| 61 | - | ||
| 62 | qpdf_offset_t | 54 | qpdf_offset_t |
| 63 | FileInputSource::findAndSkipNextEOL() | 55 | FileInputSource::findAndSkipNextEOL() |
| 64 | { | 56 | { |
| @@ -66,7 +58,7 @@ FileInputSource::findAndSkipNextEOL() | @@ -66,7 +58,7 @@ FileInputSource::findAndSkipNextEOL() | ||
| 66 | bool done = false; | 58 | bool done = false; |
| 67 | char buf[10240]; | 59 | char buf[10240]; |
| 68 | while (!done) { | 60 | while (!done) { |
| 69 | - qpdf_offset_t cur_offset = QUtil::tell(this->m->file); | 61 | + qpdf_offset_t cur_offset = QUtil::tell(this->file); |
| 70 | size_t len = this->read(buf, sizeof(buf)); | 62 | size_t len = this->read(buf, sizeof(buf)); |
| 71 | if (len == 0) { | 63 | if (len == 0) { |
| 72 | done = true; | 64 | done = true; |
| @@ -98,41 +90,41 @@ FileInputSource::findAndSkipNextEOL() | @@ -98,41 +90,41 @@ FileInputSource::findAndSkipNextEOL() | ||
| 98 | std::string const& | 90 | std::string const& |
| 99 | FileInputSource::getName() const | 91 | FileInputSource::getName() const |
| 100 | { | 92 | { |
| 101 | - return this->m->filename; | 93 | + return this->filename; |
| 102 | } | 94 | } |
| 103 | 95 | ||
| 104 | qpdf_offset_t | 96 | qpdf_offset_t |
| 105 | FileInputSource::tell() | 97 | FileInputSource::tell() |
| 106 | { | 98 | { |
| 107 | - return QUtil::tell(this->m->file); | 99 | + return QUtil::tell(this->file); |
| 108 | } | 100 | } |
| 109 | 101 | ||
| 110 | void | 102 | void |
| 111 | FileInputSource::seek(qpdf_offset_t offset, int whence) | 103 | FileInputSource::seek(qpdf_offset_t offset, int whence) |
| 112 | { | 104 | { |
| 113 | QUtil::os_wrapper( | 105 | QUtil::os_wrapper( |
| 114 | - (std::string("seek to ") + this->m->filename + ", offset " + | 106 | + (std::string("seek to ") + this->filename + ", offset " + |
| 115 | QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + | 107 | QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + |
| 116 | ")"), | 108 | ")"), |
| 117 | - QUtil::seek(this->m->file, offset, whence)); | 109 | + QUtil::seek(this->file, offset, whence)); |
| 118 | } | 110 | } |
| 119 | 111 | ||
| 120 | void | 112 | void |
| 121 | FileInputSource::rewind() | 113 | FileInputSource::rewind() |
| 122 | { | 114 | { |
| 123 | - ::rewind(this->m->file); | 115 | + ::rewind(this->file); |
| 124 | } | 116 | } |
| 125 | 117 | ||
| 126 | size_t | 118 | size_t |
| 127 | FileInputSource::read(char* buffer, size_t length) | 119 | FileInputSource::read(char* buffer, size_t length) |
| 128 | { | 120 | { |
| 129 | this->last_offset = this->tell(); | 121 | this->last_offset = this->tell(); |
| 130 | - size_t len = fread(buffer, 1, length, this->m->file); | 122 | + size_t len = fread(buffer, 1, length, this->file); |
| 131 | if (len == 0) { | 123 | if (len == 0) { |
| 132 | - if (ferror(this->m->file)) { | 124 | + if (ferror(this->file)) { |
| 133 | throw QPDFExc( | 125 | throw QPDFExc( |
| 134 | qpdf_e_system, | 126 | qpdf_e_system, |
| 135 | - this->m->filename, | 127 | + this->filename, |
| 136 | "", | 128 | "", |
| 137 | this->last_offset, | 129 | this->last_offset, |
| 138 | (std::string("read ") + QUtil::uint_to_string(length) + | 130 | (std::string("read ") + QUtil::uint_to_string(length) + |
| @@ -149,6 +141,6 @@ void | @@ -149,6 +141,6 @@ void | ||
| 149 | FileInputSource::unreadCh(char ch) | 141 | FileInputSource::unreadCh(char ch) |
| 150 | { | 142 | { |
| 151 | QUtil::os_wrapper( | 143 | QUtil::os_wrapper( |
| 152 | - this->m->filename + ": unread character", | ||
| 153 | - ungetc(static_cast<unsigned char>(ch), this->m->file)); | 144 | + this->filename + ": unread character", |
| 145 | + ungetc(static_cast<unsigned char>(ch), this->file)); | ||
| 154 | } | 146 | } |