Skip to content

Commit dbd9819

Browse files
committed
Add byteCast for conversions between different byte-sized types
https://bugs.webkit.org/show_bug.cgi?id=273380 rdar://127209334 Reviewed by Chris Dumez. * Source/JavaScriptCore/API/JSStringRef.cpp: (JSStringGetUTF8CString): Use byteCast. * Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp: (JSC::Printer::printMemory): Use static_cast instead of reinterpret_cast. * Source/JavaScriptCore/assembler/ProbeFrame.h: (JSC::Probe::Frame::Frame): Ditto. * Source/JavaScriptCore/bytecode/UnlinkedMetadataTableInlines.h: (JSC::UnlinkedMetadataTable::link): Ditto. * Source/JavaScriptCore/runtime/Identifier.h: (JSC::Identifier::equal): Use byteCast. (JSC::operator==): Ditto. * Source/JavaScriptCore/runtime/IntlCollator.cpp: (JSC::IntlCollator::compareStrings const): Ditto. * Source/JavaScriptCore/runtime/IntlLocale.cpp: (JSC::LocaleIDBuilder::setKeywordValue): Ditto. * Source/JavaScriptCore/runtime/NumberPrototype.cpp: (JSC::toStringWithRadixInternal): Removed unneeded static_cast. * Source/JavaScriptCore/wasm/WasmFormat.h: (JSC::Wasm::Segment::byte): Removed unneeded reinterpret_cast. * Source/JavaScriptCore/wasm/WasmMemory.cpp: (JSC::Wasm::Memory::fill): Use static_cast instead of reinterpret_cast. (JSC::Wasm::Memory::copy): Ditto. (JSC::Wasm::Memory::init): Ditto. * Source/JavaScriptCore/yarr/YarrPattern.cpp: (JSC::Yarr::dumpUChar32): Tweaked formatting. * Source/WTF/wtf/FastFloat.cpp: (WTF::parseDouble): Use byteCast. * Source/WTF/wtf/FileSystem.cpp: (WTF::FileSystemImpl::toStdFileSystemPath): Ditto. (WTF::FileSystemImpl::fromStdFileSystemPath): Ditto. * Source/WTF/wtf/PageBlock.h: (WTF::PageBlock::end const): Use static_cast instead of reinterpret_cast. * Source/WTF/wtf/StdLibExtras.h: Added byteCast. * Source/WTF/wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): Use byteCast. * Source/WTF/wtf/URLHelpers.cpp: (WTF::URLHelpers::userVisibleURL): Use span instead of dataAsUInt8Ptr. * Source/WTF/wtf/cf/URLCF.cpp: (WTF::URL::createCFURL const): Ditto. * Source/WTF/wtf/cf/VectorCF.h: (WTF::span): Use static_cast instead of reinterpret_cast. * Source/WTF/wtf/persistence/PersistentCoders.cpp: (WTF::Persistence::Coder<CString>::encodeForPersistence): Use span instead of dataAsUInt8Ptr. (WTF::Persistence::Coder<CString>::decodeForPersistence): Use byteCast. * Source/WTF/wtf/text/AtomStringImpl.h: Use byteCast. * Source/WTF/wtf/text/CString.h: Ditto. * Source/WTF/wtf/text/StringBuilder.h: (WTF::StringBuilder::append): Ditto. * Source/WTF/wtf/text/StringCommon.h: Ditto. * Source/WTF/wtf/text/StringConcatenate.h: Ditto. * Source/WTF/wtf/text/StringConcatenateNumbers.h: Ditto. * Source/WTF/wtf/text/StringImpl.cpp: (WTF::equalInner): Ditto. * Source/WTF/wtf/text/StringImpl.h: Ditto. * Source/WTF/wtf/text/StringView.h: Ditto. * Source/WTF/wtf/text/WTFString.cpp: (WTF::String::String): Ditto. (WTF::String::fromUTF8): Ditto. * Source/WTF/wtf/text/WTFString.h: Ditto. * Source/WTF/wtf/text/cf/AtomStringImplCF.cpp: (WTF::AtomStringImpl::add): Ditto. * Source/WTF/wtf/unicode/Collator.h: Use char8_t instead of UTF8 in the name for the collate function that takes null-terminated strings. * Source/WTF/wtf/unicode/CollatorDefault.cpp: (WTF::Collator::collate const): Use byteCast. * Source/WTF/wtf/unicode/icu/CollatorICU.cpp: (WTF::createIterator): Use byteCast. (WTF::Collator::collate const): Use createIterator. * Source/WebCore/Modules/WebGPU/GPUQueue.cpp: (WebCore::getImageBytesFromVideoFrame): Use static_cast instead of reinterpret_cast. * Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp: (WebCore::isPlayReadySanitizedInitializationData): Use byteCast. * Source/WebCore/PAL/pal/text/EncodingTables.cpp: (PAL::jis0208): Ditto. (PAL::jis0212): Ditto. (PAL::big5): Ditto. (PAL::eucKR): Ditto. (PAL::gb18030): Ditto. * Source/WebCore/PAL/pal/text/TextCodecCJK.cpp: (PAL::TextCodecCJK::eucJPDecode): Ditto. (PAL::TextCodecCJK::big5Decode): Ditto. * Source/WebCore/PAL/pal/text/TextCodecICU.cpp: (PAL::TextCodecICU::decode): Ditto. (PAL::TextCodecICU::encode const): Ditto. * Source/WebCore/PAL/pal/text/TextEncodingDetectorICU.cpp: (PAL::detectTextEncoding): Ditto. * Source/WebCore/css/process-css-pseudo-selectors.py: Ditto. * Source/WebCore/html/track/VTTScanner.h: (WebCore::VTTScanner::scan): Ditto. * Source/WebCore/html/track/WebVTTTokenizer.cpp: (WebCore::equalLiteral): Deleted. * Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm: (WebCore::showText): Use span instead of dataAsUInt8Ptr. * Source/WebCore/platform/SharedBuffer.h: Deleted dataAsCharPtr. * Source/WebCore/platform/SharedBufferChunkReader.cpp: (WebCore::SharedBufferChunkReader::nextChunk): Use byteCast. * Source/WebCore/platform/graphics/MIMESniffer.cpp: (WebCore::MIMESniffer::span8): Ditto. * Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp: (WebCore::GraphicsContextGLANGLE::initialize): Ditto. (WebCore::GraphicsContextGLANGLE::getString): Ditto. * Source/WebCore/platform/graphics/cg/ShareableBitmapCG.mm: (WebCore::ShareableBitmap::createFromImagePixels): Ditto. * Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp: (WebCore::defaultVariationValues): Use assignment instead of static_cast. * Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm: (WebCore::WebCoreDecompressionSession::decodeSample): Use byteCast. * Source/WebCore/platform/graphics/cocoa/WebMAudioUtilitiesCocoa.mm: (WebCore::parseOpusPrivateData): Ditto. * Source/WebCore/platform/graphics/cpu/arm/filters/FEBlendNeonApplier.cpp: (WebCore::FEBlendNeonApplier::applyPlatform const): Ditto. * Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp: (WebCore::ScalableImageDecoder::create): Ditto. * Source/WebCore/platform/network/cf/ResourceRequestCFNet.h: (WebCore::httpHeaderValueUsingSuitableEncoding): Use span instead of dataAsUInt8Ptr. * Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm: (WebCore::ResourceResponse::platformCertificateInfo const): Ditto. * Source/WebCore/workers/ScriptBuffer.cpp: (WebCore::ScriptBuffer::toString const): Use byteCast. (WebCore::ScriptBuffer::append): Ditto. Also fixed a mistake where this was using uint8_t instead of char8_t. * Source/WebCore/xml/XSLTProcessorLibxslt.cpp: (WebCore::docLoaderFunc): Use byteCast. (WebCore::writeToStringBuilder): Ditto. (WebCore::XSLTProcessor::transformToString): Ditto. * Source/WebCore/xml/XSLTUnicodeSort.cpp: (WebCore::xsltUnicodeSortFunction): Ditto. * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::XMLParserContext::createMemoryParser): Use byteCast. (WebCore::toString): Ditto. (WebCore::toAtomString): Ditto. (WebCore::sharedXHTMLEntity): Ditto. (WebCore::convertUTF16EntityToUTF8): Ditto. (WebCore::getXHTMLEntity): Ditto. (WebCore::xmlDocPtrForString): Ditto. (WebCore::attributesStartElementNsHandler): Ditto. * Source/WebGPU/WebGPU/BindGroup.mm: (WebGPU::Device::createExternalTextureFromPixelBuffer const): Ditto. * Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLFunctionsGenerated.h: (getBufferSubData): Ditto. * Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp: (WebKit::NetworkConnectionToWebProcess::logOnBehalfOfWebContent): Ditto. * Source/WebKit/NetworkProcess/webrtc/LibWebRTCSocketClient.cpp: (WebKit::LibWebRTCSocketClient::signalReadPacket): Ditto. * Source/WebKit/Shared/API/c/WKString.cpp: (WKStringGetUTF8CStringImpl): Ditto. * Source/WebKit/Shared/API/c/cf/WKURLCF.mm: (WKURLCopyCFURL): Use span instead of dataAsUInt8Ptr. * Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm: (WebKit::SandboxExtensionImpl::SandboxExtensionImpl): Ditto. * Source/WebKit/UIProcess/mac/LegacySessionStateCoding.cpp: (WebKit::HistoryEntryDataEncoder::operator<<): Use byteCast. (WebKit::encodeLegacySessionState): Use checked_cf_cast. * Source/WebKit/UIProcess/mac/LegacySessionStateCoding.cpp: (WebKit::HistoryEntryDataEncoder::operator<<): Use byteCast. * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocket.cpp: (WebKit::LibWebRTCSocket::signalReadPacket): Ditto. * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::getAccessibilityTreeData): Use checked_cf_cast. * Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::registerLogHook): Use byteCast. * Source/WebKitLegacy/mac/Misc/WebNSDataExtras.mm: (-[NSData _webkit_guessedMIMETypeForXML]): Ditto. * Tools/TestWebKitAPI/Tests/WTF/StdLibExtrasTests.cpp: (TestWebKitAPI::TEST(WTF_StdLibExtras, ByteCast)): Added some tests. * Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp: Rewrite tests so it's easier to see which one failed. Did not use byteCast here. * Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp: (TestWebKitAPI::TEST(WTF, StringImplEqualIgnoringASCIICaseBasic)): Ditto. (TestWebKitAPI::TEST(WTF, StringImplEqualIgnoringASCIICaseWithEmpty)): Ditto. (TestWebKitAPI::TEST(WTF, StringImplFindIgnoringASCIICaseOnEmpty)): Ditto. (TestWebKitAPI::TEST(WTF, StringImplStartsWithIgnoringASCIICaseWithNull)): Ditto. (TestWebKitAPI::TEST(WTF, StringImplStartsWithIgnoringASCIICaseWithEmpty)): Ditto. (TestWebKitAPI::TEST(WTF, StringImplEndsWithIgnoringASCIICaseWithNull)): Ditto. (TestWebKitAPI::TEST(WTF, StringImplEndsWithIgnoringASCIICaseWithEmpty)): Ditto. * Tools/TestWebKitAPI/Tests/WTF/StringView.cpp: (TestWebKitAPI::TEST(WTF, StringViewEqualIgnoringASCIICaseBasic)): Ditto. (TestWebKitAPI::TEST(WTF, StringViewEqualIgnoringASCIICaseWithEmpty)): Ditto. * Tools/TestWebKitAPI/Tests/WebCore/CBORWriterTest.cpp: (TestWebKitAPI::eq): Remomved unneeded reinterpret_cast. * Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp: (TestWebKitAPI::TEST_F(FragmentedSharedBufferTest, getSomeData)): Use byteCast and span instead of dataAsCharPtr. * Tools/TestWebKitAPI/Tests/WebKitCocoa/PDFLinkReferrer.mm: (TEST(WebKit, PDFLinkReferrer)): Use byteCast. * Tools/TestWebKitAPI/cocoa/CGImagePixelReader.cpp: (TestWebKitAPI::CGImagePixelReader::at const): Use static_cast instead of reinterpret_cast. * Tools/TestWebKitAPI/cocoa/HTTPServer.mm: (TestWebKitAPI::proxyDefinition): Use byteCast. (TestWebKitAPI::Connection::webSocketHandshake): Ditto. Canonical link: https://commits.webkit.org/279338@main
1 parent 102781a commit dbd9819

