]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Backout previous change to lib/unicode/unicodeSimpleTypes.c
authorOliver Kurth <okurth@vmware.com>
Tue, 17 Mar 2020 21:36:58 +0000 (14:36 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 17 Mar 2020 21:36:58 +0000 (14:36 -0700)
open-vm-tools/lib/unicode/unicodeSimpleTypes.c

index 0f33801681737322d00330c22cd4bceb728f5401..5ace167e2fa371235fe6863fb6b99e3f69e5487c 100644 (file)
@@ -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
 /*
  *-----------------------------------------------------------------------------