[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] boost::filesystem anomaly?
From: |
Greg Chicares |
Subject: |
[lmi] boost::filesystem anomaly? |
Date: |
Sat, 11 Jun 2016 12:23:29 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0 |
What should this print under msw?
std::string s("C:/opt/lmi/bin");
fs::path g(s, fs::no_check);
std::cout << g.string() << std::endl;
I think it should print
C:/opt/lmi/bin <-- expected
and not
C:opt/lmi/bin <-- unexpected: first slash deleted
With the first patch[0] below, I run lmi and get:
g is 'C:opt/lmi/bin'
g is 'C:opt/lmi/bin'
in two successive messageboxes. Note that the third character ("/")
of the original string is missing. (I think that's wrong.)
With the second patch[1] below, I run the unit test and get:
Running path_utility_test:
g is 'C:/opt/lmi/bin'
g is 'C:/opt/lmi/bin'
Here, the third character ("/") is preserved. (I think that's right.)
I noticed this behavior difference when I tried constructing fs::path
objects from input strings. If I did that in GUI code that is part of
$(skeleton_objects), the slash was deleted. If I did that in liblmi.dll
code that is part of $(lmi_common_objects), the slash was *not* deleted.
I guessed that the explanation must be that the GUI code called
initialize_filesystem(), which does this:
fs::path::default_name_check(fs::native);
even though that shouldn't matter because the fs::path objects are
constructed with fs::no_check; but the patches below seem to rule out
that hypothesis.
This matters because I would like to use fs::path in these functions:
Transfer(transfer_direction td, std::string& data, wxFilePickerCtrl& control)
Transfer(transfer_direction td, std::string& data, wxDirPickerCtrl& control)
and that seems to work only if I construct the fs::path in a function
defined in liblmi.dll, but that seems fragile because of the anomaly
demonstrated in the patches.
---------
[0] "the first patch":
----------8<----------
diff --git a/main_wx.cpp b/main_wx.cpp
index 8fa105b..1db6628 100644
--- a/main_wx.cpp
+++ b/main_wx.cpp
@@ -86,8 +86,18 @@ int WINAPI WinMain
try
{
+ {
+ std::string s("C:/opt/lmi/bin");
+ fs::path g(s, fs::no_check);
+ warning() << "g is '" << g.string() << "'" << std::flush;
+ }
initialize_application();
initialize_filesystem();
+ {
+ std::string s("C:/opt/lmi/bin");
+ fs::path g(s, fs::no_check);
+ warning() << "g is '" << g.string() << "'" << std::flush;
+ }
#ifndef LMI_MSW
result = wxEntry(argc, argv);
#else // LMI_MSW defined.
---------->8----------
[1] "the second patch":
diff --git a/path_utility_test.cpp b/path_utility_test.cpp
index f1c557a..2287320 100644
--- a/path_utility_test.cpp
+++ b/path_utility_test.cpp
@@ -302,8 +302,21 @@ void test_path_validation()
fs::remove("path_utility_test_file");
}
+#include "alert.hpp"
int test_main(int, char*[])
{
+ {
+ std::string s("C:/opt/lmi/bin");
+ fs::path g(s, fs::no_check);
+ warning() << "g is '" << g.string() << "'" << std::flush;
+ }
+ initialize_filesystem();
+ {
+ std::string s("C:/opt/lmi/bin");
+ fs::path g(s, fs::no_check);
+ warning() << "g is '" << g.string() << "'" << std::flush;
+ }
+
test_orthodox_filename();
test_serial_file_path();
test_unique_filepath_with_normal_filenames();
- [lmi] boost::filesystem anomaly?,
Greg Chicares <=