commit d5a3bb960d41873ccfde0bbdb4adfb762528069e Author: Nick Mathewson nickm@torproject.org Date: Tue Jul 3 10:43:43 2018 -0400
Retire U64_TO_DBL and DBL_TO_U64
These were necessary long ago to work around a bug in VC6. --- src/lib/cc/compat_compiler.h | 3 --- src/lib/tls/tortls.c | 4 ++-- src/or/confparse.c | 2 +- src/or/cpuworker.c | 2 +- src/or/hibernate.c | 3 +-- src/or/main.c | 8 ++++---- src/or/rephist.c | 4 ++-- src/or/status.c | 8 ++++---- src/test/test_util.c | 6 +++--- 9 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/src/lib/cc/compat_compiler.h b/src/lib/cc/compat_compiler.h index 42ceeadd3..0f1acc381 100644 --- a/src/lib/cc/compat_compiler.h +++ b/src/lib/cc/compat_compiler.h @@ -106,9 +106,6 @@ #endif /* !defined(HAVE_MACRO__func__) */ #endif /* defined(_MSC_VER) */
-#define U64_TO_DBL(x) ((double) (x)) -#define DBL_TO_U64(x) ((uint64_t) (x)) - #ifdef ENUM_VALS_ARE_SIGNED #define ENUM_BF(t) unsigned #else diff --git a/src/lib/tls/tortls.c b/src/lib/tls/tortls.c index 3eee41bd1..1cd22a7eb 100644 --- a/src/lib/tls/tortls.c +++ b/src/lib/tls/tortls.c @@ -2442,8 +2442,8 @@ tls_get_write_overhead_ratio,(void)) if (total_bytes_written_over_tls == 0) return 1.0;
- return U64_TO_DBL(total_bytes_written_by_tls) / - U64_TO_DBL(total_bytes_written_over_tls); + return ((double)total_bytes_written_by_tls) / + ((double)total_bytes_written_over_tls); }
/** Implement check_no_tls_errors: If there are any pending OpenSSL diff --git a/src/or/confparse.c b/src/or/confparse.c index 8db6d6080..08f5fd048 100644 --- a/src/or/confparse.c +++ b/src/or/confparse.c @@ -1117,7 +1117,7 @@ config_parse_units(const char *val, struct unit_table_t *u, int *ok)
if (!cp) { *ok = 1; - v = use_float ? DBL_TO_U64(d) : v; + v = use_float ? ((uint64_t)d) : v; goto done; }
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index 675079020..b37dfd168 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -283,7 +283,7 @@ get_overhead_for_onionskins(uint32_t *usec_out, double *frac_out, onionskins_usec_internal[onionskin_type];
*usec_out = (uint32_t)(overhead / onionskins_n_processed[onionskin_type]); - *frac_out = U64_TO_DBL(overhead) / onionskins_usec_internal[onionskin_type]; + *frac_out = ((double)overhead) / onionskins_usec_internal[onionskin_type];
return 0; } diff --git a/src/or/hibernate.c b/src/or/hibernate.c index c6190bc89..30a5edc1f 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -799,7 +799,7 @@ hibernate_soft_limit_reached(void) * - We have used up 95% of our bytes. * - We have less than 500MB of bytes left. */ - uint64_t soft_limit = DBL_TO_U64(U64_TO_DBL(acct_max) * SOFT_LIM_PCT); + uint64_t soft_limit = (uint64_t) (acct_max * SOFT_LIM_PCT); if (acct_max > SOFT_LIM_BYTES && acct_max - SOFT_LIM_BYTES > soft_limit) { soft_limit = acct_max - SOFT_LIM_BYTES; } @@ -1227,4 +1227,3 @@ hibernate_set_state_for_testing_(hibernate_state_t newstate) hibernate_state = newstate; } #endif /* defined(TOR_UNIT_TESTS) */ - diff --git a/src/or/main.c b/src/or/main.c index c2fa416d6..f07d9da8b 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -3279,12 +3279,12 @@ dumpstats(int severity) (stats_n_destroy_cells_processed)); if (stats_n_data_cells_packaged) tor_log(severity,LD_NET,"Average packaged cell fullness: %2.3f%%", - 100*(U64_TO_DBL(stats_n_data_bytes_packaged) / - U64_TO_DBL(stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)) ); + 100*(((double)stats_n_data_bytes_packaged) / + ((double)stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)) ); if (stats_n_data_cells_received) tor_log(severity,LD_NET,"Average delivered cell fullness: %2.3f%%", - 100*(U64_TO_DBL(stats_n_data_bytes_received) / - U64_TO_DBL(stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) ); + 100*(((double)stats_n_data_bytes_received) / + ((double)stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) );
cpuworker_log_onionskin_overhead(severity, ONION_HANDSHAKE_TYPE_TAP, "TAP"); cpuworker_log_onionskin_overhead(severity, ONION_HANDSHAKE_TYPE_NTOR,"ntor"); diff --git a/src/or/rephist.c b/src/or/rephist.c index 12b0225aa..34c06760b 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -1218,9 +1218,9 @@ rep_hist_bandwidth_assess(void) r = find_largest_max(read_array); w = find_largest_max(write_array); if (r>w) - return (int)(U64_TO_DBL(w)/NUM_SECS_ROLLING_MEASURE); + return (int)(((double)w)/NUM_SECS_ROLLING_MEASURE); else - return (int)(U64_TO_DBL(r)/NUM_SECS_ROLLING_MEASURE); + return (int)(((double)r)/NUM_SECS_ROLLING_MEASURE); }
/** Print the bandwidth history of b (either [dir-]read_array or diff --git a/src/or/status.c b/src/or/status.c index 5c0a768ac..4538e22a5 100644 --- a/src/or/status.c +++ b/src/or/status.c @@ -79,10 +79,10 @@ bytes_to_usage(uint64_t bytes) if (bytes < (1<<20)) { /* Less than a megabyte. */ tor_asprintf(&bw_string, "%"PRIu64" kB", (bytes>>10)); } else if (bytes < (1<<30)) { /* Megabytes. Let's add some precision. */ - double bw = U64_TO_DBL(bytes); + double bw = ((double)bytes); tor_asprintf(&bw_string, "%.2f MB", bw/(1<<20)); } else { /* Gigabytes. */ - double bw = U64_TO_DBL(bytes); + double bw = ((double)bytes); tor_asprintf(&bw_string, "%.2f GB", bw/(1<<30)); }
@@ -150,8 +150,8 @@ log_heartbeat(time_t now) double fullness_pct = 100; if (stats_n_data_cells_packaged && !hibernating) { fullness_pct = - 100*(U64_TO_DBL(stats_n_data_bytes_packaged) / - U64_TO_DBL(stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)); + 100*(((double)stats_n_data_bytes_packaged) / + ((double)stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)); } const double overhead_pct = ( r - 1.0 ) * 100.0;
diff --git a/src/test/test_util.c b/src/test/test_util.c index 67a10a8a5..e6348bfea 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -2184,10 +2184,10 @@ test_util_parse_integer(void *arg) /* Test parse_double */ double d = tor_parse_double("10", 0, (double)UINT64_MAX,&i,NULL); tt_int_op(1,OP_EQ, i); - tt_assert(DBL_TO_U64(d) == 10); + tt_assert(((uint64_t)d) == 10); d = tor_parse_double("0", 0, (double)UINT64_MAX,&i,NULL); tt_int_op(1,OP_EQ, i); - tt_assert(DBL_TO_U64(d) == 0); + tt_assert(((uint64_t)d) == 0); d = tor_parse_double(" ", 0, (double)UINT64_MAX,&i,NULL); tt_double_op(fabs(d), OP_LT, 1e-10); tt_int_op(0,OP_EQ, i); @@ -2199,7 +2199,7 @@ test_util_parse_integer(void *arg) tt_int_op(1,OP_EQ, i); d = tor_parse_double("-.0", 0, (double)UINT64_MAX,&i,NULL); tt_int_op(1,OP_EQ, i); - tt_assert(DBL_TO_U64(d) == 0); + tt_assert(((uint64_t)d) == 0); d = tor_parse_double("-10", -100.0, 100.0,&i,NULL); tt_int_op(1,OP_EQ, i); tt_double_op(fabs(d - -10.0),OP_LT, 1E-12);
tor-commits@lists.torproject.org