Skip to content

Commit c9d0b6a

Browse files
ryzokukenMylesBorins
authored andcommitted
deps: update ICU to 64.2
Update the version of the bundled ICU (deps/icu-small) to ICU version 64.2 (Unicode 12, CLDR 35) Fixes: #26388 PR-URL: #27361 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Steven R Loomis <srloomis@us.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent a49bd36 commit c9d0b6a

File tree

297 files changed

+20512
-13162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+20512
-13162
lines changed

deps/icu-small/LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
COPYRIGHT AND PERMISSION NOTICE (ICU 58 and later)
22

3-
Copyright © 1991-2018 Unicode, Inc. All rights reserved.
4-
Distributed under the Terms of Use in http://www.unicode.org/copyright.html.
3+
Copyright © 1991-2019 Unicode, Inc. All rights reserved.
4+
Distributed under the Terms of Use in https://www.unicode.org/copyright.html.
55

66
Permission is hereby granted, free of charge, to any person obtaining
77
a copy of the Unicode data files and any associated documentation

deps/icu-small/README-SMALL-ICU.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Small ICU sources - auto generated by shrink-icu-src.py
22

33
This directory contains the ICU subset used by --with-intl=small-icu (the default)
4-
It is a strict subset of ICU 63 source files with the following exception(s):
5-
* deps/icu-small/source/data/in/icudt63l.dat : Reduced-size data file
4+
It is a strict subset of ICU 64 source files with the following exception(s):
5+
* deps/icu-small/source/data/in/icudt64l.dat : Reduced-size data file
66

77

88
To rebuild this directory, see ../../tools/icu/README.md

