New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace zu with PRIsz and llu with PRIu64. #2512
Conversation
@igorpeshansky - Can you take a look at this? This is based on the discussion in the windows-fixes branch in the Stackdriver fork. |
src/daemon/common.h
Outdated
@@ -384,4 +384,8 @@ void strarray_free(char **array, size_t array_len); | |||
int check_capability(int arg); | |||
#endif /* HAVE_SYS_CAPABILITY_H */ | |||
|
|||
#ifndef PRIsz | |||
#define PRIsz PRIu64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you didn't use the latest version of those changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left out the Windows bits, since it doesn't currently run on Windows, so I couldn't make sure it all worked.
If you want, I can add them in, since it is just copying and pasting over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, I was proposing to define PRIsz
in terms of what works on Linux for now, so you could add additional cases later.
src/utils_format_graphite.c
Outdated
@@ -60,11 +60,11 @@ static int gr_format_values(char *ret, size_t ret_len, int ds_num, | |||
else if (rates != NULL) | |||
BUFFER_ADD("%f", rates[ds_num]); | |||
else if (ds->ds[ds_num].type == DS_TYPE_COUNTER) | |||
BUFFER_ADD("%llu", vl->values[ds_num].counter); | |||
BUFFER_ADD("%" PRIsz, (uint64_t)vl->values[ds_num].counter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to use PRIu64
for uint64_t
throughout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/utils_format_graphite.c
Outdated
else if (ds->ds[ds_num].type == DS_TYPE_DERIVE) | ||
BUFFER_ADD("%" PRIi64, vl->values[ds_num].derive); | ||
else if (ds->ds[ds_num].type == DS_TYPE_ABSOLUTE) | ||
BUFFER_ADD("%" PRIu64, vl->values[ds_num].absolute); | ||
BUFFER_ADD("%" PRIsz, vl->values[ds_num].absolute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here, you need PRIu64
for uint64_t
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't quite get where to use PRIu64 before. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/daemon/common.h
Outdated
@@ -384,4 +384,8 @@ void strarray_free(char **array, size_t array_len); | |||
int check_capability(int arg); | |||
#endif /* HAVE_SYS_CAPABILITY_H */ | |||
|
|||
#ifndef PRIsz | |||
#define PRIsz PRIu64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, I was proposing to define PRIsz
in terms of what works on Linux for now, so you could add additional cases later.
src/postgresql.c
Outdated
@@ -742,7 +742,7 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl, | |||
|
|||
status = snprintf(str_ptr, str_len, ",%lf", rates[i]); | |||
} else if (ds->ds[i].type == DS_TYPE_COUNTER) | |||
status = snprintf(str_ptr, str_len, ",%llu", vl->values[i].counter); | |||
status = snprintf(str_ptr, str_len, ",%" PRIu64, vl->values[i].counter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need a cast here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right with all of these. I was able to build and install without error, but it probably wasn't building these plugins and so didn't throw any error.
src/rrdcached.c
Outdated
@@ -88,7 +88,7 @@ static int value_list_to_string(char *buffer, int buffer_len, | |||
return -1; | |||
|
|||
if (ds->ds[i].type == DS_TYPE_COUNTER) { | |||
status = snprintf(buffer + offset, buffer_len - offset, ":%llu", | |||
status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, | |||
vl->values[i].counter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need a cast here?
src/rrdtool.c
Outdated
@@ -226,7 +226,7 @@ static int value_list_to_string(char *buffer, int buffer_len, | |||
vl->values[0].gauge); | |||
break; | |||
case DS_TYPE_COUNTER: | |||
status = snprintf(buffer, buffer_len, "%u:%llu", (unsigned)tt, | |||
status = snprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need a different cast here?
src/snmp.c
Outdated
@@ -1093,7 +1093,7 @@ static int csnmp_instance_list_add(csnmp_list_instances_t **head, | |||
value_t val = csnmp_value_list_to_value( | |||
vb, DS_TYPE_COUNTER, | |||
/* scale = */ 1.0, /* shift = */ 0.0, hd->name, dd->name); | |||
snprintf(il->instance, sizeof(il->instance), "%llu", val.counter); | |||
snprintf(il->instance, sizeof(il->instance), "%" PRIu64, val.counter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need a cast here?
src/utils_format_kairosdb.c
Outdated
@@ -154,7 +154,7 @@ static int values_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */ | |||
BUFFER_ADD("[["); | |||
BUFFER_ADD("%" PRIu64, CDTIME_T_TO_MS(vl->time)); | |||
BUFFER_ADD(","); | |||
BUFFER_ADD("%llu", vl->values[ds_idx].counter); | |||
BUFFER_ADD("%" PRIu64, vl->values[ds_idx].counter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need a cast here?
src/email.c
Outdated
sstrncpy(addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1)); | ||
|
||
errno = 0; | ||
if (bind(connector_socket, (struct sockaddr *)&addr, | ||
offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) == -1) { | ||
offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) == | ||
-1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd undo this change. But up to @octo.
stderr, | ||
"lcc_network_parse(raw_packet_data[%zu]): decoding string failed\n", | ||
i); | ||
fprintf(stderr, "lcc_network_parse(raw_packet_data[%" PRIsz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
fprintf(stderr, "lcc_network_parse(raw_packet_data[%" PRIsz "]):"
" decoding string failed\n",
i);
?
src/nfs.c
Outdated
@@ -488,7 +488,7 @@ static int nfs_submit_nfs4_client(const char *instance, char **fields, | |||
if (!suppress_warning) { | |||
WARNING("nfs plugin: Unexpected number of " | |||
"fields for NFSv4 %s " | |||
"statistics: %zu. ", | |||
"statistics: %" PRIsz ". ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Join with the previous line?
src/oracle.c
Outdated
@@ -532,7 +532,8 @@ static int o_read_database_query(o_database_t *db, /* {{{ */ | |||
memcpy(column_names[i], column_name, column_name_length); | |||
column_names[i][column_name_length] = 0; | |||
|
|||
DEBUG("oracle plugin: o_read_database_query: column_names[%zu] = %s; " | |||
DEBUG("oracle plugin: o_read_database_query: column_names[%" PRIsz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
DEBUG("oracle plugin: o_read_database_query: column_names[%" PRIsz "] = %s;"
" column_name_length = %" PRIu32 ";",
i, column_names[i], (uint32_t)column_name_length);
?
src/utils_lua.c
Outdated
"got %zu", | ||
WARNING("ltoc_values: invalid size for datasource \"%s\": expected %" PRIsz | ||
", " | ||
"got %" PRIsz, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Join with the previous line?
@SeanCampbell, you might also want to update the PR description (e.g., to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Friendly ping :) Should I deal with the conflicting files, or is that dealt with as the PR is merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! 👍
However, you'll have to resolve the merge conflicts before we can merge this PR. While doing that, also consider rewriting the branch for a cleaner history.
src/email.c
Outdated
struct sockaddr_un addr = { | ||
.sun_family = AF_UNIX | ||
}; | ||
struct sockaddr_un addr = {.sun_family = AF_UNIX}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is clang-format, so that's fine.
@tokkee A general comment: GitHub now has squash-and-merge. Unless we want to merge this as multiple commits for some reason, wouldn't the final squash-and-merge "just work"? |
Merged the conflicts. For rewriting the branch, do you mean just combining the commits for this PR into one? Thanks. |
… it easier to make the code platform-independent.
@tokkee Cleaned up the history commit -- what do you think? |
Friendly ping |
Thanks! I would have been fine with using squash-and-merge but wanted to leave it to Sean to decide how to split this into one or more commits. |
The new macro, PRIsz, can be defined differently on systems that don't support PRIu64, zu, and llu, which will make the code easier to port.