Skip to content

Commit

Permalink
ICU-22954 Revert to using std::u16string instead of UnicodeString.
Browse files Browse the repository at this point in the history
It seems as if icu4c-windows-cygwin-gcc only crashes if the constructor
is defined inline, so with the exception of the constructor this commit
reverts the code to commit 320220e.
  • Loading branch information
roubert committed Jan 8, 2025
1 parent a8d9f47 commit 6f93c07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
9 changes: 4 additions & 5 deletions icu4c/source/tools/ctestfw/tstdtmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <stdarg.h>

#include "unicode/tstdtmod.h"
#include "unicode/unistr.h"
#include "cmemory.h"
#include <stdio.h>
#include "cstr.h"
Expand All @@ -21,15 +20,14 @@ TestLog::~TestLog() {}

IcuTestErrorCode::IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName)
: errorCode(U_ZERO_ERROR),
testClass(callingTestClass), testName(callingTestName), scopeMessage(*new UnicodeString) {
testClass(callingTestClass), testName(callingTestName), scopeMessage() {
}

IcuTestErrorCode::~IcuTestErrorCode() {
// Safe because our errlog() does not throw exceptions.
if(isFailure()) {
errlog(false, u"destructor: expected success", nullptr);
}
delete &scopeMessage;
}

UErrorCode IcuTestErrorCode::reset() {
Expand Down Expand Up @@ -126,7 +124,8 @@ UBool IcuTestErrorCode::expectErrorAndReset(UErrorCode expectedError, const char
}

void IcuTestErrorCode::setScope(const char* message) {
scopeMessage.remove().append({ message, -1, US_INV });
UnicodeString us(message, -1, US_INV);
scopeMessage = us;
}

void IcuTestErrorCode::setScope(std::u16string_view message) {
Expand All @@ -142,7 +141,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.isEmpty()) {
if (!scopeMessage.empty()) {
msg.append(u" scope: ").append(scopeMessage);
}

Expand Down
14 changes: 2 additions & 12 deletions icu4c/source/tools/ctestfw/unicode/testlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef U_TESTFW_TESTLOG
#define U_TESTFW_TESTLOG

#include <string>
#include <string_view>
#include "unicode/utypes.h"
#include "unicode/testtype.h"
Expand All @@ -34,10 +35,6 @@ 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;
Expand Down Expand Up @@ -76,14 +73,7 @@ class T_CTEST_EXPORT_API IcuTestErrorCode {
UErrorCode errorCode;
TestLog &testClass;
const char *const testName;

// 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;
std::u16string scopeMessage;

void errlog(UBool dataErr, std::u16string_view mainMessage, const char* extraMessage) const;
};
Expand Down

0 comments on commit 6f93c07

Please sign in to comment.