Skip to content

Commit 094b749

Browse files
authored
Merge pull request #16914 from compnerd/fork
2 parents 44b3a47 + aa10c6e commit 094b749

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

tools/swift-reflection-test/overrides.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "overrides.h"
22

3+
#if !defined(_WIN32)
34
extern pid_t fork(void);
45
extern int execv(const char *path, char * const *argv);
56

@@ -10,4 +11,5 @@ pid_t _fork(void) {
1011
int _execv(const char *path, char * const *argv) {
1112
return execv(path, argv);
1213
}
14+
#endif
1315

tools/swift-reflection-test/overrides.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
#include <sys/types.h>
44

5+
#if !defined(_WIN32)
56
pid_t _fork(void);
67
int _execv(const char *path, char * const *argv);
8+
#endif
9+

tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
#include <stdio.h>
2828
#include <stdlib.h>
2929
#include <string.h>
30+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
3031
#include <unistd.h>
32+
#elif defined(_WIN32)
33+
#include <io.h>
34+
#include <fcntl.h>
35+
#endif
3136

3237
typedef struct PipeMemoryReader {
3338
int to_child[2];
@@ -194,10 +199,17 @@ void PipeMemoryReader_sendDoneMessage(const PipeMemoryReader *Reader) {
194199
static
195200
PipeMemoryReader createPipeMemoryReader() {
196201
PipeMemoryReader Reader;
202+
#if defined(_WIN32)
203+
if (pipe(Reader.to_child, 256, _O_BINARY))
204+
errnoAndExit("Couldn't create pipes to child process");
205+
if (pipe(Reader.from_child, 256, _O_BINARY))
206+
errnoAndExit("Couldn't create pipes from child process");
207+
#else
197208
if (pipe(Reader.to_child))
198209
errnoAndExit("Couldn't create pipes to child process");
199210
if (pipe(Reader.from_child))
200211
errnoAndExit("Couldn't create pipes from child process");
212+
#endif
201213
return Reader;
202214
}
203215

@@ -443,6 +455,8 @@ int reflectExistential(SwiftReflectionContextRef RC,
443455
int doDumpHeapInstance(const char *BinaryFilename) {
444456
PipeMemoryReader Pipe = createPipeMemoryReader();
445457

458+
#if defined(_WIN32)
459+
#else
446460
pid_t pid = _fork();
447461
switch (pid) {
448462
case -1:
@@ -517,6 +531,7 @@ int doDumpHeapInstance(const char *BinaryFilename) {
517531
}
518532
}
519533
}
534+
#endif
520535
return EXIT_SUCCESS;
521536
}
522537

0 commit comments

Comments
 (0)