-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Platform: port to msvcrt, add msvcrt module #3428
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,18 +98,29 @@ public var errno : Int32 { | |
get { | ||
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4) | ||
return __error().pointee | ||
// FIXME: os(Windows) should be replaced, such as triple(Cygwin) | ||
#elseif os(Android) || os(Windows) | ||
#elseif os(Android) | ||
return __errno().pointee | ||
#elseif os(Windows) | ||
#if CYGWIN | ||
return __errno().pointee | ||
#else | ||
return _errno().pointee | ||
#endif | ||
#else | ||
return __errno_location().pointee | ||
#endif | ||
} | ||
set(val) { | ||
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4) | ||
return __error().pointee = val | ||
#elseif os(Android) || os(Windows) | ||
#elseif os(Android) | ||
return __errno().pointee = val | ||
#elseif os(Windows) | ||
#if CYGWIN | ||
return __errno().pointee = val | ||
#else | ||
return _errno().pointee = val | ||
#endif | ||
#else | ||
return __errno_location().pointee = val | ||
#endif | ||
|
@@ -165,20 +176,31 @@ public func snprintf(ptr: UnsafeMutablePointer<Int8>, _ len: Int, _ format: Unsa | |
// fcntl.h | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if !os(Windows) || CYGWIN | ||
@_silgen_name("_swift_Platform_open") | ||
func _swift_Platform_open( | ||
_ path: UnsafePointer<CChar>, | ||
_ oflag: Int32, | ||
_ mode: mode_t | ||
) -> Int32 | ||
#else | ||
@_silgen_name("_swift_Platform_open") | ||
func _swift_Platform_open( | ||
_ path: UnsafePointer<CChar>, | ||
_ oflag: Int32, | ||
_ mode: Int32 | ||
) -> Int32 | ||
#endif | ||
|
||
#if !os(Windows) || CYGWIN | ||
@_silgen_name("_swift_Platform_openat") | ||
func _swift_Platform_openat( | ||
_ fd: Int32, | ||
_ path: UnsafePointer<CChar>, | ||
_ oflag: Int32, | ||
_ mode: mode_t | ||
) -> Int32 | ||
#endif | ||
|
||
public func open( | ||
_ path: UnsafePointer<CChar>, | ||
|
@@ -187,6 +209,7 @@ public func open( | |
return _swift_Platform_open(path, oflag, 0) | ||
} | ||
|
||
#if !os(Windows) || CYGWIN | ||
public func open( | ||
_ path: UnsafePointer<CChar>, | ||
_ oflag: Int32, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've shimmed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because theres no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this is not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I meant, that because it calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but I think it calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh, I see what you mean. This was supposed to have an alternate implementation with the signature change. Ill fix this in the upload that Im about to do. |
||
|
@@ -211,7 +234,17 @@ public func openat( | |
) -> Int32 { | ||
return _swift_Platform_openat(fd, path, oflag, mode) | ||
} | ||
#else | ||
public func open( | ||
_ path: UnsafePointer<CChar>, | ||
_ oflag: Int32, | ||
_ mode: Int32 | ||
) -> Int32 { | ||
return _swift_Platform_open(path, oflag, mode) | ||
} | ||
#endif | ||
|
||
#if !os(Windows) || CYGWIN | ||
@_silgen_name("_swift_Platform_fcntl") | ||
internal func _swift_Platform_fcntl( | ||
_ fd: Int32, | ||
|
@@ -248,7 +281,9 @@ public func fcntl( | |
) -> Int32 { | ||
return _swift_Platform_fcntlPtr(fd, cmd, ptr) | ||
} | ||
#endif | ||
|
||
#if !os(Windows) || CYGWIN | ||
public var S_IFMT: mode_t { return mode_t(0o170000) } | ||
public var S_IFIFO: mode_t { return mode_t(0o010000) } | ||
public var S_IFCHR: mode_t { return mode_t(0o020000) } | ||
|
@@ -286,11 +321,24 @@ public var S_IREAD: mode_t { return S_IRUSR } | |
public var S_IWRITE: mode_t { return S_IWUSR } | ||
public var S_IEXEC: mode_t { return S_IXUSR } | ||
#endif | ||
#else | ||
public var S_IFMT: Int32 { return Int32(0xf000) } | ||
|
||
public var S_IFREG: Int32 { return Int32(0x8000) } | ||
public var S_IFDIR: Int32 { return Int32(0x4000) } | ||
public var S_IFCHR: Int32 { return Int32(0x2000) } | ||
public var S_IFIFO: Int32 { return Int32(0x1000) } | ||
|
||
public var S_IREAD: Int32 { return Int32(0x0100) } | ||
public var S_IWRITE: Int32 { return Int32(0x0080) } | ||
public var S_IEXEC: Int32 { return Int32(0x0040) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Windows does not have The definitions in this block look identical otherwise. We actually also have Could we gyb this somehow? Or maybe emulate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree its painful. Windows does not have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! |
||
#endif | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ioctl.h | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if !os(Windows) || CYGWIN | ||
@_silgen_name("_swift_Platform_ioctl") | ||
internal func _swift_Platform_ioctl( | ||
_ fd: CInt, | ||
|
@@ -327,8 +375,8 @@ public func ioctl( | |
) -> CInt { | ||
return _swift_Platform_ioctl(fd, request, 0) | ||
} | ||
#endif | ||
|
||
//===----------------------------------------------------------------------===// | ||
// unistd.h | ||
//===----------------------------------------------------------------------===// | ||
|
@@ -354,14 +402,22 @@ public var SIG_DFL: sig_t? { return nil } | |
public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) } | ||
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) } | ||
public var SIG_HOLD: sig_t { return unsafeBitCast(5, to: sig_t.self) } | ||
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows) | ||
#if os(Windows) | ||
// In Cygwin, the below SIG_* have the same value with Linux. | ||
// Verified with libstdc++6 v5.3.0 in Cygwin v2.4.1 64bit. | ||
public typealias sighandler_t = _sig_func_ptr | ||
#else | ||
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) | ||
public typealias sighandler_t = __sighandler_t | ||
|
||
public var SIG_DFL: sighandler_t? { return nil } | ||
public var SIG_IGN: sighandler_t { | ||
return unsafeBitCast(1, to: sighandler_t.self) | ||
} | ||
public var SIG_ERR: sighandler_t { | ||
return unsafeBitCast(-1, to: sighandler_t.self) | ||
} | ||
public var SIG_HOLD: sighandler_t { | ||
return unsafeBitCast(2, to: sighandler_t.self) | ||
} | ||
#elseif os(Windows) | ||
#if CYGWIN | ||
public typealias sighandler_t = __sighandler_t | ||
#endif | ||
|
||
public var SIG_DFL: sighandler_t? { return nil } | ||
public var SIG_IGN: sighandler_t { | ||
|
@@ -374,21 +430,38 @@ public var SIG_HOLD: sighandler_t { | |
return unsafeBitCast(2, to: sighandler_t.self) | ||
} | ||
#else | ||
public var SIG_DFL: _crt_signal_t? { return nil } | ||
public var SIG_IGN: _crt_signal_t { | ||
return unsafeBitCast(1, to: _crt_signal_t.self) | ||
} | ||
public var SIG_ERR: _crt_signal_t { | ||
return unsafeBitCast(-1, to: _crt_signal_t.self) | ||
} | ||
#endif | ||
#else | ||
internal var _ignore = _UnsupportedPlatformError() | ||
#endif | ||
|
||
//===----------------------------------------------------------------------===// | ||
// semaphore.h | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if !os(Windows) || CYGWIN | ||
/// The value returned by `sem_open()` in the case of failure. | ||
public var SEM_FAILED: UnsafeMutablePointer<sem_t>? { | ||
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) | ||
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS. | ||
return UnsafeMutablePointer<sem_t>(bitPattern: -1) | ||
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows) | ||
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) | ||
// The value is ABI. Value verified to be correct on Glibc. | ||
return UnsafeMutablePointer<sem_t>(bitPattern: 0) | ||
#elseif os(Windows) | ||
#if CYGWIN | ||
// The value is ABI. Value verified to be correct on Glibc. | ||
return UnsafeMutablePointer<sem_t>(bitPattern: 0) | ||
#else | ||
_UnsupportedPlatformError() | ||
#endif | ||
#else | ||
_UnsupportedPlatformError() | ||
#endif | ||
|
@@ -423,6 +496,7 @@ public func sem_open( | |
) -> UnsafeMutablePointer<sem_t>? { | ||
return _swift_Platform_sem_open4(name, oflag, mode, value) | ||
} | ||
#endif | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Misc. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
@_exported import ucrt // Clang module | ||
@_exported import visualc // Clang module | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
#if
s in errno overlay are a mess :( As a separate PR, would you mind changing our implementation strategy to be more portable? We could have a C function that reads errno, and another one that writes it. These functions will use the normalerrno
macro, so they will be portable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea, will do.