[or-cvs] Workaround for brain-damaged __FILE__ handling on MSVC: kee...

Nick Mathewson nickm at seul.org
Wed Dec 22 02:32:28 UTC 2004


Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv32305/src/common

Modified Files:
	compat.c compat.h test.h tortls.h util.h 
Log Message:
Workaround for brain-damaged __FILE__ handling on MSVC: keep Nick's name out
of the warning messages.


Index: compat.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- compat.c	7 Dec 2004 07:35:32 -0000	1.22
+++ compat.c	22 Dec 2004 02:32:26 -0000	1.23
@@ -113,6 +113,29 @@
   return r;
 }
 
+/** 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 warrning messages.
+ */
+const char *
+_tor_fix_source_file(const char *fname)
+{
+  const char *cp1, *cp2;
+  cp1 = strrchr(fname, '/');
+  cp2 = strrchr(fname, '\\');
+  if (cp1 && cp2) {
+    return (cp1<cp2)?(cp2+1):(cp1+1);
+  } else if (cp1) {
+    return cp1+1;
+  } else if (cp2) {
+    return cp2+2;
+  } else {
+    return fname;
+  }
+}
+
 #ifndef UNALIGNED_INT_ACCESS_OK
 /**
  * Read a 16-bit value beginning at <b>cp</b>.  Equivalent to

Index: compat.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- compat.h	8 Dec 2004 00:40:01 -0000	1.13
+++ compat.h	22 Dec 2004 02:32:26 -0000	1.14
@@ -86,6 +86,9 @@
 #define TOR_ISXDIGIT(c) isxdigit((int)(unsigned char)(c))
 #define TOR_ISDIGIT(c)   isdigit((int)(unsigned char)(c))
 
+#define _SHORT_FILE_ (_tor_fix_source_file(__FILE__))
+const char *_tor_fix_source_file(const char *fname);
+
 /* ===== Time compatibility */
 #if !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_STRUCT_TIMEVAL_TV_SEC)
 struct timeval {

Index: test.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/test.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- test.h	29 Nov 2004 22:25:28 -0000	1.17
+++ test.h	22 Dec 2004 02:32:26 -0000	1.18
@@ -13,6 +13,7 @@
 
 #include <string.h>
 #include <stdio.h>
+#include "compat.h"
 
 #define STMT_BEGIN  do {
 #define STMT_END    } while (0)
@@ -29,7 +30,7 @@
   STMT_BEGIN                                                    \
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): assertion failed.",        \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION);                                         \
     return;                                                     \
@@ -40,7 +41,7 @@
   if (expr) { printf("."); fflush(stdout); } else {             \
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION,                                          \
       #expr);                                                   \
@@ -54,7 +55,7 @@
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
            "      (%ld != %ld)\n",                              \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION,                                          \
       #expr1, #expr2,                                           \
@@ -69,7 +70,7 @@
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
            "      (%ld == %ld)\n",                              \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION,                                          \
       #expr1, #expr2,                                           \
@@ -84,7 +85,7 @@
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
            "      (\"%s\" != \"%s\")\n",                        \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION,                                          \
       #expr1, #expr2,                                           \
@@ -99,7 +100,7 @@
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
            "      (\"%s\" == \"%s\")\n",                        \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION,                                          \
       #expr1, #expr2,                                           \
@@ -113,7 +114,7 @@
     if (!memcmp(v1,v2,(len))) { printf("."); fflush(stdout); } else {\
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION,                                          \
       #expr1, #expr2);                                          \
@@ -126,7 +127,7 @@
     if (memcmp(v1,v2,(len))) { printf("."); fflush(stdout); } else {\
     have_failed = 1;                                            \
     printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
-      __FILE__,                                                 \
+      _SHORT_FILE_,                                             \
       __LINE__,                                                 \
       PRETTY_FUNCTION,                                          \
       #expr1, #expr2);                                          \

Index: tortls.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/tortls.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- tortls.h	29 Nov 2004 22:25:29 -0000	1.22
+++ tortls.h	22 Dec 2004 02:32:26 -0000	1.23
@@ -12,6 +12,7 @@
  **/
 
 #include "../common/crypto.h"
+#include "../common/compat.h"
 
 /* Opaque structure to hold a TLS connection. */
 typedef struct tor_tls_st tor_tls;
@@ -42,7 +43,7 @@
 
 /* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
  */
-#define assert_no_tls_errors() _assert_no_tls_errors(__FILE__,__LINE__)
+#define assert_no_tls_errors() _assert_no_tls_errors(_SHORT_FILE_,__LINE__)
 
 void _assert_no_tls_errors(const char *fname, int line);
 

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -d -r1.124 -r1.125
--- util.h	30 Nov 2004 03:10:56 -0000	1.124
+++ util.h	22 Dec 2004 02:32:26 -0000	1.125
@@ -13,6 +13,7 @@
 
 #include "orconfig.h"
 #include "torint.h"
+#include "compat.h"
 #include <stdio.h>
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
@@ -38,7 +39,7 @@
 #define tor_assert(expr) do {                                 \
  if (!(expr)) {                                               \
    log(LOG_ERR, "%s:%d: %s: Assertion %s failed; aborting.",  \
-       __FILE__, __LINE__, __FUNCTION__, #expr);              \
+       _SHORT_FILE_, __LINE__, __FUNCTION__, #expr);          \
    assert(expr); /* write to console too. */                  \
    abort();  /* unreached */                                  \
  } } while (0)



More information about the tor-commits mailing list