Skip to content

Commit

Permalink
Raise error if using ev/to-file on MinGW
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrmont committed Dec 15, 2024
1 parent 6ee0578 commit 1a24d4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
19 changes: 9 additions & 10 deletions src/core/ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3309,10 +3309,7 @@ static JanetFile *get_file_for_stream(JanetStream *stream) {
FILE *f = _fdopen(fd_dup, fmt);
if (NULL == f) {
/* the stream isn't duplicated so this would close the stream
/* _close(fd); */
return NULL;
}
if (setvbuf(f, NULL, _IONBF, 0)) {
* _close(fd); */
return NULL;
}
#else
Expand All @@ -3323,24 +3320,26 @@ static JanetFile *get_file_for_stream(JanetStream *stream) {
close(newHandle);
return NULL;
}
if (setvbuf(f, NULL, _IONBF, 0)) {
close(newHandle);
return NULL;
}
#endif
return janet_makejfile(f, flags);
}

JANET_CORE_FN(janet_cfun_to_file,
"(ev/to-file)",
"Create core/file copy of the stream. This value can be used "
"when blocking IO behavior is needed. Buffering is turned off "
"for the file.") {
"when blocking IO behavior is needed.") {
janet_fixarity(argc, 1);
#ifdef JANET_MINGW
(void) argc;
(void) argv;
janet_panic("ev/to-file not supported on MinGW");
return janet_wrap_nil();
#else
JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);
JanetFile *iof = get_file_for_stream(stream);
if (iof == NULL) janet_panic("cannot make file from stream");
return janet_wrap_abstract(iof);
#endif
}

JANET_CORE_FN(janet_cfun_ev_all_tasks,
Expand Down
10 changes: 7 additions & 3 deletions test/suite-ev.janet
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,13 @@
# Now do our telnet chat
(def bob (net/connect test-host test-port :stream))
(expect-read bob "Whats your name?\n")
(def fbob (ev/to-file bob))
(file/write fbob "bob")
(:close fbob)
(if (= :mingw (os/which))
(net/write bob "bob")
(do
(def fbob (ev/to-file bob))
(file/write fbob "bob")
(file/flush fbob)
(:close fbob)))
(expect-read bob "Welcome bob\n")
(def alice (net/connect test-host test-port))
(expect-read alice "Whats your name?\n")
Expand Down

0 comments on commit 1a24d4f

Please sign in to comment.