Skip to content

Commit b74da6b

Browse files
committed
[embedded] Move int printing to C (to workaround lack of CVaListPointer)
1 parent e898a9a commit b74da6b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

test/embedded/Inputs/print.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
void print_long(long n) {
5+
printf("%ld", n);
6+
}

test/embedded/collection.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -enforce-exclusivity=none %s -c -o %t/a.o
3-
// RUN: %target-clang %t/a.o -o %t/a.out
3+
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4+
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
45
// RUN: %target-run %t/a.out | %FileCheck %s
56

67
// REQUIRES: executable_test
@@ -23,14 +24,12 @@ public func print(_ s: StaticString, terminator: StaticString = "\n") {
2324
}
2425
}
2526

26-
@_silgen_name("vprintf")
27-
func vprintf(_: UnsafePointer<UInt8>, _: UnsafeRawPointer)
27+
@_silgen_name("print_long")
28+
func print_long(_: Int)
2829

29-
var global: Int = 0
30-
public func print(_ n: Int) {
31-
let f: StaticString = "%d\n"
32-
global = n
33-
vprintf(f.utf8Start, &global)
30+
public func print(_ n: Int, terminator: StaticString = "\n") {
31+
print_long(n)
32+
print("", terminator: terminator)
3433
}
3534

3635
@_silgen_name("malloc")

0 commit comments

Comments
 (0)