|
Boost-Commit : |
From: technews_at_[hidden]
Date: 2008-02-13 00:24:08
Author: turkanis
Date: 2008-02-13 00:24:07 EST (Wed, 13 Feb 2008)
New Revision: 43238
URL: http://svn.boost.org/trac/boost/changeset/43238
Log:
added better debug output for mapped_file
Added:
branches/iostreams_dev/boost/iostreams/detail/absolute_path.hpp (contents, props changed)
branches/iostreams_dev/boost/iostreams/detail/current_directory.hpp (contents, props changed)
Text files modified:
branches/iostreams_dev/boost/iostreams/detail/system_failure.hpp | 6 ++++++
branches/iostreams_dev/libs/iostreams/src/mapped_file.cpp | 40 +++++++++++++++++++++++++++++++++++-----
2 files changed, 41 insertions(+), 5 deletions(-)
Added: branches/iostreams_dev/boost/iostreams/detail/absolute_path.hpp
==============================================================================
--- (empty file)
+++ branches/iostreams_dev/boost/iostreams/detail/absolute_path.hpp 2008-02-13 00:24:07 EST (Wed, 13 Feb 2008)
@@ -0,0 +1,46 @@
+/*
+ * Distributed under the Boost Software License, Version 1.0.(See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+ *
+ * See http://www.boost.org/libs/iostreams for documentation.
+
+ * File: boost/iostreams/detail/execute.hpp
+ * Date: Thu Dec 06 13:21:54 MST 2007
+ * Copyright: 2007-2008 CodeRage, LLC
+ * Author: Jonathan Turkanis
+ * Contact: turkanis at coderage dot com
+ *
+ * Defines the function boost::iostreams::detail::absolute_path, used for
+ * debug output for mapped files.
+ */
+
+#ifndef BOOST_IOSTREAMS_DETAIL_ABSOLUTE_PATH_HPP_INCLUDED
+#define BOOST_IOSTREAMS_DETAIL_ABSOLUTE_PATH_HPP_INCLUDED
+
+#include <string>
+#include <boost/iostreams/detail/config/windows_posix.hpp>
+#ifdef BOOST_IOSTREAMS_WINDOWS
+# include <cctype>
+#endif
+#include <boost/iostreams/detail/current_directory.hpp>
+
+namespace boost { namespace iostreams { namespace detail {
+
+// Resolves the given path relative to the current working directory
+inline std::string absolute_path(const std::string& path)
+{
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ return path.size() && (path[0] == '/' || path[0] == '\\') ||
+ path.size() > 1 && std::isalpha(path[0]) && path[1] == ':' ?
+ path :
+ current_directory() + '\\' + path;
+#else // #ifdef BOOST_IOSTREAMS_WINDOWS
+ return path.size() && (path[0] == '/') ?
+ path :
+ current_directory() + '/' + path;
+#endif // #ifdef BOOST_IOSTREAMS_WINDOWS
+}
+
+} } } // End namespaces detail, iostreams, boost.
+
+#endif // #ifndef BOOST_IOSTREAMS_DETAIL_ABSOLUTE_PATH_HPP_INCLUDED
Added: branches/iostreams_dev/boost/iostreams/detail/current_directory.hpp
==============================================================================
--- (empty file)
+++ branches/iostreams_dev/boost/iostreams/detail/current_directory.hpp 2008-02-13 00:24:07 EST (Wed, 13 Feb 2008)
@@ -0,0 +1,60 @@
+/*
+ * Distributed under the Boost Software License, Version 1.0.(See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+ *
+ * See http://www.boost.org/libs/iostreams for documentation.
+
+ * File: boost/iostreams/detail/execute.hpp
+ * Date: Thu Dec 06 13:21:54 MST 2007
+ * Copyright: 2007-2008 CodeRage, LLC
+ * Author: Jonathan Turkanis
+ * Contact: turkanis at coderage dot com
+ *
+ * Defines the function boost::iostreams::detail::current_directory, used by
+ * boost::iostreams::detail::absolute_path.
+ */
+
+#ifndef BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED
+#define BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED
+
+#include <boost/config.hpp> // make sure size_t is in std.
+#include <cstddef> // size_t
+#include <string>
+#include <boost/iostreams/detail/buffer.hpp>
+#include <boost/iostreams/detail/config/windows_posix.hpp>
+#include <boost/iostreams/detail/system_failure.hpp>
+#ifdef BOOST_IOSTREAMS_WINDOWS
+# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+# include <windows.h>
+#else
+# include <unistd.h> // sysconf.
+#endif
+
+namespace boost { namespace iostreams { namespace detail {
+
+// Returns the current working directory
+inline std::string current_directory()
+{
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ DWORD length;
+ basic_buffer<char> buf(MAX_PATH);
+ while (true) {
+ length = ::GetCurrentDirectoryA(buf.size(), buf.data());
+ if (!length)
+ throw_system_failure("failed determining current directory");
+ if (length < static_cast<DWORD>(buf.size()))
+ break;
+ buf.resize(buf.size() * 2);
+ }
+ return std::string(buf.data(), length);
+#else // #ifdef BOOST_IOSTREAMS_WINDOWS
+ basic_buffer<char> buf(pathconf(".", _PC_PATH_MAX));
+ if (!getcwd(buf.data(), static_cast<size_t>(buf.size())))
+ throw_system_failure("failed determining current directory");
+ return std::string(buf.data());
+#endif // #ifdef BOOST_IOSTREAMS_WINDOWS
+}
+
+} } } // End namespaces detail, iostreams, boost.
+
+#endif // #ifndef BOOST_IOSTREAMS_DETAIL_CURRENT_DIRECTORY_HPP_INCLUDED
Modified: branches/iostreams_dev/boost/iostreams/detail/system_failure.hpp
==============================================================================
--- branches/iostreams_dev/boost/iostreams/detail/system_failure.hpp (original)
+++ branches/iostreams_dev/boost/iostreams/detail/system_failure.hpp 2008-02-13 00:24:07 EST (Wed, 13 Feb 2008)
@@ -69,9 +69,15 @@
return BOOST_IOSTREAMS_FAILURE(result);
}
+inline BOOST_IOSTREAMS_FAILURE system_failure(const std::string& msg)
+{ return system_failure(msg.c_str()); }
+
inline void throw_system_failure(const char* msg)
{ throw system_failure(msg); }
+inline void throw_system_failure(const std::string& msg)
+{ throw system_failure(msg); }
+
} } } // End namespaces detail, iostreams, boost.
#endif // #ifndef BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
Modified: branches/iostreams_dev/libs/iostreams/src/mapped_file.cpp
==============================================================================
--- branches/iostreams_dev/libs/iostreams/src/mapped_file.cpp (original)
+++ branches/iostreams_dev/libs/iostreams/src/mapped_file.cpp 2008-02-13 00:24:07 EST (Wed, 13 Feb 2008)
@@ -14,6 +14,9 @@
#define BOOST_IOSTREAMS_SOURCE
#include <cassert>
+#ifndef NDEBUG
+# include <boost/iostreams/detail/absolute_path.hpp>
+#endif
#include <boost/iostreams/detail/config/dyn_link.hpp>
#include <boost/iostreams/detail/config/windows_posix.hpp>
#include <boost/iostreams/detail/ios.hpp> // failure.
@@ -56,6 +59,9 @@
#else
handle_ = 0;
#endif
+ #ifndef NDEBUG
+ path_.erase();
+ #endif
}
void close()
{
@@ -78,8 +84,16 @@
data_ = 0;
size_ = 0;
mode_ = BOOST_IOS::openmode();
- if (error)
- throw_system_failure("error closing mapped file");
+ if (error) {
+ std::string msg("error closing mapped file");
+ #ifndef NDEBUG
+ msg += std::string(" (\"") + path_ + "\")";
+ #endif
+ throw_system_failure(msg);
+ }
+ #ifndef NDEBUG
+ path_.erase();
+ #endif
}
char* data_;
std::size_t size_;
@@ -91,6 +105,9 @@
#else
int handle_;
#endif
+#ifndef NDEBUG
+ std::string path_;
+#endif
};
} // End namespace detail.
@@ -147,8 +164,11 @@
namespace detail {
-void cleanup_and_throw(detail::mapped_file_impl& impl, const char* msg)
+void cleanup_and_throw(detail::mapped_file_impl& impl, std::string msg)
{
+ #ifndef NDEBUG
+ msg += std::string(" (\"") + impl.path_ + "\")";
+ #endif
if (impl.mapped_handle_ != INVALID_HANDLE_VALUE)
::CloseHandle(impl.mapped_handle_);
if (impl.handle_ != NULL)
@@ -171,6 +191,9 @@
pimpl_->clear(false);
bool readonly = (p.mode & BOOST_IOS::out) == 0;
pimpl_->mode_ = readonly ? BOOST_IOS::in : (BOOST_IOS::in | BOOST_IOS::out);
+ #ifndef NDEBUG
+ pimpl_->path_ = detail::absolute_path(p.path);
+ #endif
//--------------Open underlying file--------------------------------------//
@@ -187,8 +210,9 @@
FILE_ATTRIBUTE_TEMPORARY,
NULL );
- if (pimpl_->handle_ == INVALID_HANDLE_VALUE)
+ if (pimpl_->handle_ == INVALID_HANDLE_VALUE) {
detail::cleanup_and_throw(*pimpl_, "failed opening file");
+ }
//--------------Set file size---------------------------------------------//
@@ -295,8 +319,11 @@
namespace detail {
-void cleanup_and_throw(detail::mapped_file_impl& impl, const char* msg)
+ void cleanup_and_throw(detail::mapped_file_impl& impl, std::string msg)
{
+ #ifndef NDEBUG
+ msg += std::string(" (\"") + impl.path_ + "\")";
+ #endif
if (impl.handle_ != 0)
::close(impl.handle_);
impl.clear(true);
@@ -318,6 +345,9 @@
pimpl_->clear(false);
bool readonly = (p.mode & BOOST_IOS::out) == 0;
pimpl_->mode_ = readonly ? BOOST_IOS::in : (BOOST_IOS::in | BOOST_IOS::out);
+ #ifndef NDEBUG
+ pimpl_->path_ = detail::absolute_path(p.path);
+ #endif
//--------------Open underlying file--------------------------------------//
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk