util: add is_equal to UUID API
PATCH v2 1/1 util: add is_equal to UUID API
It's going to be useful, in particular, in VMBus code massively using uuids aka GUIDs.
---
v1 -> v2:
- drop dedicated testcase (for it was of no value) and incorporate is_null and is_equal assertions into uuid_generate testcase
include/qemu/uuid.h | 2 ++ tests/test-uuid.c | 8 +++++++- util/uuid.c | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-)
include/qemu/uuid.h +2 -0
@@ -48,6 +48,8 @@ void qemu_uuid_generate(QemuUUID *out);int qemu_uuid_is_null (const QemuUUID *uu); +int qemu_uuid_is_equal (const QemuUUID *lhv,const QemuUUID *rhv); +void qemu_uuid_unparse (const QemuUUID *uuid,char *out);char *qemu_uuid_unparse_strdup (const QemuUUID *uuid);
tests/test-uuid.c +7 -1
@@ -93,12 +93,18 @@ static inline bool uuid_is_valid(QemuUUID *uuid)static void test_uuid_generate (void ) { +QemuUUID uuid_not_null = { { { +0x58 ,0x6e ,0xce ,0x27 ,0x7f ,0x09 ,0x41 ,0xe0 , +0x9e ,0x74 ,0xe9 ,0x01 ,0x31 ,0x7e ,0x9d ,0x42 + } } };QemuUUID uuid;int i;for (i =0 ; i <100 ; ++i) {qemu_uuid_generate (&uuid);g_assert (uuid_is_valid (&uuid)); +g_assert_false (qemu_uuid_is_null (&uuid)); +g_assert_false (qemu_uuid_is_equal (&uuid_not_null, &uuid)); } }
@@ -168,8 +174,8 @@ static void test_uuid_unparse_strdup(void)int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL ); -g_test_add_func ("/uuid/generate" , test_uuid_generate);g_test_add_func ("/uuid/is_null" , test_uuid_is_null); +g_test_add_func ("/uuid/generate" , test_uuid_generate);g_test_add_func ("/uuid/parse" , test_uuid_parse);g_test_add_func ("/uuid/unparse" , test_uuid_unparse);g_test_add_func ("/uuid/unparse_strdup" , test_uuid_unparse_strdup);
util/uuid.c +6 -1
@@ -41,7 +41,12 @@ void qemu_uuid_generate(QemuUUID *uuid)int qemu_uuid_is_null (const QemuUUID *uu) {static QemuUUID null_uuid; -return memcmp (uu, &null_uuid,sizeof (QemuUUID)) ==0 ; +return qemu_uuid_is_equal (uu, &null_uuid); +} + +int qemu_uuid_is_equal (const QemuUUID *lhv,const QemuUUID *rhv) +{ +return memcmp (lhv, rhv,sizeof (QemuUUID)) ==0 ; }void qemu_uuid_unparse (const QemuUUID *uuid,char *out)
Signature · 1 line
2.14.3
Quoted 81 lines · Roman Kagan
It's going to be useful, in particular, in VMBus code massively using uuids aka GUIDs.
Signed-off-by Roman Kagan <[email protected]>---
v1 -> v2:
- drop dedicated testcase (for it was of no value) and incorporateis_nullandis_equalassertions intouuid_generatetestcaseinclude/qemu/uuid.h | 2 ++ tests/test-uuid.c | 8 +++++++- util/uuid.c | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-)include/qemu/uuid.h +2
-0@@ -48,6 +48,8 @@ void qemu_uuid_generate(QemuUUID *out);int qemu_uuid_is_null (const QemuUUID *uu); +int qemu_uuid_is_equal (const QemuUUID *lhv,const QemuUUID *rhv); +void qemu_uuid_unparse (const QemuUUID *uuid,char *out);char *qemu_uuid_unparse_strdup (const QemuUUID *uuid);tests/test-uuid.c +7
-1@@ -93,12 +93,18 @@ static inline bool uuid_is_valid(QemuUUID *uuid)static void test_uuid_generate (void ) { +QemuUUID uuid_not_null = { { { +0x58 ,0x6e ,0xce ,0x27 ,0x7f ,0x09 ,0x41 ,0xe0 , +0x9e ,0x74 ,0xe9 ,0x01 ,0x31 ,0x7e ,0x9d ,0x42 + } } };QemuUUID uuid;int i;for (i =0 ; i <100 ; ++i) {qemu_uuid_generate (&uuid);g_assert (uuid_is_valid (&uuid)); +g_assert_false (qemu_uuid_is_null (&uuid)); +g_assert_false (qemu_uuid_is_equal (&uuid_not_null, &uuid)); } }@@ -168,8 +174,8 @@ static void test_uuid_unparse_strdup(void)int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL ); -g_test_add_func ("/uuid/generate" , test_uuid_generate);g_test_add_func ("/uuid/is_null" , test_uuid_is_null); +g_test_add_func ("/uuid/generate" , test_uuid_generate);g_test_add_func ("/uuid/parse" , test_uuid_parse);g_test_add_func ("/uuid/unparse" , test_uuid_unparse);g_test_add_func ("/uuid/unparse_strdup" , test_uuid_unparse_strdup);util/uuid.c +6
-1@@ -41,7 +41,12 @@ void qemu_uuid_generate(QemuUUID *uuid)int qemu_uuid_is_null (const QemuUUID *uu) {static QemuUUID null_uuid; -return memcmp (uu, &null_uuid,sizeof (QemuUUID)) ==0 ; +return qemu_uuid_is_equal (uu, &null_uuid); +} + +int qemu_uuid_is_equal (const QemuUUID *lhv,const QemuUUID *rhv) +{ +return memcmp (lhv, rhv,sizeof (QemuUUID)) ==0 ; }void qemu_uuid_unparse (const QemuUUID *uuid,char *out)Signature · 1 line
2.14.3
Thanks, queued. Will send a pull request once next release dev window opens.
Fam
Quoted 78 lines · Fam Zheng
Quoted 77 lines · Roman Kagan
It's going to be useful, in particular, in VMBus code massively using uuids aka GUIDs.
Signed-off-by Roman Kagan <[email protected]>---
v1 -> v2:
- drop dedicated testcase (for it was of no value) and incorporateis_nullandis_equalassertions intouuid_generatetestcaseinclude/qemu/uuid.h | 2 ++ tests/test-uuid.c | 8 +++++++- util/uuid.c | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-)include/qemu/uuid.h +2
-0@@ -48,6 +48,8 @@ void qemu_uuid_generate(QemuUUID *out);int qemu_uuid_is_null (const QemuUUID *uu); +int qemu_uuid_is_equal (const QemuUUID *lhv,const QemuUUID *rhv); +void qemu_uuid_unparse (const QemuUUID *uuid,char *out);char *qemu_uuid_unparse_strdup (const QemuUUID *uuid);tests/test-uuid.c +7
-1@@ -93,12 +93,18 @@ static inline bool uuid_is_valid(QemuUUID *uuid)static void test_uuid_generate (void ) { +QemuUUID uuid_not_null = { { { +0x58 ,0x6e ,0xce ,0x27 ,0x7f ,0x09 ,0x41 ,0xe0 , +0x9e ,0x74 ,0xe9 ,0x01 ,0x31 ,0x7e ,0x9d ,0x42 + } } };QemuUUID uuid;int i;for (i =0 ; i <100 ; ++i) {qemu_uuid_generate (&uuid);g_assert (uuid_is_valid (&uuid)); +g_assert_false (qemu_uuid_is_null (&uuid)); +g_assert_false (qemu_uuid_is_equal (&uuid_not_null, &uuid)); } }@@ -168,8 +174,8 @@ static void test_uuid_unparse_strdup(void)int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL ); -g_test_add_func ("/uuid/generate" , test_uuid_generate);g_test_add_func ("/uuid/is_null" , test_uuid_is_null); +g_test_add_func ("/uuid/generate" , test_uuid_generate);g_test_add_func ("/uuid/parse" , test_uuid_parse);g_test_add_func ("/uuid/unparse" , test_uuid_unparse);g_test_add_func ("/uuid/unparse_strdup" , test_uuid_unparse_strdup);util/uuid.c +6
-1@@ -41,7 +41,12 @@ void qemu_uuid_generate(QemuUUID *uuid)int qemu_uuid_is_null (const QemuUUID *uu) {static QemuUUID null_uuid; -return memcmp (uu, &null_uuid,sizeof (QemuUUID)) ==0 ; +return qemu_uuid_is_equal (uu, &null_uuid); +} + +int qemu_uuid_is_equal (const QemuUUID *lhv,const QemuUUID *rhv) +{ +return memcmp (lhv, rhv,sizeof (QemuUUID)) ==0 ; }
Quoted 6 lines
Quoted 4 lines
util/uuid.c +0
-0void qemu_uuid_unparse (const QemuUUID *uuid,char *out)Signature · 1 line
2.14.3Thanks, queued. Will send a pull request once next release dev window opens.
Ping?
Quoted 3 lines · Roman Kagan
Quoted 1 line
Thanks, queued. Will send a pull request once next release dev window opens.
Ping?
In master now.
Fam