|
Boost-Commit : |
From: technews_at_[hidden]
Date: 2008-02-13 00:47:45
Author: turkanis
Date: 2008-02-13 00:47:44 EST (Wed, 13 Feb 2008)
New Revision: 43240
URL: http://svn.boost.org/trac/boost/changeset/43240
Log:
merged changes from iostreams_dev, revisions 43059-43238: better debug output for mapped file; fixed large_file_test.cpp under UNICODE on Windows
Added:
trunk/boost/iostreams/detail/absolute_path.hpp
- copied unchanged from r43238, /branches/iostreams_dev/boost/iostreams/detail/absolute_path.hpp
trunk/boost/iostreams/detail/current_directory.hpp
- copied unchanged from r43238, /branches/iostreams_dev/boost/iostreams/detail/current_directory.hpp
Text files modified:
trunk/boost/iostreams/detail/system_failure.hpp | 6 ++++++
trunk/libs/iostreams/src/mapped_file.cpp | 40 +++++++++++++++++++++++++++++++++++-----
trunk/libs/iostreams/test/large_file_test.cpp | 32 +++++++++++++++++---------------
3 files changed, 58 insertions(+), 20 deletions(-)
Modified: trunk/boost/iostreams/detail/system_failure.hpp
==============================================================================
--- trunk/boost/iostreams/detail/system_failure.hpp (original)
+++ trunk/boost/iostreams/detail/system_failure.hpp 2008-02-13 00:47:44 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: trunk/libs/iostreams/src/mapped_file.cpp
==============================================================================
--- trunk/libs/iostreams/src/mapped_file.cpp (original)
+++ trunk/libs/iostreams/src/mapped_file.cpp 2008-02-13 00:47:44 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--------------------------------------//
Modified: trunk/libs/iostreams/test/large_file_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/large_file_test.cpp (original)
+++ trunk/libs/iostreams/test/large_file_test.cpp 2008-02-13 00:47:44 EST (Wed, 13 Feb 2008)
@@ -70,11 +70,11 @@
0, 8, 0 }; // Seek by 8GB
const int offset_list_length = sizeof(offset_list) / sizeof(int);
#ifdef LARGE_FILE_TEMP
- const char* file_name = BOOST_STRINGIZE(LARGE_FILE_TEMP);
- const bool keep_file = false;
+# define BOOST_FILE_NAME BOOST_STRINGIZE(LARGE_FILE_TEMP)
+# define BOOST_KEEP_FILE false
#else
- const char* file_name = BOOST_STRINGIZE(LARGE_FILE_KEEP);
- const bool keep_file = true;
+# define BOOST_FILE_NAME BOOST_STRINGIZE(LARGE_FILE_KEEP)
+# define BOOST_KEEP_FILE true
#endif
//------------------Definition of remove_large_file---------------------------//
@@ -83,9 +83,9 @@
void remove_large_file()
{
#ifdef BOOST_IOSTREAMS_WINDOWS
- DeleteFile(TEXT(file_name));
+ DeleteFile(TEXT(BOOST_FILE_NAME));
#else
- unlink(file_name);
+ unlink(BOOST_FILE_NAME);
#endif
}
@@ -103,7 +103,7 @@
// Check existence
WIN32_FIND_DATA info;
- HANDLE hnd = FindFirstFile(TEXT(file_name), &info);
+ HANDLE hnd = FindFirstFile(TEXT(BOOST_FILE_NAME), &info);
if (hnd == INVALID_HANDLE_VALUE)
return false;
@@ -137,7 +137,7 @@
// Check existence
struct BOOST_IOSTREAMS_FD_STAT info;
- if (BOOST_IOSTREAMS_FD_STAT(file_name, &info))
+ if (BOOST_IOSTREAMS_FD_STAT(BOOST_FILE_NAME, &info))
return false;
// Check size
@@ -187,7 +187,7 @@
for (stream_offset z = 0; z <= 8; ++z) {
try {
mapped_file_params params;
- params.path = file_name;
+ params.path = BOOST_FILE_NAME;
params.offset = z * gigabyte;
params.length = 1;
params.mode = BOOST_IOS::out;
@@ -216,7 +216,7 @@
bool create_large_file()
{
// If file exists, has correct size, and is recent, we're done
- if (keep_file && large_file_exists())
+ if (BOOST_KEEP_FILE && large_file_exists())
return true;
#ifdef BOOST_IOSTREAMS_WINDOWS
@@ -224,7 +224,7 @@
// Create file
HANDLE hnd =
CreateFile(
- TEXT(file_name),
+ TEXT(BOOST_FILE_NAME),
GENERIC_WRITE,
0,
NULL,
@@ -306,7 +306,7 @@
S_IRUSR | S_IWUSR |
S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH;
- int fd = BOOST_IOSTREAMS_FD_OPEN(file_name, oflag, pmode);
+ int fd = BOOST_IOSTREAMS_FD_OPEN(BOOST_FILE_NAME, oflag, pmode);
if (fd == -1)
return false;
@@ -363,9 +363,9 @@
class large_file {
public:
large_file() { exists_ = create_large_file(); }
- ~large_file() { if (!keep_file) remove_large_file(); }
+ ~large_file() { if (!BOOST_KEEP_FILE) remove_large_file(); }
bool exists() const { return exists_; }
- const char* path() const { return file_name; }
+ const char* path() const { return BOOST_FILE_NAME; }
private:
bool exists_;
};
@@ -396,7 +396,9 @@
// Prepare file and file descriptor
large_file large;
file_descriptor_source file;
- BOOST_REQUIRE_MESSAGE(large.exists(), "failed creating file");
+ BOOST_REQUIRE_MESSAGE(
+ large.exists(), "failed creating file \"" << BOOST_FILE_NAME << '"'
+ );
BOOST_CHECK_NO_THROW(file.open(large.path(), BOOST_IOS::binary));
// Test seeking using ios_base::beg
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