From af95542df3ab6b5a9ddce4c933ef6b2230d833eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 21 Sep 2021 21:54:53 +0200 Subject: UUIDs: rename UUID to bUUID Rename the `UUID` struct to `bUUID`. This avoids a symbol clash on Windows, which also defines `UUID`. This only pops up when a `UUID` field is used in the DNA code, which is why it wasn't a problem before (it will be once D12589 lands). No functional changes. --- source/blender/blenlib/BLI_uuid.h | 14 +++++++------- source/blender/blenlib/intern/uuid.cc | 20 +++++++++---------- source/blender/blenlib/tests/BLI_uuid_test.cc | 28 +++++++++++++-------------- 3 files changed, 31 insertions(+), 31 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_uuid.h b/source/blender/blenlib/BLI_uuid.h index 0c6fb3ae3e7..9b85f8e65bc 100644 --- a/source/blender/blenlib/BLI_uuid.h +++ b/source/blender/blenlib/BLI_uuid.h @@ -35,25 +35,25 @@ extern "C" { /** * UUID generator for random (version 4) UUIDs. See RFC4122 section 4.4. * This function is not thread-safe. */ -UUID BLI_uuid_generate_random(void); +bUUID BLI_uuid_generate_random(void); /** * Return the UUID nil value, consisting of all-zero fields. */ -UUID BLI_uuid_nil(void); +bUUID BLI_uuid_nil(void); /** Return true only if this is the nil UUID. */ -bool BLI_uuid_is_nil(UUID uuid); +bool BLI_uuid_is_nil(bUUID uuid); /** Compare two UUIDs, return true only if they are equal. */ -bool BLI_uuid_equal(UUID uuid1, UUID uuid2); +bool BLI_uuid_equal(bUUID uuid1, bUUID uuid2); /** * Format UUID as string. * The buffer must be at least 37 bytes (36 bytes for the UUID + terminating 0). * Use `UUID_STRING_LEN` from DNA_uuid_types.h if you want to use a constant for this. */ -void BLI_uuid_format(char *buffer, UUID uuid) ATTR_NONNULL(); +void BLI_uuid_format(char *buffer, bUUID uuid) ATTR_NONNULL(); /** * Parse a string as UUID. @@ -63,7 +63,7 @@ void BLI_uuid_format(char *buffer, UUID uuid) ATTR_NONNULL(); * Return true if the string could be parsed, and false otherwise. In the latter case, the UUID may * have been partially updated. */ -bool BLI_uuid_parse_string(UUID *uuid, const char *buffer) ATTR_NONNULL(); +bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL(); #ifdef __cplusplus } @@ -71,6 +71,6 @@ bool BLI_uuid_parse_string(UUID *uuid, const char *buffer) ATTR_NONNULL(); # include /** Output the UUID as formatted ASCII string, see #BLI_uuid_format(). */ -std::ostream &operator<<(std::ostream &stream, UUID uuid); +std::ostream &operator<<(std::ostream &stream, bUUID uuid); #endif diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc index f5edb356acc..ae34bcb3d32 100644 --- a/source/blender/blenlib/intern/uuid.cc +++ b/source/blender/blenlib/intern/uuid.cc @@ -27,9 +27,9 @@ #include /* Ensure the UUID struct doesn't have any padding, to be compatible with memcmp(). */ -static_assert(sizeof(UUID) == 16, "expect UUIDs to be 128 bit exactly"); +static_assert(sizeof(bUUID) == 16, "expect UUIDs to be 128 bit exactly"); -UUID BLI_uuid_generate_random() +bUUID BLI_uuid_generate_random() { static std::mt19937_64 rng = []() { std::mt19937_64 rng; @@ -57,7 +57,7 @@ UUID BLI_uuid_generate_random() return rng; }(); - UUID uuid; + bUUID uuid; /* RFC4122 suggests setting certain bits to a fixed value, and then randomizing the remaining * bits. The opposite is easier to implement, though, so that's what's done here. */ @@ -78,23 +78,23 @@ UUID BLI_uuid_generate_random() return uuid; } -UUID BLI_uuid_nil(void) +bUUID BLI_uuid_nil(void) { - const UUID nil = {0, 0, 0, 0, 0, 0}; + const bUUID nil = {0, 0, 0, 0, 0, 0}; return nil; } -bool BLI_uuid_is_nil(UUID uuid) +bool BLI_uuid_is_nil(bUUID uuid) { return BLI_uuid_equal(BLI_uuid_nil(), uuid); } -bool BLI_uuid_equal(const UUID uuid1, const UUID uuid2) +bool BLI_uuid_equal(const bUUID uuid1, const bUUID uuid2) { return std::memcmp(&uuid1, &uuid2, sizeof(uuid1)) == 0; } -void BLI_uuid_format(char *buffer, const UUID uuid) +void BLI_uuid_format(char *buffer, const bUUID uuid) { std::sprintf(buffer, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", @@ -111,7 +111,7 @@ void BLI_uuid_format(char *buffer, const UUID uuid) uuid.node[5]); } -bool BLI_uuid_parse_string(UUID *uuid, const char *buffer) +bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) { const int num_fields_parsed = std::sscanf( buffer, @@ -130,7 +130,7 @@ bool BLI_uuid_parse_string(UUID *uuid, const char *buffer) return num_fields_parsed == 11; } -std::ostream &operator<<(std::ostream &stream, UUID uuid) +std::ostream &operator<<(std::ostream &stream, bUUID uuid) { std::string buffer(36, '\0'); BLI_uuid_format(buffer.data(), uuid); diff --git a/source/blender/blenlib/tests/BLI_uuid_test.cc b/source/blender/blenlib/tests/BLI_uuid_test.cc index 31c69002c1c..731489c6c9e 100644 --- a/source/blender/blenlib/tests/BLI_uuid_test.cc +++ b/source/blender/blenlib/tests/BLI_uuid_test.cc @@ -20,7 +20,7 @@ TEST(BLI_uuid, generate_random) { - const UUID uuid = BLI_uuid_generate_random(); + const bUUID uuid = BLI_uuid_generate_random(); // The 4 MSbits represent the "version" of the UUID. const uint16_t version = uuid.time_hi_and_version >> 12; @@ -33,11 +33,11 @@ TEST(BLI_uuid, generate_random) TEST(BLI_uuid, generate_many_random) { - const UUID first_uuid = BLI_uuid_generate_random(); + const bUUID first_uuid = BLI_uuid_generate_random(); /* Generate lots of UUIDs to get some indication that the randomness is okay. */ for (int i = 0; i < 1000000; ++i) { - const UUID uuid = BLI_uuid_generate_random(); + const bUUID uuid = BLI_uuid_generate_random(); EXPECT_FALSE(BLI_uuid_equal(first_uuid, uuid)); // Check that the non-random bits are set according to RFC4122. @@ -50,8 +50,8 @@ TEST(BLI_uuid, generate_many_random) TEST(BLI_uuid, nil_value) { - const UUID nil_uuid = BLI_uuid_nil(); - const UUID zeroes_uuid = {0, 0, 0, 0, 0, 0}; + const bUUID nil_uuid = BLI_uuid_nil(); + const bUUID zeroes_uuid = {0, 0, 0, 0, 0, 0}; EXPECT_TRUE(BLI_uuid_equal(nil_uuid, zeroes_uuid)); EXPECT_TRUE(BLI_uuid_is_nil(nil_uuid)); @@ -63,8 +63,8 @@ TEST(BLI_uuid, nil_value) TEST(BLI_uuid, equality) { - const UUID uuid1 = BLI_uuid_generate_random(); - const UUID uuid2 = BLI_uuid_generate_random(); + const bUUID uuid1 = BLI_uuid_generate_random(); + const bUUID uuid2 = BLI_uuid_generate_random(); EXPECT_TRUE(BLI_uuid_equal(uuid1, uuid1)); EXPECT_FALSE(BLI_uuid_equal(uuid1, uuid2)); @@ -72,7 +72,7 @@ TEST(BLI_uuid, equality) TEST(BLI_uuid, string_formatting) { - UUID uuid; + bUUID uuid; std::string buffer(36, '\0'); memset(&uuid, 0, sizeof(uuid)); @@ -91,12 +91,12 @@ TEST(BLI_uuid, string_formatting) EXPECT_EQ("00000001-0002-0003-0405-060000000007", buffer); /* Somewhat more complex bit patterns. This is a version 1 UUID generated from Python. */ - const UUID uuid1 = {3540651616, 5282, 4588, 139, 153, {0xf7, 0x73, 0x69, 0x44, 0xdb, 0x8b}}; + const bUUID uuid1 = {3540651616, 5282, 4588, 139, 153, {0xf7, 0x73, 0x69, 0x44, 0xdb, 0x8b}}; BLI_uuid_format(buffer.data(), uuid1); EXPECT_EQ("d30a0e60-14a2-11ec-8b99-f7736944db8b", buffer); /* Namespace UUID, example listed in RFC4211. */ - const UUID namespace_dns = { + const bUUID namespace_dns = { 0x6ba7b810, 0x9dad, 0x11d1, 0x80, 0xb4, {0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}}; BLI_uuid_format(buffer.data(), namespace_dns); EXPECT_EQ("6ba7b810-9dad-11d1-80b4-00c04fd430c8", buffer); @@ -104,7 +104,7 @@ TEST(BLI_uuid, string_formatting) TEST(BLI_uuid, string_parsing_ok) { - UUID uuid; + bUUID uuid; std::string buffer(36, '\0'); const bool parsed_ok = BLI_uuid_parse_string(&uuid, "d30a0e60-14a2-11ec-8b99-f7736944db8b"); @@ -115,7 +115,7 @@ TEST(BLI_uuid, string_parsing_ok) TEST(BLI_uuid, string_parsing_capitalisation) { - UUID uuid; + bUUID uuid; std::string buffer(36, '\0'); /* RFC4122 demands acceptance of upper-case hex digits. */ @@ -129,7 +129,7 @@ TEST(BLI_uuid, string_parsing_capitalisation) TEST(BLI_uuid, string_parsing_fail) { - UUID uuid; + bUUID uuid; std::string buffer(36, '\0'); const bool parsed_ok = BLI_uuid_parse_string(&uuid, "d30a0e60!14a2-11ec-8b99-f7736944db8b"); @@ -139,7 +139,7 @@ TEST(BLI_uuid, string_parsing_fail) TEST(BLI_uuid, stream_operator) { std::stringstream ss; - const UUID uuid = {3540651616, 5282, 4588, 139, 153, {0xf7, 0x73, 0x69, 0x44, 0xdb, 0x8b}}; + const bUUID uuid = {3540651616, 5282, 4588, 139, 153, {0xf7, 0x73, 0x69, 0x44, 0xdb, 0x8b}}; ss << uuid; EXPECT_EQ(ss.str(), "d30a0e60-14a2-11ec-8b99-f7736944db8b"); } -- cgit v1.2.3