Skip to content

Commit

Permalink
Don't call any ICU methods after calling u_cleanup (#176)
Browse files Browse the repository at this point in the history
If you want to continue to use ICU after calling `u_cleanup` you'll
have to call `u_init` first.

This fixes #174.
  • Loading branch information
ermshiperete authored Nov 11, 2022
1 parent a426c10 commit 39fd6dd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Support .net 6.0

### Fixed

- Fixed crash in `Wrapper.Cleanup` (#176)

## [2.8.1] - 2022-07-08

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions source/icu.net.tests/IcuWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public void IcuVersion()
{
var result = Wrapper.IcuVersion;
Assert.That(result.Length, Is.GreaterThanOrEqualTo(4));
Assert.That(result.IndexOf("."), Is.GreaterThan(0));
Assert.That(int.TryParse(result.Substring(0, result.IndexOf(".")), out var major), Is.True);
Assert.That(result.IndexOf(".", StringComparison.Ordinal), Is.GreaterThan(0));
Assert.That(int.TryParse(result.Substring(0, result.IndexOf(".", StringComparison.Ordinal)), out var major), Is.True);
}

[Platform(Exclude = "Linux",
Expand Down
2 changes: 2 additions & 0 deletions source/icu.net/IcuWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public static ErrorCode Init()
/// Cleans up the ICU files that could be locked. This should be the last ICU method
/// that gets called.
/// </summary>
/// <remarks>This method is not thread-safe! All other threads should stop using ICU
/// before calling this function. </remarks>
/// <seealso href="http://userguide.icu-project.org/design#TOC-ICU-Initialization-and-Termination"/>
/// ------------------------------------------------------------------------------------
[PublicAPI]
Expand Down
28 changes: 14 additions & 14 deletions source/icu.net/NativeMethods/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,20 @@ internal static void Cleanup()
Trace.WriteLineIf(Verbose, "icu.net: Cleanup");
lock (_lock)
{
Methods = new MethodsContainer();
BiDiMethods = new BiDiMethodsContainer();
BreakIteratorMethods = new BreakIteratorMethodsContainer();
CodepageConversionMethods = new CodepageConversionMethodsContainer();
CollatorMethods = new CollatorMethodsContainer();
LocalesMethods = new LocalesMethodsContainer();
MessageFormatMethods = new MessageFormatMethodsContainer();
NormalizeMethods = new NormalizeMethodsContainer();
RegexMethods = new RegexMethodsContainer();
ResourceBundleMethods = new ResourceBundleMethodsContainer();
TransliteratorMethods = new TransliteratorMethodsContainer();
UnicodeSetMethods = new UnicodeSetMethodsContainer();
ResetIcuVersionInfo();

try
{
u_cleanup();
Expand All @@ -383,20 +397,6 @@ internal static void Cleanup()
}
_IcuCommonLibHandle = IntPtr.Zero;
_IcuI18NLibHandle = IntPtr.Zero;

Methods = new MethodsContainer();
BiDiMethods = new BiDiMethodsContainer();
BreakIteratorMethods = new BreakIteratorMethodsContainer();
CodepageConversionMethods = new CodepageConversionMethodsContainer();
CollatorMethods = new CollatorMethodsContainer();
LocalesMethods = new LocalesMethodsContainer();
MessageFormatMethods = new MessageFormatMethodsContainer();
NormalizeMethods = new NormalizeMethodsContainer();
RegexMethods = new RegexMethodsContainer();
ResourceBundleMethods = new ResourceBundleMethodsContainer();
TransliteratorMethods = new TransliteratorMethodsContainer();
UnicodeSetMethods = new UnicodeSetMethodsContainer();
ResetIcuVersionInfo();
}
}

Expand Down

0 comments on commit 39fd6dd

Please sign in to comment.