From 39038085714cbc48230a74a6ed7f057cd3e05df9 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 25 Apr 2016 23:30:06 +0900 Subject: [PATCH] Fix for the warning C28112: A variable which is accessed via an Interlocked function must always be accessed via an Interlocked function --- Src/Merge.cpp | 1 + Src/charsets.c | 61 ++++++++++++++++++++++------------------------------------ Src/charsets.h | 1 + 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/Src/Merge.cpp b/Src/Merge.cpp index f669e9f05..164ef32cc 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -354,6 +354,7 @@ BOOL CMergeApp::InitInstance() m_pOptions->SaveOption(OPT_FILEFILTER_CURRENT, filter); } + charsets_init(); UpdateCodepageModule(); if (m_pSourceControl) diff --git a/Src/charsets.c b/Src/charsets.c index 77d94b994..1834b832c 100644 --- a/Src/charsets.c +++ b/Src/charsets.c @@ -16,9 +16,6 @@ #include #ifndef _WIN32 #include -#define InterlockedCompareExchangePointer(addr, newv, oldv) __sync_val_compare_and_swap(addr, oldv, newv) -#else -#include #endif #include "charsets.h" @@ -1006,18 +1003,6 @@ static int SortCompareByCodePage(const void *elem1, const void *elem2) static struct _charsetInfo const *FindByName(const char *name) { struct _charsetInfo const *info = NULL; - if (index1 == NULL) - { - size_t i; - const struct _charsetInfo **index = (struct _charsetInfo **)calloc(numCharsetInfo, sizeof(void *)); - for (i = numCharsetInfo ; i-- ; ) - { - index[i] = charsetInfo + i; - } - qsort((void*)index, numCharsetInfo, sizeof(void *), CompareByName); - if (InterlockedCompareExchangePointer((void **)&index1, (void *)index, NULL) != NULL) - free((void *)index); - } if (index1 && name) { struct _charsetInfo const key = {0, name, 0, no}; @@ -1034,17 +1019,6 @@ static struct _charsetInfo const *FindByName(const char *name) static struct _charsetInfo const *FindById(unsigned id) { size_t numIndex = charsetInfo[numCharsetInfo - 1].id + 1; - if (index2 == NULL) - { - size_t i; - const struct _charsetInfo **index = (struct _charsetInfo **)calloc(numIndex, sizeof(void *)); - for (i = numCharsetInfo ; i-- ; ) - { - index[charsetInfo[i].id] = charsetInfo + i; - } - if (InterlockedCompareExchangePointer((void **)&index2, (void *)index, NULL) != NULL) - free((void *)index); - } return index2 && id < numIndex ? index2[id] : NULL; } @@ -1052,18 +1026,6 @@ static struct _charsetInfo const *FindByCodePage(unsigned codepage) { struct _charsetInfo const *info = NULL; size_t numIndex = charsetInfo[numCharsetInfo - 1].id + 1; - if (index3 == NULL) - { - size_t i; - const struct _charsetInfo **index = (struct _charsetInfo **)calloc(numIndex, sizeof(void *)); - for (i = numCharsetInfo + 1 ; i-- ; ) - { - index[charsetInfo[i].id] = charsetInfo + i; - } - qsort((void*)index, numIndex, sizeof(void *), SortCompareByCodePage); - if (InterlockedCompareExchangePointer((void **)&index3, (void *)index, NULL) != NULL) - free((void *)index); - } if (index3 && codepage) { struct _charsetInfo const key = {0, 0, codepage, no}; @@ -1077,6 +1039,29 @@ static struct _charsetInfo const *FindByCodePage(unsigned codepage) return info; } +void charsets_init(void) +{ + size_t i; + size_t numIndex = charsetInfo[numCharsetInfo - 1].id + 1; + index1 = (struct _charsetInfo **)calloc(numCharsetInfo, sizeof(void *)); + for (i = numCharsetInfo ; i-- ; ) + { + index1[i] = charsetInfo + i; + } + qsort((void*)index1, numCharsetInfo, sizeof(void *), CompareByName); + index2 = (struct _charsetInfo **)calloc(numIndex, sizeof(void *)); + for (i = numCharsetInfo ; i-- ; ) + { + index2[charsetInfo[i].id] = charsetInfo + i; + } + index3 = (struct _charsetInfo **)calloc(numIndex, sizeof(void *)); + for (i = numCharsetInfo + 1 ; i-- ; ) + { + index3[charsetInfo[i].id] = charsetInfo + i; + } + qsort((void*)index3, numIndex, sizeof(void *), SortCompareByCodePage); +} + void charsets_cleanup(void) { if (index1) diff --git a/Src/charsets.h b/Src/charsets.h index b4df16ed5..dac4259ff 100644 --- a/Src/charsets.h +++ b/Src/charsets.h @@ -23,6 +23,7 @@ extern unsigned GetEncodingCodePageFromId(unsigned id); extern const char *GetEncodingNameFromId(unsigned id); extern const char *GetEncodingNameFromCodePage(unsigned cp); +extern void charsets_init(void); extern void charsets_cleanup(void); #undef extern -- 2.11.0