@@ -42,7 +42,7 @@ swift::UUID::UUID(FromRandom_t) {
42
42
43
43
swift::UUID::UUID (FromTime_t) {
44
44
#if defined(_WIN32)
45
- ::GUID uuid;
45
+ ::UUID uuid;
46
46
::CoCreateGuid (&uuid);
47
47
48
48
memcpy (Value, &uuid, Size);
@@ -53,7 +53,8 @@ swift::UUID::UUID(FromTime_t) {
53
53
54
54
swift::UUID::UUID () {
55
55
#if defined(_WIN32)
56
- ::GUID uuid = GUID ();
56
+ ::UUID uuid = *((::UUID *)&Value);
57
+ UuidCreateNil (&uuid);
57
58
58
59
memcpy (Value, &uuid, Size);
59
60
#else
@@ -63,18 +64,11 @@ swift::UUID::UUID() {
63
64
64
65
Optional<swift::UUID> swift::UUID::fromString (const char *s) {
65
66
#if defined(_WIN32)
66
- int length = strlen (s) + 1 ;
67
- wchar_t *unicodeString = new wchar_t [length];
68
-
69
- size_t convertedChars = 0 ;
70
- errno_t conversionResult =
71
- mbstowcs_s (&convertedChars, unicodeString, length, s, length);
72
- assert (conversionResult == 0 &&
73
- " expected successful conversion of char* to wchar_t*" );
74
-
75
- ::GUID uuid;
76
- HRESULT parseResult = CLSIDFromString (unicodeString, &uuid);
77
- if (parseResult != 0 ) {
67
+ RPC_CSTR t = const_cast <RPC_CSTR>(reinterpret_cast <const unsigned char *>(s));
68
+
69
+ ::UUID uuid;
70
+ RPC_STATUS status = UuidFromStringA (t, &uuid);
71
+ if (status == RPC_S_INVALID_STRING_UUID) {
78
72
return None;
79
73
}
80
74
@@ -92,19 +86,14 @@ Optional<swift::UUID> swift::UUID::fromString(const char *s) {
92
86
void swift::UUID::toString (llvm::SmallVectorImpl<char > &out) const {
93
87
out.resize (UUID::StringBufferSize);
94
88
#if defined(_WIN32)
95
- ::GUID uuid;
89
+ ::UUID uuid;
96
90
memcpy (&uuid, Value, Size);
97
91
98
- LPOLESTR unicodeStr;
99
- StringFromCLSID (uuid, &unicodeStr);
100
-
101
- char str[StringBufferSize];
102
- int strLen = wcstombs (str, unicodeStr, sizeof (str));
103
-
104
- assert (strLen == 37 && " expected ascii convertible output from StringFromCLSID." );
105
- (void )strLen;
92
+ RPC_CSTR str;
93
+ UuidToStringA (&uuid, &str);
106
94
107
- memcpy (out.data (), str, StringBufferSize);
95
+ char * signedStr = reinterpret_cast <char *>(str);
96
+ memcpy (out.data (), signedStr, StringBufferSize);
108
97
#else
109
98
uuid_unparse_upper (Value, out.data ());
110
99
#endif
@@ -115,13 +104,14 @@ void swift::UUID::toString(llvm::SmallVectorImpl<char> &out) const {
115
104
116
105
int swift::UUID::compare (UUID y) const {
117
106
#if defined(_WIN32)
118
- ::GUID uuid1;
107
+ RPC_STATUS s;
108
+ ::UUID uuid1;
119
109
memcpy (&uuid1, Value, Size);
120
110
121
- ::GUID uuid2;
111
+ ::UUID uuid2;
122
112
memcpy (&uuid2, y.Value , Size);
123
113
124
- return memcmp (Value, y. Value , Size );
114
+ return UuidCompare (&uuid1, &uuid2, &s );
125
115
#else
126
116
return uuid_compare (Value, y.Value );
127
117
#endif
0 commit comments