[DNM][ClangImporter] Define _GNU_SOURCE - #91465
Conversation
26e6e0d to
b47f86a
Compare
|
@swift-ci please test Linux platform |
|
@swift-ci please build toolchain Linux platform |
On Linux and other glibc-based platforms, the `Glibc` module is now imported with `_GNU_SOURCE` defined, as it already was when C++ interop is enabled. This makes the following GNU extensions available without workarounds: `dladdr`, `Dl_info`, `pthread_setname_np`, `sched_getaffinity`, `cpu_set_t`, and `process_vm_readv`. This is source-breaking for the few functions that have both GNU and XSI variants, though enabling C++ interop already provoked that source break. Most notably, `strerror_r` now has the GNU flavor, returning the message rather than an error code: ```swift var buf = [CChar](repeating: 0, count: 128) let message: UnsafeMutablePointer<CChar> = strerror_r(errno, &buf, buf.count) print(String(cString: message)) ``` Addresses [SR-328](swiftlang#42950), [SR-360](swiftlang#42980), rdar://162215932, and apple/swift-system#229.
b47f86a to
faf60a1
Compare
|
@swift-ci please test Linux platform |
|
@swift-ci build toolchain Linux platform |
|
Interesting, we considered going the other way, to stop defining this for Android 6-7 years ago, but decided it wasn't worth it even that early, as some Swift code on Android probably relied on it by then. I wonder if the converse isn't true here, ie defining this with glibc too now would screw up too many Swift packages on linux, as can be seen with the failing linux CI builds here. Maybe the @swiftlang/server-workgroup has some input on how hard this glibc change is to pull off. |
|
We'll see. I didn't find an indication of why it was never done, so I figured I'd find out by trying it. Several projects jump through hoops to define |
|
Not arguing against this, as I honestly don't know what APIs exactly are gated by this define, just thought the server people would have some feedback. |
When `_XOPEN_SOURCE` is set, the stored property of `fd_set` is renamed to `fds_bits` from `__fds_bits`. Add a computed property under the old name, forwarding to the new name for compatibility.
Adds API notes for socket address parameters.
faf60a1 to
1e06cf8
Compare
|
swiftlang/swift-testing#1835 |
|
swiftlang/swift-testing#1835 |
|
I am not opposed to this since we define |
|
Absolutely! This is just a starting point. Note that I don't think that adding apinotes is the right way to do it; we probably need to add support for anonymous unions in ClangImporter. |
On Linux and other glibc-based platforms, the
Glibcmodule is now imported with_GNU_SOURCEdefined, as it already was when C++ interop is enabled.Addresses SR-328, SR-360, rdar://162215932, and apple/swift-system#229.