Skip to content

Commit 28d7386

Browse files
committed
[plugin-server] Use standard headers in CSwiftPluginServer
For whatever reason, using standard headers in modules imported from Swift code (depending on Darwin overlay) is no longer an issue.
1 parent c92f6af commit 28d7386

File tree

3 files changed

+12
-71
lines changed

3 files changed

+12
-71
lines changed

tools/swift-plugin-server/Sources/CSwiftPluginServer/PluginServer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void PluginServer_destroyConnection(const void *server) {
118118
delete static_cast<const ConnectionHandle *>(server);
119119
}
120120

121-
SwiftInt PluginServer_read(const void *server, void *data, SwiftUInt nbyte) {
121+
ptrdiff_t PluginServer_read(const void *server, void *data, size_t nbyte) {
122122
const auto *connection = static_cast<const ConnectionHandle *>(server);
123123
#if defined(_WIN32)
124124
return _read(connection->inputFD, data, nbyte);
@@ -127,7 +127,8 @@ SwiftInt PluginServer_read(const void *server, void *data, SwiftUInt nbyte) {
127127
#endif
128128
}
129129

130-
SwiftInt PluginServer_write(const void *server, const void *data, SwiftUInt nbyte) {
130+
ptrdiff_t PluginServer_write(const void *server, const void *data,
131+
size_t nbyte) {
131132
const auto *connection = static_cast<const ConnectionHandle *>(server);
132133
#if defined(_WIN32)
133134
return _write(connection->outputFD, data, nbyte);

tools/swift-plugin-server/Sources/CSwiftPluginServer/include/PluginServer.h

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,7 @@
1313
#ifndef SWIFT_PLUGINSERVER_PLUGINSERVER_H
1414
#define SWIFT_PLUGINSERVER_PLUGINSERVER_H
1515

16-
// NOTE: Partially ported from SwiftShim's SwiftStdint.h. We cannot include
17-
// that header here because it belongs to the runtime, but we need the same
18-
// logic for interoperability with Swift code in the compiler itself.
19-
// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a
20-
// result, using stdint.h here would pull in Darwin module (which includes
21-
// libc). This creates a dependency cycle, so we can't use stdint.h in
22-
// SwiftShims.
23-
// On Linux, the story is different. We get the error message
24-
// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not
25-
// found"
26-
// This is a known Clang/Ubuntu bug.
27-
28-
// Clang has been defining __INTxx_TYPE__ macros for a long time.
29-
// __UINTxx_TYPE__ are defined only since Clang 3.5.
30-
#if defined(_MSC_VER) && !defined(__clang__)
31-
typedef __int64 __swiftc_int64_t;
32-
typedef unsigned __int64 __swiftc_uint64_t;
33-
typedef int __swiftc_int32_t;
34-
typedef unsigned int __swiftc_uint32_t;
35-
#elif !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__)
36-
#include <stdint.h>
37-
typedef int64_t __swiftc_int64_t;
38-
typedef uint64_t __swiftc_uint64_t;
39-
typedef int32_t __swiftc_int32_t;
40-
typedef uint32_t __swiftc_uint32_t;
41-
typedef intptr_t __swiftc_intptr_t;
42-
typedef uintptr_t __swiftc_uintptr_t;
43-
#else
44-
typedef __INT64_TYPE__ __swiftc_int64_t;
45-
#ifdef __UINT64_TYPE__
46-
typedef __UINT64_TYPE__ __swiftc_uint64_t;
47-
#else
48-
typedef unsigned __INT64_TYPE__ __swiftc_uint64_t;
49-
#endif
50-
51-
typedef __INT32_TYPE__ __swiftc_int32_t;
52-
#ifdef __UINT32_TYPE__
53-
typedef __UINT32_TYPE__ __swiftc_uint32_t;
54-
#else
55-
typedef unsigned __INT32_TYPE__ __swiftc_uint32_t;
56-
#endif
57-
#endif
58-
59-
#define __swiftc_join3(a,b,c) a ## b ## c
60-
61-
#define __swiftc_intn_t(n) __swiftc_join3(__swiftc_int, n, _t)
62-
#define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t)
63-
64-
#if defined(_MSC_VER) && !defined(__clang__)
65-
#if defined(_WIN64)
66-
typedef __swiftc_int64_t SwiftInt;
67-
typedef __swiftc_uint64_t SwiftUInt;
68-
#elif defined(_WIN32)
69-
typedef __swiftc_int32_t SwiftInt;
70-
typedef __swiftc_uint32_t SwiftUInt;
71-
#else
72-
#error unknown windows pointer width
73-
#endif
74-
#else
75-
typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt;
76-
typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt;
77-
#endif
16+
#include <stddef.h>
7817

7918
#ifdef __cplusplus
8019
extern "C" {
@@ -92,10 +31,11 @@ const void *PluginServer_createConnection(const char **errorMessage);
9231
void PluginServer_destroyConnection(const void *connHandle);
9332

9433
/// Read bytes from the IPC communication handle.
95-
SwiftInt PluginServer_read(const void *connHandle, void *data, SwiftUInt nbyte);
34+
ptrdiff_t PluginServer_read(const void *connHandle, void *data, size_t nbyte);
9635

9736
/// Write bytes to the IPC communication handle.
98-
SwiftInt PluginServer_write(const void *connHandle, const void *data, SwiftUInt nbyte);
37+
ptrdiff_t PluginServer_write(const void *connHandle, const void *data,
38+
size_t nbyte);
9939

10040
//===----------------------------------------------------------------------===//
10141
// Dynamic link

tools/swift-plugin-server/Sources/swift-plugin-server/swift-plugin-server.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ final class PluginHostConnection: MessageConnection {
172172
var ptr = buffer.baseAddress!
173173

174174
while (bytesToWrite > 0) {
175-
let writtenSize = PluginServer_write(handle, ptr, SwiftUInt(bytesToWrite))
175+
let writtenSize = PluginServer_write(handle, ptr, bytesToWrite)
176176
if (writtenSize <= 0) {
177177
// error e.g. broken pipe.
178178
break
179179
}
180-
ptr = ptr.advanced(by: Int(writtenSize))
180+
ptr = ptr.advanced(by: writtenSize)
181181
bytesToWrite -= Int(writtenSize)
182182
}
183183
return buffer.count - bytesToWrite
@@ -193,13 +193,13 @@ final class PluginHostConnection: MessageConnection {
193193
var ptr = buffer.baseAddress!
194194

195195
while bytesToRead > 0 {
196-
let readSize = PluginServer_read(handle, ptr, SwiftUInt(bytesToRead))
196+
let readSize = PluginServer_read(handle, ptr, bytesToRead)
197197
if (readSize <= 0) {
198198
// 0: EOF (the host closed), -1: Broken pipe (the host crashed?)
199199
break;
200200
}
201-
ptr = ptr.advanced(by: Int(readSize))
202-
bytesToRead -= Int(readSize)
201+
ptr = ptr.advanced(by: readSize)
202+
bytesToRead -= readSize
203203
}
204204
return buffer.count - bytesToRead
205205
}

0 commit comments

Comments
 (0)