编译环境:
fedora31
gcc-9.3.1-2
libicu-63.2-3
-------------------------------------------------------------------------------
错误内容:
Source/JavaScriptCore/API/JSStringRef.cpp:40:35: error: invalid conversion from 'const JSChar*' {aka 'const short unsigned int*'} to 'const UChar*' {aka 'const char16_t*'} [-fpermissive]
40 | return OpaqueJSString::create(chars, numChars).leakRef();
| ^~~~~
| |
| const JSChar* {aka const short unsigned int*}
In file included from Source/JavaScriptCore/API/JSStringRef.cpp:31:
...
Source/JavaScriptCore/API/JSStringRef.cpp: In function 'OpaqueJSString* JSStringCreateWithCharactersNoCopy(const JSChar*, size_t)':
Source/JavaScriptCore/API/JSStringRef.cpp:65:68: error: invalid conversion from 'const JSChar*' {aka 'const short unsigned int*'} to 'const UChar*' {aka 'const char16_t*'} [-fpermissive]
65 | return OpaqueJSString::create(StringImpl::createWithoutCopying(chars, numChars)).leakRef();
| ^~~~~
| |
| const JSChar* {aka const short unsigned int*}
...
Source/JavaScriptCore/API/JSStringRef.cpp: In function 'const JSChar* JSStringGetCharactersPtr(JSStringRef)':
Source/JavaScriptCore/API/JSStringRef.cpp:86:30: error: invalid conversion from 'const UChar*' {aka 'const char16_t*'} to 'const JSChar*' {aka 'const short unsigned int*'} [-fpermissive]
86 | return string->characters();
| ~~~~~~~~~~~~~~~~~~^~
| |
| const UChar* {aka const char16_t*}
-------------------------------------------------------------------------------
原因分析及解决思路:
char16_t与short unsigned int字符转换过程出现问题。对出现问题的变量进行强制类型转换。
-------------------------------------------------------------------------------
修改的patch:
diff -Nuar webkitgtk-2.4.11-orig/Source/JavaScriptCore/API/JSStringRef.cpp webkitgtk-2.4.11-deve/Source/JavaScriptCore/API/JSStringRef.cpp
--- webkitgtk-2.4.11-orig/Source/JavaScriptCore/API/JSStringRef.cpp 2016-04-10 14:48:36.000000000 +0800
+++ webkitgtk-2.4.11-deve/Source/JavaScriptCore/API/JSStringRef.cpp 2020-06-22 11:09:28.255256370 +0800
@@ -37,7 +37,7 @@
JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
{
initializeThreading();
- return OpaqueJSString::create(chars, numChars).leakRef();
+ return OpaqueJSString::create((const UChar*)(UChar*)chars, numChars).leakRef();
}
JSStringRef JSStringCreateWithUTF8CString(const char* string)
@@ -62,7 +62,7 @@
JSStringRef JSStringCreateWithCharactersNoCopy(const JSChar* chars, size_t numChars)
{
initializeThreading();
- return OpaqueJSString::create(StringImpl::createWithoutCopying(chars, numChars)).leakRef();
+ return OpaqueJSString::create(StringImpl::createWithoutCopying((const UChar*)(UChar*)chars, numChars)).leakRef();
}
JSStringRef JSStringRetain(JSStringRef string)
@@ -83,7 +83,7 @@
const JSChar* JSStringGetCharactersPtr(JSStringRef string)
{
- return string->characters();
+ return (JSChar*)string->characters();
}
size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string)