Title: [275084] trunk/Source/WebCore
Revision
275084
Author
[email protected]
Date
2021-03-26 02:25:21 -0700 (Fri, 26 Mar 2021)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275083 => 275084)


--- trunk/Source/WebCore/ChangeLog	2021-03-26 08:08:03 UTC (rev 275083)
+++ trunk/Source/WebCore/ChangeLog	2021-03-26 09:25:21 UTC (rev 275084)
@@ -1,3 +1,28 @@
+2021-03-26  Yusuke Suzuki  <[email protected]>
+
+        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:
+
 2021-03-26  Jessie Berlin  <[email protected]>
 
         Update the BEFORE/SINCE, SYSTEM_VERSION_PREFIX, and MACOSX_DEPLOYMENT_TARGET flags

Modified: trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.mm (275083 => 275084)


--- trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.mm	2021-03-26 08:08:03 UTC (rev 275083)
+++ trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.mm	2021-03-26 09:25:21 UTC (rev 275084)
@@ -32,6 +32,7 @@
 #import "ApplePayShippingMethod.h"
 #import <unicode/ucurr.h>
 #import <unicode/uloc.h>
+#import <wtf/unicode/icu/ICUHelpers.h>
 
 namespace WebCore {
 
@@ -115,7 +116,7 @@
         return Exception { TypeError, "Missing currency code." };
 
     UErrorCode errorCode = U_ZERO_ERROR;
-    auto currencyCodes = std::unique_ptr<UEnumeration, void (*)(UEnumeration*)>(ucurr_openISOCurrencies(UCURR_ALL, &errorCode), uenum_close);
+    auto currencyCodes = std::unique_ptr<UEnumeration, ICUDeleter<uenum_close>>(ucurr_openISOCurrencies(UCURR_ALL, &errorCode));
 
     int32_t length;
     while (auto *currencyCodePtr = uenum_next(currencyCodes.get(), &length, &errorCode)) {

Modified: trunk/Source/WebCore/platform/text/EncodingTables.cpp (275083 => 275084)


--- trunk/Source/WebCore/platform/text/EncodingTables.cpp	2021-03-26 08:08:03 UTC (rev 275083)
+++ trunk/Source/WebCore/platform/text/EncodingTables.cpp	2021-03-26 09:25:21 UTC (rev 275084)
@@ -1066,7 +1066,7 @@
         size_t arrayIndex = 0;
         
         UErrorCode error = U_ZERO_ERROR;
-        auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error), ucnv_close };
+        auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error) };
         ASSERT(!error);
 
         constexpr size_t range = 94;
@@ -1871,7 +1871,7 @@
         size_t arrayIndex = 0;
         
         UErrorCode error = U_ZERO_ERROR;
-        auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error), ucnv_close };
+        auto icuConverter = ICUConverterPtr { ucnv_open("EUC-JP", &error) };
         ASSERT(!error);
 
         constexpr size_t range = 94;
@@ -4882,7 +4882,7 @@
         size_t arrayIndex = 0;
         
         UErrorCode error = U_ZERO_ERROR;
-        auto icuConverter = ICUConverterPtr { ucnv_open("Big-5", &error), ucnv_close };
+        auto icuConverter = ICUConverterPtr { ucnv_open("Big-5", &error) };
         ASSERT(!error);
 
         uint8_t icuInput[2];
@@ -7072,7 +7072,7 @@
     std::call_once(flag, [] {
         array = new std::array<std::pair<uint16_t, UChar>, 17048>;
         UErrorCode error = U_ZERO_ERROR;
-        auto icuConverter = ICUConverterPtr { ucnv_open("windows-949", &error), ucnv_close };
+        auto icuConverter = ICUConverterPtr { ucnv_open("windows-949", &error) };
         ASSERT(U_SUCCESS(error));
         auto getPair = [icuConverter = WTFMove(icuConverter)] (uint16_t pointer) -> Optional<std::pair<uint16_t, UChar>> {
             std::array<uint8_t, 2> icuInput { static_cast<uint8_t>(pointer / 190u + 0x81), static_cast<uint8_t>(pointer % 190u + 0x41) };
@@ -8611,7 +8611,7 @@
     std::call_once(flag, [] {
         array = new std::array<UChar, 23940>;
         UErrorCode error = U_ZERO_ERROR;
-        auto icuConverter = ICUConverterPtr { ucnv_open("gb18030", &error), ucnv_close };
+        auto icuConverter = ICUConverterPtr { ucnv_open("gb18030", &error) };
         for (size_t pointer = 0; pointer < 23940; pointer++) {
             uint8_t icuInput[2];
             icuInput[0] = pointer / 190 + 0x81;

Modified: trunk/Source/WebCore/platform/text/TextCodecICU.cpp (275083 => 275084)


--- trunk/Source/WebCore/platform/text/TextCodecICU.cpp	2021-03-26 08:08:03 UTC (rev 275083)
+++ trunk/Source/WebCore/platform/text/TextCodecICU.cpp	2021-03-26 09:25:21 UTC (rev 275084)
@@ -186,7 +186,7 @@
     }
 
     UErrorCode error = U_ZERO_ERROR;
-    m_converter = ICUConverterPtr { ucnv_open(m_canonicalConverterName, &error), ucnv_close };
+    m_converter = ICUConverterPtr { ucnv_open(m_canonicalConverterName, &error) };
     if (m_converter)
         ucnv_setFallback(m_converter.get(), true);
 }

Modified: trunk/Source/WebCore/platform/text/TextCodecICU.h (275083 => 275084)


--- trunk/Source/WebCore/platform/text/TextCodecICU.h	2021-03-26 08:08:03 UTC (rev 275083)
+++ trunk/Source/WebCore/platform/text/TextCodecICU.h	2021-03-26 09:25:21 UTC (rev 275084)
@@ -28,10 +28,11 @@
 
 #include "TextCodec.h"
 #include <unicode/ucnv.h>
+#include <wtf/unicode/icu/ICUHelpers.h>
 
 namespace WebCore {
 
-using ICUConverterPtr = std::unique_ptr<UConverter, void (*)(UConverter*)>;
+using ICUConverterPtr = std::unique_ptr<UConverter, ICUDeleter<ucnv_close>>;
 
 class TextCodecICU final : public TextCodec {
 public:
@@ -52,13 +53,13 @@
 
     const char* const m_encodingName;
     const char* const m_canonicalConverterName;
-    mutable ICUConverterPtr m_converter { nullptr, ucnv_close };
+    mutable ICUConverterPtr m_converter;
 };
 
 struct ICUConverterWrapper {
     WTF_MAKE_STRUCT_FAST_ALLOCATED;
 
-    ICUConverterPtr converter { nullptr, ucnv_close };
+    ICUConverterPtr converter;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to