Skip to content

Commit

Permalink
Use minipal toupper/lower in corehost
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Jun 22, 2024
1 parent 0262a63 commit 0b054b2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ This should be done automatically by dependency-flow, so in theory there shouldn
- System.Globalization.Tests.csproj
- System.Globalization.Nls.Tests.csproj
- System.Text.Encodings.Web.Tests.csproj
4. If the new Unicode data contains casing changes/updates, then we will also need to update `src/native/minipal/UnicodeDataGenerator/unicodedata.c` file. This file is used by most of the reflection stack whenever you specify the `BindingFlags.IgnoreCase`. In order to regenerate the contents of the `unicdedata.c` file, you need to run the Program located at `src/native/minipal/UnicodeDataGenerator/unicodedata.cs` and give a full path to the new UnicodeData.txt as a parameter.
4. If the new Unicode data contains casing changes/updates, then we will also need to update `src/native/minipal/unicodedata.c` file. This file is used by most of the reflection stack whenever you specify the `BindingFlags.IgnoreCase`. In order to regenerate the contents of the `unicdedata.c` file, you need to run the Program located at `src/native/minipal/UnicodeDataGenerator/unicodedata.cs` and give a full path to the new UnicodeData.txt as a parameter. e.g. in Unix shell:
```sh
# download UnicodeData.txt
$ curl -sSLo /tmp/UnicodeData.txt https://www.unicode.org/Public/14.0.0/ucd/UnicodeData.txt

# update unicodedata.c
$ cd runtime
$ ./dotnet.sh run --project src/native/minipal/UnicodeDataGenerator /tmp/UnicodeData.txt > src/native/minipal/unicodedata.c
```
5. Update the Regex casing equivalence table using the UnicodeData.txt file from the new Unicode version. You can find the instructions on how to do this [here](../../../System.Text.RegularExpressions/tools/Readme.md).
6. Finally, last step is to update the license for the Unicode data into our [Third party notices](../../../../../THIRD-PARTY-NOTICES.TXT) by copying the contents located in `https://www.unicode.org/license.html` to the section that has the Unicode license in our notices.
7. That's it, now commit all of the changed files, and send a PR into dotnet/runtime with the updates. If there were any special things you had to do that are not noted on this document, PLEASE UPDATE THESE INSTRUCTIONS to facilitate future updates.
1 change: 1 addition & 0 deletions src/native/corehost/hostmisc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(SOURCES
${CMAKE_CURRENT_LIST_DIR}/trace.cpp
${CMAKE_CURRENT_LIST_DIR}/utils.cpp
${CMAKE_CURRENT_LIST_DIR}/../fxr/fx_ver.cpp
${CLR_SRC_NATIVE_DIR}/minipal/unicodedata.c
)

set(HEADERS
Expand Down
5 changes: 3 additions & 2 deletions src/native/corehost/hostmisc/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "utils.h"
#include "trace.h"
#include "bundle/info.h"
#include <minipal/strings.h>
#if defined(TARGET_WINDOWS)
#include <_version.h>
#else
Expand Down Expand Up @@ -489,14 +490,14 @@ pal::string_t get_host_version_description()
pal::string_t to_lower(const pal::char_t* in) {
pal::string_t ret = in;
std::transform(ret.begin(), ret.end(), ret.begin(),
[](pal::char_t c) { return static_cast<pal::char_t>(::tolower(c)); });
[](pal::char_t c) { return static_cast<pal::char_t>(minipal_tolower_invariant(c)); });
return ret;
}

pal::string_t to_upper(const pal::char_t* in) {
pal::string_t ret = in;
std::transform(ret.begin(), ret.end(), ret.begin(),
[](pal::char_t c) { return static_cast<pal::char_t>(::toupper(c)); });
[](pal::char_t c) { return static_cast<pal::char_t>(minipal_toupper_invariant(c)); });
return ret;
}

Expand Down
15 changes: 13 additions & 2 deletions src/native/minipal/UnicodeDataGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// IF YOU NEED TO UPDATE UNICODE VERSION FOLLOW THE GUIDE AT src/libraries/System.Private.CoreLib/Tools/GenUnicodeProp/Updating-Unicode-Versions.md
//
#include <minipal/strings.h>
#include <inttypes.h>
#include <minipal/strings.h>
typedef struct
{
Expand Down Expand Up @@ -71,7 +71,18 @@ typedef struct
#define UNICODE_DATA_SIZE {numberOfCases}");

Console.WriteLine(@"
static int UnicodeDataComp(const void *opposingCode, const void *elem)
#ifdef TARGET_X86
#ifdef TARGET_WINDOWS
#define CALLBACK _cdecl
#else
#define CALLBACK __attribute__((cdecl))
#endif
#else
#define CALLBACK
#endif
static int CALLBACK UnicodeDataComp(const void *opposingCode, const void *elem)
{
CHAR16_T code = ((UnicodeDataRec*)elem)->code;
Expand Down
15 changes: 13 additions & 2 deletions src/native/minipal/unicodedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// IF YOU NEED TO UPDATE UNICODE VERSION FOLLOW THE GUIDE AT src/libraries/System.Private.CoreLib/Tools/GenUnicodeProp/Updating-Unicode-Versions.md
//

#include <minipal/strings.h>
#include <inttypes.h>
#include <minipal/strings.h>

typedef struct
{
Expand Down Expand Up @@ -2385,7 +2385,18 @@ static const UnicodeDataRec UnicodeData[] =

#define UNICODE_DATA_SIZE 2359

static int UnicodeDataComp(const void *opposingCode, const void *elem)

#ifdef TARGET_X86
#ifdef TARGET_WINDOWS
#define CALLBACK _cdecl
#else
#define CALLBACK __attribute__((cdecl))
#endif
#else
#define CALLBACK
#endif

static int CALLBACK UnicodeDataComp(const void *opposingCode, const void *elem)
{
CHAR16_T code = ((UnicodeDataRec*)elem)->code;

Expand Down

0 comments on commit 0b054b2

Please sign in to comment.