From 642d37eb0f36039d99912fc5ed663228ca13308e Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Thu, 17 Jul 2014 20:16:27 +0000 Subject: [PATCH] ICU-11003 Delete cmutex.h; change files using it to from plain C to C++. X-SVN-Rev: 36050 --- icu4c/source/common/cmutex.h | 39 --- icu4c/source/common/common.vcxproj | 4 +- icu4c/source/common/common.vcxproj.filters | 4 +- .../common/{ucnvmbcs.c => ucnvmbcs.cpp} | 275 +++++++++++------- .../common/{ustr_cnv.c => ustr_cnv.cpp} | 6 +- 5 files changed, 171 insertions(+), 157 deletions(-) delete mode 100644 icu4c/source/common/cmutex.h rename icu4c/source/common/{ucnvmbcs.c => ucnvmbcs.cpp} (99%) rename icu4c/source/common/{ustr_cnv.c => ustr_cnv.cpp} (98%) diff --git a/icu4c/source/common/cmutex.h b/icu4c/source/common/cmutex.h deleted file mode 100644 index a3814dd3d36..00000000000 --- a/icu4c/source/common/cmutex.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -********************************************************************** -* Copyright (C) 2013, International Business Machines -* Corporation and others. All Rights Reserved. -********************************************************************** -* -* File cmutex.h -* -* Minimal plain C declarations for ICU mutex functions. -* This header provides a transition path for plain C files that -* formerly included mutex.h, which is now a C++ only header. -* -* This header should not be used for new code. -* -* C++ files should include umutex.h, not this header. -* -*/ - -#ifndef __CMUTEX_H__ -#define __CMUTEX_H__ - -typedef struct UMutex UMutex; - - -/* Lock a mutex. - * @param mutex The given mutex to be locked. Pass NULL to specify - * the global ICU mutex. Recursive locks are an error - * and may cause a deadlock on some platforms. - */ -U_INTERNAL void U_EXPORT2 umtx_lock(UMutex* mutex); - -/* Unlock a mutex. - * @param mutex The given mutex to be unlocked. Pass NULL to specify - * the global ICU mutex. - */ -U_INTERNAL void U_EXPORT2 umtx_unlock (UMutex* mutex); - -#endif - diff --git a/icu4c/source/common/common.vcxproj b/icu4c/source/common/common.vcxproj index 3d12b5a1c07..9a1a5d10b7e 100644 --- a/icu4c/source/common/common.vcxproj +++ b/icu4c/source/common/common.vcxproj @@ -328,7 +328,7 @@ - + @@ -457,7 +457,7 @@ - + diff --git a/icu4c/source/common/common.vcxproj.filters b/icu4c/source/common/common.vcxproj.filters index de082990c38..5082ac19ea5 100644 --- a/icu4c/source/common/common.vcxproj.filters +++ b/icu4c/source/common/common.vcxproj.filters @@ -232,7 +232,7 @@ conversion - + conversion @@ -502,7 +502,7 @@ strings - + strings diff --git a/icu4c/source/common/ucnvmbcs.c b/icu4c/source/common/ucnvmbcs.cpp similarity index 99% rename from icu4c/source/common/ucnvmbcs.c rename to icu4c/source/common/ucnvmbcs.cpp index 143daf69af7..da143d79a01 100644 --- a/icu4c/source/common/ucnvmbcs.c +++ b/icu4c/source/common/ucnvmbcs.cpp @@ -1,11 +1,11 @@ /* ****************************************************************************** * -* Copyright (C) 2000-2013, International Business Machines +* Copyright (C) 2000-2014, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** -* file name: ucnvmbcs.c +* file name: ucnvmbcs.cpp * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 @@ -56,7 +56,9 @@ #include "ucnv_cnv.h" #include "cmemory.h" #include "cstring.h" -#include "cmutex.h" +#include "umutex.h" + +#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) /* control optimizations according to the platform */ #define MBCS_UNROLL_SINGLE_TO_BMP 1 @@ -359,8 +361,161 @@ * adding new ones without crashing an unaware converter */ -static const UConverterImpl _SBCSUTF8Impl; -static const UConverterImpl _DBCSUTF8Impl; +/** + * Callback from ucnv_MBCSEnumToUnicode(), takes 32 mappings from + * consecutive sequences of bytes, starting from the one encoded in value, + * to Unicode code points. (Multiple mappings to reduce per-function call overhead.) + * Does not currently support m:n mappings or reverse fallbacks. + * This function will not be called for sequences of bytes with leading zeros. + * + * @param context an opaque pointer, as passed into ucnv_MBCSEnumToUnicode() + * @param value contains 1..4 bytes of the first byte sequence, right-aligned + * @param codePoints resulting Unicode code points, or negative if a byte sequence does + * not map to anything + * @return TRUE to continue enumeration, FALSE to stop + */ +typedef UBool U_CALLCONV +UConverterEnumToUCallback(const void *context, uint32_t value, UChar32 codePoints[32]); + +static void +ucnv_MBCSLoad(UConverterSharedData *sharedData, + UConverterLoadArgs *pArgs, + const uint8_t *raw, + UErrorCode *pErrorCode); + +static void +ucnv_MBCSUnload(UConverterSharedData *sharedData); + +static void +ucnv_MBCSOpen(UConverter *cnv, + UConverterLoadArgs *pArgs, + UErrorCode *pErrorCode); + +static UChar32 +ucnv_MBCSGetNextUChar(UConverterToUnicodeArgs *pArgs, + UErrorCode *pErrorCode); + +static void +ucnv_MBCSGetStarters(const UConverter* cnv, + UBool starters[256], + UErrorCode *pErrorCode); + +static const char * +ucnv_MBCSGetName(const UConverter *cnv); + +static void +ucnv_MBCSWriteSub(UConverterFromUnicodeArgs *pArgs, + int32_t offsetIndex, + UErrorCode *pErrorCode); + +static UChar32 +ucnv_MBCSGetNextUChar(UConverterToUnicodeArgs *pArgs, + UErrorCode *pErrorCode); + +static void +ucnv_SBCSFromUTF8(UConverterFromUnicodeArgs *pFromUArgs, + UConverterToUnicodeArgs *pToUArgs, + UErrorCode *pErrorCode); + +static void +ucnv_MBCSGetUnicodeSet(const UConverter *cnv, + const USetAdder *sa, + UConverterUnicodeSet which, + UErrorCode *pErrorCode); + +static void +ucnv_DBCSFromUTF8(UConverterFromUnicodeArgs *pFromUArgs, + UConverterToUnicodeArgs *pToUArgs, + UErrorCode *pErrorCode); + +static const UConverterImpl _SBCSUTF8Impl={ + UCNV_MBCS, + + ucnv_MBCSLoad, + ucnv_MBCSUnload, + + ucnv_MBCSOpen, + NULL, + NULL, + + ucnv_MBCSToUnicodeWithOffsets, + ucnv_MBCSToUnicodeWithOffsets, + ucnv_MBCSFromUnicodeWithOffsets, + ucnv_MBCSFromUnicodeWithOffsets, + ucnv_MBCSGetNextUChar, + + ucnv_MBCSGetStarters, + ucnv_MBCSGetName, + ucnv_MBCSWriteSub, + NULL, + ucnv_MBCSGetUnicodeSet, + + NULL, + ucnv_SBCSFromUTF8 +}; + +static const UConverterImpl _DBCSUTF8Impl={ + UCNV_MBCS, + + ucnv_MBCSLoad, + ucnv_MBCSUnload, + + ucnv_MBCSOpen, + NULL, + NULL, + + ucnv_MBCSToUnicodeWithOffsets, + ucnv_MBCSToUnicodeWithOffsets, + ucnv_MBCSFromUnicodeWithOffsets, + ucnv_MBCSFromUnicodeWithOffsets, + ucnv_MBCSGetNextUChar, + + ucnv_MBCSGetStarters, + ucnv_MBCSGetName, + ucnv_MBCSWriteSub, + NULL, + ucnv_MBCSGetUnicodeSet, + + NULL, + ucnv_DBCSFromUTF8 +}; + +static const UConverterImpl _MBCSImpl={ + UCNV_MBCS, + + ucnv_MBCSLoad, + ucnv_MBCSUnload, + + ucnv_MBCSOpen, + NULL, + NULL, + + ucnv_MBCSToUnicodeWithOffsets, + ucnv_MBCSToUnicodeWithOffsets, + ucnv_MBCSFromUnicodeWithOffsets, + ucnv_MBCSFromUnicodeWithOffsets, + ucnv_MBCSGetNextUChar, + + ucnv_MBCSGetStarters, + ucnv_MBCSGetName, + ucnv_MBCSWriteSub, + NULL, + ucnv_MBCSGetUnicodeSet, + NULL, + NULL +}; + + +/* Static data is in tools/makeconv/ucnvstat.c for data-based + * converters. Be sure to update it as well. + */ + +const UConverterSharedData _MBCSData={ + sizeof(UConverterSharedData), 1, + NULL, NULL, NULL, FALSE, &_MBCSImpl, + 0, {} +}; + /* GB 18030 data ------------------------------------------------------------ */ @@ -473,22 +628,6 @@ static int32_t getSISOBytes(SISO_Option option, uint32_t cnvOption, uint8_t *val /* Miscellaneous ------------------------------------------------------------ */ -/** - * Callback from ucnv_MBCSEnumToUnicode(), takes 32 mappings from - * consecutive sequences of bytes, starting from the one encoded in value, - * to Unicode code points. (Multiple mappings to reduce per-function call overhead.) - * Does not currently support m:n mappings or reverse fallbacks. - * This function will not be called for sequences of bytes with leading zeros. - * - * @param context an opaque pointer, as passed into ucnv_MBCSEnumToUnicode() - * @param value contains 1..4 bytes of the first byte sequence, right-aligned - * @param codePoints resulting Unicode code points, or negative if a byte sequence does - * not map to anything - * @return TRUE to continue enumeration, FALSE to stop - */ -typedef UBool U_CALLCONV -UConverterEnumToUCallback(const void *context, uint32_t value, UChar32 codePoints[32]); - /* similar to ucnv_MBCSGetNextUChar() but recursive */ static UBool enumToU(UConverterMBCSTable *mbcsTable, int8_t stateProps[], @@ -987,7 +1126,7 @@ _extFromU(UConverter *cnv, const UConverterSharedData *sharedData, int32_t i; range=gb18030Ranges[0]; - for(i=0; itoUBytes[0], cnv->toUBytes[1], cnv->toUBytes[2], cnv->toUBytes[3]); range=gb18030Ranges[0]; - for(i=0; ioutputType==MBCS_OUTPUT_EXT_ONLY) { - UConverterLoadArgs args={ 0 }; + UConverterLoadArgs args={}; UConverterSharedData *baseSharedData; const int32_t *extIndexes; const char *baseName; @@ -5479,7 +5618,7 @@ unassigned: static void ucnv_MBCSGetStarters(const UConverter* cnv, UBool starters[256], - UErrorCode *pErrorCode) { + UErrorCode *) { const int32_t *state0; int i; @@ -5572,90 +5711,4 @@ ucnv_MBCSGetType(const UConverter* converter) { return (UConverterType)UCNV_MBCS; } -static const UConverterImpl _SBCSUTF8Impl={ - UCNV_MBCS, - - ucnv_MBCSLoad, - ucnv_MBCSUnload, - - ucnv_MBCSOpen, - NULL, - NULL, - - ucnv_MBCSToUnicodeWithOffsets, - ucnv_MBCSToUnicodeWithOffsets, - ucnv_MBCSFromUnicodeWithOffsets, - ucnv_MBCSFromUnicodeWithOffsets, - ucnv_MBCSGetNextUChar, - - ucnv_MBCSGetStarters, - ucnv_MBCSGetName, - ucnv_MBCSWriteSub, - NULL, - ucnv_MBCSGetUnicodeSet, - - NULL, - ucnv_SBCSFromUTF8 -}; - -static const UConverterImpl _DBCSUTF8Impl={ - UCNV_MBCS, - - ucnv_MBCSLoad, - ucnv_MBCSUnload, - - ucnv_MBCSOpen, - NULL, - NULL, - - ucnv_MBCSToUnicodeWithOffsets, - ucnv_MBCSToUnicodeWithOffsets, - ucnv_MBCSFromUnicodeWithOffsets, - ucnv_MBCSFromUnicodeWithOffsets, - ucnv_MBCSGetNextUChar, - - ucnv_MBCSGetStarters, - ucnv_MBCSGetName, - ucnv_MBCSWriteSub, - NULL, - ucnv_MBCSGetUnicodeSet, - - NULL, - ucnv_DBCSFromUTF8 -}; - -static const UConverterImpl _MBCSImpl={ - UCNV_MBCS, - - ucnv_MBCSLoad, - ucnv_MBCSUnload, - - ucnv_MBCSOpen, - NULL, - NULL, - - ucnv_MBCSToUnicodeWithOffsets, - ucnv_MBCSToUnicodeWithOffsets, - ucnv_MBCSFromUnicodeWithOffsets, - ucnv_MBCSFromUnicodeWithOffsets, - ucnv_MBCSGetNextUChar, - - ucnv_MBCSGetStarters, - ucnv_MBCSGetName, - ucnv_MBCSWriteSub, - NULL, - ucnv_MBCSGetUnicodeSet -}; - - -/* Static data is in tools/makeconv/ucnvstat.c for data-based - * converters. Be sure to update it as well. - */ - -const UConverterSharedData _MBCSData={ - sizeof(UConverterSharedData), 1, - NULL, NULL, NULL, FALSE, &_MBCSImpl, - 0 -}; - #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */ diff --git a/icu4c/source/common/ustr_cnv.c b/icu4c/source/common/ustr_cnv.cpp similarity index 98% rename from icu4c/source/common/ustr_cnv.c rename to icu4c/source/common/ustr_cnv.cpp index f46d937daed..b33c6a5ea35 100644 --- a/icu4c/source/common/ustr_cnv.c +++ b/icu4c/source/common/ustr_cnv.cpp @@ -1,11 +1,11 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2013, International Business Machines +* Copyright (C) 1998-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* -* file name: ustr_cnv.c +* file name: ustr_cnv.cpp * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 @@ -24,7 +24,7 @@ #include "unicode/ucnv.h" #include "cstring.h" #include "cmemory.h" -#include "cmutex.h" +#include "umutex.h" #include "ustr_cnv.h" /* mutexed access to a shared default converter ----------------------------- */