1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-13 00:50:26 +00:00

Fix some bugs.

This commit is contained in:
Calvin Rose 2018-08-21 13:09:01 -04:00
parent 08236af578
commit 5464fd5173
3 changed files with 14 additions and 3 deletions

View File

@ -32,6 +32,7 @@ BINDIR=$(PREFIX)/bin
# TODO - when api is finalized, only export public symbols instead of using rdynamic # TODO - when api is finalized, only export public symbols instead of using rdynamic
# which exports all symbols. Saves a few KB in binary. # which exports all symbols. Saves a few KB in binary.
#CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -g
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden
CLIBS=-lm -ldl CLIBS=-lm -ldl
PREFIX=/usr/local PREFIX=/usr/local
@ -117,10 +118,12 @@ valgrind: $(DST_TARGET)
test: $(DST_TARGET) test: $(DST_TARGET)
./$(DST_TARGET) test/suite0.dst ./$(DST_TARGET) test/suite0.dst
./$(DST_TARGET) test/suite1.dst ./$(DST_TARGET) test/suite1.dst
./$(DST_TARGET) test/suite2.dst
valtest: $(DST_TARGET) valtest: $(DST_TARGET)
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite0.dst valgrind --leak-check=full -v ./$(DST_TARGET) test/suite0.dst
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite1.dst valgrind --leak-check=full -v ./$(DST_TARGET) test/suite1.dst
valgrind --leak-check=full -v ./$(DST_TARGET) test/suite2.dst
################### ###################
##### Natives ##### ##### Natives #####

View File

@ -362,7 +362,7 @@
accum) accum)
(defmacro coro (defmacro coro
"A wrapper for making fibers. Same as (fiber (fn [] ...body))." "A wrapper for making fibers. Same as (fiber.new (fn @[] ...body))."
[& body] [& body]
(tuple fiber.new (apply tuple 'fn @[] body))) (tuple fiber.new (apply tuple 'fn @[] body)))
@ -1266,7 +1266,7 @@
get a chunk of source code. Should return nil for end of file." get a chunk of source code. Should return nil for end of file."
@[getchunk onvalue onerr] @[getchunk onvalue onerr]
(def newenv (make-env)) (def newenv (make-env))
(default getchunk (fn [buf] (default getchunk (fn @[buf]
(file.read stdin :line buf))) (file.read stdin :line buf)))
(default onvalue (fn [x] (default onvalue (fn [x]
(put newenv '_ @{:value x}) (put newenv '_ @{:value x})

View File

@ -454,6 +454,7 @@ static const uint8_t *unmarshal_one_env(
const uint8_t *end = st->end; const uint8_t *end = st->end;
if (data >= end) longjmp(st->err, UMR_EOS); if (data >= end) longjmp(st->err, UMR_EOS);
if (*data == LB_FUNCENV_REF) { if (*data == LB_FUNCENV_REF) {
data++;
int32_t index = readint(st, &data); int32_t index = readint(st, &data);
if (index < 0 || index >= dst_v_count(st->lookup_envs)) if (index < 0 || index >= dst_v_count(st->lookup_envs))
longjmp(st->err, UMR_INVALID_REFERENCE); longjmp(st->err, UMR_INVALID_REFERENCE);
@ -479,6 +480,8 @@ static const uint8_t *unmarshal_one_env(
data = unmarshal_one(st, data, env->as.values + i, flags); data = unmarshal_one(st, data, env->as.values + i, flags);
} }
} }
/* Set out */
*out = env;
} }
return data; return data;
} }
@ -492,6 +495,7 @@ static const uint8_t *unmarshal_one_def(
const uint8_t *end = st->end; const uint8_t *end = st->end;
if (data >= end) longjmp(st->err, UMR_EOS); if (data >= end) longjmp(st->err, UMR_EOS);
if (*data == LB_FUNCDEF_REF) { if (*data == LB_FUNCDEF_REF) {
data++;
int32_t index = readint(st, &data); int32_t index = readint(st, &data);
if (index < 0 || index >= dst_v_count(st->lookup_defs)) if (index < 0 || index >= dst_v_count(st->lookup_defs))
longjmp(st->err, UMR_INVALID_REFERENCE); longjmp(st->err, UMR_INVALID_REFERENCE);
@ -552,6 +556,7 @@ static const uint8_t *unmarshal_one_def(
((uint32_t)(data[1]) << 8) | ((uint32_t)(data[1]) << 8) |
((uint32_t)(data[2]) << 16) | ((uint32_t)(data[2]) << 16) |
((uint32_t)(data[3]) << 24); ((uint32_t)(data[3]) << 24);
data += 4;
} }
/* Unmarshal environments */ /* Unmarshal environments */
@ -596,6 +601,9 @@ static const uint8_t *unmarshal_one_def(
/* Validate */ /* Validate */
if (dst_verify(def)) longjmp(st->err, UMR_INVALID_BYTECODE); if (dst_verify(def)) longjmp(st->err, UMR_INVALID_BYTECODE);
/* Set def */
*out = def;
} }
return data; return data;
} }
@ -696,7 +704,7 @@ static const uint8_t *unmarshal_one(
*out = dst_wrap_function(func); *out = dst_wrap_function(func);
dst_array_push(&st->lookup, *out); dst_array_push(&st->lookup, *out);
for (int32_t i = 0; i < def->environments_length; i++) { for (int32_t i = 0; i < def->environments_length; i++) {
data = unmarshal_one_env(st, data, func->envs + i, flags + 1); data = unmarshal_one_env(st, data, &(func->envs[i]), flags + 1);
} }
return data; return data;
} }