From 8b2d278840c962f5b82fe7e0d96e7d756edce4b7 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 26 Oct 2021 17:46:24 -0500 Subject: [PATCH] Add min-of and max-of. --- src/boot/boot.janet | 8 ++++++++ src/core/ev.c | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 3cce23b2..194680ed 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -698,6 +698,14 @@ "Returns the numeric minimum of the arguments." [& args] (extreme < args)) +(defn max-of + "Returns the numeric maximum of the argument sequence." + [args] (extreme > args)) + +(defn min-of + "Returns the numeric minimum of the argument sequence." + [args] (extreme < args)) + (defn first "Get the first element from an indexed data structure." [xs] diff --git a/src/core/ev.c b/src/core/ev.c index 113f49fd..89048b7e 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -234,6 +234,9 @@ static void add_timeout(JanetTimeout to) { /* Create a new event listener */ static JanetListenerState *janet_listen_impl(JanetStream *stream, JanetListener behavior, int mask, size_t size, void *user) { + if (stream->flags & JANET_STREAM_CLOSED) { + janet_panic("cannot listen on closed stream"); + } if (stream->_mask & mask) { janet_panic("cannot listen for duplicate event on stream"); } @@ -344,8 +347,10 @@ static void janet_stream_close_impl(JanetStream *stream, int is_gc) { { CloseHandle(stream->handle); } + stream->handle = INVALID_HANDLE_VALUE; #else close(stream->handle); + stream->handle = -1; #endif }