Merge pull request #680 from kiwix/fix_windows_compilation

Add a new private constructor not deprecated for Reader.
This commit is contained in:
Kelson 2022-01-18 16:31:32 +01:00 committed by GitHub
commit 2ccea8e370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -94,7 +94,8 @@ class Reader
* *
* @param archive The shared pointer to the Archive object. * @param archive The shared pointer to the Archive object.
*/ */
explicit DEPRECATED Reader(const std::shared_ptr<zim::Archive> archive); explicit DEPRECATED Reader(const std::shared_ptr<zim::Archive> archive)
: Reader(archive, true) {};
#ifndef _WIN32 #ifndef _WIN32
explicit DEPRECATED Reader(int fd); explicit DEPRECATED Reader(int fd);
DEPRECATED Reader(int fd, zim::offset_type offset, zim::size_type size); DEPRECATED Reader(int fd, zim::offset_type offset, zim::size_type size);
@ -490,6 +491,15 @@ class Reader
private: private:
std::map<const std::string, unsigned int> parseCounterMetadata() const; std::map<const std::string, unsigned int> parseCounterMetadata() const;
// Reader is deprecated, so we've marked the constructor as deprecated.
// But we still need to construct the reader (in our deprecated code)
// To avoid warning because we use deprecated function, we create a
// constructor not deprecated. The `bool marker` is unused, it sole purpose
// is to change the signature to have a different constructor.
// This one is not deprecated and we must use it in our private code.
Reader(const std::shared_ptr<zim::Archive> archive, bool marker);
friend class Library;
}; };
} }

View File

@ -219,7 +219,7 @@ std::shared_ptr<Reader> Library::getReaderById(const std::string& id)
if ( !archive ) if ( !archive )
return nullptr; return nullptr;
const auto reader = make_shared<Reader>(archive); const shared_ptr<Reader> reader(new Reader(archive, true));
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
m_readers[id] = reader; m_readers[id] = reader;
return reader; return reader;

View File

@ -52,7 +52,7 @@ Reader::Reader(const string zimFilePath)
srand(time(nullptr)); srand(time(nullptr));
} }
Reader::Reader(const std::shared_ptr<zim::Archive> archive) Reader::Reader(const std::shared_ptr<zim::Archive> archive, bool _marker)
: zimArchive(archive), : zimArchive(archive),
zimFilePath(archive->getFilename()) zimFilePath(archive->getFilename())
{} {}