diff options
Diffstat (limited to 'src/dutil/dictutil.cpp')
| -rw-r--r-- | src/dutil/dictutil.cpp | 111 |
1 files changed, 63 insertions, 48 deletions
diff --git a/src/dutil/dictutil.cpp b/src/dutil/dictutil.cpp index 1f0f9e43..0d0743eb 100644 --- a/src/dutil/dictutil.cpp +++ b/src/dutil/dictutil.cpp | |||
| @@ -2,6 +2,21 @@ | |||
| 2 | 2 | ||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | |||
| 6 | // Exit macros | ||
| 7 | #define DictExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
| 8 | #define DictExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
| 9 | #define DictExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
| 10 | #define DictExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define DictExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define DictExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DICTUTIL, x, s, __VA_ARGS__) | ||
| 13 | #define DictExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DICTUTIL, p, x, e, s, __VA_ARGS__) | ||
| 14 | #define DictExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, p, x, s, __VA_ARGS__) | ||
| 15 | #define DictExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DICTUTIL, p, x, e, s, __VA_ARGS__) | ||
| 16 | #define DictExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DICTUTIL, p, x, s, __VA_ARGS__) | ||
| 17 | #define DictExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DICTUTIL, e, x, s, __VA_ARGS__) | ||
| 18 | #define DictExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DICTUTIL, g, x, s, __VA_ARGS__) | ||
| 19 | |||
| 5 | // These should all be primes, and spaced reasonably apart (currently each is about 4x the last) | 20 | // These should all be primes, and spaced reasonably apart (currently each is about 4x the last) |
| 6 | const DWORD MAX_BUCKET_SIZES[] = { | 21 | const DWORD MAX_BUCKET_SIZES[] = { |
| 7 | 503, | 22 | 503, |
| @@ -61,7 +76,7 @@ static HRESULT StringHash( | |||
| 61 | __in const STRINGDICT_STRUCT *psd, | 76 | __in const STRINGDICT_STRUCT *psd, |
| 62 | __in DWORD dwNumBuckets, | 77 | __in DWORD dwNumBuckets, |
| 63 | __in_z LPCWSTR pszString, | 78 | __in_z LPCWSTR pszString, |
| 64 | __out LPDWORD pdwHash | 79 | __out DWORD *pdwHash |
| 65 | ); | 80 | ); |
| 66 | static BOOL IsMatchExact( | 81 | static BOOL IsMatchExact( |
| 67 | __in const STRINGDICT_STRUCT *psd, | 82 | __in const STRINGDICT_STRUCT *psd, |
| @@ -122,11 +137,11 @@ extern "C" HRESULT DAPI DictCreateWithEmbeddedKey( | |||
| 122 | { | 137 | { |
| 123 | HRESULT hr = S_OK; | 138 | HRESULT hr = S_OK; |
| 124 | 139 | ||
| 125 | ExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); | 140 | DictExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); |
| 126 | 141 | ||
| 127 | // Allocate the handle | 142 | // Allocate the handle |
| 128 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); | 143 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); |
| 129 | ExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); | 144 | DictExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); |
| 130 | 145 | ||
| 131 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); | 146 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); |
| 132 | 147 | ||
| @@ -151,7 +166,7 @@ extern "C" HRESULT DAPI DictCreateWithEmbeddedKey( | |||
| 151 | 166 | ||
| 152 | // Finally, allocate our initial buckets | 167 | // Finally, allocate our initial buckets |
| 153 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); | 168 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); |
| 154 | ExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); | 169 | DictExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); |
| 155 | 170 | ||
| 156 | LExit: | 171 | LExit: |
| 157 | return hr; | 172 | return hr; |
| @@ -166,11 +181,11 @@ extern "C" HRESULT DAPI DictCreateStringList( | |||
| 166 | { | 181 | { |
| 167 | HRESULT hr = S_OK; | 182 | HRESULT hr = S_OK; |
| 168 | 183 | ||
| 169 | ExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); | 184 | DictExitOnNull(psdHandle, hr, E_INVALIDARG, "Handle not specified while creating dict"); |
| 170 | 185 | ||
| 171 | // Allocate the handle | 186 | // Allocate the handle |
| 172 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); | 187 | *psdHandle = static_cast<STRINGDICT_HANDLE>(MemAlloc(sizeof(STRINGDICT_STRUCT), FALSE)); |
| 173 | ExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); | 188 | DictExitOnNull(*psdHandle, hr, E_OUTOFMEMORY, "Failed to allocate dictionary object"); |
| 174 | 189 | ||
| 175 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); | 190 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(*psdHandle); |
| 176 | 191 | ||
| @@ -195,7 +210,7 @@ extern "C" HRESULT DAPI DictCreateStringList( | |||
| 195 | 210 | ||
| 196 | // Finally, allocate our initial buckets | 211 | // Finally, allocate our initial buckets |
| 197 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); | 212 | psd->ppvBuckets = static_cast<void**>(MemAlloc(sizeof(void *) * MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], TRUE)); |
| 198 | ExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); | 213 | DictExitOnNull(psd->ppvBuckets, hr, E_OUTOFMEMORY, "Failed to allocate buckets for dictionary"); |
| 199 | 214 | ||
| 200 | LExit: | 215 | LExit: |
| 201 | return hr; | 216 | return hr; |
| @@ -212,7 +227,7 @@ extern "C" HRESULT DAPI DictCreateStringListFromArray( | |||
| 212 | STRINGDICT_HANDLE sd = NULL; | 227 | STRINGDICT_HANDLE sd = NULL; |
| 213 | 228 | ||
| 214 | hr = DictCreateStringList(&sd, cStringArray, dfFlags); | 229 | hr = DictCreateStringList(&sd, cStringArray, dfFlags); |
| 215 | ExitOnFailure(hr, "Failed to create the string dictionary."); | 230 | DictExitOnFailure(hr, "Failed to create the string dictionary."); |
| 216 | 231 | ||
| 217 | for (DWORD i = 0; i < cStringArray; ++i) | 232 | for (DWORD i = 0; i < cStringArray; ++i) |
| 218 | { | 233 | { |
| @@ -221,12 +236,12 @@ extern "C" HRESULT DAPI DictCreateStringListFromArray( | |||
| 221 | hr = DictKeyExists(sd, wzKey); | 236 | hr = DictKeyExists(sd, wzKey); |
| 222 | if (E_NOTFOUND != hr) | 237 | if (E_NOTFOUND != hr) |
| 223 | { | 238 | { |
| 224 | ExitOnFailure(hr, "Failed to check the string dictionary."); | 239 | DictExitOnFailure(hr, "Failed to check the string dictionary."); |
| 225 | } | 240 | } |
| 226 | else | 241 | else |
| 227 | { | 242 | { |
| 228 | hr = DictAddKey(sd, wzKey); | 243 | hr = DictAddKey(sd, wzKey); |
| 229 | ExitOnFailure(hr, "Failed to add \"%ls\" to the string dictionary.", wzKey); | 244 | DictExitOnFailure(hr, "Failed to add \"%ls\" to the string dictionary.", wzKey); |
| 230 | } | 245 | } |
| 231 | } | 246 | } |
| 232 | 247 | ||
| @@ -252,7 +267,7 @@ extern "C" HRESULT DAPI DictCompareStringListToArray( | |||
| 252 | hr = DictKeyExists(sdStringList, rgwzStringArray[i]); | 267 | hr = DictKeyExists(sdStringList, rgwzStringArray[i]); |
| 253 | if (E_NOTFOUND != hr) | 268 | if (E_NOTFOUND != hr) |
| 254 | { | 269 | { |
| 255 | ExitOnFailure(hr, "Failed to check the string dictionary."); | 270 | DictExitOnFailure(hr, "Failed to check the string dictionary."); |
| 256 | ExitFunction1(hr = S_OK); | 271 | ExitFunction1(hr = S_OK); |
| 257 | } | 272 | } |
| 258 | } | 273 | } |
| @@ -273,19 +288,19 @@ extern "C" HRESULT DAPI DictAddKey( | |||
| 273 | DWORD dwIndex = 0; | 288 | DWORD dwIndex = 0; |
| 274 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); | 289 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); |
| 275 | 290 | ||
| 276 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); | 291 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); |
| 277 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while adding value to dict"); | 292 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while adding value to dict"); |
| 278 | 293 | ||
| 279 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 294 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
| 280 | { | 295 | { |
| 281 | hr = E_INVALIDARG; | 296 | hr = E_INVALIDARG; |
| 282 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 297 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
| 283 | } | 298 | } |
| 284 | 299 | ||
| 285 | if (DICT_STRING_LIST != psd->dtType) | 300 | if (DICT_STRING_LIST != psd->dtType) |
| 286 | { | 301 | { |
| 287 | hr = E_INVALIDARG; | 302 | hr = E_INVALIDARG; |
| 288 | ExitOnFailure(hr, "Tried to add key without value to wrong dictionary type! This dictionary type is: %d", psd->dtType); | 303 | DictExitOnFailure(hr, "Tried to add key without value to wrong dictionary type! This dictionary type is: %d", psd->dtType); |
| 289 | } | 304 | } |
| 290 | 305 | ||
| 291 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) | 306 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) |
| @@ -299,18 +314,18 @@ extern "C" HRESULT DAPI DictAddKey( | |||
| 299 | hr = S_OK; | 314 | hr = S_OK; |
| 300 | } | 315 | } |
| 301 | } | 316 | } |
| 302 | ExitOnFailure(hr, "Failed to grow dictionary"); | 317 | DictExitOnFailure(hr, "Failed to grow dictionary"); |
| 303 | } | 318 | } |
| 304 | 319 | ||
| 305 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, pszString, &dwIndex); | 320 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, pszString, &dwIndex); |
| 306 | ExitOnFailure(hr, "Failed to get index to insert into"); | 321 | DictExitOnFailure(hr, "Failed to get index to insert into"); |
| 307 | 322 | ||
| 308 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); | 323 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); |
| 309 | ExitOnFailure(hr, "Failed to resize list of items in dictionary"); | 324 | DictExitOnFailure(hr, "Failed to resize list of items in dictionary"); |
| 310 | ++psd->dwNumItems; | 325 | ++psd->dwNumItems; |
| 311 | 326 | ||
| 312 | hr = StrAllocString(reinterpret_cast<LPWSTR *>(&(psd->ppvBuckets[dwIndex])), pszString, 0); | 327 | hr = StrAllocString(reinterpret_cast<LPWSTR *>(&(psd->ppvBuckets[dwIndex])), pszString, 0); |
| 313 | ExitOnFailure(hr, "Failed to allocate copy of string"); | 328 | DictExitOnFailure(hr, "Failed to allocate copy of string"); |
| 314 | 329 | ||
| 315 | psd->ppvItemList[psd->dwNumItems-1] = psd->ppvBuckets[dwIndex]; | 330 | psd->ppvItemList[psd->dwNumItems-1] = psd->ppvBuckets[dwIndex]; |
| 316 | 331 | ||
| @@ -330,23 +345,23 @@ extern "C" HRESULT DAPI DictAddValue( | |||
| 330 | DWORD dwIndex = 0; | 345 | DWORD dwIndex = 0; |
| 331 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); | 346 | STRINGDICT_STRUCT *psd = static_cast<STRINGDICT_STRUCT *>(sdHandle); |
| 332 | 347 | ||
| 333 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); | 348 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while adding value to dict"); |
| 334 | ExitOnNull(pvValue, hr, E_INVALIDARG, "Value not specified while adding value to dict"); | 349 | DictExitOnNull(pvValue, hr, E_INVALIDARG, "Value not specified while adding value to dict"); |
| 335 | 350 | ||
| 336 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 351 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
| 337 | { | 352 | { |
| 338 | hr = E_INVALIDARG; | 353 | hr = E_INVALIDARG; |
| 339 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 354 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
| 340 | } | 355 | } |
| 341 | 356 | ||
| 342 | if (DICT_EMBEDDED_KEY != psd->dtType) | 357 | if (DICT_EMBEDDED_KEY != psd->dtType) |
| 343 | { | 358 | { |
| 344 | hr = E_INVALIDARG; | 359 | hr = E_INVALIDARG; |
| 345 | ExitOnFailure(hr, "Tried to add key/value pair to wrong dictionary type! This dictionary type is: %d", psd->dtType); | 360 | DictExitOnFailure(hr, "Tried to add key/value pair to wrong dictionary type! This dictionary type is: %d", psd->dtType); |
| 346 | } | 361 | } |
| 347 | 362 | ||
| 348 | wzKey = GetKey(psd, pvValue); | 363 | wzKey = GetKey(psd, pvValue); |
| 349 | ExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified while adding value to dict"); | 364 | DictExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified while adding value to dict"); |
| 350 | 365 | ||
| 351 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) | 366 | if ((psd->dwNumItems + 1) >= MAX_BUCKET_SIZES[psd->dwBucketSizeIndex] / MAX_BUCKETS_TO_ITEMS_RATIO) |
| 352 | { | 367 | { |
| @@ -359,14 +374,14 @@ extern "C" HRESULT DAPI DictAddValue( | |||
| 359 | hr = S_OK; | 374 | hr = S_OK; |
| 360 | } | 375 | } |
| 361 | } | 376 | } |
| 362 | ExitOnFailure(hr, "Failed to grow dictionary"); | 377 | DictExitOnFailure(hr, "Failed to grow dictionary"); |
| 363 | } | 378 | } |
| 364 | 379 | ||
| 365 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, wzKey, &dwIndex); | 380 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], psd->ppvBuckets, wzKey, &dwIndex); |
| 366 | ExitOnFailure(hr, "Failed to get index to insert into"); | 381 | DictExitOnFailure(hr, "Failed to get index to insert into"); |
| 367 | 382 | ||
| 368 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); | 383 | hr = MemEnsureArraySize(reinterpret_cast<void **>(&(psd->ppvItemList)), psd->dwNumItems + 1, sizeof(void *), 1000); |
| 369 | ExitOnFailure(hr, "Failed to resize list of items in dictionary"); | 384 | DictExitOnFailure(hr, "Failed to resize list of items in dictionary"); |
| 370 | ++psd->dwNumItems; | 385 | ++psd->dwNumItems; |
| 371 | 386 | ||
| 372 | pvOffset = TranslateValueToOffset(psd, pvValue); | 387 | pvOffset = TranslateValueToOffset(psd, pvValue); |
| @@ -385,15 +400,15 @@ extern "C" HRESULT DAPI DictGetValue( | |||
| 385 | { | 400 | { |
| 386 | HRESULT hr = S_OK; | 401 | HRESULT hr = S_OK; |
| 387 | 402 | ||
| 388 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); | 403 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); |
| 389 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); | 404 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); |
| 390 | 405 | ||
| 391 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); | 406 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); |
| 392 | 407 | ||
| 393 | if (DICT_EMBEDDED_KEY != psd->dtType) | 408 | if (DICT_EMBEDDED_KEY != psd->dtType) |
| 394 | { | 409 | { |
| 395 | hr = E_INVALIDARG; | 410 | hr = E_INVALIDARG; |
| 396 | ExitOnFailure(hr, "Tried to lookup value in wrong dictionary type! This dictionary type is: %d", psd->dtType); | 411 | DictExitOnFailure(hr, "Tried to lookup value in wrong dictionary type! This dictionary type is: %d", psd->dtType); |
| 397 | } | 412 | } |
| 398 | 413 | ||
| 399 | hr = GetValue(psd, pszString, ppvValue); | 414 | hr = GetValue(psd, pszString, ppvValue); |
| @@ -401,7 +416,7 @@ extern "C" HRESULT DAPI DictGetValue( | |||
| 401 | { | 416 | { |
| 402 | ExitFunction(); | 417 | ExitFunction(); |
| 403 | } | 418 | } |
| 404 | ExitOnFailure(hr, "Failed to call internal GetValue()"); | 419 | DictExitOnFailure(hr, "Failed to call internal GetValue()"); |
| 405 | 420 | ||
| 406 | LExit: | 421 | LExit: |
| 407 | return hr; | 422 | return hr; |
| @@ -414,8 +429,8 @@ extern "C" HRESULT DAPI DictKeyExists( | |||
| 414 | { | 429 | { |
| 415 | HRESULT hr = S_OK; | 430 | HRESULT hr = S_OK; |
| 416 | 431 | ||
| 417 | ExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); | 432 | DictExitOnNull(sdHandle, hr, E_INVALIDARG, "Handle not specified while searching dict"); |
| 418 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); | 433 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); |
| 419 | 434 | ||
| 420 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); | 435 | const STRINGDICT_STRUCT *psd = static_cast<const STRINGDICT_STRUCT *>(sdHandle); |
| 421 | 436 | ||
| @@ -425,7 +440,7 @@ extern "C" HRESULT DAPI DictKeyExists( | |||
| 425 | { | 440 | { |
| 426 | ExitFunction(); | 441 | ExitFunction(); |
| 427 | } | 442 | } |
| 428 | ExitOnFailure(hr, "Failed to call internal GetValue()"); | 443 | DictExitOnFailure(hr, "Failed to call internal GetValue()"); |
| 429 | 444 | ||
| 430 | LExit: | 445 | LExit: |
| 431 | return hr; | 446 | return hr; |
| @@ -467,7 +482,7 @@ static HRESULT StringHash( | |||
| 467 | if (DICT_FLAG_CASEINSENSITIVE & psd->dfFlags) | 482 | if (DICT_FLAG_CASEINSENSITIVE & psd->dfFlags) |
| 468 | { | 483 | { |
| 469 | hr = StrAllocStringToUpperInvariant(&sczNewKey, pszString, 0); | 484 | hr = StrAllocStringToUpperInvariant(&sczNewKey, pszString, 0); |
| 470 | ExitOnFailure(hr, "Failed to convert the string to upper-case."); | 485 | DictExitOnFailure(hr, "Failed to convert the string to upper-case."); |
| 471 | 486 | ||
| 472 | wzKey = sczNewKey; | 487 | wzKey = sczNewKey; |
| 473 | } | 488 | } |
| @@ -522,17 +537,17 @@ static HRESULT GetValue( | |||
| 522 | void *pvCandidateValue = NULL; | 537 | void *pvCandidateValue = NULL; |
| 523 | DWORD dwIndex = 0; | 538 | DWORD dwIndex = 0; |
| 524 | 539 | ||
| 525 | ExitOnNull(psd, hr, E_INVALIDARG, "Handle not specified while searching dict"); | 540 | DictExitOnNull(psd, hr, E_INVALIDARG, "Handle not specified while searching dict"); |
| 526 | ExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); | 541 | DictExitOnNull(pszString, hr, E_INVALIDARG, "String not specified while searching dict"); |
| 527 | 542 | ||
| 528 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 543 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
| 529 | { | 544 | { |
| 530 | hr = E_INVALIDARG; | 545 | hr = E_INVALIDARG; |
| 531 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 546 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
| 532 | } | 547 | } |
| 533 | 548 | ||
| 534 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); | 549 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); |
| 535 | ExitOnFailure(hr, "Failed to hash the string."); | 550 | DictExitOnFailure(hr, "Failed to hash the string."); |
| 536 | 551 | ||
| 537 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; | 552 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; |
| 538 | 553 | ||
| @@ -553,7 +568,7 @@ static HRESULT GetValue( | |||
| 553 | { | 568 | { |
| 554 | ExitFunction(); | 569 | ExitFunction(); |
| 555 | } | 570 | } |
| 556 | ExitOnFailure(hr, "Failed to find index to get"); | 571 | DictExitOnFailure(hr, "Failed to find index to get"); |
| 557 | 572 | ||
| 558 | if (NULL != ppvValue) | 573 | if (NULL != ppvValue) |
| 559 | { | 574 | { |
| @@ -581,7 +596,7 @@ static HRESULT GetInsertIndex( | |||
| 581 | DWORD dwOriginalIndexCandidate = 0; | 596 | DWORD dwOriginalIndexCandidate = 0; |
| 582 | 597 | ||
| 583 | hr = StringHash(psd, dwBucketCount, pszString, &dwOriginalIndexCandidate); | 598 | hr = StringHash(psd, dwBucketCount, pszString, &dwOriginalIndexCandidate); |
| 584 | ExitOnFailure(hr, "Failed to hash the string."); | 599 | DictExitOnFailure(hr, "Failed to hash the string."); |
| 585 | 600 | ||
| 586 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; | 601 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; |
| 587 | 602 | ||
| @@ -604,7 +619,7 @@ static HRESULT GetInsertIndex( | |||
| 604 | { | 619 | { |
| 605 | // The dict table is full - this error seems to be a reasonably close match | 620 | // The dict table is full - this error seems to be a reasonably close match |
| 606 | hr = HRESULT_FROM_WIN32(ERROR_DATABASE_FULL); | 621 | hr = HRESULT_FROM_WIN32(ERROR_DATABASE_FULL); |
| 607 | ExitOnRootFailure(hr, "Failed to add item '%ls' to dict table because dict table is full of items", pszString); | 622 | DictExitOnRootFailure(hr, "Failed to add item '%ls' to dict table because dict table is full of items", pszString); |
| 608 | } | 623 | } |
| 609 | } | 624 | } |
| 610 | 625 | ||
| @@ -626,11 +641,11 @@ static HRESULT GetIndex( | |||
| 626 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) | 641 | if (psd->dwBucketSizeIndex >= countof(MAX_BUCKET_SIZES)) |
| 627 | { | 642 | { |
| 628 | hr = E_INVALIDARG; | 643 | hr = E_INVALIDARG; |
| 629 | ExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); | 644 | DictExitOnFailure(hr, "Invalid dictionary - bucket size index is out of range"); |
| 630 | } | 645 | } |
| 631 | 646 | ||
| 632 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); | 647 | hr = StringHash(psd, MAX_BUCKET_SIZES[psd->dwBucketSizeIndex], pszString, &dwOriginalIndexCandidate); |
| 633 | ExitOnFailure(hr, "Failed to hash the string."); | 648 | DictExitOnFailure(hr, "Failed to hash the string."); |
| 634 | 649 | ||
| 635 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; | 650 | DWORD dwIndexCandidate = dwOriginalIndexCandidate; |
| 636 | 651 | ||
| @@ -704,18 +719,18 @@ static HRESULT GrowDictionary( | |||
| 704 | } | 719 | } |
| 705 | 720 | ||
| 706 | hr = ::SizeTMult(sizeof(void *), MAX_BUCKET_SIZES[dwNewBucketSizeIndex], &cbAllocSize); | 721 | hr = ::SizeTMult(sizeof(void *), MAX_BUCKET_SIZES[dwNewBucketSizeIndex], &cbAllocSize); |
| 707 | ExitOnFailure(hr, "Overflow while calculating allocation size to grow dictionary"); | 722 | DictExitOnFailure(hr, "Overflow while calculating allocation size to grow dictionary"); |
| 708 | 723 | ||
| 709 | ppvNewBuckets = static_cast<void**>(MemAlloc(cbAllocSize, TRUE)); | 724 | ppvNewBuckets = static_cast<void**>(MemAlloc(cbAllocSize, TRUE)); |
| 710 | ExitOnNull(ppvNewBuckets, hr, E_OUTOFMEMORY, "Failed to allocate %u buckets while growing dictionary", MAX_BUCKET_SIZES[dwNewBucketSizeIndex]); | 725 | DictExitOnNull(ppvNewBuckets, hr, E_OUTOFMEMORY, "Failed to allocate %u buckets while growing dictionary", MAX_BUCKET_SIZES[dwNewBucketSizeIndex]); |
| 711 | 726 | ||
| 712 | for (DWORD i = 0; i < psd->dwNumItems; ++i) | 727 | for (DWORD i = 0; i < psd->dwNumItems; ++i) |
| 713 | { | 728 | { |
| 714 | wzKey = GetKey(psd, TranslateOffsetToValue(psd, psd->ppvItemList[i])); | 729 | wzKey = GetKey(psd, TranslateOffsetToValue(psd, psd->ppvItemList[i])); |
| 715 | ExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified in existing dict value"); | 730 | DictExitOnNull(wzKey, hr, E_INVALIDARG, "String not specified in existing dict value"); |
| 716 | 731 | ||
| 717 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[dwNewBucketSizeIndex], ppvNewBuckets, wzKey, &dwInsertIndex); | 732 | hr = GetInsertIndex(psd, MAX_BUCKET_SIZES[dwNewBucketSizeIndex], ppvNewBuckets, wzKey, &dwInsertIndex); |
| 718 | ExitOnFailure(hr, "Failed to get index to insert into"); | 733 | DictExitOnFailure(hr, "Failed to get index to insert into"); |
| 719 | 734 | ||
| 720 | ppvNewBuckets[dwInsertIndex] = psd->ppvItemList[i]; | 735 | ppvNewBuckets[dwInsertIndex] = psd->ppvItemList[i]; |
| 721 | } | 736 | } |
