Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src-draft/trunk]: src/external/apache2/llvm/dist/libcxx/src/filesystem Drop ...



details:   https://anonhg.NetBSD.org/src-all/rev/7760798dc486
branches:  trunk
changeset: 952767:7760798dc486
user:      Joerg Sonnenberger <joerg%bec.de@localhost>
date:      Thu Feb 04 16:07:23 2021 +0100

description:
Drop a template layer and use format string checks instead

diffstat:

 external/apache2/llvm/dist/libcxx/src/filesystem/directory_iterator.cpp |   6 +-
 external/apache2/llvm/dist/libcxx/src/filesystem/filesystem_common.h    |  42 +++++-----
 external/apache2/llvm/dist/libcxx/src/filesystem/operations.cpp         |  23 ++--
 3 files changed, 35 insertions(+), 36 deletions(-)

diffs (160 lines):

diff -r 9e9e21345815 -r 7760798dc486 external/apache2/llvm/dist/libcxx/src/filesystem/directory_iterator.cpp
--- a/external/apache2/llvm/dist/libcxx/src/filesystem/directory_iterator.cpp   Thu Feb 04 16:06:45 2021 +0100
+++ b/external/apache2/llvm/dist/libcxx/src/filesystem/directory_iterator.cpp   Thu Feb 04 16:07:23 2021 +0100
@@ -272,7 +272,7 @@
     path root = move(__imp_->__root_);
     __imp_.reset();
     if (m_ec)
-      err.report(m_ec, "at root \"%s\"", root);
+      err.report(m_ec, "at root \"%s\"", root.c_str());
   }
   return *this;
 }
@@ -359,7 +359,7 @@
   if (m_ec) {
     path root = move(stack.top().__root_);
     __imp_.reset();
-    err.report(m_ec, "at root \"%s\"", root);
+    err.report(m_ec, "at root \"%s\"", root.c_str());
   } else {
     __imp_.reset();
   }
@@ -404,7 +404,7 @@
     } else {
       path at_ent = move(curr_it.__entry_.__p_);
       __imp_.reset();
-      err.report(m_ec, "attempting recursion into \"%s\"", at_ent);
+      err.report(m_ec, "attempting recursion into \"%s\"", at_ent.c_str());
     }
   }
   return false;
diff -r 9e9e21345815 -r 7760798dc486 external/apache2/llvm/dist/libcxx/src/filesystem/filesystem_common.h
--- a/external/apache2/llvm/dist/libcxx/src/filesystem/filesystem_common.h      Thu Feb 04 16:06:45 2021 +0100
+++ b/external/apache2/llvm/dist/libcxx/src/filesystem/filesystem_common.h      Thu Feb 04 16:07:23 2021 +0100
@@ -57,7 +57,7 @@
 
 namespace {
 
-static string format_string_imp(const char* msg, ...) {
+static __attribute__((__format__(__printf__, 1, 0))) string format_string_impl(const char* msg, va_list args) {
   // we might need a second shot at this, so pre-emptivly make a copy
   struct GuardVAList {
     va_list& target;
@@ -73,9 +73,6 @@
         va_end(target);
     }
   };
-  va_list args;
-  va_start(args, msg);
-  GuardVAList args_guard(args);
 
   va_list args_cp;
   va_copy(args_cp, args);
@@ -108,17 +105,10 @@
   return result;
 }
 
-const path::value_type* unwrap(path::string_type const& s) { return s.c_str(); }
-const path::value_type* unwrap(path const& p) { return p.native().c_str(); }
-template <class Arg>
-Arg const& unwrap(Arg const& a) {
-  static_assert(!is_class<Arg>::value, "cannot pass class here");
-  return a;
-}
-
-template <class... Args>
-string format_string(const char* fmt, Args const&... args) {
-  return format_string_imp(fmt, unwrap(args)...);
+static __attribute__((__format__(__printf__, 1, 2))) string format_string(const char* msg, ...) {
+    va_list args;
+    va_start(args, msg);
+    return format_string_impl(msg, args);
 }
 
 error_code capture_errno() {
@@ -190,14 +180,15 @@
     _LIBCPP_UNREACHABLE();
   }
 
-  template <class... Args>
-  T report(const error_code& ec, const char* msg, Args const&... args) const {
+  __attribute__((__format__(__printf__, 3, 0)))
+  T report_impl(const error_code& ec, const char* msg, va_list args) const {
     if (ec_) {
+      va_end(args);
       *ec_ = ec;
       return error_value<T>();
     }
     string what =
-        string("in ") + func_name_ + ": " + format_string(msg, args...);
+        string("in ") + func_name_ + ": " + format_string_impl(msg, args);
     switch (bool(p1_) + bool(p2_)) {
     case 0:
       __throw_filesystem_error(what, ec);
@@ -209,11 +200,20 @@
     _LIBCPP_UNREACHABLE();
   }
 
+  __attribute__((__format__(__printf__, 3, 4)))
+  T report(const error_code& ec, const char* msg, ...) const {
+    va_list args;
+    va_start(args, msg);
+    return report_impl(ec, msg, args);
+  }
+
   T report(errc const& err) const { return report(make_error_code(err)); }
 
-  template <class... Args>
-  T report(errc const& err, const char* msg, Args const&... args) const {
-    return report(make_error_code(err), msg, args...);
+  __attribute__((__format__(__printf__, 3, 4)))
+  T report(errc const& err, const char* msg, ...) const {
+    va_list args;
+    va_start(args, msg);
+    return report_impl(make_error_code(err), msg, args);
   }
 
 private:
diff -r 9e9e21345815 -r 7760798dc486 external/apache2/llvm/dist/libcxx/src/filesystem/operations.cpp
--- a/external/apache2/llvm/dist/libcxx/src/filesystem/operations.cpp   Thu Feb 04 16:06:45 2021 +0100
+++ b/external/apache2/llvm/dist/libcxx/src/filesystem/operations.cpp   Thu Feb 04 16:07:23 2021 +0100
@@ -987,16 +987,15 @@
   if (detail::mkdir(p.c_str(), attr_stat.st_mode) == 0)
     return true;
 
-  if (errno == EEXIST) {
-    error_code mec = capture_errno();
-    error_code ignored_ec;
-    const file_status st = status(p, ignored_ec);
-    if (!is_directory(st)) {
-      err.report(mec);
-    }
-  } else {
-    err.report(capture_errno());
-  }
+  if (errno != EEXIST)
+    return err.report(capture_errno());
+
+  mec = capture_errno();
+  error_code ignored_ec;
+  st = status(p, ignored_ec);
+  if (!is_directory(st))
+    return err.report(mec);
+
   return false;
 }
 
@@ -1360,11 +1359,11 @@
   error_code m_ec;
   file_status st = detail::posix_stat(p, &m_ec);
   if (!status_known(st))
-    return err.report(m_ec, "cannot access path \"" PS_FMT "\"", p);
+    return err.report(m_ec, "cannot access path \"" PS_FMT "\"", p.c_str());
 
   if (!exists(st) || !is_directory(st))
     return err.report(errc::not_a_directory, "path \"" PS_FMT "\" is not a directory",
-                      p);
+                      p.c_str());
 
   return p;
 }



Home | Main Index | Thread Index | Old Index