Skip to content

[Stdlib] Remove SwiftPrivate's dependency on Darwin. #20475

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion stdlib/private/SwiftPrivate/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

import SwiftShims
import SwiftOverlayShims

public struct _FDInputStream {
public let fd: CInt
Expand Down
27 changes: 0 additions & 27 deletions stdlib/public/SwiftShims/LibcOverlayShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ typedef int mode_t;
#include <semaphore.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#endif

#include <errno.h>
Expand Down Expand Up @@ -114,32 +113,6 @@ int static inline _swift_stdlib_openat(int fd, const char *path, int oflag,
}
#endif

static inline __swift_ssize_t
_swift_stdlib_read(int fd, void *buf, size_t nbyte) {
#if defined(_WIN32)
return _read(fd, buf, nbyte);
#else
return read(fd, buf, nbyte);
#endif
}

static inline __swift_ssize_t
_swift_stdlib_write(int fd, const void *buf, size_t nbyte) {
#if defined(_WIN32)
return _write(fd, buf, nbyte);
#else
return write(fd, buf, nbyte);
#endif
}

static inline int _swift_stdlib_close(int fd) {
#if defined(_WIN32)
return _close(fd);
#else
return close(fd);
#endif
}

#if __has_feature(nullability)
#pragma clang assume_nonnull end
#endif
Expand Down
8 changes: 8 additions & 0 deletions stdlib/public/SwiftShims/LibcShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ static inline void _swift_stdlib_free(void *ptr) {
free(ptr);
}

// <unistd.h>
SWIFT_RUNTIME_STDLIB_SPI
__swift_ssize_t _swift_stdlib_read(int fd, void *buf, __swift_size_t nbyte);
SWIFT_RUNTIME_STDLIB_SPI
__swift_ssize_t _swift_stdlib_write(int fd, const void *buf, __swift_size_t nbyte);
SWIFT_RUNTIME_STDLIB_SPI
int _swift_stdlib_close(int fd);

// String handling <string.h>
SWIFT_READONLY
static inline __swift_size_t _swift_stdlib_strlen(const char *s) {
Expand Down
30 changes: 30 additions & 0 deletions stdlib/public/stubs/LibcShims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

#include <type_traits>

Expand Down Expand Up @@ -50,3 +51,32 @@ __swift_size_t swift::_swift_stdlib_fwrite_stdout(const void *ptr,
__swift_size_t nitems) {
return fwrite(ptr, size, nitems, stdout);
}

SWIFT_RUNTIME_STDLIB_SPI
__swift_ssize_t
swift::_swift_stdlib_read(int fd, void *buf, __swift_size_t nbyte) {
#if defined(_WIN32)
return _read(fd, buf, nbyte);
#else
return read(fd, buf, nbyte);
#endif
}

SWIFT_RUNTIME_STDLIB_SPI
__swift_ssize_t
swift::_swift_stdlib_write(int fd, const void *buf, __swift_size_t nbyte) {
#if defined(_WIN32)
return _write(fd, buf, nbyte);
#else
return write(fd, buf, nbyte);
#endif
}

SWIFT_RUNTIME_STDLIB_SPI
int swift::_swift_stdlib_close(int fd) {
#if defined(_WIN32)
return _close(fd);
#else
return close(fd);
#endif
}