[Debtags-commits] [svn] r1584 - in tagcoll/trunk: . tagcoll
Enrico Zini
enrico at costa.debian.org
Wed Feb 15 17:22:13 UTC 2006
Author: enrico
Date: Wed Feb 15 17:22:11 2006
New Revision: 1584
Modified:
tagcoll/trunk/ (props changed)
tagcoll/trunk/tagcoll/MMapIndex.cc
tagcoll/trunk/tagcoll/MMapIndex.h
Log:
r7334 at viaza: enrico | 2006-02-15 17:46:04 +0100
Made mastermmapindex defaultconstructible
Modified: tagcoll/trunk/tagcoll/MMapIndex.cc
==============================================================================
--- tagcoll/trunk/tagcoll/MMapIndex.cc (original)
+++ tagcoll/trunk/tagcoll/MMapIndex.cc Wed Feb 15 17:22:11 2006
@@ -35,11 +35,40 @@
using namespace Tagcoll;
using namespace stringf;
-MasterMMapIndex::MasterMMapIndex(const std::string& filename) : m_filename(filename), m_fd(-1), m_buf(0)
+MasterMMapIndex::MasterMMapIndex() : m_fd(-1), m_buf(0) {}
+
+MasterMMapIndex::MasterMMapIndex(const std::string& filename)
+ : m_filename(filename), m_fd(-1), m_buf(0)
+{
+ // If init throws here, the destructor isn't called (since we're in the
+ // constructor), so we do the cleanup and rethrow.
+ try {
+ init(filename);
+ } catch (...) {
+ if (m_buf)
+ munmap((void*)m_buf, m_size);
+ if (m_fd != -1)
+ close(m_fd);
+ throw;
+ }
+}
+
+MasterMMapIndex::~MasterMMapIndex()
+{
+ // Unmap and close the file
+ if (m_buf)
+ munmap((void*)m_buf, m_size);
+ if (m_fd != -1)
+ close(m_fd);
+}
+
+void MasterMMapIndex::init(const std::string& filename)
{
+ m_filename = filename;
+
// Open the file
if ((m_fd = open(m_filename.c_str(), O_RDONLY)) == -1)
- throw SystemException(errno, "opening index file " + filename);
+ throw SystemException(errno, "opening index file " + m_filename);
off_t size = lseek(m_fd, 0, SEEK_END);
if (size == (off_t)-1)
@@ -57,12 +86,6 @@
}
}
-MasterMMapIndex::~MasterMMapIndex()
-{
- // Unmap and close the file
- munmap((void*)m_buf, m_size);
- close(m_fd);
-}
MMapIndex::MMapIndex()
: m_master(0), m_buf(0), m_size(0) {}
Modified: tagcoll/trunk/tagcoll/MMapIndex.h
==============================================================================
--- tagcoll/trunk/tagcoll/MMapIndex.h (original)
+++ tagcoll/trunk/tagcoll/MMapIndex.h Wed Feb 15 17:22:11 2006
@@ -49,8 +49,11 @@
const char* m_buf;
public:
+ MasterMMapIndex();
MasterMMapIndex(const std::string& filename);
~MasterMMapIndex();
+
+ void init(const std::string& filename);
friend class MMapIndex;
};
More information about the Debtags-commits
mailing list