75 files changed

Lines changed: 285 additions & 239 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/JavaScriptCore/API/JSStringRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSiz
9898
if (!string || !buffer || !bufferSize)
9999
return 0;
100100

101-
std::span<char8_t> target { reinterpret_cast<char8_t*>(buffer), bufferSize - 1 };
101+
std::span<char8_t> target { byteCast<char8_t>(buffer), bufferSize - 1 };
102102
WTF::Unicode::ConversionResult<char8_t> result;
103103
if (string->is8Bit())
104104
result = WTF::Unicode::convert(string->span8(), target);

Source/JavaScriptCore/assembler/MacroAssemblerPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void printMemory(PrintStream& out, Context& context)
125125
break;
126126
}
127127
case Memory::AddressType::AbsoluteAddress: {
128-
ptr = reinterpret_cast<uint8_t*>(const_cast<void*>(memory.u.absoluteAddress.m_ptr));
128+
ptr = static_cast<uint8_t*>(const_cast<void*>(memory.u.absoluteAddress.m_ptr));
129129
break;
130130
}
131131
}

Source/JavaScriptCore/assembler/ProbeFrame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Probe {
3636
class Frame {
3737
public:
3838
Frame(void* frameBase, Stack& stack)
39-
: m_frameBase { reinterpret_cast<uint8_t*>(frameBase) }
39+
: m_frameBase { static_cast<uint8_t*>(frameBase) }
4040
, m_stack { stack }
4141
{ }
4242

Source/JavaScriptCore/bytecode/UnlinkedMetadataTableInlines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ ALWAYS_INLINE RefPtr<MetadataTable> UnlinkedMetadataTable::link()
131131
MetadataStatistics::numberOfCopiesFromLinking++;
132132
MetadataStatistics::linkingCopyMemory += sizeof(LinkingData) + totalSize;
133133
#endif
134-
buffer = reinterpret_cast<uint8_t*>(MetadataTableMalloc::malloc(sizeof(LinkingData) + totalSize));
134+
buffer = static_cast<uint8_t*>(MetadataTableMalloc::malloc(sizeof(LinkingData) + totalSize));
135135
memcpy(buffer + valueProfileSize + sizeof(LinkingData), m_rawBuffer + valueProfileSize + sizeof(LinkingData), offsetTableSize);
136136
}
137137
// FIXME: Is this needed since we'll clear the data in the CodeBlock Constructor... Plus I could see caching value profiles being profitable.

Source/JavaScriptCore/runtime/Identifier.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Identifier {
147147
friend bool operator==(const Identifier&, const char*);
148148

149149
static bool equal(const StringImpl*, const LChar*);
150-
static inline bool equal(const StringImpl* a, const char* b) { return Identifier::equal(a, reinterpret_cast<const LChar*>(b)); };
150+
static inline bool equal(const StringImpl* a, const char* b) { return Identifier::equal(a, byteCast<LChar>(b)); };
151151
static bool equal(const StringImpl*, std::span<const LChar>);
152152
static bool equal(const StringImpl*, std::span<const UChar>);
153153
static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); }
@@ -234,7 +234,7 @@ inline bool operator==(const Identifier& a, const LChar* b)
234234

