summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pool <mbp@sourcefrog.net>2004-09-10 02:48:58 +0000
committerMartin Pool <mbp@sourcefrog.net>2004-09-10 02:48:58 +0000
commita770b0d695be1ef730a15442730d7b37d4772d4f (patch)
tree0555b62a83d55b1eb074e6aed494f3f2a7497be1
parent2e68e0024ce60ab22364fcde9d7b56a98c480ba4 (diff)
downloadlibrsync-a770b0d695be1ef730a15442730d7b37d4772d4f.tar.gz
#1024881
Use %lu or %llu if possible to print uint64 values, rather than converting to double. (I can't see any measurable difference in overall benchmarks because finding sums is so slow, but it's still good to fix.)
-rw-r--r--NEWS3
-rw-r--r--THANKS1
-rw-r--r--delta.c8
-rw-r--r--emit.c5
-rw-r--r--job.c6
-rw-r--r--netint.c2
-rw-r--r--patch.c20
-rw-r--r--scoop.c22
-rw-r--r--stats.c28
-rw-r--r--trace.h27
-rw-r--r--tube.c4
11 files changed, 79 insertions, 47 deletions
diff --git a/NEWS b/NEWS
index 0b14605..f693233 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,9 @@ Changes in 0.9.7 (release pending)
* #1022764: Fix corrupted encoding of some COPY commands in large
files.
+ * #1024881: Print long integers directly, rather than via casts to
+ double.
+
* Fix printf formats for size_t: both the format and the argument
should be cast to long.
diff --git a/THANKS b/THANKS
index e3ab9ed..4d0b3a4 100644
--- a/THANKS
+++ b/THANKS
@@ -91,6 +91,7 @@ Contributors for 0.9.7 (release pending)
* Martin Pool <mbp@users.sourceforge.net>
- sf project admin
- documentation updates.
+ - bug fixes
* John Goerzen <jgoerzen@complete.org>
- Debian package maintainence
diff --git a/delta.c b/delta.c
index f50762b..453bd6d 100644
--- a/delta.c
+++ b/delta.c
@@ -333,8 +333,9 @@ inline rs_result rs_appendflush(rs_job_t *job)
{
/* if last is a match, emit it and reset last by resetting basis_len */
if (job->basis_len) {
- rs_trace("matched %.0f bytes at %.0f!",
- (double) job->basis_len, (double) job->basis_pos);
+ rs_trace("matched " PRINTF_FORMAT_U64 " bytes at " PRINTF_FORMAT_U64 "!",
+ PRINTF_CAST_U64(job->basis_len),
+ PRINTF_CAST_U64(job->basis_pos));
rs_emit_copy_cmd(job, job->basis_pos, job->basis_len);
job->basis_len=0;
return rs_processmatch(job);
@@ -399,7 +400,8 @@ static rs_result rs_delta_s_slack(rs_job_t *job)
size_t avail = stream->avail_in;
if (avail) {
- rs_trace("emit slack delta for %.0f available bytes", (double) avail);
+ rs_trace("emit slack delta for " PRINTF_FORMAT_U64
+ " available bytes", PRINTF_CAST_U64(avail));
rs_emit_literal_cmd(job, avail);
rs_tube_copy(job, avail);
return RS_RUNNING;
diff --git a/emit.c b/emit.c
index d17d0dc..eedb495 100644
--- a/emit.c
+++ b/emit.c
@@ -130,8 +130,9 @@ rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
len_bytes);
}
- rs_trace("emit COPY_N%d_N%d(where=%.0f, len=%.0f), cmd_byte=%#x",
- where_bytes, len_bytes, (double) where, (double) len, cmd);
+ rs_trace("emit COPY_N%d_N%d(where=" PRINTF_FORMAT_U64
+ ", len=" PRINTF_FORMAT_U64 "), cmd_byte=%#x",
+ where_bytes, len_bytes, PRINTF_CAST_U64(where), PRINTF_CAST_U64(len), cmd);
rs_squirt_byte(job, cmd);
rs_squirt_netint(job, where, where_bytes);
rs_squirt_netint(job, len, len_bytes);
diff --git a/job.c b/job.c
index 5d8935d..516db7f 100644
--- a/job.c
+++ b/job.c
@@ -148,9 +148,9 @@ rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers)
if ((orig_in == buffers->avail_in) && (orig_out == buffers->avail_out)
&& orig_in && orig_out) {
rs_log(RS_LOG_ERR, "internal error: job made no progress "
- "[orig_in=%.0f, orig_out=%.0f, final_in=%.0f, final_out=%.0f]",
- (double) orig_in, (double) orig_out, (double) buffers->avail_in,
- (double) buffers->avail_out);
+ "[orig_in=" PRINTF_FORMAT_U64 ", orig_out=" PRINTF_FORMAT_U64 ", final_in=" PRINTF_FORMAT_U64 ", final_out=" PRINTF_FORMAT_U64 "]",
+ PRINTF_CAST_U64(orig_in), PRINTF_CAST_U64(orig_out), PRINTF_CAST_U64(buffers->avail_in),
+ PRINTF_CAST_U64(buffers->avail_out));
return RS_INTERNAL_ERROR;
}
diff --git a/netint.c b/netint.c
index 6989309..37173fd 100644
--- a/netint.c
+++ b/netint.c
@@ -179,6 +179,6 @@ int rs_int_len(rs_long_t val)
else if (!(val & ~(rs_long_t)0xffffffffffffffff))
return 8;
else {
- rs_fatal("can't encode integer %.0f yet", (double) val);
+ rs_fatal("can't encode integer " PRINTF_FORMAT_U64 " yet", PRINTF_CAST_U64(val));
}
}
diff --git a/patch.c b/patch.c
index 0545301..9501f46 100644
--- a/patch.c
+++ b/patch.c
@@ -68,9 +68,9 @@ static rs_result rs_patch_s_cmdbyte(rs_job_t *job)
job->cmd = &rs_prototab[job->op];
- rs_trace("got command byte 0x%02x (%s), len_1=%.0f", job->op,
+ rs_trace("got command byte 0x%02x (%s), len_1=" PRINTF_FORMAT_U64 "", job->op,
rs_op_kind_name(job->cmd->kind),
- (double) job->cmd->len_1);
+ PRINTF_CAST_U64(job->cmd->len_1));
if (job->cmd->len_1)
job->statefn = rs_patch_s_params;
@@ -150,10 +150,10 @@ static rs_result rs_patch_s_literal(rs_job_t *job)
{
rs_long_t len = job->param1;
- rs_trace("LITERAL(len=%.0f)", (double) len);
+ rs_trace("LITERAL(len=" PRINTF_FORMAT_U64 ")", PRINTF_CAST_U64(len));
if (len < 0) {
- rs_log(RS_LOG_ERR, "invalid length=%.0f on LITERAL command", (double) len);
+ rs_log(RS_LOG_ERR, "invalid length=" PRINTF_FORMAT_U64 " on LITERAL command", PRINTF_CAST_U64(len));
return RS_CORRUPT;
}
@@ -177,15 +177,15 @@ static rs_result rs_patch_s_copy(rs_job_t *job)
where = job->param1;
len = job->param2;
- rs_trace("COPY(where=%.0f, len=%.0f)", (double) where, (double) len);
+ rs_trace("COPY(where=" PRINTF_FORMAT_U64 ", len=" PRINTF_FORMAT_U64 ")", PRINTF_CAST_U64(where), PRINTF_CAST_U64(len));
if (len < 0) {
- rs_log(RS_LOG_ERR, "invalid length=%.0f on COPY command", (double) len);
+ rs_log(RS_LOG_ERR, "invalid length=" PRINTF_FORMAT_U64 " on COPY command", PRINTF_CAST_U64(len));
return RS_CORRUPT;
}
if (where < 0) {
- rs_log(RS_LOG_ERR, "invalid where=%.0f on COPY command", (double) where);
+ rs_log(RS_LOG_ERR, "invalid where=" PRINTF_FORMAT_U64 " on COPY command", PRINTF_CAST_U64(where));
return RS_CORRUPT;
}
@@ -224,8 +224,8 @@ static rs_result rs_patch_s_copying(rs_job_t *job)
if (!len)
return RS_BLOCKED;
- rs_trace("copy %.0f bytes from basis at offset %.0f",
- (double) len, (double) job->basis_pos);
+ rs_trace("copy " PRINTF_FORMAT_U64 " bytes from basis at offset " PRINTF_FORMAT_U64 "",
+ PRINTF_CAST_U64(len), PRINTF_CAST_U64(job->basis_pos));
ptr = buf = rs_alloc(len, "basis buffer");
@@ -235,7 +235,7 @@ static rs_result rs_patch_s_copying(rs_job_t *job)
else
rs_trace("copy callback returned %s", rs_strerror(result));
- rs_trace("got %.0f bytes back from basis callback", (double) len);
+ rs_trace("got " PRINTF_FORMAT_U64 " bytes back from basis callback", PRINTF_CAST_U64(len));
memcpy(buffs->next_out, ptr, len);
diff --git a/scoop.c b/scoop.c
index 5baf87a..d2e2a70 100644
--- a/scoop.c
+++ b/scoop.c
@@ -93,8 +93,8 @@ void rs_scoop_input(rs_job_t *job, size_t len)
if (job->scoop_buf)
free(job->scoop_buf);
job->scoop_buf = job->scoop_next = newbuf;
- rs_trace("resized scoop buffer to %.0f bytes from %.0f",
- (double) newsize, (double) job->scoop_alloc);
+ rs_trace("resized scoop buffer to " PRINTF_FORMAT_U64 " bytes from " PRINTF_FORMAT_U64 "",
+ PRINTF_CAST_U64(newsize), PRINTF_CAST_U64(job->scoop_alloc));
job->scoop_alloc = newsize;
} else {
/* this buffer size is fine, but move the existing
@@ -111,7 +111,7 @@ void rs_scoop_input(rs_job_t *job, size_t len)
assert(tocopy + job->scoop_avail <= job->scoop_alloc);
memcpy(job->scoop_next + job->scoop_avail, stream->next_in, tocopy);
- rs_trace("accepted %.0f bytes from input to scoop", (double) tocopy);
+ rs_trace("accepted " PRINTF_FORMAT_U64 " bytes from input to scoop", PRINTF_CAST_U64(tocopy));
job->scoop_avail += tocopy;
stream->next_in += tocopy;
stream->avail_in -= tocopy;
@@ -171,7 +171,7 @@ rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
if (job->scoop_avail >= len) {
/* We have enough data queued to satisfy the request,
* so go straight from the scoop buffer. */
- rs_trace("got %.0f bytes direct from scoop", (double) len);
+ rs_trace("got " PRINTF_FORMAT_U64 " bytes direct from scoop", PRINTF_CAST_U64(len));
*ptr = job->scoop_next;
return RS_DONE;
} else if (job->scoop_avail) {
@@ -181,26 +181,26 @@ rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
rs_scoop_input(job, len);
if (job->scoop_avail < len) {
- rs_trace("still have only %.0f bytes in scoop",
- (double) job->scoop_avail);
+ rs_trace("still have only " PRINTF_FORMAT_U64 " bytes in scoop",
+ PRINTF_CAST_U64(job->scoop_avail));
return RS_BLOCKED;
} else {
- rs_trace("scoop now has %.0f bytes, this is enough",
- (double) job->scoop_avail);
+ rs_trace("scoop now has " PRINTF_FORMAT_U64 " bytes, this is enough",
+ PRINTF_CAST_U64(job->scoop_avail));
*ptr = job->scoop_next;
return RS_DONE;
}
} else if (stream->avail_in >= len) {
/* There's enough data in the stream's input */
*ptr = stream->next_in;
- rs_trace("got %.0f bytes from input buffer", (double) len);
+ rs_trace("got " PRINTF_FORMAT_U64 " bytes from input buffer", PRINTF_CAST_U64(len));
return RS_DONE;
} else if (stream->avail_in > 0) {
/* Nothing was queued before, but we don't have enough
* data to satisfy the request. So queue what little
* we have, and try again next time. */
- rs_trace("couldn't satisfy request for %.0f, scooping %.0f bytes",
- (double) len, (double) job->scoop_avail);
+ rs_trace("couldn't satisfy request for " PRINTF_FORMAT_U64 ", scooping " PRINTF_FORMAT_U64 " bytes",
+ PRINTF_CAST_U64(len), PRINTF_CAST_U64(job->scoop_avail));
rs_scoop_input(job, len);
return RS_BLOCKED;
} else if (stream->eof_in) {
diff --git a/stats.c b/stats.c
index 1c5051a..78db417 100644
--- a/stats.c
+++ b/stats.c
@@ -85,34 +85,34 @@ rs_format_stats(rs_stats_t const * stats,
if (stats->lit_cmds) {
len += snprintf(buf+len, size-len,
- "literal[%d cmds, %.0f bytes, %.0f cmdbytes] ",
+ "literal[%d cmds, " PRINTF_FORMAT_U64 " bytes, " PRINTF_FORMAT_U64 " cmdbytes] ",
stats->lit_cmds,
- (double) stats->lit_bytes,
- (double) stats->lit_cmdbytes);
+ PRINTF_CAST_U64(stats->lit_bytes),
+ PRINTF_CAST_U64(stats->lit_cmdbytes));
}
if (stats->sig_cmds) {
len += snprintf(buf+len, size-len,
- "in-place-signature[%.0f cmds, %.0f bytes] ",
- (double) stats->sig_cmds,
- (double) stats->sig_bytes);
+ "in-place-signature[" PRINTF_FORMAT_U64 " cmds, " PRINTF_FORMAT_U64 " bytes] ",
+ PRINTF_CAST_U64(stats->sig_cmds),
+ PRINTF_CAST_U64(stats->sig_bytes));
}
if (stats->copy_cmds || stats->false_matches) {
len += snprintf(buf+len, size-len,
- "copy[%.0f cmds, %.0f bytes, %.0f false, %.0f cmdbytes]",
- (double) stats->copy_cmds,
- (double) stats->copy_bytes,
- (double) stats->false_matches,
- (double) stats->copy_cmdbytes);
+ "copy[" PRINTF_FORMAT_U64 " cmds, " PRINTF_FORMAT_U64 " bytes, " PRINTF_FORMAT_U64 " false, " PRINTF_FORMAT_U64 " cmdbytes]",
+ PRINTF_CAST_U64(stats->copy_cmds),
+ PRINTF_CAST_U64(stats->copy_bytes),
+ PRINTF_CAST_U64(stats->false_matches),
+ PRINTF_CAST_U64(stats->copy_cmdbytes));
}
if (stats->sig_blocks) {
len += snprintf(buf+len, size-len,
- "signature[%.0f blocks, %.0f bytes per block]",
- (double) stats->sig_blocks,
- (double) stats->block_len);
+ "signature[" PRINTF_FORMAT_U64 " blocks, " PRINTF_FORMAT_U64 " bytes per block]",
+ PRINTF_CAST_U64(stats->sig_blocks),
+ PRINTF_CAST_U64(stats->block_len));
}
return buf;
diff --git a/trace.h b/trace.h
index 2bb8552..63928e6 100644
--- a/trace.h
+++ b/trace.h
@@ -3,7 +3,7 @@
* librsync -- generate and apply network deltas
* $Id$
*
- * Copyright (C) 2000, 2001 by Martin Pool <mbp@samba.org>
+ * Copyright (C) 2000, 2001, 2004 by Martin Pool <mbp@samba.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -36,6 +36,31 @@
* fatal terminates the whole process
*/
+
+
+/* There is no portable way in C99 to printf 64-bit types. Many
+ * platforms do have a format which will do it, but it's not
+ * standardized. Therefore these macros.
+ *
+ * Not all platforms using gnu C necessarily have a corresponding
+ * printf, but it's probably a good starting point. Most unix systems
+ * seem to use %ll.
+ */
+#if SIZEOF_LONG == 8
+# define PRINTF_CAST_U64(x) ((unsigned long) (x))
+# define PRINTF_FORMAT_U64 "%lu"
+#elif defined(__GNUC__)
+# define PRINTF_CAST_U64(x) ((unsigned long long) (x))
+# define PRINTF_FORMAT_U64 "%llu"
+#else
+ /* This conversion works everywhere, but it's probably pretty slow.
+ *
+ * Note that 'f' takes a double vararg, not a float. */
+# define PRINTF_CAST_U64(x) ((double) (x))
+# define PRINTF_FORMAT_U64 "%.0f"
+#endif
+
+
#if defined(HAVE_VARARG_MACROS) && defined(__GNUC__)
/*
* TODO: Don't assume this is a gcc thing; rather test in autoconf for
diff --git a/tube.c b/tube.c
index 8006f77..7bd63ed 100644
--- a/tube.c
+++ b/tube.c
@@ -170,8 +170,8 @@ static void rs_tube_catchup_copy(rs_job_t *job)
job->copy_len -= this_copy;
- rs_trace("copied %.0f bytes from input buffer, %.0f remain to be copied",
- (double) this_copy, (double) job->copy_len);
+ rs_trace("copied " PRINTF_FORMAT_U64 " bytes from input buffer, " PRINTF_FORMAT_U64 " remain to be copied",
+ PRINTF_CAST_U64(this_copy), PRINTF_CAST_U64(job->copy_len));
}
}