|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2026 Apple Inc. and the Swift.org project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of Swift.org project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +#if canImport(FoundationEssentials) |
| 16 | +import FoundationEssentials |
| 17 | +#else |
| 18 | +import Foundation |
| 19 | +#endif |
| 20 | + |
| 21 | + |
| 22 | +// ==== -------------------------------------------------- |
| 23 | +// Thunks for Data |
| 24 | + |
| 25 | +@_cdecl("swiftjava_getType_SwiftRuntimeFunctions_Data") |
| 26 | +public func swiftjava_getType_SwiftRuntimeFunctions_Data() -> UnsafeMutableRawPointer /* Any.Type */ { |
| 27 | + return unsafeBitCast(Data.self, to: UnsafeMutableRawPointer.self) |
| 28 | +} |
| 29 | + |
| 30 | +@_cdecl("swiftjava_SwiftRuntimeFunctions_Data_init_bytes_count") |
| 31 | +public func swiftjava_SwiftRuntimeFunctions_Data_init_bytes_count(_ bytes: UnsafeRawPointer, _ count: Int, _ _result: UnsafeMutableRawPointer) { |
| 32 | + _result.assumingMemoryBound(to: Data.self).initialize(to: Data(bytes: bytes, count: count)) |
| 33 | +} |
| 34 | + |
| 35 | +@_cdecl("swiftjava_SwiftRuntimeFunctions_Data_init__") |
| 36 | +public func swiftjava_SwiftRuntimeFunctions_Data_init__(_ bytes_pointer: UnsafeRawPointer, _ bytes_count: Int, _ _result: UnsafeMutableRawPointer) { |
| 37 | + _result.assumingMemoryBound(to: Data.self).initialize(to: Data([UInt8](UnsafeRawBufferPointer(start: bytes_pointer, count: bytes_count)))) |
| 38 | +} |
| 39 | + |
| 40 | +@_cdecl("swiftjava_SwiftRuntimeFunctions_Data_count$get") |
| 41 | +public func swiftjava_SwiftRuntimeFunctions_Data_count$get(_ self: UnsafeRawPointer) -> Int { |
| 42 | + return self.assumingMemoryBound(to: Data.self).pointee.count |
| 43 | +} |
| 44 | + |
| 45 | +@_cdecl("swiftjava_SwiftRuntimeFunctions_Data_withUnsafeBytes__") |
| 46 | +public func swiftjava_SwiftRuntimeFunctions_Data_withUnsafeBytes__(_ body: @convention(c) (UnsafeRawPointer?, Int) -> Void, _ self: UnsafeRawPointer) { |
| 47 | + self.assumingMemoryBound(to: Data.self).pointee.withUnsafeBytes({ (_0) in |
| 48 | + return body(_0.baseAddress, _0.count) |
| 49 | + }) |
| 50 | +} |
| 51 | + |
| 52 | +@_cdecl("swiftjava_SwiftRuntimeFunctions_Data_copyBytes__") |
| 53 | +public func swiftjava_SwiftRuntimeFunctions_Data_copyBytes__( |
| 54 | + selfPointer: UnsafeRawPointer, |
| 55 | + destinationPointer: UnsafeMutableRawPointer, |
| 56 | + count: Int |
| 57 | +) { |
| 58 | + let data = selfPointer.assumingMemoryBound(to: Data.self).pointee |
| 59 | + data.withUnsafeBytes { buffer in |
| 60 | + destinationPointer.copyMemory(from: buffer.baseAddress!, byteCount: count) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +// ==== -------------------------------------------------- |
| 65 | +// Thunks for DataProtocol |
| 66 | + |
| 67 | +@_cdecl("swiftjava_getType_SwiftRuntimeFunctions_DataProtocol") |
| 68 | +public func swiftjava_getType_SwiftRuntimeFunctions_DataProtocol() -> UnsafeMutableRawPointer /* Any.Type */ { |
| 69 | + return unsafeBitCast((any DataProtocol).self, to: UnsafeMutableRawPointer.self) |
| 70 | +} |
0 commit comments