235235
inline bool operator==(const Identifier& a, const char* b)
236236
{
237-
return Identifier::equal(a, reinterpret_cast<const LChar*>(b));
237+
return Identifier::equal(a, byteCast<LChar>(b));
238238
}
239239

240240
inline bool Identifier::equal(const StringImpl* r, const LChar* s)

Source/JavaScriptCore/runtime/IntlCollator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ UCollationResult IntlCollator::compareStrings(JSGlobalObject* globalObject, Stri
301301
}
302302

303303
if (x.is8Bit() && y.is8Bit() && x.containsOnlyASCII() && y.containsOnlyASCII()) {
304-
auto xCharacters = spanReinterpretCast<const char>(x.span8());
305-
auto yCharacters = spanReinterpretCast<const char>(y.span8());
304+
auto xCharacters = byteCast<char>(x.span8());
305+
auto yCharacters = byteCast<char>(y.span8());
306306
return ucol_strcollUTF8(m_collator.get(), xCharacters.data(), xCharacters.size(), yCharacters.data(), yCharacters.size(), &status);
307307
}
308308

Source/JavaScriptCore/runtime/IntlLocale.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ bool LocaleIDBuilder::setKeywordValue(ASCIILiteral key, StringView value)
178178

179179
ASSERT(value.containsOnlyASCII());
180180
Vector<char, 32> rawValue(value.length() + 1);
181-
value.getCharacters(reinterpret_cast<LChar*>(rawValue.data()));
181+
value.getCharacters(byteCast<LChar>(rawValue.data()));
182182
rawValue[value.length()] = '\0';
183183

