Skip to content

Commit 6f1b831

Browse files
authored
Merge pull request swiftlang#83933 from compnerd/unsafe
Windows: annotate unsafe constructs in the overlay
2 parents ae2b46e + eafc814 commit 6f1b831

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

stdlib/public/Platform/Platform.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,29 @@ public var stdin: UnsafeMutablePointer<FILE> { return _swift_stdlib_stdin() }
7878
public var stdout: UnsafeMutablePointer<FILE> { return _swift_stdlib_stdout() }
7979
public var stderr: UnsafeMutablePointer<FILE> { return _swift_stdlib_stderr() }
8080
#elseif os(Windows)
81-
public var stdin: UnsafeMutablePointer<FILE> { return __acrt_iob_func(0) }
82-
public var stdout: UnsafeMutablePointer<FILE> { return __acrt_iob_func(1) }
83-
public var stderr: UnsafeMutablePointer<FILE> { return __acrt_iob_func(2) }
81+
public var stdin: UnsafeMutablePointer<FILE> {
82+
return unsafe __acrt_iob_func(0)
83+
}
84+
85+
public var stdout: UnsafeMutablePointer<FILE> {
86+
return unsafe __acrt_iob_func(1)
87+
}
88+
89+
public var stderr: UnsafeMutablePointer<FILE> {
90+
return unsafe __acrt_iob_func(2)
91+
}
8492

85-
public var STDIN_FILENO: Int32 { return _fileno(stdin) }
86-
public var STDOUT_FILENO: Int32 { return _fileno(stdout) }
87-
public var STDERR_FILENO: Int32 { return _fileno(stderr) }
93+
public var STDIN_FILENO: Int32 {
94+
return unsafe _fileno(stdin)
95+
}
96+
97+
public var STDOUT_FILENO: Int32 {
98+
return unsafe _fileno(stdout)
99+
}
100+
101+
public var STDERR_FILENO: Int32 {
102+
return unsafe _fileno(stderr)
103+
}
88104
#endif
89105

90106

