Skip to content

Commit

Permalink
tools: update icu to 65.1
Browse files Browse the repository at this point in the history
Update the version of the bundled ICU (deps/icu-small) to ICU version
65.2.

Fixes: #30211
Fixes: #29540

PR-URL: #30232
Reviewed-By: Steven R Loomis <srloomis@us.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
  • Loading branch information
albertyw authored and targos committed Dec 9, 2019
1 parent c440f3f commit 0cb7720
Show file tree
Hide file tree
Showing 453 changed files with 11,832 additions and 5,897 deletions.
4 changes: 2 additions & 2 deletions deps/icu-small/README-FULL-ICU.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ICU sources - auto generated by shrink-icu-src.py

This directory contains the ICU subset used by --with-intl=full-icu
It is a strict subset of ICU 64 source files with the following exception(s):
* deps/icu-small/source/data/in/icudt64l.dat.bz2 : compressed data file
It is a strict subset of ICU 65 source files with the following exception(s):
* deps/icu-small/source/data/in/icudt65l.dat.bz2 : compressed data file


To rebuild this directory, see ../../tools/icu/README.md
2 changes: 1 addition & 1 deletion deps/icu-small/source/common/brkeng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ ICULanguageBreakFactory::getEngineFor(UChar32 c) {
const LanguageBreakEngine *lbe = NULL;
UErrorCode status = U_ZERO_ERROR;

static UMutex gBreakEngineMutex = U_MUTEX_INITIALIZER;
static UMutex gBreakEngineMutex;
Mutex m(&gBreakEngineMutex);

if (fEngines == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion deps/icu-small/source/common/brkiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ ICUBreakIteratorService::~ICUBreakIteratorService() {}
// defined in ucln_cmn.h
U_NAMESPACE_END

static icu::UInitOnce gInitOnceBrkiter;
static icu::UInitOnce gInitOnceBrkiter = U_INITONCE_INITIALIZER;
static icu::ICULocaleService* gService = NULL;


Expand Down
2 changes: 1 addition & 1 deletion deps/icu-small/source/common/bytesinkutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class U_COMMON_API ByteSinkUtil {
ByteSink &sink, uint32_t options, Edits *edits);
};

class CharStringByteSink : public ByteSink {
class U_COMMON_API CharStringByteSink : public ByteSink {
public:
CharStringByteSink(CharString* dest);
~CharStringByteSink() override;
Expand Down
13 changes: 5 additions & 8 deletions deps/icu-small/source/common/characterproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ UBool U_CALLCONV characterproperties_cleanup();
constexpr int32_t NUM_INCLUSIONS = UPROPS_SRC_COUNT + UCHAR_INT_LIMIT - UCHAR_INT_START;

struct Inclusion {
UnicodeSet *fSet;
UInitOnce fInitOnce;
UnicodeSet *fSet = nullptr;
UInitOnce fInitOnce = U_INITONCE_INITIALIZER;
};
Inclusion gInclusions[NUM_INCLUSIONS]; // cached getInclusions()

UnicodeSet *sets[UCHAR_BINARY_LIMIT] = {};

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

icu::UMutex *cpMutex() {
static icu::UMutex m = U_MUTEX_INITIALIZER;
return &m;
}
icu::UMutex cpMutex;

//----------------------------------------------------------------
// Inclusions list
Expand Down Expand Up @@ -361,7 +358,7 @@ u_getBinaryPropertySet(UProperty property, UErrorCode *pErrorCode) {
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
return nullptr;
}
Mutex m(cpMutex());
Mutex m(&cpMutex);
UnicodeSet *set = sets[property];
if (set == nullptr) {
sets[property] = set = makeSet(property, *pErrorCode);
Expand All @@ -377,7 +374,7 @@ u_getIntPropertyMap(UProperty property, UErrorCode *pErrorCode) {
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
return nullptr;
}
Mutex m(cpMutex());
Mutex m(&cpMutex);
UCPMap *map = maps[property - UCHAR_INT_START];
if (map == nullptr) {
maps[property - UCHAR_INT_START] = map = makeMap(property, *pErrorCode);
Expand Down
23 changes: 23 additions & 0 deletions deps/icu-small/source/common/charstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ CharString& CharString::operator=(CharString&& src) U_NOEXCEPT {
return *this;
}

char *CharString::cloneData(UErrorCode &errorCode) const {
if (U_FAILURE(errorCode)) { return nullptr; }
char *p = static_cast<char *>(uprv_malloc(len + 1));
if (p == nullptr) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
}
uprv_memcpy(p, buffer.getAlias(), len + 1);
return p;
}

CharString &CharString::copyFrom(const CharString &s, UErrorCode &errorCode) {
if(U_SUCCESS(errorCode) && this!=&s && ensureCapacity(s.len+1, 0, errorCode)) {
len=s.len;
Expand All @@ -52,6 +63,18 @@ int32_t CharString::lastIndexOf(char c) const {
return -1;
}

bool CharString::contains(StringPiece s) const {
if (s.empty()) { return false; }
const char *p = buffer.getAlias();
int32_t lastStart = len - s.length();
for (int32_t i = 0; i <= lastStart; ++i) {
if (uprv_memcmp(p + i, s.data(), s.length()) == 0) {
return true;
}
}
return false;
}

CharString &CharString::truncate(int32_t newLength) {
if(newLength<0) {
newLength=0;
Expand Down
14 changes: 14 additions & 0 deletions deps/icu-small/source/common/charstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,24 @@ class U_COMMON_API CharString : public UMemory {

const char *data() const { return buffer.getAlias(); }
char *data() { return buffer.getAlias(); }
/**
* Allocates length()+1 chars and copies the NUL-terminated data().
* The caller must uprv_free() the result.
*/
char *cloneData(UErrorCode &errorCode) const;

bool operator==(StringPiece other) const {
return len == other.length() && (len == 0 || uprv_memcmp(data(), other.data(), len) == 0);
}
bool operator!=(StringPiece other) const {
return !operator==(other);
}

/** @return last index of c, or -1 if c is not in this string */
int32_t lastIndexOf(char c) const;

bool contains(StringPiece s) const;

CharString &clear() { len=0; buffer[0]=0; return *this; }
CharString &truncate(int32_t newLength);

Expand Down
45 changes: 22 additions & 23 deletions deps/icu-small/source/common/cmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,37 @@ uprv_free(void *mem);
U_CAPI void * U_EXPORT2
uprv_calloc(size_t num, size_t size) U_MALLOC_ATTR U_ALLOC_SIZE_ATTR2(1,2);

/**
* This should align the memory properly on any machine.
* This is very useful for the safeClone functions.
*/
typedef union {
long t1;
double t2;
void *t3;
} UAlignedMemory;

/**
* Get the least significant bits of a pointer (a memory address).
* For example, with a mask of 3, the macro gets the 2 least significant bits,
* which will be 0 if the pointer is 32-bit (4-byte) aligned.
*
* ptrdiff_t is the most appropriate integer type to cast to.
* size_t should work too, since on most (or all?) platforms it has the same
* width as ptrdiff_t.
* uintptr_t is the most appropriate integer type to cast to.
*/
#define U_POINTER_MASK_LSB(ptr, mask) (((ptrdiff_t)(char *)(ptr)) & (mask))
#define U_POINTER_MASK_LSB(ptr, mask) ((uintptr_t)(ptr) & (mask))

/**
* Get the amount of bytes that a pointer is off by from
* the previous UAlignedMemory-aligned pointer.
*/
#define U_ALIGNMENT_OFFSET(ptr) U_POINTER_MASK_LSB(ptr, sizeof(UAlignedMemory) - 1)

/**
* Get the amount of bytes to add to a pointer
* in order to get the next UAlignedMemory-aligned address.
* Create & return an instance of "type" in statically allocated storage.
* e.g.
* static std::mutex *myMutex = STATIC_NEW(std::mutex);
* To destroy an object created in this way, invoke the destructor explicitly, e.g.
* myMutex->~mutex();
* DO NOT use delete.
* DO NOT use with class UMutex, which has specific support for static instances.
*
* STATIC_NEW is intended for use when
* - We want a static (or global) object.
* - We don't want it to ever be destructed, or to explicitly control destruction,
* to avoid use-after-destruction problems.
* - We want to avoid an ordinary heap allocated object,
* to avoid the possibility of memory allocation failures, and
* to avoid memory leak reports, from valgrind, for example.
* This is defined as a macro rather than a template function because each invocation
* must define distinct static storage for the object being returned.
*/
#define U_ALIGNMENT_OFFSET_UP(ptr) (sizeof(UAlignedMemory) - U_ALIGNMENT_OFFSET(ptr))
#define STATIC_NEW(type) [] () { \
alignas(type) static char storage[sizeof(type)]; \
return new(storage) type();} ()

/**
* Heap clean up function, called from u_cleanup()
Expand Down
2 changes: 1 addition & 1 deletion deps/icu-small/source/common/edits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ UBool Edits::growArray() {
return TRUE;
}

UBool Edits::copyErrorTo(UErrorCode &outErrorCode) {
UBool Edits::copyErrorTo(UErrorCode &outErrorCode) const {
if (U_FAILURE(outErrorCode)) { return TRUE; }
if (U_SUCCESS(errorCode_)) { return FALSE; }
outErrorCode = errorCode_;
Expand Down
2 changes: 1 addition & 1 deletion deps/icu-small/source/common/filteredbrk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class SimpleFilteredSentenceBreakIterator : public BreakIterator {
status = U_SAFECLONE_ALLOCATED_WARNING;
return clone();
}
virtual BreakIterator* clone(void) const { return new SimpleFilteredSentenceBreakIterator(*this); }
virtual SimpleFilteredSentenceBreakIterator* clone() const { return new SimpleFilteredSentenceBreakIterator(*this); }
virtual UClassID getDynamicClassID(void) const { return NULL; }
virtual UBool operator==(const BreakIterator& o) const { if(this==&o) return true; return false; }

Expand Down
60 changes: 46 additions & 14 deletions deps/icu-small/source/common/localebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,18 @@ _isKeywordValue(const char* key, const char* value, int32_t value_len)
}

static void
_copyExtensions(const Locale& from, Locale* to, bool validate, UErrorCode& errorCode)
_copyExtensions(const Locale& from, icu::StringEnumeration *keywords,
Locale& to, bool validate, UErrorCode& errorCode)
{
if (U_FAILURE(errorCode)) { return; }
LocalPointer<icu::StringEnumeration> iter(from.createKeywords(errorCode));
if (U_FAILURE(errorCode) || iter.isNull()) { return; }
LocalPointer<icu::StringEnumeration> ownedKeywords;
if (keywords == nullptr) {
ownedKeywords.adoptInstead(from.createKeywords(errorCode));
if (U_FAILURE(errorCode) || ownedKeywords.isNull()) { return; }
keywords = ownedKeywords.getAlias();
}
const char* key;
while ((key = iter->next(nullptr, errorCode)) != nullptr) {
while ((key = keywords->next(nullptr, errorCode)) != nullptr) {
CharString value;
CharStringByteSink sink(&value);
from.getKeywordValue(key, sink, errorCode);
Expand All @@ -176,34 +181,34 @@ _copyExtensions(const Locale& from, Locale* to, bool validate, UErrorCode& error
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
to->setKeywordValue(key, value.data(), errorCode);
to.setKeywordValue(key, value.data(), errorCode);
if (U_FAILURE(errorCode)) { return; }
}
}

void static
_clearUAttributesAndKeyType(Locale* locale, UErrorCode& errorCode)
_clearUAttributesAndKeyType(Locale& locale, UErrorCode& errorCode)
{
// Clear Unicode attributes
locale->setKeywordValue(kAttributeKey, "", errorCode);
locale.setKeywordValue(kAttributeKey, "", errorCode);

// Clear all Unicode keyword values
LocalPointer<icu::StringEnumeration> iter(locale->createUnicodeKeywords(errorCode));
LocalPointer<icu::StringEnumeration> iter(locale.createUnicodeKeywords(errorCode));
if (U_FAILURE(errorCode) || iter.isNull()) { return; }
const char* key;
while ((key = iter->next(nullptr, errorCode)) != nullptr) {
locale->setUnicodeKeywordValue(key, nullptr, errorCode);
locale.setUnicodeKeywordValue(key, nullptr, errorCode);
}
}

static void
_setUnicodeExtensions(Locale* locale, const CharString& value, UErrorCode& errorCode)
_setUnicodeExtensions(Locale& locale, const CharString& value, UErrorCode& errorCode)
{
// Add the unicode extensions to extensions_
CharString locale_str("und-u-", errorCode);
locale_str.append(value, errorCode);
_copyExtensions(
Locale::forLanguageTag(locale_str.data(), errorCode),
Locale::forLanguageTag(locale_str.data(), errorCode), nullptr,
locale, false, errorCode);
}

Expand Down Expand Up @@ -235,10 +240,10 @@ LocaleBuilder& LocaleBuilder::setExtension(char key, StringPiece value)
status_);
return *this;
}
_clearUAttributesAndKeyType(extensions_, status_);
_clearUAttributesAndKeyType(*extensions_, status_);
if (U_FAILURE(status_)) { return *this; }
if (!value.empty()) {
_setUnicodeExtensions(extensions_, value_str, status_);
_setUnicodeExtensions(*extensions_, value_str, status_);
}
return *this;
}
Expand Down Expand Up @@ -401,6 +406,24 @@ Locale makeBogusLocale() {
return bogus;
}

void LocaleBuilder::copyExtensionsFrom(const Locale& src, UErrorCode& errorCode)
{
if (U_FAILURE(errorCode)) { return; }
LocalPointer<icu::StringEnumeration> keywords(src.createKeywords(errorCode));
if (U_FAILURE(errorCode) || keywords.isNull() || keywords->count(errorCode) == 0) {
// Error, or no extensions to copy.
return;
}
if (extensions_ == nullptr) {
extensions_ = new Locale();
if (extensions_ == nullptr) {
status_ = U_MEMORY_ALLOCATION_ERROR;
return;
}
}
_copyExtensions(src, keywords.getAlias(), *extensions_, false, errorCode);
}

Locale LocaleBuilder::build(UErrorCode& errorCode)
{
if (U_FAILURE(errorCode)) {
Expand All @@ -425,12 +448,21 @@ Locale LocaleBuilder::build(UErrorCode& errorCode)
}
Locale product(locale_str.data());
if (extensions_ != nullptr) {
_copyExtensions(*extensions_, &product, true, errorCode);
_copyExtensions(*extensions_, nullptr, product, true, errorCode);
}
if (U_FAILURE(errorCode)) {
return makeBogusLocale();
}
return product;
}

UBool LocaleBuilder::copyErrorTo(UErrorCode &outErrorCode) const {
if (U_FAILURE(outErrorCode)) {
// Do not overwrite the older error code
return TRUE;
}
outErrorCode = status_;
return U_FAILURE(outErrorCode);
}

U_NAMESPACE_END
Loading

0 comments on commit 0cb7720

Please sign in to comment.