This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Implement ISO/IEC TS 18822 C++ File system TS


On mingw-w64 there are now more issues to do with using the narrow
versions of some functions, I was able to get dir.cc to compile with
the attached patch to give you an idea.

ops.cc fails as well, again a lot of it seems to be wide char issues,
I've attached the messages.

Thanks!

On 2 May 2015 at 05:05, Jonathan Wakely <jwakely@redhat.com> wrote:
> On 01/05/15 20:38 +0100, Jonathan Wakely wrote:
>>
>> On 01/05/15 21:28 +0200, Daniel KrÃgler wrote:
>>>
>>> But if I read your implementation of path::compare(const path& p)
>>> correctly it *also* may allocate memory by copying _M_pathname into a
>>> _Cmpt object.
>>
>>
>> Yes, I agree that there's a bug here that could cause it to
>> std::terminate.
>>
>>> I was wondering whether for this comparison there exists
>>> real need to *copy* _M_pathname (potentially exceeding the memory
>>> limits). Wouldn't it be possible to define a _CmptRef type that for
>>> the purpose of implementing compare(const path& p) just refers to
>>> references of the _M_pathname and therefore doesn't need to allocate
>>> any dynamic storage? (I should have spoken of a new type _CmptRef and
>>> not of your existing _Cmpt).
>>
>>
>>
>> Ah, I see what you mean (I thought you were suggesting some
>> improvements to _Cmpt itself ... which might be possible so I'm glad
>> you made me think about it :-)
>>
>> I think I wrote compare() like that because it was easier, and when I
>> first implemented this we had COW strings so it wouldn't throw when
>> copying. That isn't true now, so I need to change it.
>
>
> And here's the fix for this noexcept issue, it was very simple in the
> end, thanks for the idea.
>
> Tested powerpc64le-linux, committed to trunk.
>
diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
index 016a78d..af42a5a 100644
--- a/libstdc++-v3/src/filesystem/dir.cc
+++ b/libstdc++-v3/src/filesystem/dir.cc
@@ -69,7 +69,7 @@ struct fs::_Dir
 {
   _Dir() : dirp(nullptr) { }
 
-  _Dir(DIR* dirp, const fs::path& path) : dirp(dirp), path(path) { }
+  _Dir(_WDIR* dirp, const fs::path& path) : dirp(dirp), path(path) { }
 
   _Dir(_Dir&& d)
   : dirp(std::exchange(d.dirp, nullptr)), path(std::move(d.path)),
@@ -78,11 +78,11 @@ struct fs::_Dir
 
   _Dir& operator=(_Dir&&) = delete;
 
-  ~_Dir() { if (dirp) ::closedir(dirp); }
+  ~_Dir() { if (dirp) ::_wclosedir(dirp); }
 
   bool advance(ErrorCode);
 
-  DIR*			dirp;
+  _WDIR*			dirp;
   fs::path		path;
   directory_entry	entry;
   file_type		type = file_type::none;
@@ -99,7 +99,7 @@ namespace
   fs::_Dir
   opendir(const fs::path& p, fs::directory_options options, ErrorCode ec)
   {
-    if (DIR* dirp = ::opendir(p.c_str()))
+    if (_WDIR* dirp = ::opendir(p.c_str()))
       return {dirp, p};
 
     const int err = errno;
@@ -125,7 +125,7 @@ namespace
   }
 
   inline fs::file_type
-  get_file_type(const dirent& d __attribute__((__unused__)))
+  get_file_type(const _wdirent& d __attribute__((__unused__)))
   {
 #ifdef _GLIBCXX_HAVE_STRUCT_DIRENT_D_TYPE
     switch (d.d_type)
@@ -155,11 +155,11 @@ namespace
   }
 
   int
-  native_readdir(DIR* dirp, ::dirent*& entryp)
+  native_readdir(_WDIR* dirp, ::_wdirent*& entryp)
   {
 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
     errno = 0;
-    if ((entryp = ::readdir(dirp)))
+    if ((entryp = ::_wreaddir(dirp)))
       return 0;
     return errno;
 #else
@@ -171,8 +171,8 @@ namespace
 bool
 fs::_Dir::advance(ErrorCode ec)
 {
-  ::dirent ent;
-  ::dirent* result = &ent;
+  ::_wdirent ent;
+  ::_wdirent* result = &ent;
   if (int err = native_readdir(dirp, result))
     {
       if (!ec)
@@ -185,7 +185,7 @@ fs::_Dir::advance(ErrorCode ec)
   else if (result != nullptr)
     {
       // skip past dot and dot-dot
-      if (!strcmp(ent.d_name, ".") || !strcmp(ent.d_name, ".."))
+      if (!wcscmp(ent.d_name, L".") || !wcscmp(ent.d_name, L".."))
 	return advance(std::move(ec));
       entry = fs::directory_entry{path / ent.d_name};
       type = get_file_type(ent);
@@ -260,7 +260,7 @@ recursive_directory_iterator(const path& p, directory_options options,
                                  error_code* ec)
 : _M_options(options), _M_pending(true)
 {
-  if (DIR* dirp = ::opendir(p.c_str()))
+  if (_WDIR* dirp = ::opendir(p.c_str()))
     {
       _M_dirs = std::make_shared<_Dir_stack>();
       _M_dirs->push(_Dir{ dirp, p });

Attachment: ops.cc.error
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]