@@ -272,10 +288,10 @@ public var SIG_HOLD: sighandler_t {
272288
#elseif os(Windows)
273289
public var SIG_DFL: _crt_signal_t? { return nil }
274290
public var SIG_IGN: _crt_signal_t {
275-
return unsafeBitCast(1, to: _crt_signal_t.self)
291+
return unsafe unsafeBitCast(1, to: _crt_signal_t.self)
276292
}
277293
public var SIG_ERR: _crt_signal_t {
278-
return unsafeBitCast(-1, to: _crt_signal_t.self)
294+
return unsafe unsafeBitCast(-1, to: _crt_signal_t.self)
279295
}
280296
#elseif os(WASI)
281297
// No signals support on WASI yet, see https://github.com/WebAssembly/WASI/issues/166.

stdlib/public/Platform/tgmath.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public func lgamma(_ x: ${T}) -> (${T}, Int) {
295295
@_transparent
296296
public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) {
297297
var quo = Int32(0)
298-
let rem = remquo${f}(${CT}(x), ${CT}(y), &quo)
298+
let rem = unsafe remquo${f}(${CT}(x), ${CT}(y), &quo)
299299
return (${T}(rem), Int(quo))
300300
}
301301
% if T == 'Float80':
@@ -313,7 +313,7 @@ public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) {
313313
@_transparent
314314
@_unavailableInEmbedded
315315
public func nan(_ tag: String) -> ${T} {
316-
return ${T}(nan${f}(tag))
316+
return ${T}(unsafe nan${f}(tag))
317317
}
318318
% if T == 'Float80':
319319
#endif

stdlib/public/Windows/WinSDK.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public var STD_ERROR_HANDLE: DWORD {
5656
// handleapi.h
5757
@inlinable
5858
public var INVALID_HANDLE_VALUE: HANDLE {
59-
HANDLE(bitPattern: -1)!
59+
unsafe HANDLE(bitPattern: -1)!
6060
}
6161

6262
// shellapi.h
@@ -163,78 +163,78 @@ public var PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: DWORD_PTR {
163163
// windef.h
164164
@inlinable
165165
public var DPI_AWARENESS_CONTEXT_UNAWARE: DPI_AWARENESS_CONTEXT {
166-
DPI_AWARENESS_CONTEXT(bitPattern: -1)!
166+
unsafe DPI_AWARENESS_CONTEXT(bitPattern: -1)!
167167
}
168168

169169
@inlinable
170170
public var DPI_AWARENESS_CONTEXT_SYSTEM_AWARE: DPI_AWARENESS_CONTEXT {
171-
DPI_AWARENESS_CONTEXT(bitPattern: -2)!
171+
unsafe DPI_AWARENESS_CONTEXT(bitPattern: -2)!
172172
}
173173

174174
@inlinable
175175
public var DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE: DPI_AWARENESS_CONTEXT {
176-
DPI_AWARENESS_CONTEXT(bitPattern: -3)!
176+
unsafe DPI_AWARENESS_CONTEXT(bitPattern: -3)!
177177
}
178178

179179
@inlinable
180180
public var DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2: DPI_AWARENESS_CONTEXT {
181-
DPI_AWARENESS_CONTEXT(bitPattern: -4)!
181+
unsafe DPI_AWARENESS_CONTEXT(bitPattern: -4)!
182182
}
183183

184184
@inlinable
185185
public var DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED: DPI_AWARENESS_CONTEXT {
186-
DPI_AWARENESS_CONTEXT(bitPattern: -5)!
186+
unsafe DPI_AWARENESS_CONTEXT(bitPattern: -5)!
187187
}
188188

189189
// winreg.h
190190
@inlinable
191191
public var HKEY_CLASSES_ROOT: HKEY {
192-
HKEY(bitPattern: UInt(0x80000000))!
192+
unsafe HKEY(bitPattern: UInt(0x80000000))!
193193
}
194194

195195
@inlinable
196196
public var HKEY_CURRENT_USER: HKEY {
197-
HKEY(bitPattern: UInt(0x80000001))!
197+
unsafe HKEY(bitPattern: UInt(0x80000001))!
198198
}
199199

200200
@inlinable
201201
public var HKEY_LOCAL_MACHINE: HKEY {
202-
HKEY(bitPattern: UInt(0x80000002))!
202+
unsafe HKEY(bitPattern: UInt(0x80000002))!
203203
}
204204

205205
@inlinable
206206
public var HKEY_USERS: HKEY {
207-
HKEY(bitPattern: UInt(0x80000003))!
207+
unsafe HKEY(bitPattern: UInt(0x80000003))!
208208
}
209209

210210
@inlinable
211211
public var HKEY_PERFORMANCE_DATA: HKEY {
212-
HKEY(bitPattern: UInt(0x80000004))!
212+
unsafe HKEY(bitPattern: UInt(0x80000004))!
213213
}
214214

215215
@inlinable
216216
public var HKEY_PERFORMANCE_TEXT: HKEY {
217-
HKEY(bitPattern: UInt(0x80000050))!
217+
unsafe HKEY(bitPattern: UInt(0x80000050))!
218218
}
219219

220220
@inlinable
221221
public var HKEY_PERFORMANCE_NLSTEXT: HKEY {
222-
HKEY(bitPattern: UInt(0x80000060))!
222+
unsafe HKEY(bitPattern: UInt(0x80000060))!
223223
}
224224

225225
@inlinable
226226
public var HKEY_CURRENT_CONFIG: HKEY {
227-
HKEY(bitPattern: UInt(0x80000005))!
227+
unsafe HKEY(bitPattern: UInt(0x80000005))!
228228
}
229229

230230
@inlinable
231231
public var HKEY_DYN_DATA: HKEY {
232-
HKEY(bitPattern: UInt(0x80000006))!
232+
unsafe HKEY(bitPattern: UInt(0x80000006))!
233233
}
234234

235235
@inlinable
236236
public var HKEY_CURRENT_USER_LOCAL_SETTINGS: HKEY {
237-
HKEY(bitPattern: UInt(0x80000007))!
237+
unsafe HKEY(bitPattern: UInt(0x80000007))!
238238
}
239239

240240
// Richedit.h

0 commit comments

Comments
 (0)