/*********************************************************
- * 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
#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[] = {
/*
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;
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;
}
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;
char **argv, // IN (OPT)
char **envp) // IN (OPT)
{
- HashTable_FreeUnsafe(unicodeEncCache);
- unicodeEncCache = NULL;
-
if (argv != NULL) {
Util_FreeStringList(argv, argc + 1);
}
}
}
-
#ifdef TEST_CUSTOM_ICU_DATA_FILE
/*
*-----------------------------------------------------------------------------