1 From 843cc40119d36873f9670975c7815fbd38481093 Mon Sep 17 00:00:00 2001
2 From: Chris Kühl <chrisk@openismus.com>
3 Date: Thu, 12 May 2011 21:43:31 +0000
4 Subject: Fix for issues on 32-bit machines.
6 https://bugzilla.gnome.org/show_bug.cgi?id=649842
8 diff --git a/src/load-graph.cpp b/src/load-graph.cpp
9 index a6d2a7e..9291179 100644
10 --- a/src/load-graph.cpp
11 +++ b/src/load-graph.cpp
12 @@ -399,7 +399,7 @@ net_scale (LoadGraph *g, guint64 din, guint64 dout)
13 new_max = 1.1 * new_max;
14 // make sure max is not 0 to avoid / 0
15 // default to 125 bytes == 1kbit
16 - new_max = std::max(new_max, 125UL);
17 + new_max = std::max(new_max, G_GUINT64_CONSTANT(125));
20 // round up to get some extra space
21 @@ -407,7 +407,7 @@ net_scale (LoadGraph *g, guint64 din, guint64 dout)
22 new_max = 1.1 * new_max;
23 // make sure max is not 0 to avoid / 0
25 - new_max = std::max(new_max, 1024UL);
26 + new_max = std::max(new_max, G_GUINT64_CONSTANT(1024));
28 // decompose new_max = coef10 * 2**(base10 * 10)
29 // where coef10 and base10 are integers and coef10 < 2**10
30 @@ -417,8 +417,8 @@ net_scale (LoadGraph *g, guint64 din, guint64 dout)
32 guint64 pow2 = std::floor(log2(new_max));
33 guint64 base10 = pow2 / 10.0;
34 - guint64 coef10 = std::ceil(new_max / double(1UL <<(base10 * 10)));
35 - g_assert(new_max <= (coef10 * (1UL << (base10 * 10))));
36 + guint64 coef10 = std::ceil(new_max / double(G_GUINT64_CONSTANT(1) << (base10 * 10)));
37 + g_assert(new_max <= (coef10 * (G_GUINT64_CONSTANT(1) << (base10 * 10))));
39 // then decompose coef10 = x * 10**factor10
40 // where factor10 is integer and x < 10
41 @@ -431,13 +431,16 @@ net_scale (LoadGraph *g, guint64 din, guint64 dout)
42 if (coef10 % g->num_bars() != 0)
43 coef10 = coef10 + (g->num_bars() - coef10 % g->num_bars());
44 g_assert(coef10 % g->num_bars() == 0);
46 - new_max = coef10 * (1UL << guint64(base10 * 10));
47 - procman_debug("bak %lu new_max %lu pow2 %lu coef10 %lu", bak_max, new_max, pow2, coef10);
48 + new_max = coef10 * (G_GUINT64_CONSTANT(1) << guint64(base10 * 10));
49 + procman_debug("bak %" G_GUINT64_FORMAT " new_max %" G_GUINT64_FORMAT
50 + "pow2 %" G_GUINT64_FORMAT " coef10 %" G_GUINT64_FORMAT,
51 + bak_max, new_max, pow2, coef10);
54 if (bak_max > new_max) {
55 - procman_debug("overflow detected: bak=%lu new=%lu", bak_max, new_max);
56 + procman_debug("overflow detected: bak=%" G_GUINT64_FORMAT
57 + " new=%" G_GUINT64_FORMAT,
62 @@ -455,7 +458,10 @@ net_scale (LoadGraph *g, guint64 din, guint64 dout)
66 - procman_debug("rescale dmax = %lu max = %lu new_max = %lu", dmax, g->net.max, new_max);
67 + procman_debug("rescale dmax = %" G_GUINT64_FORMAT
68 + " max = %" G_GUINT64_FORMAT
69 + " new_max = %" G_GUINT64_FORMAT,
70 + dmax, g->net.max, new_max);
74 diff --git a/src/util.cpp b/src/util.cpp
75 index 234e6fc..7183ff4 100644
78 @@ -163,14 +163,14 @@ procman::format_size(guint64 size, guint64 max_size, bool want_bits)
81 const Format all_formats[2][4] = {
82 - { { 1UL << 10, N_("%.1f KiB") },
83 - { 1UL << 20, N_("%.1f MiB") },
84 - { 1UL << 30, N_("%.1f GiB") },
85 - { 1UL << 40, N_("%.1f TiB") } },
86 - { { 1000, N_("%.1f kbit") },
87 - { 1000000, N_("%.1f Mbit") },
88 - { 1000000000, N_("%.1f Gbit") },
89 - { 1000000000000, N_("%.1f Tbit") } }
90 + { { G_GUINT64_CONSTANT(1) << 10, N_("%.1f KiB") },
91 + { G_GUINT64_CONSTANT(1) << 20, N_("%.1f MiB") },
92 + { G_GUINT64_CONSTANT(1) << 30, N_("%.1f GiB") },
93 + { G_GUINT64_CONSTANT(1) << 40, N_("%.1f TiB") } },
94 + { { G_GUINT64_CONSTANT(1000), N_("%.1f kbit") },
95 + { G_GUINT64_CONSTANT(1000000), N_("%.1f Mbit") },
96 + { G_GUINT64_CONSTANT(1000000000), N_("%.1f Gbit") },
97 + { G_GUINT64_CONSTANT(1000000000000), N_("%.1f Tbit") } }
100 const Format (&formats)[4] = all_formats[want_bits ? 1 : 0];