Skip to content
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

Merged
merged 2 commits into from Dec 15, 2017
Merged

Conversation

SeanCampbell
Copy link
Contributor

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.

@SeanCampbell
Copy link
Contributor Author

@igorpeshansky - Can you take a look at this? This is based on the discussion in the windows-fixes branch in the Stackdriver fork.

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

@@ -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
Copy link
Contributor

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.

@igorpeshansky
Copy link
Contributor

@octo @tokkee This should now be ready for review...

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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,
Copy link
Contributor

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);
Copy link
Contributor

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?

@@ -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);
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

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 ". ",
Copy link
Contributor

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
Copy link
Contributor

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,
Copy link
Contributor

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?

@igorpeshansky
Copy link
Contributor

@SeanCampbell, you might also want to update the PR description (e.g., to Replace "llu" with PRIu64 and "zu" with PRIsz in format strings).
@octo, @tokkee, once this is approved, it would probably make sense to either squash-and-merge or rewrite the history on the PR branch before merging.

@SeanCampbell SeanCampbell changed the title Replace PRIu64, zu, and llu with PRIsz. Replace zu with PRIsz and llu with PRIu64. Nov 3, 2017
Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

@SeanCampbell
Copy link
Contributor Author

Friendly ping :)

Should I deal with the conflicting files, or is that dealt with as the PR is merged?

@SeanCampbell
Copy link
Contributor Author

@octo @tokkee Friendly ping on this :) Is there anything I should clean up before this is reviewed or merged?

Copy link
Member

@tokkee tokkee left a 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};
Copy link
Member

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.

@igorpeshansky
Copy link
Contributor

@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"?

@SeanCampbell
Copy link
Contributor Author

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.
@SeanCampbell
Copy link
Contributor Author

@tokkee Cleaned up the history commit -- what do you think?

@SeanCampbell
Copy link
Contributor Author

Friendly ping

@tokkee
Copy link
Member

tokkee commented Dec 15, 2017

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.

@tokkee tokkee merged commit 77ca1a4 into collectd:master Dec 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants