Skip to content

Commit f4db1dd

Browse files
authored
Merge pull request #19614 from mikeash/no-internal-export
[Stdlib] Change SWIFT_RUNTIME_STDLIB_INTERNAL to not export the symbol.
2 parents fa0ba4f + b05c9e9 commit f4db1dd

39 files changed

+481
-424
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ void swift_registerTypeMetadataRecords(const TypeMetadataRecord *begin,
810810
/// Return the superclass, if any. The result is nullptr for root
811811
/// classes and class protocol types.
812812
SWIFT_CC(swift)
813-
SWIFT_RUNTIME_STDLIB_API
813+
SWIFT_RUNTIME_STDLIB_INTERNAL
814814
const Metadata *_swift_class_getSuperclass(const Metadata *theClass);
815815

816816
#if !NDEBUG

stdlib/private/SwiftPrivate/IO.swift

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

1313
import SwiftShims
14+
import SwiftOverlayShims
1415

1516
public struct _FDInputStream {
1617
public let fd: CInt
@@ -55,7 +56,7 @@ public struct _FDInputStream {
5556
(_buffer) in
5657
let addr = _buffer.baseAddress! + self._bufferUsed
5758
let size = bufferFree
58-
return _stdlib_read(fd, addr, size)
59+
return _swift_stdlib_read(fd, addr, size)
5960
}
6061
if readResult == 0 {
6162
isEOF = true
@@ -71,7 +72,7 @@ public struct _FDInputStream {
7172
if isClosed {
7273
return
7374
}
74-
let result = _stdlib_close(fd)
75+
let result = _swift_stdlib_close(fd)
7576
if result < 0 {
7677
fatalError("close() returned an error")
7778
}
@@ -104,7 +105,7 @@ public struct _FDOutputStream : TextOutputStream {
104105
var writtenBytes = 0
105106
let bufferSize = utf8CStr.count - 1
106107
while writtenBytes != bufferSize {
107-
let result = _stdlib_write(
108+
let result = _swift_stdlib_write(
108109
self.fd, UnsafeRawPointer(utf8CStr.baseAddress! + Int(writtenBytes)),
109110
bufferSize - writtenBytes)
110111
if result < 0 {
@@ -119,7 +120,7 @@ public struct _FDOutputStream : TextOutputStream {
119120
if isClosed {
120121
return
121122
}
122-
let result = _stdlib_close(fd)
123+
let result = _swift_stdlib_close(fd)
123124
if result < 0 {
124125
fatalError("close() returned an error")
125126
}

stdlib/public/Platform/Platform.swift

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

1313
import SwiftShims
14+
import SwiftOverlayShims
1415

1516
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1617
//===----------------------------------------------------------------------===//
@@ -80,10 +81,10 @@ func _convertDarwinBooleanToBool(_ x: DarwinBoolean) -> Bool {
8081

8182
public var errno : Int32 {
8283
get {
83-
return _stdlib_getErrno()
84+
return _swift_stdlib_getErrno()
8485
}
8586
set(val) {
86-
return _stdlib_setErrno(val)
87+
return _swift_stdlib_setErrno(val)
8788
}
8889
}
8990

@@ -142,7 +143,7 @@ public func open(
142143
_ path: UnsafePointer<CChar>,
143144
_ oflag: Int32
144145
) -> Int32 {
145-
return _stdlib_open(path, oflag, 0)
146+
return _swift_stdlib_open(path, oflag, 0)
146147
}
147148

148149
#if os(Windows)
@@ -151,23 +152,23 @@ public func open(
151152
_ oflag: Int32,
152153
_ mode: Int32
153154
) -> Int32 {
154-
return _stdlib_open(path, oflag, mode)
155+
return _swift_stdlib_open(path, oflag, mode)
155156
}
156157
#else
157158
public func open(
158159
_ path: UnsafePointer<CChar>,
159160
_ oflag: Int32,
160161
_ mode: mode_t
161162
) -> Int32 {
162-
return _stdlib_open(path, oflag, mode)
163+
return _swift_stdlib_open(path, oflag, mode)
163164
}
164165

165166
public func openat(
166167
_ fd: Int32,
167168
_ path: UnsafePointer<CChar>,
168169
_ oflag: Int32
169170
) -> Int32 {
170-
return _stdlib_openat(fd, path, oflag, 0)
171+
return _swift_stdlib_openat(fd, path, oflag, 0)
171172
}
172173

173174
public func openat(
@@ -176,30 +177,30 @@ public func openat(
176177
_ oflag: Int32,
177178
_ mode: mode_t
178179
) -> Int32 {
179-
return _stdlib_openat(fd, path, oflag, mode)
180+
return _swift_stdlib_openat(fd, path, oflag, mode)
180181
}
181182

182183
public func fcntl(
183184
_ fd: Int32,
184185
_ cmd: Int32
185186
) -> Int32 {
186-
return _stdlib_fcntl(fd, cmd, 0)
187+
return _swift_stdlib_fcntl(fd, cmd, 0)
187188
}
188189

189190
public func fcntl(
190191
_ fd: Int32,
191192
_ cmd: Int32,
192193
_ value: Int32
193194
) -> Int32 {
194-
return _stdlib_fcntl(fd, cmd, value)
195+
return _swift_stdlib_fcntl(fd, cmd, value)
195196
}
196197

197198
public func fcntl(
198199
_ fd: Int32,
199200
_ cmd: Int32,
200201
_ ptr: UnsafeMutableRawPointer
201202
) -> Int32 {
202-
return _stdlib_fcntlPtr(fd, cmd, ptr)
203+
return _swift_stdlib_fcntlPtr(fd, cmd, ptr)
203204
}
204205

205206
// !os(Windows)
@@ -267,22 +268,22 @@ public func ioctl(
267268
_ request: UInt,
268269
_ value: CInt
269270
) -> CInt {
270-
return _stdlib_ioctl(fd, request, value)
271+
return _swift_stdlib_ioctl(fd, request, value)
271272
}
272273

273274
public func ioctl(
274275
_ fd: CInt,
275276
_ request: UInt,
276277
_ ptr: UnsafeMutableRawPointer
277278
) -> CInt {
278-
return _stdlib_ioctlPtr(fd, request, ptr)
279+
return _swift_stdlib_ioctlPtr(fd, request, ptr)
279280
}
280281

281282
public func ioctl(
282283
_ fd: CInt,
283284
_ request: UInt
284285
) -> CInt {
285-
return _stdlib_ioctl(fd, request, 0)
286+
return _swift_stdlib_ioctl(fd, request, 0)
286287
}
287288

288289
// !os(Windows)
@@ -374,7 +375,6 @@ public func sem_open(
374375
_ oflag: Int32
375376
) -> UnsafeMutablePointer<sem_t>? {
376377
return _stdlib_sem_open2(name, oflag)
377-
.assumingMemoryBound(to: sem_t.self)
378378
}
379379

380380
public func sem_open(
@@ -384,7 +384,6 @@ public func sem_open(
384384
_ value: CUnsignedInt
385385
) -> UnsafeMutablePointer<sem_t>? {
386386
return _stdlib_sem_open4(name, oflag, mode, value)
387-
.assumingMemoryBound(to: sem_t.self)
388387
}
389388
#endif
390389

@@ -395,7 +394,7 @@ public func sem_open(
395394
// Some platforms don't have `extern char** environ` imported from C.
396395
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
397396
public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?> {
398-
return _stdlib_getEnviron()
397+
return _swift_stdlib_getEnviron()
399398
}
400399
#elseif os(Linux)
401400
public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?> {

stdlib/public/SwiftShims/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ set(sources
55
GlobalObjects.h
66
HeapObject.h
77
KeyPath.h
8+
LibcOverlayShims.h
89
LibcShims.h
10+
Random.h
911
RefCount.h
1012
RuntimeShims.h
1113
RuntimeStubs.h
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//===--- LibcOverlayShims.h - Static inline shims for POSIX functions. --*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Provide small wrappers for POSIX functionality that can't be used
14+
// directly from Swift due to varargs or other issues.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_STDLIB_SHIMS_LIBCOVERLAYSHIMS_H
19+
#define SWIFT_STDLIB_SHIMS_LIBCOVERLAYSHIMS_H
20+
21+
#include "Visibility.h"
22+
23+
#if defined(_WIN32) && !defined(__CYGWIN__)
24+
#include <io.h>
25+
#define WIN32_LEAN_AND_MEAN
26+
#include <Windows.h>
27+
typedef int mode_t;
28+
#else
29+
#include <semaphore.h>
30+
#include <sys/ioctl.h>
31+
#include <sys/types.h>
32+
#include <unistd.h>
33+
#endif
34+
35+
#include <errno.h>
36+
#include <fcntl.h>
37+
38+
#if __has_feature(nullability)
39+
#pragma clang assume_nonnull begin
40+
#endif
41+
42+
// File control <fcntl.h>
43+
#if !defined(_WIN32) || defined(__CYGWIN__)
44+
static inline int _swift_stdlib_fcntl(int fd, int cmd, int value) {
45+
return fcntl(fd, cmd, value);
46+
}
47+
48+
static inline int _swift_stdlib_fcntlPtr(int fd, int cmd, void* ptr) {
49+
return fcntl(fd, cmd, ptr);
50+
}
51+
#endif
52+
53+
// Environment
54+
#if defined(__FreeBSD__)
55+
static inline char * _Nullable * _Null_unspecified _swift_stdlib_getEnviron() {
56+
extern char **environ;
57+
return environ;
58+
}
59+
#elif defined(__APPLE__)
60+
static inline char * _Nullable *_swift_stdlib_getEnviron() {
61+
extern char * _Nullable **_NSGetEnviron(void);
62+
return *_NSGetEnviron();
63+
}
64+
#endif
65+
66+
// System error numbers <errno.h>
67+
static inline int _swift_stdlib_getErrno() {
68+
return errno;
69+
}
70+
71+
static inline void _swift_stdlib_setErrno(int value) {
72+
errno = value;
73+
}
74+
75+
// Semaphores <semaphore.h>
76+
#if !defined(_WIN32) || defined(__CYGWIN__)
77+
static inline sem_t *_stdlib_sem_open2(const char *name, int oflag) {
78+
return sem_open(name, oflag);
79+
}
80+
81+
static inline sem_t *_stdlib_sem_open4(const char *name, int oflag,
82+
mode_t mode, unsigned int value) {
83+
return sem_open(name, oflag, mode, value);
84+
}
85+
86+
#endif // !(defined(_WIN32) && !defined(__CYGWIN__))
87+
88+
// I/O control <ioctl.h>
89+
#if !defined(_WIN32) || defined(__CYGWIN__)
90+
static inline int _swift_stdlib_ioctl(int fd, unsigned long int request, int value) {
91+
return ioctl(fd, request, value);
92+
}
93+
94+
static inline int _swift_stdlib_ioctlPtr(int fd, unsigned long int request, void* ptr) {
95+
return ioctl(fd, request, ptr);
96+
}
97+
#endif
98+
99+
#if defined(_WIN32) && !defined(__CYGWIN__)
100+
// Windows
101+
static inline int _swift_stdlib_open(const char *path, int oflag, mode_t mode) {
102+
return _open(path, oflag, static_cast<int>(mode));
103+
}
104+
105+
#else
106+
// not Windows
107+
int static inline _swift_stdlib_open(const char *path, int oflag, mode_t mode) {
108+
return open(path, oflag, mode);
109+
}
110+
111+
int static inline _swift_stdlib_openat(int fd, const char *path, int oflag,
112+
mode_t mode) {
113+
return openat(fd, path, oflag, mode);
114+
}
115+
#endif
116+
117+
static inline ssize_t
118+
_swift_stdlib_read(int fd, void *buf, size_t nbyte) {
119+
#if defined(_WIN32)
120+
return _read(fd, buf, nbyte);
121+
#else
122+
return read(fd, buf, nbyte);
123+
#endif
124+
}
125+
126+
static inline ssize_t
127+
_swift_stdlib_write(int fd, const void *buf, size_t nbyte) {
128+
#if defined(_WIN32)
129+
return _write(fd, buf, nbyte);
130+
#else
131+
return write(fd, buf, nbyte);
132+
#endif
133+
}
134+
135+
static inline int _swift_stdlib_close(int fd) {
136+
#if defined(_WIN32)
137+
return _close(fd);
138+
#else
139+
return close(fd);
140+
#endif
141+
}
142+
143+
#if __has_feature(nullability)
144+
#pragma clang assume_nonnull end
145+
#endif
146+
147+
#endif // SWIFT_STDLIB_SHIMS_LIBCOVERLAYSHIMS_H

0 commit comments

Comments
 (0)