Skip to content

Use the new Bionic module from Swift 6 where possible #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Sources/Foundation/FileHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ open class FileHandle : NSObject, @unchecked Sendable {
if options.contains(.alwaysMapped) {
// Filesizes are often 64bit even on 32bit systems
let mapSize = min(length, Int(clamping: statbuf.st_size))
#if canImport(Android)
// Bionic mmap() now returns _Nonnull, so the force unwrap below isn't needed.
let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)
#else
let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)!
#endif
// Swift does not currently expose MAP_FAILURE
if data != UnsafeMutableRawPointer(bitPattern: -1) {
return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import WinSDK

#if os(WASI)
import WASILibc
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

#if os(Windows)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/NSLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#if canImport(Glibc)
import Glibc
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

#if os(Windows)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import Darwin
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

// NOTE: this represents PLATFORM_PATH_STYLE
Expand Down
7 changes: 0 additions & 7 deletions Sources/Foundation/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,6 @@ open class Process: NSObject, @unchecked Sendable {
var spawnAttrs: posix_spawnattr_t? = nil
#else
var spawnAttrs: posix_spawnattr_t = posix_spawnattr_t()
#endif
#if os(Android)
guard var spawnAttrs else {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the point of this is, as it's set to nil just a couple lines above and fails to compile with NDK 26.

throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno), userInfo: [
NSURLErrorKey:self.executableURL!
])
}
#endif
try _throwIfPosixError(posix_spawnattr_init(&spawnAttrs))
try _throwIfPosixError(posix_spawnattr_setflags(&spawnAttrs, .init(POSIX_SPAWN_SETPGROUP)))
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import WinSDK
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

// WORKAROUND_SR9811
Expand Down
4 changes: 2 additions & 2 deletions Sources/plutil/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import Glibc
#elseif canImport(Musl)
import Foundation
import Musl
#elseif canImport(Android)
#elseif canImport(Bionic)
import Foundation
import Android
import Bionic
#elseif canImport(CRT)
import Foundation
import CRT
Expand Down
4 changes: 2 additions & 2 deletions Sources/xdgTestHelper/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import FoundationNetworking
#endif
#if os(Windows)
import WinSDK
#elseif os(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

enum HelperCheckStatus : Int32 {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Foundation/FTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Dispatch
import Glibc
#elseif canImport(Darwin)
import Darwin
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

final class ServerSemaphore : Sendable {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Foundation/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import Dispatch
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

#if !os(Windows)
Expand Down
4 changes: 2 additions & 2 deletions Tests/Foundation/TestFileHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import Dispatch
#if os(Windows)
import WinSDK
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

class TestFileHandle : XCTestCase {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Foundation/TestProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//

import Synchronization
#if canImport(Android)
import Android
#if canImport(Bionic)
import Bionic
#endif

class TestProcess : XCTestCase {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Foundation/TestSocketPort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//
#if os(Windows)
import WinSDK
#elseif canImport(Android)
import Android
#elseif canImport(Bionic)
import Bionic
#endif

class TestPortDelegateWithBlock: NSObject, PortDelegate {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Foundation/TestURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if canImport(Android)
import Android
#if canImport(Bionic)
import Bionic
#endif

let kURLTestParsingTestsKey = "ParsingTests"
Expand Down