Skip to content

Commit b6bdafe

Browse files
authored
Merge pull request #77013 from kubamracek/embedded-concurrency-no-stderr
[Concurrency] Avoid relying on stderr, fprintf(), write() in Embedded Concurrency runtime
2 parents 700493e + d2dac4e commit b6bdafe

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,14 @@ void swift::swift_task_reportUnexpectedExecutor(
645645
&details);
646646
}
647647

648-
#if defined(_WIN32)
648+
#if defined(_WIN32) && !SWIFT_CONCURRENCY_EMBEDDED
649649
#define STDERR_FILENO 2
650650
_write(STDERR_FILENO, message, strlen(message));
651-
#else
651+
#elif !SWIFT_CONCURRENCY_EMBEDDED
652652
fputs(message, stderr);
653653
fflush(stderr);
654+
#else
655+
puts(message);
654656
#endif
655657
#if SWIFT_STDLIB_HAS_ASL
656658
#pragma clang diagnostic push

stdlib/public/Concurrency/Error.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ SWIFT_NORETURN
2121
SWIFT_VFORMAT(2)
2222
void swift::swift_Concurrency_fatalErrorv(uint32_t flags, const char *format,
2323
va_list val) {
24+
#if !SWIFT_CONCURRENCY_EMBEDDED
2425
vfprintf(stderr, format, val);
26+
#else
27+
vprintf(format, val);
28+
#endif
2529
abort();
2630
}
2731

stdlib/public/Concurrency/TaskAlloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static TaskAllocator &allocator(AsyncTask *task) {
4747
static GlobalAllocator global;
4848
return global.allocator;
4949
#else
50-
fprintf(stderr, "global allocator fallback not available\n");
50+
puts("global allocator fallback not available\n");
5151
abort();
5252
#endif
5353
}

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,13 @@ struct TaskGroupStatus {
610610
}
611611
#endif
612612

613-
#if defined(_WIN32)
613+
#if defined(_WIN32) && !SWIFT_CONCURRENCY_EMBEDDED
614614
#define STDERR_FILENO 2
615615
_write(STDERR_FILENO, message, strlen(message));
616-
#elif defined(STDERR_FILENO)
616+
#elif defined(STDERR_FILENO) && !SWIFT_CONCURRENCY_EMBEDDED
617617
write(STDERR_FILENO, message, strlen(message));
618+
#else
619+
puts(message);
618620
#endif
619621
#if defined(SWIFT_STDLIB_HAS_ASL)
620622
#pragma clang diagnostic push

test/embedded/dependencies-concurrency-custom-executor.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
// RUN: test -z "`comm -13 %t/allowed-dependencies.txt %t/actual-dependencies.txt`"
1212

1313
// DEP: ___assert_rtn
14-
// DEP: ___error
1514
// DEP: ___stack_chk_fail
1615
// DEP: ___stack_chk_guard
17-
// DEP: ___stderrp
1816
// DEP: _abort
1917
// DEP: _clock_gettime
2018
// DEP: _exit
@@ -27,11 +25,10 @@
2725
// DEP: _nanosleep
2826
// DEP: _posix_memalign
2927
// DEP: _putchar
28+
// DEP: _puts
3029
// DEP: _strlen
31-
// DEP: _vfprintf
3230
// DEP: _vprintf
3331
// DEP: _vsnprintf
34-
// DEP: _write
3532

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

test/embedded/dependencies-concurrency.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,13 @@
99
// Fail if there is any entry in actual-dependencies.txt that's not in allowed-dependencies.txt
1010
// RUN: test -z "`comm -13 %t/allowed-dependencies.txt %t/actual-dependencies.txt`"
1111

12-
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc
13-
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKcm
14-
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6insertEmPKc
15-
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev
1612
// DEP: __ZNSt3__16chrono12steady_clock3nowEv
17-
// DEP: __ZNSt3__19to_stringEj
18-
// DEP: __ZNSt3__19to_stringEy
19-
// DEP: __ZdlPv
20-
// DEP: __ZdlPvm
21-
// DEP: __Znwm
2213
// DEP: ___assert_rtn
2314
// DEP: ___error
2415
// DEP: ___stack_chk_fail
2516
// DEP: ___stack_chk_guard
26-
// DEP: ___stderrp
2717
// DEP: _abort
2818
// DEP: _exit
29-
// DEP: _fprintf
3019
// DEP: _free
3120
// DEP: _malloc
3221
// DEP: _memmove
@@ -35,10 +24,10 @@
3524
// DEP: _nanosleep
3625
// DEP: _posix_memalign
3726
// DEP: _putchar
27+
// DEP: _puts
3828
// DEP: _strlen
39-
// DEP: _vfprintf
29+
// DEP: _vprintf
4030
// DEP: _vsnprintf
41-
// DEP: _write
4231

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

0 commit comments

Comments
 (0)