[llvm-commits] [compiler-rt] r167291 - in /compiler-rt/trunk/lib: sanitizer_common/sanitizer_common.cc sanitizer_common/sanitizer_libc.h sanitizer_common/sanitizer_win.cc tsan/rtl/tsan_flags.cc

Alexey Samsonov samsonov at google.com
Fri Nov 2 02:38:48 PDT 2012


Author: samsonov
Date: Fri Nov  2 04:38:47 2012
New Revision: 167291

URL: http://llvm.org/viewvc/llvm-project?rev=167291&view=rev
Log:
[Sanitizer] Use kStderrFd constant instead of hardcoded 2

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=167291&r1=167290&r2=167291&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri Nov  2 04:38:47 2012
@@ -18,7 +18,7 @@
 
 // By default, dump to stderr. If report_fd is kInvalidFd, try to obtain file
 // descriptor by opening file in report_path.
-static fd_t report_fd = 2;
+static fd_t report_fd = kStderrFd;
 static char report_path[4096];  // Set via __sanitizer_set_report_path.
 
 static void (*DieCallback)(void);
@@ -54,7 +54,7 @@
   if (report_fd == kInvalidFd) {
     fd_t fd = internal_open(report_path, true);
     if (fd == kInvalidFd) {
-      report_fd = 2;
+      report_fd = kStderrFd;
       Report("ERROR: Can't open file: %s\n", report_path);
       Die();
     }
@@ -147,21 +147,22 @@
 void __sanitizer_set_report_path(const char *path) {
   if (!path) return;
   uptr len = internal_strlen(path);
-  if (len > sizeof(__sanitizer::report_path) - 100) {
+  if (len > sizeof(report_path) - 100) {
     Report("ERROR: Path is too long: %c%c%c%c%c%c%c%c...\n",
            path[0], path[1], path[2], path[3],
            path[4], path[5], path[6], path[7]);
     Die();
   }
-  internal_snprintf(__sanitizer::report_path,
-                    sizeof(__sanitizer::report_path), "%s.%d", path, GetPid());
-  __sanitizer::report_fd = kInvalidFd;
+  internal_snprintf(report_path, sizeof(report_path), "%s.%d", path, GetPid());
+  report_fd = kInvalidFd;
 }
 
 void __sanitizer_set_report_fd(int fd) {
-  if (__sanitizer::report_fd > 2 && __sanitizer::report_fd != kInvalidFd)
-    internal_close(__sanitizer::report_fd);
-  __sanitizer::report_fd = fd;
+  if (report_fd != kStdoutFd &&
+      report_fd != kStderrFd &&
+      report_fd != kInvalidFd)
+    internal_close(report_fd);
+  report_fd = fd;
 }
 
 }  // extern "C"

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h?rev=167291&r1=167290&r2=167291&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h Fri Nov  2 04:38:47 2012
@@ -55,6 +55,9 @@
 // I/O
 typedef int fd_t;
 const fd_t kInvalidFd = -1;
+const fd_t kStdinFd = 0;
+const fd_t kStdoutFd = 1;
+const fd_t kStderrFd = 2;
 int internal_close(fd_t fd);
 fd_t internal_open(const char *filename, bool write);
 uptr internal_read(fd_t fd, void *buf, uptr count);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=167291&r1=167290&r2=167291&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Fri Nov  2 04:38:47 2012
@@ -163,7 +163,7 @@
 }
 
 uptr internal_write(fd_t fd, const void *buf, uptr count) {
-  if (fd != 2)
+  if (fd != kStderrFd)
     UNIMPLEMENTED();
   HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
   if (err == 0)

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=167291&r1=167290&r2=167291&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Fri Nov  2 04:38:47 2012
@@ -47,7 +47,7 @@
   f->strip_path_prefix = "";
   f->suppressions = "";
   f->exitcode = 66;
-  f->log_fileno = 2;
+  f->log_fileno = kStderrFd;
   f->atexit_sleep_ms = 1000;
   f->verbosity = 0;
   f->profile_memory = "";





More information about the llvm-commits mailing list