From be0d4c28e4ebd85ef0cd992989b5ed55476d84ce Mon Sep 17 00:00:00 2001 From: sogaiu <983021772@users.noreply.github.com> Date: Thu, 7 Oct 2021 16:38:40 +0900 Subject: [PATCH 01/11] Add argument to janet_panicf call --- src/core/vm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/vm.c b/src/core/vm.c index 9316b045..e6c1a7fd 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -1493,7 +1493,9 @@ JanetSignal janet_pcall( Janet janet_mcall(const char *name, int32_t argc, Janet *argv) { /* At least 1 argument */ - if (argc < 1) janet_panicf("method :%s expected at least 1 argument"); + if (argc < 1) { + janet_panicf("method :%s expected at least 1 argument", name); + } /* Find method */ Janet method = janet_method_lookup(argv[0], name); if (janet_checktype(method, JANET_NIL)) { From 52ed68bfeb39b3c95d0b60d2fc43d872330b24a5 Mon Sep 17 00:00:00 2001 From: sogaiu <983021772@users.noreply.github.com> Date: Thu, 7 Oct 2021 20:58:50 +0900 Subject: [PATCH 02/11] Add argument to janet_panicf call (2) --- src/core/corelib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/corelib.c b/src/core/corelib.c index 60485b00..a1edc837 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -137,7 +137,7 @@ static const char *janet_dyncstring(const char *name, const char *dflt) { const uint8_t *jstr = janet_unwrap_string(x); const char *cstr = (const char *)jstr; if (strlen(cstr) != (size_t) janet_string_length(jstr)) { - janet_panicf("string %v contains embedded 0s"); + janet_panicf("string %v contains embedded 0s", x); } return cstr; } From 3b1d787fbeb8b63261df265bf4a1601c59709f17 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 8 Oct 2021 08:35:47 -0500 Subject: [PATCH 03/11] Address #829 - Set state->event inside linked list traversal for epoll. --- src/core/ev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ev.c b/src/core/ev.c index 21b5df94..7b68a3ec 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -1511,8 +1511,8 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) { JanetStream *stream = p; int mask = events[i].events; JanetListenerState *state = stream->state; - state->event = events + i; while (NULL != state) { + state->event = events + i; JanetListenerState *next_state = state->_next; JanetAsyncStatus status1 = JANET_ASYNC_STATUS_NOT_DONE; JanetAsyncStatus status2 = JANET_ASYNC_STATUS_NOT_DONE; From 3e5bd460a5abd2f29baf9a750023ee27ed3b83f8 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 8 Oct 2021 09:25:00 -0500 Subject: [PATCH 04/11] Add line/col info to parse error in janet_[dobytes, dostring] --- src/core/run.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/run.c b/src/core/run.c index 36b895e6..77d08a22 100644 --- a/src/core/run.c +++ b/src/core/run.c @@ -79,7 +79,13 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char const char *e = janet_parser_error(&parser); errflags |= 0x04; ret = janet_cstringv(e); - janet_eprintf("parse error in %s: %s\n", sourcePath, e); + int32_t line = parser.line; + int32_t col = parser.column; + if (line > 0 && col > 0) { + janet_eprintf("%s:%d:%d: parse error: %s\n", sourcePath, line, col, e); + } else { + janet_eprintf("%s: parse error: %s\n", sourcePath, e); + } done = 1; break; } From 684f3ac1722b4f48022f386741fda1c6f3ccc070 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 10 Oct 2021 09:07:56 -0500 Subject: [PATCH 05/11] Add optional base to scan-number. --- src/core/corelib.c | 14 ++++++++++---- src/core/run.c | 6 +----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/core/corelib.c b/src/core/corelib.c index a1edc837..ecd65257 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -398,15 +398,21 @@ JANET_CORE_FN(janet_core_is_abstract, } JANET_CORE_FN(janet_core_scannumber, - "(scan-number str)", + "(scan-number str &opt base)", "Parse a number from a byte sequence an return that number, either and integer " "or a real. The number " "must be in the same format as numbers in janet source code. Will return nil " - "on an invalid number.") { + "on an invalid number. Optionally provide a base - if a base is provided, no " + "radix specifier is expected at the beginning of the number.") { double number; - janet_fixarity(argc, 1); + janet_arity(argc, 1, 2); JanetByteView view = janet_getbytes(argv, 0); - if (janet_scan_number(view.bytes, view.len, &number)) + int32_t base = janet_optinteger(argv, argc, 1, 0); + int valid = base == 0 || (base >= 2 && base <= 36); + if (!valid) { + janet_panicf("expected base between 2 and 36, got %d", base); + } + if (janet_scan_number_base(view.bytes, view.len, base, &number)) return janet_wrap_nil(); return janet_wrap_number(number); } diff --git a/src/core/run.c b/src/core/run.c index 77d08a22..f90a640c 100644 --- a/src/core/run.c +++ b/src/core/run.c @@ -81,11 +81,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char ret = janet_cstringv(e); int32_t line = parser.line; int32_t col = parser.column; - if (line > 0 && col > 0) { - janet_eprintf("%s:%d:%d: parse error: %s\n", sourcePath, line, col, e); - } else { - janet_eprintf("%s: parse error: %s\n", sourcePath, e); - } + janet_eprintf("%s:%d:%d: parse error: %s\n", sourcePath, line, col, e); done = 1; break; } From f0da793f9988a053b1dff61d2e6acc5edd0ac94b Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 10 Oct 2021 09:27:31 -0500 Subject: [PATCH 06/11] Prepare for 1.18.0 release --- CHANGELOG.md | 5 ++++- src/conf/janetconf.h | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08e04422..bddb1af7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. -## Unreleased - ??? +## 1.18.0 - 2021-10-10 +- Allow `ev/cancel` to work on already scheduled fibers. +- Fix bugs with ev/ module. +- Add optional `base` argument to scan-number - Add `-i` flag to janet binary to make it easier to run image files from the command line - Remove `thread/` module. - Add `(number ...)` pattern to peg for more efficient number parsing using Janet's diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index d78e3257..9e6365cd 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -6,8 +6,8 @@ #define JANET_VERSION_MAJOR 1 #define JANET_VERSION_MINOR 18 #define JANET_VERSION_PATCH 0 -#define JANET_VERSION_EXTRA "-dev" -#define JANET_VERSION "1.18.0-dev" +#define JANET_VERSION_EXTRA "" +#define JANET_VERSION "1.18.0" /* #define JANET_BUILD "local" */ From 9bf5cd83c3cd98002893a72c0fad20026fae4cac Mon Sep 17 00:00:00 2001 From: MorganPeterson Date: Mon, 11 Oct 2021 13:45:31 -0400 Subject: [PATCH 07/11] updated string/bytes docs to reflect return value as tuple --- src/core/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/string.c b/src/core/string.c index f082d9cf..cc895bc6 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -218,7 +218,7 @@ JANET_CORE_FN(cfun_string_repeat, JANET_CORE_FN(cfun_string_bytes, "(string/bytes str)", - "Returns an array of integers that are the byte values of the string.") { + "Returns a tuple of integers that are the byte values of the string.") { janet_fixarity(argc, 1); JanetByteView view = janet_getbytes(argv, 0); Janet *tup = janet_tuple_begin(view.len); From 0774e79e4fb6262e41217c8e89eca3b0675ce2de Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 14 Oct 2021 13:57:51 -0500 Subject: [PATCH 08/11] Pass non-blocking pipes to subprocesses on non-windows platform. --- src/core/ev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/ev.c b/src/core/ev.c index 7b68a3ec..54a7a195 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -2558,15 +2558,16 @@ void janet_ev_sendto_string(JanetStream *stream, JanetString str, void *dest, in static volatile long PipeSerialNumber; #endif +/* + * mode = 0: both sides non-blocking. + * mode = 1: only read side non-blocking: write side sent to subprocess + * mode = 2: only write side non-blocking: read side sent to subprocess + */ int janet_make_pipe(JanetHandle handles[2], int mode) { #ifdef JANET_WINDOWS /* * On windows, the built in CreatePipe function doesn't support overlapped IO * so we lift from the windows source code and modify for our own version. - * - * mode = 0: both sides non-blocking. - * mode = 1: only read side non-blocking: write side sent to subprocess - * mode = 2: only write side non-blocking: read side sent to subprocess */ JanetHandle shandle, chandle; UCHAR PipeNameBuffer[MAX_PATH]; @@ -2616,10 +2617,9 @@ int janet_make_pipe(JanetHandle handles[2], int mode) { } return 0; #else - (void) mode; if (pipe(handles)) return -1; - if (fcntl(handles[0], F_SETFL, O_NONBLOCK)) goto error; - if (fcntl(handles[1], F_SETFL, O_NONBLOCK)) goto error; + if (mode != 2 && fcntl(handles[0], F_SETFL, O_NONBLOCK)) goto error; + if (mode != 1 && fcntl(handles[1], F_SETFL, O_NONBLOCK)) goto error; return 0; error: close(handles[0]); From 74c9cf03d0dbeac1d956d8063241875084c5e331 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 14 Oct 2021 17:25:12 -0500 Subject: [PATCH 09/11] Fix -r switch in repl --- src/boot/boot.janet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 528c619f..3cce23b2 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -3573,7 +3573,7 @@ 1) "v" (fn [&] (print janet/version "-" janet/build) (os/exit 0) 1) "s" (fn [&] (set raw-stdin true) (set should-repl true) 1) - "r" (fn [&] (set should-repl true) 0) + "r" (fn [&] (set should-repl true) 1) "p" (fn [&] (set exit-on-error false) 1) "q" (fn [&] (set quiet true) 1) "i" (fn [&] (set expect-image true) 1) From e0dba85cbbea772f9116bf78d1ded14cfcee0d73 Mon Sep 17 00:00:00 2001 From: Brad Svercl Date: Thu, 14 Oct 2021 21:18:35 -0500 Subject: [PATCH 10/11] Support Android (termux) --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 123607db..0223f775 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,10 @@ ifeq ($(UNAME), Haiku) LDCONFIG:=true LDFLAGS=-Wl,--export-dynamic endif +# For Android (termux) +ifeq ($(shell uname -o), Android) + CLIBS:=$(CLIBS) -landroid-spawn +endif $(shell mkdir -p build/core build/c build/boot) all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h From 559fd70737576aeccc7f24095790af223164ae03 Mon Sep 17 00:00:00 2001 From: Brad Svercl Date: Fri, 15 Oct 2021 21:39:03 -0500 Subject: [PATCH 11/11] Add android-spawn to meson.build if found --- meson.build | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 32100a18..e4df9a57 100644 --- a/meson.build +++ b/meson.build @@ -30,6 +30,7 @@ header_path = join_paths(get_option('prefix'), get_option('includedir'), 'janet' cc = meson.get_compiler('c') m_dep = cc.find_library('m', required : false) dl_dep = cc.find_library('dl', required : false) +android_spawn_dep = cc.find_library('android-spawn', required : false) thread_dep = dependency('threads') # Link options @@ -160,7 +161,7 @@ mainclient_src = [ janet_boot = executable('janet-boot', core_src, boot_src, include_directories : incdir, c_args : '-DJANET_BOOTSTRAP', - dependencies : [m_dep, dl_dep, thread_dep], + dependencies : [m_dep, dl_dep, thread_dep, android_spawn_dep], native : true) # Build janet.c @@ -173,7 +174,7 @@ janetc = custom_target('janetc', 'JANET_PATH', janet_path ]) -janet_dependencies = [m_dep, dl_dep] +janet_dependencies = [m_dep, dl_dep, android_spawn_dep] if not get_option('single_threaded') janet_dependencies += thread_dep endif