diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-07-17 00:39:05 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-07-17 00:39:05 +0000 |
commit | e572d5990c4ed5100338a4e1ad4cae6a55329b4f (patch) | |
tree | 18ec12edf7054392a0203a327a5b4bd11f9026b2 | |
parent | 169d6c4aca43ea574762f42542a9db4745396ff8 (diff) | |
download | tor-e572d5990c4ed5100338a4e1ad4cae6a55329b4f.tar.gz tor-e572d5990c4ed5100338a4e1ad4cae6a55329b4f.zip |
MSVC6 is apparently terrified of unnatural cross-breeding between uint64_t and double, and needs more persuasion than usual to cast one to the other. Issue identified by Frediano Ziglio; patch revised for minimal impact on non-MSVC6 compilers.
svn:r6768
-rw-r--r-- | src/common/compat.h | 13 | ||||
-rw-r--r-- | src/or/hibernate.c | 2 | ||||
-rw-r--r-- | src/or/main.c | 4 | ||||
-rw-r--r-- | src/or/rephist.c | 6 |
4 files changed, 18 insertions, 7 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index abacce231a..fde91172d4 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -76,6 +76,19 @@ #endif /* ifndef MAVE_MACRO__func__ */ #endif /* if not windows */ +#if defined(_MSC_VER) && (_MSC_VER < 1300) +/* MSVC versions before 7 apparently don't believe that you can cast uint64_t + * to double and really mean it. */ +extern inline double U64_TO_DBL(uint64_t x) { + int64_t i = (int64_t) x; + return (i < 0) ? ((double) INT64_MAX) : (double) i; +} +#define DBL_TO_U64(x) ((uint64_t)(int64_t) (x)) +#else +#define U64_TO_DBL(x) ((double) (x)) +#define DBL_TO_U64(x) ((uint64_t) (x)) +#endif + /* ===== String compatibility */ #ifdef MS_WINDOWS /* Windows names string functions differently from most other platforms. */ diff --git a/src/or/hibernate.c b/src/or/hibernate.c index d4e6ceb078..b41bf44ed9 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -683,7 +683,7 @@ hibernate_hard_limit_reached(void) static int hibernate_soft_limit_reached(void) { - uint64_t soft_limit = (uint64_t) ((get_options()->AccountingMax) * .95); + uint64_t soft_limit = DBL_TO_U64((get_options()->AccountingMax) * .95); if (!soft_limit) return 0; return n_bytes_read_in_interval >= soft_limit diff --git a/src/or/main.c b/src/or/main.c index bb562a5723..7b2364a4f9 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1359,11 +1359,11 @@ dumpstats(int severity) U64_PRINTF_ARG(stats_n_destroy_cells_processed)); if (stats_n_data_cells_packaged) log(severity,LD_NET,"Average packaged cell fullness: %2.3f%%", - 100*(((double)stats_n_data_bytes_packaged) / + 100*(U64_TO_DBL(stats_n_data_bytes_packaged) / (stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)) ); if (stats_n_data_cells_received) log(severity,LD_NET,"Average delivered cell fullness: %2.3f%%", - 100*(((double)stats_n_data_bytes_received) / + 100*(U64_TO_DBL(stats_n_data_bytes_received) / (stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) ); if (now - time_of_process_start >= 0) diff --git a/src/or/rephist.c b/src/or/rephist.c index 2459d46b7d..3d391ad94d 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -577,11 +577,9 @@ rep_hist_bandwidth_assess(void) r = find_largest_max(read_array); w = find_largest_max(write_array); if (r>w) - return (int)(w/(double)NUM_SECS_ROLLING_MEASURE); + return (int)(U64_TO_DBL(w)/NUM_SECS_ROLLING_MEASURE); else - return (int)(r/(double)NUM_SECS_ROLLING_MEASURE); - - return 0; + return (int)(U64_TO_DBL(r)/NUM_SECS_ROLLING_MEASURE); } /** |