[tor-commits] [tor/master] Remove util_bug dependency on compat.h

nickm at torproject.org nickm at torproject.org
Tue Jun 26 15:27:41 UTC 2018


commit 6fc2d532274ead9c903c6d94b1a513b8d9b6f677
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Jun 22 11:51:58 2018 -0400

    Remove util_bug dependency on compat.h
---
 src/common/compat.c       | 26 --------------------------
 src/common/compat.h       |  8 --------
 src/common/token_bucket.c |  2 +-
 src/common/util_bug.c     | 29 ++++++++++++++++++++++++++++-
 src/common/util_bug.h     | 12 ++++++++++--
 5 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/src/common/compat.c b/src/common/compat.c
index 467c51d6e..8e418f4c1 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -493,32 +493,6 @@ tor_strtok_r_impl(char *str, const char *sep, char **lasts)
   return start;
 }
 
-#ifdef _WIN32
-/** Take a filename and return a pointer to its final element.  This
- * function is called on __FILE__ to fix a MSVC nit where __FILE__
- * contains the full path to the file.  This is bad, because it
- * confuses users to find the home directory of the person who
- * compiled the binary in their warning messages.
- */
-const char *
-tor_fix_source_file(const char *fname)
-{
-  const char *cp1, *cp2, *r;
-  cp1 = strrchr(fname, '/');
-  cp2 = strrchr(fname, '\\');
-  if (cp1 && cp2) {
-    r = (cp1<cp2)?(cp2+1):(cp1+1);
-  } else if (cp1) {
-    r = cp1+1;
-  } else if (cp2) {
-    r = cp2+1;
-  } else {
-    r = fname;
-  }
-  return r;
-}
-#endif /* defined(_WIN32) */
-
 /**
  * Read a 16-bit value beginning at <b>cp</b>.  Equivalent to
  * *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid
diff --git a/src/common/compat.h b/src/common/compat.h
index f91c22425..691824a2e 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -92,14 +92,6 @@ char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
 #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
 #endif
 
-#ifdef _WIN32
-#define SHORT_FILE__ (tor_fix_source_file(__FILE__))
-const char *tor_fix_source_file(const char *fname);
-#else
-#define SHORT_FILE__ (__FILE__)
-#define tor_fix_source_file(s) (s)
-#endif /* defined(_WIN32) */
-
 /* ===== Time compatibility */
 
 struct tm *tor_localtime_r(const time_t *timep, struct tm *result);
diff --git a/src/common/token_bucket.c b/src/common/token_bucket.c
index a028b08a0..502e8eac5 100644
--- a/src/common/token_bucket.c
+++ b/src/common/token_bucket.c
@@ -19,6 +19,7 @@
 #define TOKEN_BUCKET_PRIVATE
 
 #include "common/token_bucket.h"
+#include "common/compat.h"
 #include "common/util_bug.h"
 
 /**
@@ -252,4 +253,3 @@ token_bucket_rw_dec(token_bucket_rw_t *bucket,
     flags |= TB_WRITE;
   return flags;
 }
-
diff --git a/src/common/util_bug.c b/src/common/util_bug.c
index 0e6190caf..c68519b74 100644
--- a/src/common/util_bug.c
+++ b/src/common/util_bug.c
@@ -15,6 +15,7 @@
 #include "lib/container/smartlist.h"
 #endif
 #include "lib/malloc/util_malloc.h"
+#include "lib/string/printf.h"
 
 #ifdef __COVERITY__
 int bug_macro_deadcode_dummy__ = 0;
@@ -40,7 +41,7 @@ tor_end_capture_bugs_(void)
     return;
   SMARTLIST_FOREACH(bug_messages, char *, cp, tor_free(cp));
   smartlist_free(bug_messages);
-  bug_messages = NULL;
+nn  bug_messages = NULL;
 }
 const smartlist_t *
 tor_get_captured_bug_log_(void)
@@ -119,3 +120,29 @@ tor_bug_occurred_(const char *fname, unsigned int line,
   }
 #endif
 }
+
+#ifdef _WIN32
+/** Take a filename and return a pointer to its final element.  This
+ * function is called on __FILE__ to fix a MSVC nit where __FILE__
+ * contains the full path to the file.  This is bad, because it
+ * confuses users to find the home directory of the person who
+ * compiled the binary in their warning messages.
+ */
+const char *
+tor_fix_source_file(const char *fname)
+{
+  const char *cp1, *cp2, *r;
+  cp1 = strrchr(fname, '/');
+  cp2 = strrchr(fname, '\\');
+  if (cp1 && cp2) {
+    r = (cp1<cp2)?(cp2+1):(cp1+1);
+  } else if (cp1) {
+    r = cp1+1;
+  } else if (cp2) {
+    r = cp2+1;
+  } else {
+    r = fname;
+  }
+  return r;
+}
+#endif /* defined(_WIN32) */
diff --git a/src/common/util_bug.h b/src/common/util_bug.h
index fb5ab25c1..a0753c807 100644
--- a/src/common/util_bug.h
+++ b/src/common/util_bug.h
@@ -37,8 +37,8 @@
 #define TOR_UTIL_BUG_H
 
 #include "orconfig.h"
-#include <stdlib.h>
-#include "common/compat.h"
+#include "lib/cc/compat_compiler.h"
+#include "lib/log/torlog.h"
 #include "lib/testsupport/testsupport.h"
 
 /* Replace assert() with a variant that sends failures to the log before
@@ -192,6 +192,14 @@ void tor_bug_occurred_(const char *fname, unsigned int line,
                        const char *func, const char *expr,
                        int once);
 
+#ifdef _WIN32
+#define SHORT_FILE__ (tor_fix_source_file(__FILE__))
+const char *tor_fix_source_file(const char *fname);
+#else
+#define SHORT_FILE__ (__FILE__)
+#define tor_fix_source_file(s) (s)
+#endif /* defined(_WIN32) */
+
 #ifdef TOR_UNIT_TESTS
 void tor_capture_bugs_(int n);
 void tor_end_capture_bugs_(void);





More information about the tor-commits mailing list