Skip to content

Commit 69b3cc0

Browse files
authored
[overlay] Declaring MAP_FAILED (#4971)
Clang importer is unable to handle `((void *)-1)`, therefore manually declaring the said constant in both Darwin and Glibc modules. rdar://problem/26689135
1 parent d9dd8f7 commit 69b3cc0

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

stdlib/public/Platform/Darwin.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
@_exported import Darwin // Clang module
14+
15+
public let MAP_FAILED =
16+
UnsafeMutableRawPointer(bitPattern: -1)! as UnsafeMutableRawPointer!

stdlib/public/Platform/Glibc.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
@_exported import SwiftGlibc // Clang module
14+
15+
public let MAP_FAILED =
16+
UnsafeMutableRawPointer(bitPattern: -1)! as UnsafeMutableRawPointer!

test/stdlib/mmap.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-run-simple-swift %t
2+
// REQUIRES: executable_test
3+
4+
import StdlibUnittest
5+
#if os(Linux)
6+
import Glibc
7+
#else
8+
import Darwin
9+
#endif
10+
11+
var MMapTests = TestSuite("MMaptests")
12+
13+
MMapTests.test("MAP_FAILED") {
14+
expectEqual(mmap(nil, 0, 0, 0, 0, 0), MAP_FAILED)
15+
}
16+
17+
runAllTests()

0 commit comments

Comments
 (0)