Rename nitems and string variables to avoid collisions

Rename the `nitems` variable to `num_items` to avoid collisions with the
macro in sys/param.h for counting elements in an array

Similarly, rename `string` to `string_arr` to avoid future collisions with
potential keywords, as well as make it clear that `string_arr` isn't a char*
value, but instead a char** value.

Differential Revision: https://reviews.freebsd.org/D4769 (part of larger diff)
MFC after: 5 days
Reviewed by: oshogbo
Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
ngie 2016-01-04 03:02:44 +00:00
parent 9b4418aa8d
commit f07e33e8a7

View File

@ -50,7 +50,7 @@ ATF_TEST_CASE_BODY(nvlist_bool_array__basic)
const bool *const_result;
bool *result;
nvlist_t *nvl;
size_t nitems;
size_t num_items;
unsigned int i;
const char *key;
@ -69,16 +69,16 @@ ATF_TEST_CASE_BODY(nvlist_bool_array__basic)
ATF_REQUIRE(nvlist_exists_bool_array(nvl, key));
ATF_REQUIRE(nvlist_exists_bool_array(nvl, "nvl/bool"));
const_result = nvlist_get_bool_array(nvl, key, &nitems);
ATF_REQUIRE_EQ(nitems, 16);
const_result = nvlist_get_bool_array(nvl, key, &num_items);
ATF_REQUIRE_EQ(num_items, 16);
ATF_REQUIRE(const_result != NULL);
for (i = 0; i < nitems; i++)
for (i = 0; i < num_items; i++)
ATF_REQUIRE_EQ(const_result[i], testbool[i]);
result = nvlist_take_bool_array(nvl, key, &nitems);
ATF_REQUIRE_EQ(nitems, 16);
result = nvlist_take_bool_array(nvl, key, &num_items);
ATF_REQUIRE_EQ(num_items, 16);
ATF_REQUIRE(const_result != NULL);
for (i = 0; i < nitems; i++)
for (i = 0; i < num_items; i++)
ATF_REQUIRE_EQ(result[i], testbool[i]);
ATF_REQUIRE(!nvlist_exists_bool_array(nvl, key));
@ -95,10 +95,10 @@ ATF_TEST_CASE_BODY(nvlist_string_array__basic)
const char * const *const_result;
char **result;
nvlist_t *nvl;
size_t nitems;
size_t num_items;
unsigned int i;
const char *key;
const char *string[8] = { "a", "b", "kot", "foo",
const char *string_arr[8] = { "a", "b", "kot", "foo",
"tests", "nice test", "", "abcdef" };
key = "nvl/string";
@ -107,32 +107,33 @@ ATF_TEST_CASE_BODY(nvlist_string_array__basic)
ATF_REQUIRE(nvlist_empty(nvl));
ATF_REQUIRE(!nvlist_exists_string_array(nvl, key));
nvlist_add_string_array(nvl, key, string, 8);
nvlist_add_string_array(nvl, key, string_arr, 8);
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(nvlist_exists_string_array(nvl, key));
ATF_REQUIRE(nvlist_exists_string_array(nvl, "nvl/string"));
const_result = nvlist_get_string_array(nvl, key, &nitems);
const_result = nvlist_get_string_array(nvl, key, &num_items);
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE(nitems == 8);
for (i = 0; i < nitems; i++) {
if (string[i] != NULL) {
ATF_REQUIRE(strcmp(const_result[i], string[i]) == 0);
ATF_REQUIRE(num_items == 8);
for (i = 0; i < num_items; i++) {
if (string_arr[i] != NULL) {
ATF_REQUIRE(strcmp(const_result[i],
string_arr[i]) == 0);
} else {
ATF_REQUIRE(const_result[i] == string[i]);
ATF_REQUIRE(const_result[i] == string_arr[i]);
}
}
result = nvlist_take_string_array(nvl, key, &nitems);
result = nvlist_take_string_array(nvl, key, &num_items);
ATF_REQUIRE(result != NULL);
ATF_REQUIRE_EQ(nitems, 8);
for (i = 0; i < nitems; i++) {
if (string[i] != NULL) {
ATF_REQUIRE_EQ(strcmp(result[i], string[i]), 0);
ATF_REQUIRE_EQ(num_items, 8);
for (i = 0; i < num_items; i++) {
if (string_arr[i] != NULL) {
ATF_REQUIRE_EQ(strcmp(result[i], string_arr[i]), 0);
} else {
ATF_REQUIRE_EQ(result[i], string[i]);
ATF_REQUIRE_EQ(result[i], string_arr[i]);
}
}
@ -152,7 +153,7 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__basic)
int fd[32], *result;
const int *const_result;
nvlist_t *nvl;
size_t nitems;
size_t num_items;
unsigned int i;
const char *key;
@ -173,20 +174,20 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__basic)
ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, key));
ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, "nvl/descriptor"));
const_result = nvlist_get_descriptor_array(nvl, key, &nitems);
const_result = nvlist_get_descriptor_array(nvl, key, &num_items);
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE(nitems == 32);
for (i = 0; i < nitems; i++) {
ATF_REQUIRE(num_items == 32);
for (i = 0; i < num_items; i++) {
ATF_REQUIRE(fd_is_valid(const_result[i]));
if (i > 0)
ATF_REQUIRE(const_result[i] != const_result[i - 1]);
}
result = nvlist_take_descriptor_array(nvl, key, &nitems);
result = nvlist_take_descriptor_array(nvl, key, &num_items);
ATF_REQUIRE(result != NULL);
ATF_REQUIRE_EQ(nitems, 32);
for (i = 0; i < nitems; i++) {
ATF_REQUIRE_EQ(num_items, 32);
for (i = 0; i < num_items; i++) {
ATF_REQUIRE(fd_is_valid(result[i]));
if (i > 0)
ATF_REQUIRE(const_result[i] != const_result[i - 1]);
@ -196,7 +197,7 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__basic)
ATF_REQUIRE(nvlist_empty(nvl));
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
for (i = 0; i < nitems; i++) {
for (i = 0; i < num_items; i++) {
close(result[i]);
close(fd[i]);
}
@ -210,7 +211,7 @@ ATF_TEST_CASE_BODY(nvlist_number_array__basic)
const uint64_t *const_result;
uint64_t *result;
nvlist_t *nvl;
size_t nitems;
size_t num_items;
unsigned int i;
const char *key;
const uint64_t number[8] = { 0, UINT_MAX, 7, 123, 90,
@ -228,17 +229,17 @@ ATF_TEST_CASE_BODY(nvlist_number_array__basic)
ATF_REQUIRE(nvlist_exists_number_array(nvl, key));
ATF_REQUIRE(nvlist_exists_number_array(nvl, "nvl/number"));
const_result = nvlist_get_number_array(nvl, key, &nitems);
const_result = nvlist_get_number_array(nvl, key, &num_items);
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE(nitems == 8);
for (i = 0; i < nitems; i++)
ATF_REQUIRE(num_items == 8);
for (i = 0; i < num_items; i++)
ATF_REQUIRE_EQ(const_result[i], number[i]);
result = nvlist_take_number_array(nvl, key, &nitems);
result = nvlist_take_number_array(nvl, key, &num_items);
ATF_REQUIRE(result != NULL);
ATF_REQUIRE_EQ(nitems, 8);
for (i = 0; i < nitems; i++)
ATF_REQUIRE_EQ(num_items, 8);
for (i = 0; i < num_items; i++)
ATF_REQUIRE_EQ(result[i], number[i]);
ATF_REQUIRE(!nvlist_exists_string_array(nvl, key));
@ -256,7 +257,7 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__basic)
const nvlist_t * const *const_result;
nvlist_t **result;
nvlist_t *nvl;
size_t nitems;
size_t num_items;
unsigned int i;
const char *somestr[8] = { "a", "b", "c", "d", "e", "f", "g", "h" };
const char *key;
@ -282,14 +283,14 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__basic)
ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, key));
ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, "nvl/nvlist"));
const_result = nvlist_get_nvlist_array(nvl, key, &nitems);
const_result = nvlist_get_nvlist_array(nvl, key, &num_items);
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE(nitems == 8);
ATF_REQUIRE(num_items == 8);
for (i = 0; i < nitems; i++) {
for (i = 0; i < num_items; i++) {
ATF_REQUIRE_EQ(nvlist_error(const_result[i]), 0);
if (i < nitems - 1) {
if (i < num_items - 1) {
ATF_REQUIRE(nvlist_get_array_next(const_result[i]) ==
const_result[i + 1]);
} else {
@ -304,10 +305,10 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__basic)
"nvl/string"), somestr[i]) == 0);
}
result = nvlist_take_nvlist_array(nvl, key, &nitems);
result = nvlist_take_nvlist_array(nvl, key, &num_items);
ATF_REQUIRE(result != NULL);
ATF_REQUIRE_EQ(nitems, 8);
for (i = 0; i < nitems; i++) {
ATF_REQUIRE_EQ(num_items, 8);
for (i = 0; i < num_items; i++) {
ATF_REQUIRE_EQ(nvlist_error(result[i]), 0);
ATF_REQUIRE(nvlist_get_array_next(result[i]) == NULL);
ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == NULL);
@ -335,8 +336,8 @@ ATF_TEST_CASE_BODY(nvlist_clone_array)
const nvlist_t *nvl;
bool testbool[16];
int testfd[16];
size_t i, nitems;
const char *string[8] = { "a", "b", "kot", "foo",
size_t i, num_items;
const char *string_arr[8] = { "a", "b", "kot", "foo",
"tests", "nice test", "", "abcdef" };
const char *somestr[8] = { "a", "b", "c", "d", "e", "f", "g", "h" };
const uint64_t number[8] = { 0, UINT_MAX, 7, 123, 90,
@ -363,7 +364,7 @@ ATF_TEST_CASE_BODY(nvlist_clone_array)
ATF_REQUIRE(nvlist_exists_bool_array(src, "nvl/bool"));
ATF_REQUIRE(!nvlist_exists_string_array(src, "nvl/string"));
nvlist_add_string_array(src, "nvl/string", string, 8);
nvlist_add_string_array(src, "nvl/string", string_arr, 8);
ATF_REQUIRE_EQ(nvlist_error(src), 0);
ATF_REQUIRE(nvlist_exists_string_array(src, "nvl/string"));
@ -387,52 +388,52 @@ ATF_TEST_CASE_BODY(nvlist_clone_array)
ATF_REQUIRE(dst != NULL);
ATF_REQUIRE(nvlist_exists_bool_array(dst, "nvl/bool"));
(void) nvlist_get_bool_array(dst, "nvl/bool", &nitems);
ATF_REQUIRE_EQ(nitems, 16);
for (i = 0; i < nitems; i++) {
(void) nvlist_get_bool_array(dst, "nvl/bool", &num_items);
ATF_REQUIRE_EQ(num_items, 16);
for (i = 0; i < num_items; i++) {
ATF_REQUIRE(
nvlist_get_bool_array(dst, "nvl/bool", &nitems)[i] ==
nvlist_get_bool_array(src, "nvl/bool", &nitems)[i]);
nvlist_get_bool_array(dst, "nvl/bool", &num_items)[i] ==
nvlist_get_bool_array(src, "nvl/bool", &num_items)[i]);
}
ATF_REQUIRE(nvlist_exists_string_array(dst, "nvl/string"));
(void) nvlist_get_string_array(dst, "nvl/string", &nitems);
ATF_REQUIRE_EQ(nitems, 8);
for (i = 0; i < nitems; i++) {
(void) nvlist_get_string_array(dst, "nvl/string", &num_items);
ATF_REQUIRE_EQ(num_items, 8);
for (i = 0; i < num_items; i++) {
if (nvlist_get_string_array(dst, "nvl/string",
&nitems)[i] == NULL) {
&num_items)[i] == NULL) {
ATF_REQUIRE(nvlist_get_string_array(dst, "nvl/string",
&nitems)[i] == nvlist_get_string_array(src,
"nvl/string", &nitems)[i]);
&num_items)[i] == nvlist_get_string_array(src,
"nvl/string", &num_items)[i]);
} else {
ATF_REQUIRE(strcmp(nvlist_get_string_array(dst,
"nvl/string", &nitems)[i], nvlist_get_string_array(
src, "nvl/string", &nitems)[i]) == 0);
"nvl/string", &num_items)[i], nvlist_get_string_array(
src, "nvl/string", &num_items)[i]) == 0);
}
}
ATF_REQUIRE(nvlist_exists_descriptor_array(dst, "nvl/fd"));
(void) nvlist_get_descriptor_array(dst, "nvl/fd", &nitems);
ATF_REQUIRE_EQ(nitems, 16);
for (i = 0; i < nitems; i++) {
(void) nvlist_get_descriptor_array(dst, "nvl/fd", &num_items);
ATF_REQUIRE_EQ(num_items, 16);
for (i = 0; i < num_items; i++) {
ATF_REQUIRE(fd_is_valid(
nvlist_get_descriptor_array(dst, "nvl/fd", &nitems)[i]));
nvlist_get_descriptor_array(dst, "nvl/fd", &num_items)[i]));
}
ATF_REQUIRE(nvlist_exists_number_array(dst, "nvl/number"));
(void) nvlist_get_number_array(dst, "nvl/number", &nitems);
ATF_REQUIRE_EQ(nitems, 8);
(void) nvlist_get_number_array(dst, "nvl/number", &num_items);
ATF_REQUIRE_EQ(num_items, 8);
for (i = 0; i < nitems; i++) {
for (i = 0; i < num_items; i++) {
ATF_REQUIRE(
nvlist_get_number_array(dst, "nvl/number", &nitems)[i] ==
nvlist_get_number_array(src, "nvl/number", &nitems)[i]);
nvlist_get_number_array(dst, "nvl/number", &num_items)[i] ==
nvlist_get_number_array(src, "nvl/number", &num_items)[i]);
}
ATF_REQUIRE(nvlist_exists_nvlist_array(dst, "nvl/array"));
(void) nvlist_get_nvlist_array(dst, "nvl/array", &nitems);
ATF_REQUIRE_EQ(nitems, 8);
for (i = 0; i < nitems; i++) {
nvl = nvlist_get_nvlist_array(dst, "nvl/array", &nitems)[i];
(void) nvlist_get_nvlist_array(dst, "nvl/array", &num_items);
ATF_REQUIRE_EQ(num_items, 8);
for (i = 0; i < num_items; i++) {
nvl = nvlist_get_nvlist_array(dst, "nvl/array", &num_items)[i];
ATF_REQUIRE(nvlist_exists_string(nvl, "nvl/nvl/teststr"));
ATF_REQUIRE(strcmp(nvlist_get_string(nvl, "nvl/nvl/teststr"),
somestr[i]) == 0);
@ -454,7 +455,7 @@ ATF_TEST_CASE_BODY(nvlist_bool_array__move)
bool *testbool;
const bool *const_result;
nvlist_t *nvl;
size_t nitems, count;
size_t num_items, count;
unsigned int i;
const char *key;
@ -475,11 +476,11 @@ ATF_TEST_CASE_BODY(nvlist_bool_array__move)
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(nvlist_exists_bool_array(nvl, key));
const_result = nvlist_get_bool_array(nvl, key, &nitems);
ATF_REQUIRE_EQ(nitems, count);
const_result = nvlist_get_bool_array(nvl, key, &num_items);
ATF_REQUIRE_EQ(num_items, count);
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE(const_result == testbool);
for (i = 0; i < nitems; i++)
for (i = 0; i < num_items; i++)
ATF_REQUIRE_EQ(const_result[i], (i % 2 == 0));
nvlist_destroy(nvl);
@ -491,7 +492,7 @@ ATF_TEST_CASE_BODY(nvlist_string_array__move)
char **teststr;
const char * const *const_result;
nvlist_t *nvl;
size_t nitems, count;
size_t num_items, count;
unsigned int i;
const char *key;
@ -516,11 +517,11 @@ ATF_TEST_CASE_BODY(nvlist_string_array__move)
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(nvlist_exists_string_array(nvl, key));
const_result = nvlist_get_string_array(nvl, key, &nitems);
ATF_REQUIRE_EQ(nitems, count);
const_result = nvlist_get_string_array(nvl, key, &num_items);
ATF_REQUIRE_EQ(num_items, count);
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE((intptr_t)const_result == (intptr_t)teststr);
for (i = 0; i < nitems; i++) {
for (i = 0; i < num_items; i++) {
ATF_REQUIRE_EQ(const_result[i][0], (char)('a' + i));
ATF_REQUIRE_EQ(const_result[i][1], '\0');
}
@ -534,7 +535,7 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__move)
nvlist **testnv;
const nvlist * const *const_result;
nvlist_t *nvl;
size_t nitems, count;
size_t num_items, count;
unsigned int i;
const char *key;
@ -557,14 +558,14 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__move)
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(nvlist_exists_nvlist_array(nvl, key));
const_result = nvlist_get_nvlist_array(nvl, key, &nitems);
ATF_REQUIRE_EQ(nitems, count);
const_result = nvlist_get_nvlist_array(nvl, key, &num_items);
ATF_REQUIRE_EQ(num_items, count);
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE((intptr_t)const_result == (intptr_t)testnv);
for (i = 0; i < nitems; i++) {
for (i = 0; i < num_items; i++) {
ATF_REQUIRE_EQ(nvlist_error(const_result[i]), 0);
ATF_REQUIRE(nvlist_empty(const_result[i]));
if (i < nitems - 1) {
if (i < num_items - 1) {
ATF_REQUIRE(nvlist_get_array_next(const_result[i]) ==
const_result[i + 1]);
} else {
@ -584,7 +585,7 @@ ATF_TEST_CASE_BODY(nvlist_number_array__move)
uint64_t *testnumber;
const uint64_t *const_result;
nvlist_t *nvl;
size_t nitems, count;
size_t num_items, count;
unsigned int i;
const char *key;
@ -605,11 +606,11 @@ ATF_TEST_CASE_BODY(nvlist_number_array__move)
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(nvlist_exists_number_array(nvl, key));
const_result = nvlist_get_number_array(nvl, key, &nitems);
ATF_REQUIRE_EQ(nitems, count);
const_result = nvlist_get_number_array(nvl, key, &num_items);
ATF_REQUIRE_EQ(num_items, count);
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE(const_result == testnumber);
for (i = 0; i < nitems; i++)
for (i = 0; i < num_items; i++)
ATF_REQUIRE_EQ(const_result[i], i);
nvlist_destroy(nvl);
@ -621,7 +622,7 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__move)
int *testfd;
const int *const_result;
nvlist_t *nvl;
size_t nitems, count;
size_t num_items, count;
unsigned int i;
const char *key;
@ -644,11 +645,11 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__move)
ATF_REQUIRE(!nvlist_empty(nvl));
ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, key));
const_result = nvlist_get_descriptor_array(nvl, key, &nitems);
ATF_REQUIRE_EQ(nitems, count);
const_result = nvlist_get_descriptor_array(nvl, key, &num_items);
ATF_REQUIRE_EQ(num_items, count);
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE(const_result == testfd);
for (i = 0; i < nitems; i++)
for (i = 0; i < num_items; i++)
ATF_REQUIRE(fd_is_valid(const_result[i]));
nvlist_destroy(nvl);
@ -988,7 +989,7 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__pack)
{
nvlist_t *nvl;
const char *key;
size_t nitems;
size_t num_items;
unsigned int i;
const int *const_result;
int desc[32], fd, socks[2];
@ -1021,7 +1022,7 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__pack)
ATF_REQUIRE(nvlist_send(fd, nvl) >= 0);
for (i = 0; i < nitems; i++)
for (i = 0; i < num_items; i++)
close(desc[i]);
} else {
/* Parent */
@ -1034,10 +1035,10 @@ ATF_TEST_CASE_BODY(nvlist_descriptor_array__pack)
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
ATF_REQUIRE(nvlist_exists_descriptor_array(nvl, key));
const_result = nvlist_get_descriptor_array(nvl, key, &nitems);
const_result = nvlist_get_descriptor_array(nvl, key, &num_items);
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE_EQ(nitems, 32);
for (i = 0; i < nitems; i++)
ATF_REQUIRE_EQ(num_items, 32);
for (i = 0; i < num_items; i++)
ATF_REQUIRE(fd_is_valid(const_result[i]));
atf::utils::wait(pid, 0, "", "");
@ -1096,7 +1097,7 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__pack)
const nvlist_t * const *const_result;
nvlist_t **result;
nvlist_t *nvl;
size_t nitems, packed_size;
size_t num_items, packed_size;
unsigned int i;
void *packed;
const char *somestr[8] = { "a", "b", "c", "d", "e", "f", "g", "h" };
@ -1130,12 +1131,12 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__pack)
ATF_REQUIRE_EQ(nvlist_error(unpacked), 0);
ATF_REQUIRE(nvlist_exists_nvlist_array(unpacked, key));
const_result = nvlist_get_nvlist_array(unpacked, key, &nitems);
const_result = nvlist_get_nvlist_array(unpacked, key, &num_items);
ATF_REQUIRE(const_result != NULL);
ATF_REQUIRE_EQ(nitems, 8);
for (i = 0; i < nitems; i++) {
ATF_REQUIRE_EQ(num_items, 8);
for (i = 0; i < num_items; i++) {
ATF_REQUIRE_EQ(nvlist_error(const_result[i]), 0);
if (i < nitems - 1) {
if (i < num_items - 1) {
ATF_REQUIRE(nvlist_get_array_next(const_result[i]) ==
const_result[i + 1]);
} else {