Skip to content

Commit

Permalink
[K/N] Add workaround for KT-48591
Browse files Browse the repository at this point in the history
The root case for the bug is that we import runtime functions with
signext parameters, but KChars are zeroext. Workaround this mismatch
by fixing signatures of functions that we consider "dangerous".

The correct fix will be too big to be included in 1.5.31 and 1.6.0.
  • Loading branch information
sbogolepov authored and Space committed Sep 10, 2021
1 parent 5d4d91e commit f2109a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kotlin-native/runtime/src/main/cpp/KString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ KBoolean Kotlin_Char_isISOControl(KChar ch) {
return (ch <= 0x1F) || (ch >= 0x7F && ch <= 0x9F);
}

KBoolean Kotlin_Char_isHighSurrogate(KChar ch) {
KBoolean Kotlin_Char_isHighSurrogate(KCharSignExt ch) {
return ((ch & 0xfc00) == 0xd800);
}

KBoolean Kotlin_Char_isLowSurrogate(KChar ch) {
KBoolean Kotlin_Char_isLowSurrogate(KCharSignExt ch) {
return ((ch & 0xfc00) == 0xdc00);
}

Expand Down
4 changes: 4 additions & 0 deletions kotlin-native/runtime/src/main/cpp/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
typedef bool KBoolean;
typedef int8_t KByte;
typedef uint16_t KChar;
/**
* Hack for KT-48591.
*/
typedef int16_t KCharSignExt;
typedef int16_t KShort;
typedef int32_t KInt;
typedef int64_t KLong;
Expand Down

0 comments on commit f2109a7

Please sign in to comment.