aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Zaborski <oshogbo@FreeBSD.org>2018-06-18 21:26:58 +0000
committerMariusz Zaborski <oshogbo@FreeBSD.org>2018-06-18 21:26:58 +0000
commitd82e41b6b82113e242b02f7a0193c6e6b26d495f (patch)
treea545b6becf82095b67d163153b86e7fab0f24db9
parent30665f3c42302105793ba18027ec02fd24801b9e (diff)
downloadsrc-d82e41b6b82113e242b02f7a0193c6e6b26d495f.tar.gz
src-d82e41b6b82113e242b02f7a0193c6e6b26d495f.zip
libnv: Remove nvlist argument from cnvlist_{take,free}_* functions.
All information which are need for those operations is already stored in the cookie. We decided not to bump libnv version because this API is not used yet in the base system. Reviewed by: pjd
Notes
Notes: svn path=/head/; revision=335343
-rw-r--r--lib/libnv/tests/cnv_tests.cc36
-rw-r--r--share/man/man9/cnv.950
-rw-r--r--sys/contrib/libnv/cnvlist.c16
-rw-r--r--sys/sys/cnv.h44
4 files changed, 76 insertions, 70 deletions
diff --git a/lib/libnv/tests/cnv_tests.cc b/lib/libnv/tests/cnv_tests.cc
index 8df47376678a..8e79c28d5056 100644
--- a/lib/libnv/tests/cnv_tests.cc
+++ b/lib/libnv/tests/cnv_tests.cc
@@ -575,7 +575,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_bool)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- ATF_REQUIRE_EQ(cnvlist_take_bool(nvl, cookie), value);
+ ATF_REQUIRE_EQ(cnvlist_take_bool(cookie), value);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -618,7 +618,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_number)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- ATF_REQUIRE_EQ(cnvlist_take_number(nvl, cookie), value);
+ ATF_REQUIRE_EQ(cnvlist_take_number(cookie), value);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -662,7 +662,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_string)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- out_string = cnvlist_take_string(nvl, cookie);
+ out_string = cnvlist_take_string(cookie);
ATF_REQUIRE(out_string != NULL);
ATF_REQUIRE_EQ(strcmp(out_string, value), 0);
@@ -725,7 +725,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_nvlist)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- result = cnvlist_take_nvlist(nvl, cookie);
+ result = cnvlist_take_nvlist(cookie);
ATF_REQUIRE(!nvlist_exists_nvlist(nvl, key));
ATF_REQUIRE(result == value);
@@ -784,7 +784,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_bool_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- out_array = cnvlist_take_bool_array(nvl, cookie, &nitems);
+ out_array = cnvlist_take_bool_array(cookie, &nitems);
ATF_REQUIRE_EQ(nitems, 16);
ATF_REQUIRE(out_array != NULL);
for (i = 0; i < 16; i++)
@@ -836,7 +836,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_number_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- out_array = cnvlist_take_number_array(nvl, cookie, &nitems);
+ out_array = cnvlist_take_number_array(cookie, &nitems);
ATF_REQUIRE(out_array != NULL);
ATF_REQUIRE_EQ(nitems, 16);
@@ -885,7 +885,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_string_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- out_array = cnvlist_take_string_array(nvl, cookie, &nitems);
+ out_array = cnvlist_take_string_array(cookie, &nitems);
ATF_REQUIRE_EQ(nitems, 4);
for (i = 0; i < 4; i++) {
ATF_REQUIRE(out_array[i] != NULL);
@@ -957,7 +957,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_nvlist_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- result = cnvlist_take_nvlist_array(nvl, cookie, &num_items);
+ result = cnvlist_take_nvlist_array(cookie, &num_items);
ATF_REQUIRE(result != NULL);
ATF_REQUIRE_EQ(num_items, 8);
@@ -1022,7 +1022,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_binary)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- out_binary = cnvlist_take_binary(nvl, cookie, &out_size);
+ out_binary = cnvlist_take_binary(cookie, &out_size);
ATF_REQUIRE_EQ(out_size, in_size);
ATF_REQUIRE_EQ(memcmp(in_binary, out_binary, out_size), 0);
@@ -1069,7 +1069,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_bool)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_bool(nvl, cookie);
+ cnvlist_free_bool(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1112,7 +1112,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_number)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_number(nvl, cookie);
+ cnvlist_free_number(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1155,7 +1155,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_string)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_string(nvl, cookie);
+ cnvlist_free_string(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1215,7 +1215,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_nvlist)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_nvlist(nvl, cookie);
+ cnvlist_free_nvlist(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1262,7 +1262,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_binary)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_binary(nvl, cookie);
+ cnvlist_free_binary(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1309,7 +1309,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_bool_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_bool_array(nvl, cookie);
+ cnvlist_free_bool_array(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1354,7 +1354,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_number_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_number_array(nvl, cookie);
+ cnvlist_free_number_array(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1396,7 +1396,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_string_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_string_array(nvl, cookie);
+ cnvlist_free_string_array(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1459,7 +1459,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_nvlist_array)
cookie = NULL;
ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
- cnvlist_free_nvlist_array(nvl, cookie);
+ cnvlist_free_nvlist_array(cookie);
cookie = NULL;
ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
diff --git a/share/man/man9/cnv.9 b/share/man/man9/cnv.9
index 5d5a57963e32..737a1b2fb518 100644
--- a/share/man/man9/cnv.9
+++ b/share/man/man9/cnv.9
@@ -66,52 +66,52 @@
.Fn cnvlist_get_descriptor_array "const void *cookie" "size_t *nitemsp"
.\"
.Ft bool
-.Fn cnvlist_take_bool "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_take_bool "void *cookie"
.Ft uint64_t
-.Fn cnvlist_take_number "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_take_number "void *cookie"
.Ft "const char *"
-.Fn cnvlist_take_string "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_take_string "void *cookie"
.Ft "const nvlist_t *"
-.Fn cnvlist_take_nvlist "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_take_nvlist "void *cookie"
.Ft "const void *"
-.Fn cnvlist_take_binary "nvlist_t *nvl" "void *cookie" "size_t *sizep"
+.Fn cnvlist_take_binary "void *cookie" "size_t *sizep"
.Ft "const bool *"
-.Fn cnvlist_take_bool_array "nvlist_t *nvl" "void *cookie" "size_t *nitemsp"
+.Fn cnvlist_take_bool_array "void *cookie" "size_t *nitemsp"
.Ft "const uint64_t *"
-.Fn cnvlist_take_number_array "nvlist_t *nvl" "void *cookie" "size_t *nitemsp"
+.Fn cnvlist_take_number_array "void *cookie" "size_t *nitemsp"
.Ft "const char * const *"
-.Fn cnvlist_take_string_array "nvlist_t *nvl" "void *cookie" "size_t *nitemsp"
+.Fn cnvlist_take_string_array "void *cookie" "size_t *nitemsp"
.Ft "const nvlist_t * const *"
-.Fn cnvlist_take_nvlist_array "nvlist_t *nvl" "void *cookie" "size_t *nitemsp"
+.Fn cnvlist_take_nvlist_array "void *cookie" "size_t *nitemsp"
.Ft int
-.Fn cnvlist_take_descriptor "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_take_descriptor "void *cookie"
.Ft "const int *"
-.Fn cnvlist_take_descriptor_array "nvlist_t *nvl" "void *cookie" "size_t *nitemsp"
+.Fn cnvlist_take_descriptor_array "void *cookie" "size_t *nitemsp"
.\"
.Ft void
-.Fn cnvlist_free_null "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_null "void *cookie"
.Ft void
-.Fn cnvlist_free_bool "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_bool "void *cookie"
.Ft void
-.Fn cnvlist_free_number "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_number "void *cookie"
.Ft void
-.Fn cnvlist_free_string "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_string "void *cookie"
.Ft void
-.Fn cnvlist_free_nvlist "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_nvlist "void *cookie"
.Ft void
-.Fn cnvlist_free_descriptor "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_descriptor "void *cookie"
.Ft void
-.Fn cnvlist_free_binary "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_binary "void *cookie"
.Ft void
-.Fn cnvlist_free_bool_array "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_bool_array "void *cookie"
.Ft void
-.Fn cnvlist_free_number_array "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_number_array "void *cookie"
.Ft void
-.Fn cnvlist_free_string_array "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_string_array "void *cookie"
.Ft void
-.Fn cnvlist_free_nvlist_array "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_nvlist_array "void *cookie"
.Ft void
-.Fn cnvlist_free_descriptor_array "nvlist_t *nvl" "void *cookie"
+.Fn cnvlist_free_descriptor_array "void *cookie"
.Sh DESCRIPTION
The
.Nm libnv
@@ -192,8 +192,8 @@ while (nvlist_next(nvl, &type, &cookie) != NULL) {
}
}
-name = cnvlist_take_string(nvl, scookie);
-cnvlist_free_bool(nvl, bcookie);
+name = cnvlist_take_string(scookie);
+cnvlist_free_bool(bcookie);
printf("test2: %s\\n", name);
free(name);
diff --git a/sys/contrib/libnv/cnvlist.c b/sys/contrib/libnv/cnvlist.c
index 2a1134855df7..a35ddc482105 100644
--- a/sys/contrib/libnv/cnvlist.c
+++ b/sys/contrib/libnv/cnvlist.c
@@ -124,14 +124,16 @@ cnvlist_get_binary(const void *cookie, size_t *sizep)
#define CNVLIST_TAKE(ftype, type, NVTYPE) \
ftype \
-cnvlist_take_##type(nvlist_t *nvl, void *cookie) \
+cnvlist_take_##type(void *cookie) \
{ \
ftype value; \
+ nvlist_t *nvl; \
\
if (nvpair_type(cookie) != NV_TYPE_##NVTYPE) { \
nvlist_report_missing(NV_TYPE_##NVTYPE, \
nvpair_name(cookie)); \
} \
+ nvl = nvpair_nvlist(cookie); \
value = (ftype)(intptr_t)nvpair_get_##type(cookie); \
nvlist_remove_nvpair(nvl, cookie); \
nvpair_free_structure(cookie); \
@@ -150,14 +152,16 @@ CNVLIST_TAKE(int, descriptor, DESCRIPTOR)
#define CNVLIST_TAKE_ARRAY(ftype, type, NVTYPE) \
ftype \
-cnvlist_take_##type(nvlist_t *nvl, void *cookie, size_t *nitemsp) \
+cnvlist_take_##type(void *cookie, size_t *nitemsp) \
{ \
ftype value; \
+ nvlist_t *nvl; \
\
if (nvpair_type(cookie) != NV_TYPE_##NVTYPE) { \
nvlist_report_missing(NV_TYPE_##NVTYPE, \
nvpair_name(cookie)); \
} \
+ nvl = nvpair_nvlist(cookie); \
value = (ftype)(intptr_t)nvpair_get_##type(cookie, nitemsp); \
nvlist_remove_nvpair(nvl, cookie); \
nvpair_free_structure(cookie); \
@@ -175,12 +179,14 @@ CNVLIST_TAKE_ARRAY(int *, descriptor_array, DESCRIPTOR_ARRAY);
#undef CNVLIST_TAKE_ARRAY
void *
-cnvlist_take_binary(nvlist_t *nvl, void *cookie, size_t *sizep)
+cnvlist_take_binary(void *cookie, size_t *sizep)
{
void *value;
+ nvlist_t *nvl;
if (nvpair_type(cookie) != NV_TYPE_BINARY)
nvlist_report_missing(NV_TYPE_BINARY, nvpair_name(cookie));
+ nvl = nvpair_nvlist(cookie);
value = (void *)(intptr_t)nvpair_get_binary(cookie, sizep);
nvlist_remove_nvpair(nvl, cookie);
nvpair_free_structure(cookie);
@@ -190,10 +196,10 @@ cnvlist_take_binary(nvlist_t *nvl, void *cookie, size_t *sizep)
#define CNVLIST_FREE(type) \
void \
-cnvlist_free_##type(nvlist_t *nvl, void *cookie) \
+cnvlist_free_##type(void *cookie) \
{ \
\
- nvlist_free_nvpair(nvl, cookie); \
+ nvlist_free_nvpair(nvpair_nvlist(cookie), cookie); \
}
CNVLIST_FREE(bool)
diff --git a/sys/sys/cnv.h b/sys/sys/cnv.h
index 9ce8bc4807a6..1e56cfbedd90 100644
--- a/sys/sys/cnv.h
+++ b/sys/sys/cnv.h
@@ -82,18 +82,18 @@ const int *cnvlist_get_descriptor_array(const void *cookie, size_t *nitemsp);
* The caller is responsible for freeing received data.
*/
-bool cnvlist_take_bool(nvlist_t *nvl, void *cookie);
-uint64_t cnvlist_take_number(nvlist_t *nvl, void *cookie);
-char *cnvlist_take_string(nvlist_t *nvl, void *cookie);
-nvlist_t *cnvlist_take_nvlist(nvlist_t *nvl, void *cookie);
-void *cnvlist_take_binary(nvlist_t *nvl, void *cookie, size_t *sizep);
-bool *cnvlist_take_bool_array(nvlist_t *nvl, void *cookie, size_t *nitemsp);
-uint64_t *cnvlist_take_number_array(nvlist_t *nvl, void *cookie, size_t *nitemsp);
-char **cnvlist_take_string_array(nvlist_t *nvl, void *cookie, size_t *nitemsp);
-nvlist_t **cnvlist_take_nvlist_array(nvlist_t *nvl, void *cookie, size_t *nitemsp);
+bool cnvlist_take_bool(void *cookie);
+uint64_t cnvlist_take_number(void *cookie);
+char *cnvlist_take_string(void *cookie);
+nvlist_t *cnvlist_take_nvlist(void *cookie);
+void *cnvlist_take_binary(void *cookie, size_t *sizep);
+bool *cnvlist_take_bool_array(void *cookie, size_t *nitemsp);
+uint64_t *cnvlist_take_number_array(void *cookie, size_t *nitemsp);
+char **cnvlist_take_string_array(void *cookie, size_t *nitemsp);
+nvlist_t **cnvlist_take_nvlist_array(void *cookie, size_t *nitemsp);
#ifndef _KERNEL
-int cnvlist_take_descriptor(nvlist_t *nvl, void *cookie);
-int *cnvlist_take_descriptor_array(nvlist_t *nvl, void *cookie, size_t *nitemsp);
+int cnvlist_take_descriptor(void *cookie);
+int *cnvlist_take_descriptor_array(void *cookie, size_t *nitemsp);
#endif
/*
@@ -101,18 +101,18 @@ int *cnvlist_take_descriptor_array(nvlist_t *nvl, void *cookie, size_t *nitem
* and frees memory associated with it.
*/
-void cnvlist_free_bool(nvlist_t *nvl, void *cookie);
-void cnvlist_free_number(nvlist_t *nvl, void *cookie);
-void cnvlist_free_string(nvlist_t *nvl, void *cookie);
-void cnvlist_free_nvlist(nvlist_t *nvl, void *cookie);
-void cnvlist_free_binary(nvlist_t *nvl, void *cookie);
-void cnvlist_free_bool_array(nvlist_t *nvl, void *cookie);
-void cnvlist_free_number_array(nvlist_t *nvl, void *cookie);
-void cnvlist_free_string_array(nvlist_t *nvl, void *cookie);
-void cnvlist_free_nvlist_array(nvlist_t *nvl, void *cookie);
+void cnvlist_free_bool(void *cookie);
+void cnvlist_free_number(void *cookie);
+void cnvlist_free_string(void *cookie);
+void cnvlist_free_nvlist(void *cookie);
+void cnvlist_free_binary(void *cookie);
+void cnvlist_free_bool_array(void *cookie);
+void cnvlist_free_number_array(void *cookie);
+void cnvlist_free_string_array(void *cookie);
+void cnvlist_free_nvlist_array(void *cookie);
#ifndef _KERNEL
-void cnvlist_free_descriptor(nvlist_t *nvl, void *cookie);
-void cnvlist_free_descriptor_array(nvlist_t *nvl, void *cookie);
+void cnvlist_free_descriptor(void *cookie);
+void cnvlist_free_descriptor_array(void *cookie);
#endif
__END_DECLS