From: Oliver Kurth Date: Tue, 17 Mar 2020 21:36:58 +0000 (-0700) Subject: Backout previous change to lib/unicode/unicodeSimpleTypes.c X-Git-Tag: stable-11.1.0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1aab2602bc198fcc98d9aadfbd71771063f6c3b9;p=thirdparty%2Fopen-vm-tools.git Backout previous change to lib/unicode/unicodeSimpleTypes.c --- diff --git a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c index 0f3380168..5ace167e2 100644 --- a/open-vm-tools/lib/unicode/unicodeSimpleTypes.c +++ b/open-vm-tools/lib/unicode/unicodeSimpleTypes.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2020 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2019 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -57,19 +57,12 @@ static char *UnicodeNormalizeEncodingName(const char *encoding); #define UNSUPPORTED FALSE #define IN_FULL_ICU FALSE -/* - * Thread-safe hash table to speed up encoding name -> IANA table - * index lookups. - */ -static Atomic_Ptr unicodeHashTablePtr; -static HashTable *unicodeEncCache = NULL; - static struct xRef { int MIBenum; // Assigned by IANA int winACP; // Windows code page from GetACP() StringEncoding encoding; // ICU encoding enum Bool isSupported; // VMware supported encoding - int preferredMime; // Index of preferred MIME name + int preferredMime; // Index of preferred MIME name const char *names[MAXCHARSETNAMES]; // Encoding name and aliases } xRef[] = { /* @@ -2470,6 +2463,13 @@ UnicodeNormalizeEncodingName(const char *encodingName) // IN static int UnicodeIANALookup(const char *encodingName) // IN { + /* + * Thread-safe hash table to speed up encoding name -> IANA table + * index lookups. + */ + static Atomic_Ptr htPtr; + static HashTable *encCache = NULL; + char *name = NULL; char *candidate = NULL; const char *p; @@ -2479,15 +2479,12 @@ UnicodeIANALookup(const char *encodingName) // IN void *idx; size_t windowsPrefixLen = sizeof "windows-" - 1 /* NUL */; - if (UNLIKELY(unicodeEncCache == NULL)) { - unicodeEncCache = - HashTable_AllocOnce(&unicodeHashTablePtr, 128, - HASH_ISTRING_KEY | HASH_FLAG_ATOMIC | - HASH_FLAG_COPYKEY, NULL); + if (UNLIKELY(encCache == NULL)) { + encCache = HashTable_AllocOnce(&htPtr, 128, HASH_ISTRING_KEY | HASH_FLAG_ATOMIC | + HASH_FLAG_COPYKEY, free); } - if (unicodeEncCache && - HashTable_Lookup(unicodeEncCache, encodingName, &idx)) { + if (encCache && HashTable_Lookup(encCache, encodingName, &idx)) { return (int)(uintptr_t)idx; } @@ -2549,8 +2546,8 @@ done: free(name); free(candidate); - if (unicodeEncCache) { - HashTable_Insert(unicodeEncCache, encodingName, (void *)(uintptr_t)i); + if (encCache) { + HashTable_Insert(encCache, encodingName, (void *)(uintptr_t)i); } return i; @@ -2940,9 +2937,6 @@ Unicode_Shutdown(int argc, // IN char **argv, // IN (OPT) char **envp) // IN (OPT) { - HashTable_FreeUnsafe(unicodeEncCache); - unicodeEncCache = NULL; - if (argv != NULL) { Util_FreeStringList(argv, argc + 1); } @@ -2952,7 +2946,6 @@ Unicode_Shutdown(int argc, // IN } } - #ifdef TEST_CUSTOM_ICU_DATA_FILE /* *-----------------------------------------------------------------------------