1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-23 06:50:26 +00:00

added MARSH_EOS check

This commit is contained in:
J.-F. Cap 2019-02-24 18:45:14 +01:00
parent 8e0d7f2539
commit 0eae75a5c2
2 changed files with 16 additions and 0 deletions

View File

@ -72,3 +72,15 @@
(printf "properties:\n%p" (tarray/properties (A :array)))
(printf "row properties:\n%p" (tarray/properties (matrix/row A 1)))
# test marshalling
(def a (tarray/new :float64 20))
(set (a 0) math/pi)
(set (a 1) 1234)
(def b (unmarshal (marshal a)))
(printf "%p" (tarray/properties b))
(print (b 0))
(print (b 1))

View File

@ -919,10 +919,14 @@ void janet_unmarshal_size(JanetMarshalContext *ctx, size_t *i) {
void janet_unmarshal_byte(JanetMarshalContext *ctx, uint8_t *b) {
UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
MARSH_EOS(st, ctx->data);
*b = *(ctx->data++);
};
void janet_unmarshal_bytes(JanetMarshalContext *ctx, uint8_t *dest, int32_t len) {
UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
MARSH_EOS(st, ctx->data+len-1);
memcpy(dest, ctx->data, len);
ctx->data += len;
}