Skip to content

Commit c0c5e58

Browse files
committed
Use ICUDeleter to encode ucnv_close/uenum_close call into type of deleter of std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=223503 Reviewed by Alex Christensen. Use ICUDeleter<ucnv_close> instead of holding ucnv_close pointer in ICUConverterPtr. This deleter encodes ucnv_close calls into type so that we do not need to hold a pointer to ucnv_close. We also use ICUDeleter<uenum_close> in place where we use UEnumeration. * Modules/applepay/PaymentRequestValidator.mm: (WebCore::validateCurrencyCode): * platform/text/EncodingTables.cpp: (WebCore::jis0208): (WebCore::jis0212): (WebCore::big5): (WebCore::eucKR): (WebCore::gb18030): * platform/text/TextCodecICU.cpp: (WebCore::TextCodecICU::createICUConverter const): * platform/text/TextCodecICU.h: Canonical link: https://commits.webkit.org/235795@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275084 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent ba7d6c6 commit c0c5e58

5 files changed

Lines changed: 37 additions & 10 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
2021-03-26 Yusuke Suzuki <ysuzuki@apple.com>
2+
3+
Use ICUDeleter to encode ucnv_close/uenum_close call into type of deleter of std::unique_ptr
4+
https://bugs.webkit.org/show_bug.cgi?id=223503
5+
6+
Reviewed by Alex Christensen.
7+
8+
Use ICUDeleter<ucnv_close> instead of holding ucnv_close pointer in ICUConverterPtr.
9+
This deleter encodes ucnv_close calls into type so that we do not need to hold a pointer
10+
to ucnv_close.
11+
12+
We also use ICUDeleter<uenum_close> in place where we use UEnumeration.
13+
14+
* Modules/applepay/PaymentRequestValidator.mm:
15+
(WebCore::validateCurrencyCode):
16+
* platform/text/EncodingTables.cpp:
17+
(WebCore::jis0208):
18+
(WebCore::jis0212):
19+
(WebCore::big5):
20+
(WebCore::eucKR):
21+
(WebCore::gb18030):
22+
* platform/text/TextCodecICU.cpp:
23+
(WebCore::TextCodecICU::createICUConverter const):
24+
* platform/text/TextCodecICU.h:
25+
126
2021-03-26 Jessie Berlin <jberlin@webkit.org>
227

328
Update the BEFORE/SINCE, SYSTEM_VERSION_PREFIX, and MACOSX_DEPLOYMENT_TARGET flags

Source/WebCore/Modules/applepay/PaymentRequestValidator.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#import "ApplePayShippingMethod.h"
3333
#import <unicode/ucurr.h>
3434
#import <unicode/uloc.h>
35+
#import <wtf/unicode/icu/ICUHelpers.h>
3536

3637
namespace WebCore {
3738

@@ -115,7 +116,7 @@
115116
return Exception { TypeError, "Missing currency code." };
116117

117118
UErrorCode errorCode = U_ZERO_ERROR;
118-
auto currencyCodes = std::unique_ptr<UEnumeration, void (*)(UEnumeration*)>(ucurr_openISOCurrencies(UCURR_ALL, &errorCode), uenum_close);
119+
auto currencyCodes = std::unique_ptr<UEnumeration, ICUDeleter<uenum_close>>(ucurr_openISOCurrencies(UCURR_ALL, &errorCode));
119120

120121
int32_t length;
121122
while (auto *currencyCodePtr = uenum_next(currencyCodes.get(), &length, &errorCode)) {

Source/WebCore/platform/text/EncodingTables.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ const std::array<std::pair<uint16_t, UChar>, 7724>& jis0208()
10661066
size_t arrayIndex = 0;
10671067

10681068
UErrorCode error = U_ZERO_ERROR;
1069-
auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error), ucnv_close };
1069+
auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error) };
10701070
ASSERT(!error);
10711071

10721072
constexpr size_t range = 94;
@@ -1871,7 +1871,7 @@ const std::array<std::pair<uint16_t, UChar>, 6067>& jis0212()
18711871
size_t arrayIndex = 0;
18721872

