]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Convert float config to double, add rounding
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 8 Apr 2018 13:28:58 +0000 (15:28 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 23 Apr 2018 19:51:15 +0000 (21:51 +0200)
We were getting different results when converting "float" to
integers, on 32-bit versus 64-bit platforms. So use "roundf".

Also exposed a typo in another testsuite, where we only cleaned
files as a result of roundoff... Make cleaning explicit again.

src/cleanup.c
test/suites/cleanup.bash

index 1fc78e27f7a57c82707f1d198f6b64ed1b507d89..dbb657843c3f951b90e073eeed185a5c41138ee9 100644 (file)
@@ -17,6 +17,9 @@
 
 #include "ccache.h"
 
+#include <float.h>
+#include <math.h>
+
 static struct files {
        char *fname;
        time_t mtime;
@@ -162,8 +165,8 @@ clean_up_dir(struct conf *conf, const char *dir, float limit_multiple)
        // When "max files" or "max cache size" is reached, one of the 16 cache
        // subdirectories is cleaned up. When doing so, files are deleted (in LRU
        // order) until the levels are below limit_multiple.
-       cache_size_threshold = conf->max_size * limit_multiple / 16;
-       files_in_cache_threshold = conf->max_files * limit_multiple / 16;
+       cache_size_threshold = roundf(conf->max_size * limit_multiple / 16);
+       files_in_cache_threshold = roundf(conf->max_files * limit_multiple / 16);
 
        num_files = 0;
        cache_size = 0;
index 8eaac4f6ef7721f3138f557403369118b864385c..45dccb0832db71e696175a02f0280ed6bdd8863a 100644 (file)
@@ -152,7 +152,7 @@ SUITE_cleanup() {
     TEST ".o file is removed before .stderr"
 
     prepare_cleanup_test_dir $CCACHE_DIR/a
-    $CCACHE -F 474 -M 0 >/dev/null
+    $CCACHE -F 464 -M 0 >/dev/null
     backdate 0 $CCACHE_DIR/a/result9-4017.stderr
     $CCACHE -c >/dev/null
     expect_file_missing $CCACHE_DIR/a/result9-4017.stderr
@@ -167,7 +167,7 @@ SUITE_cleanup() {
     TEST ".stderr file is not removed before .o"
 
     prepare_cleanup_test_dir $CCACHE_DIR/a
-    $CCACHE -F 474 -M 0 >/dev/null
+    $CCACHE -F 464 -M 0 >/dev/null
     backdate 0 $CCACHE_DIR/a/result9-4017.o
     $CCACHE -c >/dev/null
     expect_file_exists $CCACHE_DIR/a/result9-4017.stderr