public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-11040] libstdc++: Simplify resource management in directory iterators
@ 2023-10-04 11:28 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-10-04 11:28 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:8d552ceae829b0859d5e225e6529de1cd636a311

commit r11-11040-g8d552ceae829b0859d5e225e6529de1cd636a311
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Feb 8 15:57:58 2022 +0000

    libstdc++: Simplify resource management in directory iterators
    
    This replaces the _Dir constructor that takes ownership of an existing
    DIR* resource with one that takes a _Dir_base rvalue instead. This means
    a raw DIR* is never passed around, but is always owned by a _Dir_base
    object.
    
    libstdc++-v3/ChangeLog:
    
            * src/c++17/fs_dir.cc (_Dir(DIR*, const path&)): Change first
            parameter to _Dir_base&&.
            * src/filesystem/dir-common.h (_Dir_base(DIR*)): Remove.
            * src/filesystem/dir.cc (_Dir(DIR*, const path&)): Change first
            parameter to _Dir_base&&.
    
    (cherry picked from commit 1ef6085f09b50e0aa3e5a5d15ebf8752e8aa8a72)

Diff:
---
 libstdc++-v3/src/c++17/fs_dir.cc         | 4 ++--
 libstdc++-v3/src/filesystem/dir-common.h | 2 --
 libstdc++-v3/src/filesystem/dir.cc       | 4 ++--
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/src/c++17/fs_dir.cc b/libstdc++-v3/src/c++17/fs_dir.cc
index 42042751276..96b55ae0fa5 100644
--- a/libstdc++-v3/src/c++17/fs_dir.cc
+++ b/libstdc++-v3/src/c++17/fs_dir.cc
@@ -57,7 +57,7 @@ struct fs::_Dir : _Dir_base
       path = p;
   }
 
-  _Dir(posix::DIR* dirp, const path& p) : _Dir_base(dirp), path(p) { }
+  _Dir(_Dir_base&& d, const path& p) : _Dir_base(std::move(d)), path(p) { }
 
   _Dir(_Dir&&) = default;
 
@@ -140,7 +140,7 @@ struct fs::_Dir : _Dir_base
     _Dir_base d(dirfd, pathname, skip_permission_denied, nofollow, ec);
     // If this->path is empty, the new _Dir should have an empty path too.
     const fs::path& p = this->path.empty() ? this->path : this->entry.path();
-    return _Dir(std::exchange(d.dirp, nullptr), p);
+    return _Dir(std::move(d), p);
   }
 
   bool
diff --git a/libstdc++-v3/src/filesystem/dir-common.h b/libstdc++-v3/src/filesystem/dir-common.h
index bc734881782..647cd7a6e5c 100644
--- a/libstdc++-v3/src/filesystem/dir-common.h
+++ b/libstdc++-v3/src/filesystem/dir-common.h
@@ -89,8 +89,6 @@ is_permission_denied_error(int e)
 
 struct _Dir_base
 {
-  _Dir_base(posix::DIR* dirp = nullptr) : dirp(dirp) { }
-
   // If no error occurs then dirp is non-null,
   // otherwise null (even if a permission denied error is ignored).
   _Dir_base(int fd, const posix::char_type* pathname,
diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
index 6d16a8bc20b..85003eb170b 100644
--- a/libstdc++-v3/src/filesystem/dir.cc
+++ b/libstdc++-v3/src/filesystem/dir.cc
@@ -59,7 +59,7 @@ struct fs::_Dir : std::filesystem::_Dir_base
       path = p;
   }
 
-  _Dir(posix::DIR* dirp, const path& p) : _Dir_base(dirp), path(p) { }
+  _Dir(_Dir_base&& d, const path& p) : _Dir_base(std::move(d)), path(p) { }
 
   _Dir(_Dir&&) = default;
 
@@ -133,7 +133,7 @@ struct fs::_Dir : std::filesystem::_Dir_base
   {
     auto [dirfd, pathname] = dir_and_pathname();
     _Dir_base d(dirfd, pathname, skip_permission_denied, nofollow, ec);
-    return _Dir(std::exchange(d.dirp, nullptr), entry.path());
+    return _Dir(std::move(d), entry.path());
   }
 
   fs::path		path;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-04 11:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-04 11:28 [gcc r11-11040] libstdc++: Simplify resource management in directory iterators Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).