184184
UErrorCode status = U_ZERO_ERROR;

Source/JavaScriptCore/runtime/NumberPrototype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static String toStringWithRadixInternal(int32_t number, unsigned radix)
354354
do {
355355
uint32_t index = positiveNumber % radix;
356356
ASSERT(index < sizeof(radixDigits));
357-
*--p = static_cast<LChar>(radixDigits[index]);
357+
*--p = radixDigits[index];
358358
positiveNumber /= radix;
359359
} while (positiveNumber);
360360

Source/JavaScriptCore/wasm/WasmFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ struct Segment {
598598
uint8_t& byte(uint32_t pos)
599599
{
600600
ASSERT(pos < sizeInBytes);
601-
return *reinterpret_cast<uint8_t*>(reinterpret_cast<char*>(this) + sizeof(Segment) + pos);
601+
return *(reinterpret_cast<uint8_t*>(this) + sizeof(Segment) + pos);
602602
}
603603

604604
static void destroy(Segment*);

Source/JavaScriptCore/wasm/WasmMemory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ bool Memory::fill(uint32_t offset, uint8_t targetValue, uint32_t count)
411411
if (offset + count > m_handle->size())
412412
return false;
413413

414-
memset(reinterpret_cast<uint8_t*>(basePointer()) + offset, targetValue, count);
414+
memset(static_cast<uint8_t*>(basePointer()) + offset, targetValue, count);
415415
return true;
416416
}
417417

@@ -429,7 +429,7 @@ bool Memory::copy(uint32_t dstAddress, uint32_t srcAddress, uint32_t count)
429429
if (!count)
430430
return true;
431431

432-
uint8_t* base = reinterpret_cast<uint8_t*>(basePointer());
432+
uint8_t* base = static_cast<uint8_t*>(basePointer());
433433
// Source and destination areas might overlap, so using memmove.
434434
memmove(base + dstAddress, base + srcAddress, count);
435435
return true;
@@ -446,7 +446,7 @@ bool Memory::init(uint32_t offset, const uint8_t* data, uint32_t length)
446446
if (!length)
447447
return true;
448448

449-
memcpy(reinterpret_cast<uint8_t*>(basePointer()) + offset, data, length);
449+
memcpy(static_cast<uint8_t*>(basePointer()) + offset, data, length);
450450
return true;
451451
}
452452

0 commit comments

Comments
 (0)