Skip to content

swift-reflection-test: preprocess for windows build #16914

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 1 commit into from
Nov 7, 2018
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
2 changes: 2 additions & 0 deletions tools/swift-reflection-test/overrides.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "overrides.h"

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

Expand All @@ -10,4 +11,5 @@ pid_t _fork(void) {
int _execv(const char *path, char * const *argv) {
return execv(path, argv);
}
#endif

3 changes: 3 additions & 0 deletions tools/swift-reflection-test/overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

#include <sys/types.h>

#if !defined(_WIN32)
pid_t _fork(void);
int _execv(const char *path, char * const *argv);
#endif

15 changes: 15 additions & 0 deletions tools/swift-reflection-test/swift-reflection-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#elif defined(_WIN32)
#include <io.h>
#include <fcntl.h>
#endif

typedef struct PipeMemoryReader {
int to_child[2];
Expand Down Expand Up @@ -265,10 +270,17 @@ void PipeMemoryReader_sendDoneMessage(const PipeMemoryReader *Reader) {
static
PipeMemoryReader createPipeMemoryReader() {
PipeMemoryReader Reader;
#if defined(_WIN32)
if (pipe(Reader.to_child, 256, _O_BINARY))
errnoAndExit("Couldn't create pipes to child process");
if (pipe(Reader.from_child, 256, _O_BINARY))
errnoAndExit("Couldn't create pipes from child process");
#else
if (pipe(Reader.to_child))
errnoAndExit("Couldn't create pipes to child process");
if (pipe(Reader.from_child))
errnoAndExit("Couldn't create pipes from child process");
#endif
return Reader;
}

Expand Down Expand Up @@ -441,6 +453,8 @@ int reflectExistential(SwiftReflectionContextRef RC,
int doDumpHeapInstance(const char *BinaryFilename) {
PipeMemoryReader Pipe = createPipeMemoryReader();

#if defined(_WIN32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right here's where I'd want a comment, I think, even if it's just "Windows doesn't have an equivalent to fork, so we'll have to do this in-process."

#else
pid_t pid = _fork();
switch (pid) {
case -1:
Expand Down Expand Up @@ -515,6 +529,7 @@ int doDumpHeapInstance(const char *BinaryFilename) {
}
}
}
#endif
return EXIT_SUCCESS;
}

Expand Down