From b14fcb068b1d464748814b0c330c86b0092b6460 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 22 Feb 2019 17:10:24 -0500 Subject: [PATCH] Update janet_pcall interface The programmer can now not only get the used fiber, but provide a fiber to reuse if many calls are made in succession. --- src/core/io.c | 3 +++ src/core/peg.c | 1 - src/core/vm.c | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/io.c b/src/core/io.c index 474e833a..44904517 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -198,6 +198,9 @@ static Janet cfun_io_fread(int32_t argc, Janet *argv) { if (fsize < 0) { janet_panicf("could not get file size of %v", argv[0]); } + if (fsize > (INT32_MAX)) { + janet_panic("file to large to read into buffer"); + } fseek(iof->file, 0, SEEK_SET); read_chunk(iof, buffer, (int32_t) fsize); } diff --git a/src/core/peg.c b/src/core/peg.c index 23611364..2ab2244f 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -1057,7 +1057,6 @@ static Janet cfun_peg_match(int32_t argc, Janet *argv) { s.captures = janet_array(0); s.scratch = janet_buffer(10); s.tags = janet_buffer(10); - s.constants = peg->constants; s.bytecode = peg->bytecode; const uint8_t *result = peg_rule(&s, s.bytecode, bytes.bytes + start); diff --git a/src/core/vm.c b/src/core/vm.c index ed951706..6777dc83 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -852,7 +852,12 @@ JanetSignal janet_pcall( const Janet *argv, Janet *out, JanetFiber **f) { - JanetFiber *fiber = janet_fiber(fun, 64, argc, argv); + JanetFiber *fiber; + if (f && *f) { + fiber = janet_fiber_reset(*f, fun, argc, argv); + } else { + fiber = janet_fiber(fun, 64, argc, argv); + } if (f) *f = fiber; if (!fiber) { *out = janet_cstringv("arity mismatch");