Skip to content

[Concurrency] Avoid relying on stderr, fprintf(), write() in Embedded Concurrency runtime #77013

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
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
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,14 @@ void swift::swift_task_reportUnexpectedExecutor(
&details);
}

#if defined(_WIN32)
#if defined(_WIN32) && !SWIFT_CONCURRENCY_EMBEDDED
#define STDERR_FILENO 2
_write(STDERR_FILENO, message, strlen(message));
#else
#elif !SWIFT_CONCURRENCY_EMBEDDED
fputs(message, stderr);
fflush(stderr);
#else
puts(message);
#endif
#if SWIFT_STDLIB_HAS_ASL
#pragma clang diagnostic push
Expand Down
4 changes: 4 additions & 0 deletions stdlib/public/Concurrency/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ SWIFT_NORETURN
SWIFT_VFORMAT(2)
void swift::swift_Concurrency_fatalErrorv(uint32_t flags, const char *format,
va_list val) {
#if !SWIFT_CONCURRENCY_EMBEDDED
vfprintf(stderr, format, val);
#else
vprintf(format, val);
#endif
abort();
}

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/TaskAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static TaskAllocator &allocator(AsyncTask *task) {
static GlobalAllocator global;
return global.allocator;
#else
fprintf(stderr, "global allocator fallback not available\n");
puts("global allocator fallback not available\n");
abort();
#endif
}
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/TaskGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,13 @@ struct TaskGroupStatus {
}
#endif

#if defined(_WIN32)
#if defined(_WIN32) && !SWIFT_CONCURRENCY_EMBEDDED
#define STDERR_FILENO 2
_write(STDERR_FILENO, message, strlen(message));
#elif defined(STDERR_FILENO)
#elif defined(STDERR_FILENO) && !SWIFT_CONCURRENCY_EMBEDDED
write(STDERR_FILENO, message, strlen(message));
#else
puts(message);
#endif
#if defined(SWIFT_STDLIB_HAS_ASL)
#pragma clang diagnostic push
Expand Down
5 changes: 1 addition & 4 deletions test/embedded/dependencies-concurrency-custom-executor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
// RUN: test -z "`comm -13 %t/allowed-dependencies.txt %t/actual-dependencies.txt`"

// DEP: ___assert_rtn
// DEP: ___error
// DEP: ___stack_chk_fail
// DEP: ___stack_chk_guard
// DEP: ___stderrp
// DEP: _abort
// DEP: _clock_gettime
// DEP: _exit
Expand All @@ -27,11 +25,10 @@
// DEP: _nanosleep
// DEP: _posix_memalign
// DEP: _putchar
// DEP: _puts
// DEP: _strlen
// DEP: _vfprintf
// DEP: _vprintf
// DEP: _vsnprintf
// DEP: _write

// RUN: %target-run %t/a.out | %FileCheck %s

Expand Down
15 changes: 2 additions & 13 deletions test/embedded/dependencies-concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,13 @@
// Fail if there is any entry in actual-dependencies.txt that's not in allowed-dependencies.txt
// RUN: test -z "`comm -13 %t/allowed-dependencies.txt %t/actual-dependencies.txt`"

// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKcm
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6insertEmPKc
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev
// DEP: __ZNSt3__16chrono12steady_clock3nowEv
// DEP: __ZNSt3__19to_stringEj
// DEP: __ZNSt3__19to_stringEy
// DEP: __ZdlPv
// DEP: __ZdlPvm
// DEP: __Znwm
// DEP: ___assert_rtn
// DEP: ___error
// DEP: ___stack_chk_fail
// DEP: ___stack_chk_guard
// DEP: ___stderrp
// DEP: _abort
// DEP: _exit
// DEP: _fprintf
// DEP: _free
// DEP: _malloc
// DEP: _memmove
Expand All @@ -35,10 +24,10 @@
// DEP: _nanosleep
// DEP: _posix_memalign
// DEP: _putchar
// DEP: _puts
// DEP: _strlen
// DEP: _vfprintf
// DEP: _vprintf
// DEP: _vsnprintf
// DEP: _write

// RUN: %target-run %t/a.out | %FileCheck %s

Expand Down