1212
1313#if DEPLOYMENT_RUNTIME_SWIFT
1414
15+ #if canImport(Glibc)
16+ @usableFromInline let calloc = Glibc . calloc
17+ @usableFromInline let malloc = Glibc . malloc
18+ @usableFromInline let free = Glibc . free
19+ @usableFromInline let memset = Glibc . memset
20+ @usableFromInline let memcpy = Glibc . memcpy
21+ @usableFromInline let memcmp = Glibc . memcmp
22+ #elseif canImport(WASILibc)
23+ @usableFromInline let calloc = WASILibc . calloc
24+ @usableFromInline let malloc = WASILibc . malloc
25+ @usableFromInline let free = WASILibc . free
26+ @usableFromInline let memset = WASILibc . memset
27+ @usableFromInline let memcpy = WASILibc . memcpy
28+ @usableFromInline let memcmp = WASILibc . memcmp
29+ #endif
30+
1531#if !canImport(Darwin)
1632@inlinable // This is @inlinable as trivially computable.
1733internal func malloc_good_size( _ size: Int ) -> Int {
@@ -23,6 +39,8 @@ internal func malloc_good_size(_ size: Int) -> Int {
2339
2440#if canImport(Glibc)
2541import Glibc
42+ #elseif canImport(WASILibc)
43+ import WASILibc
2644#endif
2745
2846internal func __NSDataInvokeDeallocatorUnmap( _ mem: UnsafeMutableRawPointer , _ length: Int ) {
@@ -577,6 +595,7 @@ internal class __NSSwiftData : NSData {
577595 _range = range
578596 }
579597
598+ #if !os(WASI)
580599 public required init ? ( coder aDecoder: NSCoder ) {
581600 fatalError ( " This should have been encoded as NSData. " )
582601 }
@@ -585,6 +604,7 @@ internal class __NSSwiftData : NSData {
585604 // This should encode this object just like NSData does, and .classForCoder should do the rest.
586605 super. encode ( with: aCoder)
587606 }
607+ #endif
588608
589609 override var length : Int {
590610 return _range. upperBound - _range. lowerBound
@@ -650,11 +670,11 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
650670 @usableFromInline
651671 @frozen
652672 internal struct InlineData {
653- #if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
673+ #if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
654674 @usableFromInline typealias Buffer = ( UInt8 , UInt8 , UInt8 , UInt8 , UInt8 , UInt8 , UInt8 , UInt8 ,
655675 UInt8 , UInt8 , UInt8 , UInt8 , UInt8 , UInt8 ) //len //enum
656676 @usableFromInline var bytes : Buffer
657- #elseif arch(i386) || arch(arm)
677+ #elseif arch(i386) || arch(arm) || arch(wasm32)
658678 @usableFromInline typealias Buffer = ( UInt8 , UInt8 , UInt8 , UInt8 ,
659679 UInt8 , UInt8 ) //len //enum
660680 @usableFromInline var bytes : Buffer
@@ -683,7 +703,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
683703 assert ( count <= MemoryLayout< Buffer> . size)
684704#if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
685705 bytes = ( UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) )
686- #elseif arch(i386) || arch(arm)
706+ #elseif arch(i386) || arch(arm) || arch(wasm32)
687707 bytes = ( UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) , UInt8 ( 0 ) )
688708#else
689709 #error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
@@ -866,7 +886,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
866886
867887#if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
868888 @usableFromInline internal typealias HalfInt = Int32
869- #elseif arch(i386) || arch(arm)
889+ #elseif arch(i386) || arch(arm) || arch(wasm32)
870890 @usableFromInline internal typealias HalfInt = Int16
871891#else
872892 #error("This architecture isn't known. Add it to the 32-bit or 64-bit line.")
@@ -2012,6 +2032,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
20122032 }
20132033 }
20142034
2035+ #if !os(WASI)
20152036 /// Initialize a `Data` with the contents of a `URL`.
20162037 ///
20172038 /// - parameter url: The `URL` to read.
@@ -2024,6 +2045,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
20242045 return Data ( bytes: d. bytes, count: d. length)
20252046 }
20262047 }
2048+ #endif
20272049
20282050 /// Initialize a `Data` from a Base-64 encoded String using the given options.
20292051 ///
@@ -2287,6 +2309,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
22872309 }
22882310#endif
22892311
2312+ #if !os(WASI)
22902313 /// Write the contents of the `Data` to a location.
22912314 ///
22922315 /// - parameter url: The location to write the data into.
@@ -2307,6 +2330,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
23072330#endif
23082331 }
23092332 }
2333+ #endif
23102334
23112335 // MARK: -
23122336
0 commit comments