<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 31, 2016, at 4:14 PM, Rui Ueyama <<a href="mailto:ruiu@google.com" class="">ruiu@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 31, 2016 at 4:05 PM, Mehdi Amini via llvm-commits<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Author: mehdi_amini<br class="">Date: Thu Mar 31 18:05:26 2016<br class="">New Revision: 265068<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=265068&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=265068&view=rev</a><br class="">Log:<br class="">Add disk_space() to llvm::fs<br class=""><br class="">Summary: Adapted from Boost::filesystem.<br class="">(This is a reapply by reverting commit r265062 and fixing the WinAPI part)<br class=""><br class="">Differential Revision:<span class="Apple-converted-space"> </span><a href="http://reviews.llvm.org/D18467" rel="noreferrer" target="_blank" class="">http://reviews.llvm.org/D18467</a><br class=""><br class="">From: Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>><br class=""><br class="">Modified:<br class="">   <span class="Apple-converted-space"> </span>llvm/trunk/include/llvm/Support/FileSystem.h<br class="">   <span class="Apple-converted-space"> </span>llvm/trunk/lib/Support/Unix/Path.inc<br class="">   <span class="Apple-converted-space"> </span>llvm/trunk/lib/Support/Windows/Path.inc<br class=""><br class="">Modified: llvm/trunk/include/llvm/Support/FileSystem.h<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=265068&r1=265067&r2=265068&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=265068&r1=265067&r2=265068&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/Support/FileSystem.h (original)<br class="">+++ llvm/trunk/include/llvm/Support/FileSystem.h Thu Mar 31 18:05:26 2016<br class="">@@ -32,6 +32,7 @@<br class=""> #include "llvm/ADT/Twine.h"<br class=""> #include "llvm/Support/DataTypes.h"<br class=""> #include "llvm/Support/ErrorHandling.h"<br class="">+#include "llvm/Support/ErrorOr.h"<br class=""> #include "llvm/Support/TimeValue.h"<br class=""> #include <ctime><br class=""> #include <iterator><br class="">@@ -648,6 +649,17 @@ std::error_code identify_magic(const Twi<br class=""><br class=""> std::error_code getUniqueID(const Twine Path, UniqueID &Result);<br class=""><br class="">+/// @brief Get disk space usage information.<br class="">+///<br class="">+/// Note: Users must be careful about "Time Of Check, Time Of Use" kind of bug.<br class="">+/// Note: Windows reports results according to the quota allocated to the user.<br class="">+///<br class="">+/// @param Path Input path.<br class="">+/// @returns a space_info structure filled with the capacity, free, and<br class="">+/// available space on the device \a Path is on. A platform specific error_code<br class="">+/// is returned on error.<br class="">+ErrorOr<space_info> disk_space(const Twine Path);<br class=""></blockquote><div class=""><br class=""></div><div class="">I think you need to change the parameter type to `const Twine &`. </div></div></div></div></div></blockquote><div><br class=""></div><div>Oh your right, I was about to do it after your comment on phab, but then the windows bot yelled at me and I've been busy fixing the build to the point where I forgot. I'm glad you double-checked!</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">As documented in Twine.h, Twine's implementation relies on the ability to store pointers to temporary stock objects which may be deallocated at the end of a statement, so having a Twine as a local variable (or a parameter) is not correct.</div></div></div></div></div></blockquote><div><br class=""></div><div>You can't take ownership of the Twine, but this is not what happens here, is there a correctness issue (I see the inefficiency issue)? The twine will points to objects that are in the caller frame and won't be deallocated before the end of the call?</div><div><br class=""></div><div>-- </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">+<br class=""> /// This class represents a memory mapped file. It is based on<br class=""> /// boost::iostreams::mapped_file.<br class=""> class mapped_file_region {<br class=""><br class="">Modified: llvm/trunk/lib/Support/Unix/Path.inc<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=265068&r1=265067&r2=265068&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=265068&r1=265067&r2=265068&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Support/Unix/Path.inc (original)<br class="">+++ llvm/trunk/lib/Support/Unix/Path.inc Thu Mar 31 18:05:26 2016<br class="">@@ -60,6 +60,24 @@<br class=""> # define PATH_MAX 4096<br class=""> #endif<br class=""><br class="">+#include <sys/types.h><br class="">+#if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__ANDROID__)<br class="">+#include <sys/statvfs.h><br class="">+#define STATVFS statvfs<br class="">+#define STATVFS_F_FRSIZE(vfs) vfs.f_frsize<br class="">+#else<br class="">+#ifdef __OpenBSD__<br class="">+#include <sys/param.h><br class="">+#elif defined(__ANDROID__)<br class="">+#include <sys/vfs.h><br class="">+#else<br class="">+#include <sys/mount.h><br class="">+#endif<br class="">+#define STATVFS statfs<br class="">+#define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize)<br class="">+#endif<br class="">+<br class="">+<br class=""> using namespace llvm;<br class=""><br class=""> namespace llvm {<br class="">@@ -70,7 +88,7 @@ namespace fs {<br class="">     defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__)<br class=""> static int<br class=""> test_dir(char ret[PATH_MAX], const char *dir, const char *bin)<br class="">-{<br class="">+{<br class="">   struct stat sb;<br class="">   char fullpath[PATH_MAX];<br class=""><br class="">@@ -190,6 +208,18 @@ UniqueID file_status::getUniqueID() cons<br class="">   return UniqueID(fs_st_dev, fs_st_ino);<br class=""> }<br class=""><br class="">+ErrorOr<space_info> disk_space(const Twine Path) {<br class="">+  struct STATVFS Vfs;<br class="">+  if (::STATVFS(Path.str().c_str(), &Vfs))<br class="">+    return std::error_code(errno, std::generic_category());<br class="">+  auto FrSize = STATVFS_F_FRSIZE(Vfs);<br class="">+  space_info SpaceInfo;<br class="">+  SpaceInfo.capacity = static_cast<uint64_t>(Vfs.f_blocks) * FrSize;<br class="">+  SpaceInfo.free = static_cast<uint64_t>(Vfs.f_bfree) * FrSize;<br class="">+  SpaceInfo.available = static_cast<uint64_t>(Vfs.f_bavail) * FrSize;<br class="">+  return SpaceInfo;<br class="">+}<br class="">+<br class=""> std::error_code current_path(SmallVectorImpl<char> &result) {<br class="">   result.clear();<br class=""><br class=""><br class="">Modified: llvm/trunk/lib/Support/Windows/Path.inc<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=265068&r1=265067&r2=265068&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=265068&r1=265067&r2=265068&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Support/Windows/Path.inc (original)<br class="">+++ llvm/trunk/lib/Support/Windows/Path.inc Thu Mar 31 18:05:26 2016<br class="">@@ -151,6 +151,19 @@ UniqueID file_status::getUniqueID() cons<br class="">   return UniqueID(VolumeSerialNumber, FileID);<br class=""> }<br class=""><br class="">+ErrorOr<space_info> disk_space(const Twine Path) {<br class="">+  PULARGE_INTEGER Avail, Total, Free;<br class="">+  if (!::GetDiskFreeSpaceExA(Path.str().c_str(), &Avail, &Total, &Free))<br class="">+    return mapWindowsError(::GetLastError());<br class="">+  space_info SpaceInfo;<br class="">+  SpaceInfo.capacity =<br class="">+      (static_cast<uint64_t>(Total.HighPart) << 32) + Total.LowPart;<br class="">+  SpaceInfo.Free = (static_cast<uint64_t>(Free.HighPart) << 32) + Free.LowPart;<br class="">+  SpaceInfo.available =<br class="">+      (static_cast<uint64_t>(Avail.HighPart) << 32) + Avail.LowPart;<br class="">+  return SpaceInfo;<br class="">+}<br class="">+<br class=""> TimeValue file_status::getLastAccessedTime() const {<br class="">   ULARGE_INTEGER UI;<br class="">   UI.LowPart = LastAccessedTimeLow;<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a></blockquote></div></div></div></div></blockquote></div><br class=""></body></html>