Skip to content

Commit

Permalink
Move unicodedata to minipal (dotnet#102139)
Browse files Browse the repository at this point in the history
* Move unicodedata to minipal

* Fix linux build

* Shave off a few bytes with 'static const'

* Add a separate header

* Regenerate unicodedata.c

* Cleanups
  • Loading branch information
am11 authored May 16, 2024
1 parent 76cd4be commit 5025f5e
Show file tree
Hide file tree
Showing 16 changed files with 2,596 additions and 2,628 deletions.
3 changes: 0 additions & 3 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3963,9 +3963,6 @@ PALIMPORT DLLEXPORT int __cdecl _putenv(const char *);

#define ERANGE 34

PALIMPORT WCHAR __cdecl PAL_ToUpperInvariant(WCHAR);
PALIMPORT WCHAR __cdecl PAL_ToLowerInvariant(WCHAR);

/****************PAL Perf functions for PInvoke*********************/
#if PAL_PERF
PALIMPORT
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ set(SOURCES
init/sxs.cpp
loader/module.cpp
locale/unicode.cpp
locale/unicodedata.cpp
${CLR_SRC_NATIVE_DIR}/minipal/utf8.c
${CLR_SRC_NATIVE_DIR}/minipal/unicodedata.c
map/common.cpp
map/map.cpp
map/virtual.cpp
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/cruntime/wchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Module Name:
#include "config.h"
#endif

#include <wctype.h>
#include <errno.h>
#include <algorithm>

Expand Down
31 changes: 0 additions & 31 deletions src/coreclr/pal/src/include/pal/unicodedata.h

This file was deleted.

143 changes: 0 additions & 143 deletions src/coreclr/pal/src/locale/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

/*++
Module Name:
unicode.cpp
Abstract:
Implementation of all functions related to Unicode support
Revision History:
--*/

#include "pal/thread.hpp"
Expand All @@ -27,7 +17,6 @@ Revision History:
#include <minipal/utf8.h>
#include "pal/cruntime.h"
#include "pal/stackstring.hpp"
#include "pal/unicodedata.h"

#include <pthread.h>
#include <locale.h>
Expand All @@ -39,138 +28,6 @@ using namespace CorUnix;

SET_DEFAULT_DEBUG_CHANNEL(UNICODE);

/*++
Function:
UnicodeDataComp
This is the comparison function used by the bsearch function to search
for unicode characters in the UnicodeData array.
Parameter:
pnKey
The unicode character value to search for.
elem
A pointer to a UnicodeDataRec.
Return value:
<0 if pnKey < elem->nUnicodeValue
0 if pnKey == elem->nUnicodeValue
>0 if pnKey > elem->nUnicodeValue
--*/
static int UnicodeDataComp(const void *pnKey, const void *elem)
{
WCHAR uValue = ((UnicodeDataRec*)elem)->nUnicodeValue;

if (*((INT*)pnKey) < uValue)
{
return -1;
}
else if (*((INT*)pnKey) > uValue)
{
return 1;
}
else
{
return 0;
}
}

/*++
Function:
GetUnicodeData
This function is used to get information about a Unicode character.
Parameters:
nUnicodeValue
The numeric value of the Unicode character to get information about.
pDataRec
The UnicodeDataRec to fill in with the data for the Unicode character.
Return value:
TRUE if the Unicode character was found.
--*/
BOOL GetUnicodeData(INT nUnicodeValue, UnicodeDataRec *pDataRec)
{
BOOL bRet;

UnicodeDataRec *dataRec;
INT nNumOfChars = UNICODE_DATA_SIZE;
dataRec = (UnicodeDataRec *) bsearch(&nUnicodeValue, UnicodeData, nNumOfChars,
sizeof(UnicodeDataRec), UnicodeDataComp);
if (dataRec == NULL)
{
bRet = FALSE;
}
else
{
bRet = TRUE;
*pDataRec = *dataRec;
}
return bRet;
}

char16_t
__cdecl
PAL_ToUpperInvariant( char16_t c )
{
UnicodeDataRec dataRec;

PERF_ENTRY(PAL_ToUpperInvariant);
ENTRY("PAL_ToUpperInvariant (c=%d)\n", c);

if (!GetUnicodeData(c, &dataRec))
{
TRACE( "Unable to retrieve unicode data for the character %c.\n", c );
LOGEXIT("PAL_ToUpperInvariant returns int %d\n", c );
PERF_EXIT(PAL_ToUpperInvariant);
return c;
}

if ( dataRec.nFlag != LOWER_CASE )
{
LOGEXIT("PAL_ToUpperInvariant returns int %d\n", c );
PERF_EXIT(PAL_ToUpperInvariant);
return c;
}
else
{
LOGEXIT("PAL_ToUpperInvariant returns int %d\n", dataRec.nOpposingCase );
PERF_EXIT(PAL_ToUpperInvariant);
return dataRec.nOpposingCase;
}
}

char16_t
__cdecl
PAL_ToLowerInvariant( char16_t c )
{
UnicodeDataRec dataRec;

PERF_ENTRY(PAL_ToLowerInvariant);
ENTRY("PAL_ToLowerInvariant (c=%d)\n", c);

if (!GetUnicodeData(c, &dataRec))
{
TRACE( "Unable to retrieve unicode data for the character %c.\n", c );
LOGEXIT("PAL_ToLowerInvariant returns int %d\n", c );
PERF_EXIT(PAL_ToLowerInvariant);
return c;
}

if ( dataRec.nFlag != UPPER_CASE )
{
LOGEXIT("PAL_ToLowerInvariant returns int %d\n", c );
PERF_EXIT(PAL_ToLowerInvariant);
return c;
}
else
{
LOGEXIT("PAL_ToLowerInvariant returns int %d\n", dataRec.nOpposingCase );
PERF_EXIT(PAL_ToLowerInvariant);
return dataRec.nOpposingCase;
}
}

/*++
Function:
GetConsoleOutputCP
Expand Down
Loading

0 comments on commit 5025f5e

Please sign in to comment.