deps/icu-small/source/common/brkeng.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ static void U_CALLCONV _deleteEngine(void *obj) {
124124
U_CDECL_END
125125
U_NAMESPACE_BEGIN
126126

127-
static UMutex gBreakEngineMutex = U_MUTEX_INITIALIZER;
128-
129127
const LanguageBreakEngine *
130128
ICULanguageBreakFactory::getEngineFor(UChar32 c) {
131129
const LanguageBreakEngine *lbe = NULL;
132130
UErrorCode status = U_ZERO_ERROR;
133131

132+
static UMutex gBreakEngineMutex = U_MUTEX_INITIALIZER;
134133
Mutex m(&gBreakEngineMutex);
135134

136135
if (fEngines == NULL) {
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// © 2018 and later: Unicode, Inc. and others.
2+
// License & terms of use: http://www.unicode.org/copyright.html
3+
4+
#ifndef __CAPI_HELPER_H__
5+
#define __CAPI_HELPER_H__
6+
7+
#include "unicode/utypes.h"
8+
9+
U_NAMESPACE_BEGIN
10+
11+
/**
12+
* An internal helper class to help convert between C and C++ APIs.
13+
*/
14+
template<typename CType, typename CPPType, int32_t kMagic>
15+
class IcuCApiHelper {
16+
public:
17+
/**
18+
* Convert from the C type to the C++ type (const version).
19+
*/
20+
static const CPPType* validate(const CType* input, UErrorCode& status);
21+
22+
/**
23+
* Convert from the C type to the C++ type (non-const version).
24+
*/
25+
static CPPType* validate(CType* input, UErrorCode& status);
26+
27+
/**
28+
* Convert from the C++ type to the C type (const version).
29+
*/
30+
const CType* exportConstForC() const;
31+
32+
/**
33+
* Convert from the C++ type to the C type (non-const version).
34+
*/
35+
CType* exportForC();
36+
37+
/**
38+
* Invalidates the object.
39+
*/
40+
~IcuCApiHelper();
41+
42+
private:
43+
/**
44+
* While the object is valid, fMagic equals kMagic.
45+
*/
46+
int32_t fMagic = kMagic;
47+
};
48+
49+
50+
template<typename CType, typename CPPType, int32_t kMagic>
51+
const CPPType*
52+
IcuCApiHelper<CType, CPPType, kMagic>::validate(const CType* input, UErrorCode& status) {
53+
if (U_FAILURE(status)) {
54+
return nullptr;
55+
}
56+
if (input == nullptr) {
57+
status = U_ILLEGAL_ARGUMENT_ERROR;
58+
return nullptr;
59+
}
60+
auto* impl = reinterpret_cast<const CPPType*>(input);
61+
if (static_cast<const IcuCApiHelper<CType, CPPType, kMagic>*>(impl)->fMagic != kMagic) {
62+
status = U_INVALID_FORMAT_ERROR;
63+
return nullptr;
64+
}
65+
return impl;
66+
}
67+
68+
template<typename CType, typename CPPType, int32_t kMagic>
69+
CPPType*
70+
IcuCApiHelper<CType, CPPType, kMagic>::validate(CType* input, UErrorCode& status) {
71+
auto* constInput = static_cast<const CType*>(input);
72+
auto* validated = validate(constInput, status);
73+
return const_cast<CPPType*>(validated);
74+
}
75+
76+
template<typename CType, typename CPPType, int32_t kMagic>
77+
const CType*
78+
IcuCApiHelper<CType, CPPType, kMagic>::exportConstForC() const {
79+
return reinterpret_cast<const CType*>(static_cast<const CPPType*>(this));
80+
}
81+
82+
template<typename CType, typename CPPType, int32_t kMagic>
83+
CType*
84+
IcuCApiHelper<CType, CPPType, kMagic>::exportForC() {
85+
return reinterpret_cast<CType*>(static_cast<CPPType*>(this));
86+
}
87+
88+
template<typename CType, typename CPPType, int32_t kMagic>
89+
IcuCApiHelper<CType, CPPType, kMagic>::~IcuCApiHelper() {
90+
// head off application errors by preventing use of of deleted objects.
91+
fMagic = 0;
92+
}
93+
94+
95+
U_NAMESPACE_END
96+
97+
#endif // __CAPI_HELPER_H__

deps/icu-small/source/common/characterproperties.cpp

+80-30
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,34 @@
2323
#include "umutex.h"
2424
#include "uprops.h"
2525

26+
using icu::LocalPointer;
27+
#if !UCONFIG_NO_NORMALIZATION
28+
using icu::Normalizer2Factory;
29+
using icu::Normalizer2Impl;
30+
#endif
2631
using icu::UInitOnce;
2732
using icu::UnicodeSet;
2833

2934
namespace {
3035

3136
UBool U_CALLCONV characterproperties_cleanup();
3237

38+
constexpr int32_t NUM_INCLUSIONS = UPROPS_SRC_COUNT + UCHAR_INT_LIMIT - UCHAR_INT_START;
39+
3340
struct Inclusion {
3441
UnicodeSet *fSet;
3542
UInitOnce fInitOnce;
3643
};
37-
Inclusion gInclusions[UPROPS_SRC_COUNT]; // cached getInclusions()
44+
Inclusion gInclusions[NUM_INCLUSIONS]; // cached getInclusions()
3845

3946
UnicodeSet *sets[UCHAR_BINARY_LIMIT] = {};
4047

4148
UCPMap *maps[UCHAR_INT_LIMIT - UCHAR_INT_START] = {};
4249

43-
UMutex cpMutex = U_MUTEX_INITIALIZER;
50+
icu::UMutex *cpMutex() {
51+
static icu::UMutex m = U_MUTEX_INITIALIZER;
52+
return &m;
53+
}
4454

4555
//----------------------------------------------------------------
4656
// Inclusions list
@@ -80,43 +90,29 @@ UBool U_CALLCONV characterproperties_cleanup() {
8090
return TRUE;
8191
}
8292

83-
} // namespace
84-
85-
U_NAMESPACE_BEGIN
86-
87-
/*
88-
Reduce excessive reallocation, and make it easier to detect initialization problems.
89-
Usually you don't see smaller sets than this for Unicode 5.0.
90-
*/
91-
constexpr int32_t DEFAULT_INCLUSION_CAPACITY = 3072;
92-
93-
void U_CALLCONV CharacterProperties::initInclusion(UPropertySource src, UErrorCode &errorCode) {
93+
void U_CALLCONV initInclusion(UPropertySource src, UErrorCode &errorCode) {
9494
// This function is invoked only via umtx_initOnce().
95-
// This function is a friend of class UnicodeSet.
96-
9795
U_ASSERT(0 <= src && src < UPROPS_SRC_COUNT);
9896
if (src == UPROPS_SRC_NONE) {
9997
errorCode = U_INTERNAL_PROGRAM_ERROR;
10098
return;
10199
}
102-
UnicodeSet * &incl = gInclusions[src].fSet;
103-
U_ASSERT(incl == nullptr);
100+
U_ASSERT(gInclusions[src].fSet == nullptr);
104101

105-
incl = new UnicodeSet();
106-
if (incl == nullptr) {
102+
LocalPointer<UnicodeSet> incl(new UnicodeSet());
103+
if (incl.isNull()) {
107104
errorCode = U_MEMORY_ALLOCATION_ERROR;
108105
return;
109106
}
110107
USetAdder sa = {
111-
(USet *)incl,
108+
(USet *)incl.getAlias(),
112109
_set_add,
113110
_set_addRange,
114111
_set_addString,
115112
nullptr, // don't need remove()
116113
nullptr // don't need removeRange()
117114
};
118115

119-
incl->ensureCapacity(DEFAULT_INCLUSION_CAPACITY, errorCode);
120116
switch(src) {
121117
case UPROPS_SRC_CHAR:
122118
uchar_addPropertyStarts(&sa, &errorCode);
@@ -183,12 +179,15 @@ void U_CALLCONV CharacterProperties::initInclusion(UPropertySource src, UErrorCo
183179
}
184180

185181
if (U_FAILURE(errorCode)) {
186-
delete incl;
187-
incl = nullptr;
188182
return;
189183
}
190-
// Compact for caching
184+
if (incl->isBogus()) {
185+
errorCode = U_MEMORY_ALLOCATION_ERROR;
186+
return;
187+
}
188+
// Compact for caching.
191189
incl->compact();
190+
gInclusions[src].fSet = incl.orphan();
192191
ucln_common_registerCleanup(UCLN_COMMON_CHARACTERPROPERTIES, characterproperties_cleanup);
193192
}
194193

@@ -199,15 +198,66 @@ const UnicodeSet *getInclusionsForSource(UPropertySource src, UErrorCode &errorC
199198
return nullptr;
200199
}
201200
Inclusion &i = gInclusions[src];
202-
umtx_initOnce(i.fInitOnce, &CharacterProperties::initInclusion, src, errorCode);
201+
umtx_initOnce(i.fInitOnce, &initInclusion, src, errorCode);
203202
return i.fSet;
204203
}
205204

205+
void U_CALLCONV initIntPropInclusion(UProperty prop, UErrorCode &errorCode) {
206+
// This function is invoked only via umtx_initOnce().
207+
U_ASSERT(UCHAR_INT_START <= prop && prop < UCHAR_INT_LIMIT);
208+
int32_t inclIndex = UPROPS_SRC_COUNT + prop - UCHAR_INT_START;
209+
U_ASSERT(gInclusions[inclIndex].fSet == nullptr);
210+
UPropertySource src = uprops_getSource(prop);
211+
const UnicodeSet *incl = getInclusionsForSource(src, errorCode);
212+
if (U_FAILURE(errorCode)) {
213+
return;
214+
}
215+
216+
LocalPointer<UnicodeSet> intPropIncl(new UnicodeSet(0, 0));
217+
if (intPropIncl.isNull()) {
218+
errorCode = U_MEMORY_ALLOCATION_ERROR;
219+
return;
220+
}
221+
int32_t numRanges = incl->getRangeCount();
222+
int32_t prevValue = 0;
223+
for (int32_t i = 0; i < numRanges; ++i) {
224+
UChar32 rangeEnd = incl->getRangeEnd(i);
225+
for (UChar32 c = incl->getRangeStart(i); c <= rangeEnd; ++c) {
226+
// TODO: Get a UCharacterProperty.IntProperty to avoid the property dispatch.
227+
int32_t value = u_getIntPropertyValue(c, prop);
228+
if (value != prevValue) {
229+
intPropIncl->add(c);
230+
prevValue = value;
231+
}
232+
}
233+
}
234+
235+
if (intPropIncl->isBogus()) {
236+
errorCode = U_MEMORY_ALLOCATION_ERROR;
237+
return;
238+
}
239+
// Compact for caching.
240+
intPropIncl->compact();
241+
gInclusions[inclIndex].fSet = intPropIncl.orphan();
242+
ucln_common_registerCleanup(UCLN_COMMON_CHARACTERPROPERTIES, characterproperties_cleanup);
243+
}
244+
245+
} // namespace
246+
247+
U_NAMESPACE_BEGIN
248+
206249
const UnicodeSet *CharacterProperties::getInclusionsForProperty(
207250
UProperty prop, UErrorCode &errorCode) {
208251
if (U_FAILURE(errorCode)) { return nullptr; }
209-
UPropertySource src = uprops_getSource(prop);
210-
return getInclusionsForSource(src, errorCode);
252+
if (UCHAR_INT_START <= prop && prop < UCHAR_INT_LIMIT) {
253+
int32_t inclIndex = UPROPS_SRC_COUNT + prop - UCHAR_INT_START;
254+
Inclusion &i = gInclusions[inclIndex];
255+
umtx_initOnce(i.fInitOnce, &initIntPropInclusion, prop, errorCode);
256+
return i.fSet;
257+
} else {
258+
UPropertySource src = uprops_getSource(prop);
259+
return getInclusionsForSource(src, errorCode);
260+
}
211261
}
212262

213263
U_NAMESPACE_END
@@ -216,7 +266,7 @@ namespace {
216266

217267
UnicodeSet *makeSet(UProperty property, UErrorCode &errorCode) {
218268
if (U_FAILURE(errorCode)) { return nullptr; }
219-
icu::LocalPointer<UnicodeSet> set(new UnicodeSet());
269+
LocalPointer<UnicodeSet> set(new UnicodeSet());
220270
if (set.isNull()) {
221271
errorCode = U_MEMORY_ALLOCATION_ERROR;
222272
return nullptr;
@@ -311,7 +361,7 @@ u_getBinaryPropertySet(UProperty property, UErrorCode *pErrorCode) {
311361
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
312362
return nullptr;
313363
}
314-
Mutex m(&cpMutex);
364+
Mutex m(cpMutex());
315365
UnicodeSet *set = sets[property];
316366
if (set == nullptr) {
317367
sets[property] = set = makeSet(property, *pErrorCode);
@@ -327,7 +377,7 @@ u_getIntPropertyMap(UProperty property, UErrorCode *pErrorCode) {
327377
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
328378
return nullptr;
329379
}
330-
Mutex m(&cpMutex);
380+
Mutex m(cpMutex());
331381
UCPMap *map = maps[property - UCHAR_INT_START];
332382
if (map == nullptr) {
333383
maps[property - UCHAR_INT_START] = map = makeMap(property, *pErrorCode);

0 commit comments

Comments
 (0)