18731873
UErrorCode error = U_ZERO_ERROR;
1874-
auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error), ucnv_close };
1874+
auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error) };
18751875
ASSERT(!error);
18761876

18771877
constexpr size_t range = 94;
@@ -4882,7 +4882,7 @@ const std::array<std::pair<uint16_t, UChar32>, 18590>& big5()
48824882
size_t arrayIndex = 0;
48834883

48844884
UErrorCode error = U_ZERO_ERROR;
4885-
auto icuConverter = ICUConverterPtr { ucnv_open("Big-5", &error), ucnv_close };
4885+
auto icuConverter = ICUConverterPtr { ucnv_open("Big-5", &error) };
48864886
ASSERT(!error);
48874887

48884888
uint8_t icuInput[2];
@@ -7072,7 +7072,7 @@ const std::array<std::pair<uint16_t, UChar>, 17048>& eucKR()
70727072
std::call_once(flag, [] {
70737073
array = new std::array<std::pair<uint16_t, UChar>, 17048>;
70747074
UErrorCode error = U_ZERO_ERROR;
7075-
auto icuConverter = ICUConverterPtr { ucnv_open("windows-949", &error), ucnv_close };
7075+
auto icuConverter = ICUConverterPtr { ucnv_open("windows-949", &error) };
70767076
ASSERT(U_SUCCESS(error));
70777077
auto getPair = [icuConverter = WTFMove(icuConverter)] (uint16_t pointer) -> Optional<std::pair<uint16_t, UChar>> {
70787078
std::array<uint8_t, 2> icuInput { static_cast<uint8_t>(pointer / 190u + 0x81), static_cast<uint8_t>(pointer % 190u + 0x41) };
@@ -8611,7 +8611,7 @@ const std::array<UChar, 23940>& gb18030()
86118611
std::call_once(flag, [] {
86128612
array = new std::array<UChar, 23940>;
86138613
UErrorCode error = U_ZERO_ERROR;
8614-
auto icuConverter = ICUConverterPtr { ucnv_open("gb18030", &error), ucnv_close };
8614+
auto icuConverter = ICUConverterPtr { ucnv_open("gb18030", &error) };
86158615
for (size_t pointer = 0; pointer < 23940; pointer++) {
86168616
uint8_t icuInput[2];
86178617
icuInput[0] = pointer / 190 + 0x81;

Source/WebCore/platform/text/TextCodecICU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void TextCodecICU::createICUConverter() const
186186
}
187187

188188
UErrorCode error = U_ZERO_ERROR;
189-
m_converter = ICUConverterPtr { ucnv_open(m_canonicalConverterName, &error), ucnv_close };
189+
m_converter = ICUConverterPtr { ucnv_open(m_canonicalConverterName, &error) };
190190
if (m_converter)
191191
ucnv_setFallback(m_converter.get(), true);
192192
}

Source/WebCore/platform/text/TextCodecICU.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828

2929
#include "TextCodec.h"
3030
#include <unicode/ucnv.h>
31+
#include <wtf/unicode/icu/ICUHelpers.h>
3132

3233
namespace WebCore {
3334

34-
using ICUConverterPtr = std::unique_ptr<UConverter, void (*)(UConverter*)>;
35+
using ICUConverterPtr = std::unique_ptr<UConverter, ICUDeleter<ucnv_close>>;
3536

3637
class TextCodecICU final : public TextCodec {
3738
public:
@@ -52,13 +53,13 @@ class TextCodecICU final : public TextCodec {
5253

5354
const char* const m_encodingName;
5455
const char* const m_canonicalConverterName;
55-
mutable ICUConverterPtr m_converter { nullptr, ucnv_close };
56+
mutable ICUConverterPtr m_converter;
5657
};
5758

5859
struct ICUConverterWrapper {
5960
WTF_MAKE_STRUCT_FAST_ALLOCATED;
6061

61-
ICUConverterPtr converter { nullptr, ucnv_close };
62+
ICUConverterPtr converter;
6263
};
6364

6465
} // namespace WebCore

0 commit comments

Comments
 (0)