From 1a24d4fc86617de3faa3bd920d31931da9e0f877 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Sun, 15 Dec 2024 21:00:52 +0900 Subject: [PATCH] Raise error if using `ev/to-file` on MinGW --- src/core/ev.c | 19 +++++++++---------- test/suite-ev.janet | 10 +++++++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/core/ev.c b/src/core/ev.c index ce27c838..5d4e04c5 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -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 @@ -3323,10 +3320,6 @@ 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); } @@ -3334,13 +3327,19 @@ static JanetFile *get_file_for_stream(JanetStream *stream) { 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, diff --git a/test/suite-ev.janet b/test/suite-ev.janet index 46820953..724bf24a 100644 --- a/test/suite-ev.janet +++ b/test/suite-ev.janet @@ -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")