-
Notifications
You must be signed in to change notification settings - Fork 11
/
swift-android-both-ndks.patch
132 lines (123 loc) · 7.76 KB
/
swift-android-both-ndks.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
index a538a297..0a757c4b 100644
--- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
@@ -310,9 +310,15 @@ open class FileHandle : NSObject {
let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)
// Swift does not currently expose MAP_FAILURE
if data != UnsafeMutableRawPointer(bitPattern: -1) {
+ #if os(Android)
+ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in
+ munmap(buffer, length)
+ }
+ #else
return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in
munmap(buffer, length)
}
+ #endif
}
}
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
index d90ece91..d2bbd22b 100644
--- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
@@ -741,13 +741,13 @@ extension FileManager {
ps.deinitialize(count: 2)
ps.deallocate()
- if stream != nil {
+ if let openStream = stream {
defer {
- fts_close(stream)
+ fts_close(openStream)
}
- while let current = fts_read(stream)?.pointee {
- let itemPath = string(withFileSystemRepresentation: current.fts_path, length: Int(current.fts_pathlen))
+ while let current = fts_read(openStream)?.pointee, let current_path = current.fts_path {
+ let itemPath = string(withFileSystemRepresentation: current_path, length: Int(current.fts_pathlen))
guard alreadyConfirmed || shouldRemoveItemAtPath(itemPath, isURL: isURL) else {
continue
}
@@ -762,11 +768,11 @@ extension FileManager {
do {
switch Int32(current.fts_info) {
case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE:
- if unlink(current.fts_path) == -1 {
+ if unlink(current_path) == -1 {
throw _NSErrorWithErrno(errno, reading: false, path: itemPath)
}
case FTS_DP:
- if rmdir(current.fts_path) == -1 {
+ if rmdir(current_path) == -1 {
throw _NSErrorWithErrno(errno, reading: false, path: itemPath)
}
case FTS_DNR, FTS_ERR, FTS_NS:
@@ -1135,14 +1149,14 @@ extension FileManager {
}
_current = fts_read(stream)
- while let current = _current {
- let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen))
+ while let current = _current, let current_path = current.pointee.fts_path {
+ let filename = FileManager.default.string(withFileSystemRepresentation: current_path, length: Int(current.pointee.fts_pathlen))
switch Int32(current.pointee.fts_info) {
case FTS_D:
let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true)
if skipDescendants {
- fts_set(_stream, _current, FTS_SKIP)
+ fts_set(stream, current, FTS_SKIP)
}
if showFile {
return URL(fileURLWithPath: filename, isDirectory: true)
@@ -1315,7 +1329,7 @@ extension FileManager {
let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in
return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in
// This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard.
- if rename(newItemFS, originalFS) == 0 {
+ if let newFS = newItemFS, let origFS = originalFS, rename(newFS, origFS) == 0 {
return nil
} else {
return errno
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
index 1aa3038a..9fdb495c 100644
--- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
@@ -568,13 +568,13 @@ open class FileManager : NSObject {
let attributes = try windowsFileAttributes(atPath: path)
let type = FileAttributeType(attributes: attributes, atPath: path)
#else
- if let pwd = getpwuid(s.st_uid), pwd.pointee.pw_name != nil {
- let name = String(cString: pwd.pointee.pw_name)
+ if let pwd = getpwuid(s.st_uid), let pwd_name = pwd.pointee.pw_name {
+ let name = String(cString: pwd_name)
result[.ownerAccountName] = name
}
- if let grd = getgrgid(s.st_gid), grd.pointee.gr_name != nil {
- let name = String(cString: grd.pointee.gr_name)
+ if let grd = getgrgid(s.st_gid), let grd_name = grd.pointee.gr_name {
+ let name = String(cString: grd_name)
result[.groupOwnerAccountName] = name
}
diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift
index 5fe7b29c..ce571abe 100644
--- a/swift-corelibs-foundation/Sources/Foundation/Host.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift
@@ -25,7 +25,8 @@ import WinSDK
// getnameinfo uses size_t for its 4th and 6th arguments.
private func getnameinfo(_ addr: UnsafePointer<sockaddr>?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
- return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
+ guard let saddr = addr else { return -1 }
+ return Glibc.getnameinfo(saddr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
}
// getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically.
diff --git a/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift b/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift
index 4d6577d0..aa22dade 100644
--- a/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift
+++ b/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift
@@ -136,7 +136,7 @@ import var TSCBasic.stdoutStream
}
#else
case .signalled(let signal):
- let errorMessage = strsignal(signal).map { String(cString: $0) } ?? ""
+ let errorMessage = String(cString: strsignal(signal))
messages = constructJobSignalledMessages(job: job, error: errorMessage, output: output,
signal: signal, pid: pid).map {
ParsableMessage(name: job.kind.rawValue, kind: .signalled($0))