Files
main/programming/misc/icu4c/files/fedora/0008-ICU-22954-Workaround-Replace-std-u16string-member-wi.patch
2025-02-23 12:56:51 +03:00

112 lines
4.0 KiB
Diff

From df0422ed3fc945386c5633cb8f4717fdce31f9fb Mon Sep 17 00:00:00 2001
From: Fredrik Roubert <roubert@google.com>
Date: Mon, 30 Dec 2024 21:26:37 +0900
Subject: [PATCH] ICU-22954 Workaround: Replace std::u16string member with
UnicodeString&.
---
icu4c/source/tools/ctestfw/tstdtmod.cpp | 12 +++++++++---
icu4c/source/tools/ctestfw/unicode/testlog.h | 18 +++++++++++++-----
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/icu4c/source/tools/ctestfw/tstdtmod.cpp b/icu4c/source/tools/ctestfw/tstdtmod.cpp
index 5a8e1ef7365..15e8913d2b8 100644
--- icu4c/source/tools/ctestfw/tstdtmod.cpp
+++ icu4c/source/tools/ctestfw/tstdtmod.cpp
@@ -11,6 +11,7 @@
#include <stdarg.h>
#include "unicode/tstdtmod.h"
+#include "unicode/unistr.h"
#include "cmemory.h"
#include <stdio.h>
#include "cstr.h"
@@ -18,11 +19,17 @@
TestLog::~TestLog() {}
+IcuTestErrorCode::IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName)
+ : errorCode(U_ZERO_ERROR),
+ testClass(callingTestClass), testName(callingTestName), scopeMessage(*new UnicodeString) {
+}
+
IcuTestErrorCode::~IcuTestErrorCode() {
// Safe because our errlog() does not throw exceptions.
if(isFailure()) {
errlog(false, u"destructor: expected success", nullptr);
}
+ delete &scopeMessage;
}
UErrorCode IcuTestErrorCode::reset() {
@@ -119,8 +126,7 @@ UBool IcuTestErrorCode::expectErrorAndReset(UErrorCode expectedError, const char
}
void IcuTestErrorCode::setScope(const char* message) {
- UnicodeString us(message, -1, US_INV);
- scopeMessage = us;
+ scopeMessage.remove().append({ message, -1, US_INV });
}
void IcuTestErrorCode::setScope(std::u16string_view message) {
@@ -136,7 +142,7 @@ void IcuTestErrorCode::errlog(UBool dataErr, std::u16string_view mainMessage, co
msg.append(u' ').append(mainMessage);
msg.append(u" but got error: ").append(UnicodeString(errorName(), -1, US_INV));
- if (!scopeMessage.empty()) {
+ if (!scopeMessage.isEmpty()) {
msg.append(u" scope: ").append(scopeMessage);
}
diff --git a/icu4c/source/tools/ctestfw/unicode/testlog.h b/icu4c/source/tools/ctestfw/unicode/testlog.h
index a5e62e80d73..44e99954f91 100644
--- icu4c/source/tools/ctestfw/unicode/testlog.h
+++ icu4c/source/tools/ctestfw/unicode/testlog.h
@@ -13,7 +13,6 @@
#ifndef U_TESTFW_TESTLOG
#define U_TESTFW_TESTLOG
-#include <string>
#include <string_view>
#include "unicode/utypes.h"
#include "unicode/testtype.h"
@@ -35,14 +34,16 @@ class T_CTEST_EXPORT_API TestLog {
// unit tests that work without U_SHOW_CPLUSPLUS_API.
// So instead we *copy* the ErrorCode API.
+U_NAMESPACE_BEGIN
+class UnicodeString;
+U_NAMESPACE_END
+
class T_CTEST_EXPORT_API IcuTestErrorCode {
public:
IcuTestErrorCode(const IcuTestErrorCode&) = delete;
IcuTestErrorCode& operator=(const IcuTestErrorCode&) = delete;
- IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName)
- : errorCode(U_ZERO_ERROR),
- testClass(callingTestClass), testName(callingTestName), scopeMessage() {}
+ IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName);
virtual ~IcuTestErrorCode();
// ErrorCode API
@@ -75,7 +76,14 @@ class T_CTEST_EXPORT_API IcuTestErrorCode {
UErrorCode errorCode;
TestLog &testClass;
const char *const testName;
- std::u16string scopeMessage;
+
+ // It's not possible to use a UnicodeString member directly here because
+ // that won't work without U_SHOW_CPLUSPLUS_API, but it's also not possible
+ // to use a std::u16string member because for unknown reasons that leads to
+ // a crash in the icu4c-windows-cygwin-gcc CI job. As a workaround, the
+ // UnicodeString class is forward declared to make it possible to use a
+ // reference here and then heap allocate the object in the constructor.
+ UnicodeString& scopeMessage;
void errlog(UBool dataErr, std::u16string_view mainMessage, const char* extraMessage) const;
};
--
2.47.1