Skip to content

Commit b20b238

Browse files
committed
Use new Libc naming
Fix Random.swift with new Libc naming
1 parent cb6292c commit b20b238

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ __swift_uint32_t _stdlib_cxx11_mt19937_uniform(__swift_uint32_t upper_bound);
147147

148148
// Random number for stdlib
149149
SWIFT_RUNTIME_STDLIB_INTERFACE
150-
void _swift_stdlib_random(void *buf,
150+
void _stdlib_random(void *buf,
151151
__swift_ssize_t nbytes,
152152
__swift_uint32_t debug_flags);
153153

stdlib/public/core/Random.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public struct Random : RandomNumberGenerator {
129129
@_inlineable
130130
public func next() -> UInt {
131131
var random: UInt = 0
132-
_swift_stdlib_random(&random, MemoryLayout<UInt>.size, _fatalErrorFlags())
132+
_stdlib_random(&random, MemoryLayout<UInt>.size, _fatalErrorFlags())
133133
return random
134134
}
135135
}

stdlib/public/stubs/LibcShims.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,6 @@ int swift::_stdlib_memcmp(const void *s1, const void *s2,
8989
return memcmp(s1, s2, n);
9090
}
9191

92-
SWIFT_RUNTIME_STDLIB_INTERFACE
93-
int swift::_swift_stdlib_open(const char *path, int oflags) {
94-
#if defined(_WIN32)
95-
return _open(path, oflags);
96-
#else
97-
return open(path, oflags);
98-
#endif
99-
}
100-
10192
SWIFT_RUNTIME_STDLIB_INTERFACE
10293
__swift_ssize_t
10394
swift::_stdlib_read(int fd, void *buf, __swift_size_t nbyte) {
@@ -348,15 +339,15 @@ swift::_stdlib_cxx11_mt19937_uniform(__swift_uint32_t upper_bound) {
348339
|| ( defined(TARGET_OS_IPHONE) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 10000 ) \
349340
|| ( defined(TARGET_OS_MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 )
350341
SWIFT_RUNTIME_STDLIB_INTERFACE
351-
void swift::_swift_stdlib_random(void *buf,
342+
void swift::_stdlib_random(void *buf,
352343
__swift_ssize_t nbytes,
353344
__swift_uint32_t debug_flags) {
354345
arc4random_buf(buf, nbytes);
355346
}
356347
#else
357348
#include <Security/Security.h>
358349
SWIFT_RUNTIME_STDLIB_INTERFACE
359-
void swift::_swift_stdlib_random(void *buf,
350+
void swift::_stdlib_random(void *buf,
360351
__swift_ssize_t nbytes,
361352
__swift_uint32_t debug_flags) {
362353
if (SecRandomCopyBytes(kSecRandomDefault, nbytes, buf) != 0) {
@@ -373,7 +364,7 @@ void swift::_swift_stdlib_random(void *buf,
373364
#define _GNU_SOURCE
374365
#include <sys/syscall.h>
375366
SWIFT_RUNTIME_STDLIB_INTERFACE
376-
void swift::_swift_stdlib_random(void *buf,
367+
void swift::_stdlib_random(void *buf,
377368
__swift_ssize_t nbytes,
378369
__swift_uint32_t debug_flags) {
379370
int result = syscall(SYS_getrandom, buf, nbytes, 0);
@@ -383,18 +374,18 @@ void swift::_swift_stdlib_random(void *buf,
383374
}
384375
#else
385376
SWIFT_RUNTIME_STDLIB_INTERFACE
386-
void swift::_swift_stdlib_random(void *buf,
377+
void swift::_stdlib_random(void *buf,
387378
__swift_ssize_t nbytes,
388379
__swift_uint32_t debug_flags) {
389380
int oflags = O_RDONLY;
390-
int fd = swift::_swift_stdlib_open("/dev/urandom", oflags);
381+
int fd = swift::_stdlib_open("/dev/urandom", oflags);
391382
if (fd < 0) {
392383
fatalError(debug_flags, "Fatal error: Unable to open /dev/urandom\n");
393384
}
394-
if (swift::_swift_stdlib_read(fd, buf, nbytes) < 0) {
385+
if (swift::_stdlib_read(fd, buf, nbytes) < 0) {
395386
fatalError(debug_flags, "Fatal error: Unable to read /dev/urandom\n");
396387
}
397-
swift::_swift_stdlib_close(fd);
388+
swift::_stdlib_close(fd);
398389
}
399390
#endif
400391
#endif

0 commit comments

Comments
 (0)