mirror of
https://github.com/janet-lang/janet
synced 2024-11-24 09:17:17 +00:00
Address #336 case 3
Fix error condition for bad abstract types - don't return NULL, panic.
This commit is contained in:
parent
553e38ffd6
commit
5bbd507858
@ -1098,7 +1098,7 @@ static const uint8_t *unmarshal_one_abstract(UnmarshalState *st, const uint8_t *
|
|||||||
Janet key;
|
Janet key;
|
||||||
data = unmarshal_one(st, data, &key, flags + 1);
|
data = unmarshal_one(st, data, &key, flags + 1);
|
||||||
const JanetAbstractType *at = janet_get_abstract_type(key);
|
const JanetAbstractType *at = janet_get_abstract_type(key);
|
||||||
if (at == NULL) return NULL;
|
if (at == NULL) goto oops;
|
||||||
if (at->unmarshal) {
|
if (at->unmarshal) {
|
||||||
JanetMarshalContext context = {NULL, st, flags, data, at};
|
JanetMarshalContext context = {NULL, st, flags, data, at};
|
||||||
*out = janet_wrap_abstract(at->unmarshal(&context));
|
*out = janet_wrap_abstract(at->unmarshal(&context));
|
||||||
@ -1107,7 +1107,8 @@ static const uint8_t *unmarshal_one_abstract(UnmarshalState *st, const uint8_t *
|
|||||||
}
|
}
|
||||||
return context.data;
|
return context.data;
|
||||||
}
|
}
|
||||||
return NULL;
|
oops:
|
||||||
|
janet_panic("invalid abstract type");
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint8_t *unmarshal_one(
|
static const uint8_t *unmarshal_one(
|
||||||
|
@ -212,5 +212,6 @@
|
|||||||
|
|
||||||
(assert-error "unmarshal errors 1" (unmarshal @"\xd6\xb9\xb9"))
|
(assert-error "unmarshal errors 1" (unmarshal @"\xd6\xb9\xb9"))
|
||||||
(assert-error "unmarshal errors 2" (unmarshal @"\xd7bc"))
|
(assert-error "unmarshal errors 2" (unmarshal @"\xd7bc"))
|
||||||
|
(assert-error "unmarshal errors 3" (unmarshal "\xd3\x01\xd9\x01\x62\xcf\x03\x78\x79\x7a" load-image-dict))
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
@ -8,15 +8,15 @@
|
|||||||
|
|
||||||
(def cases [
|
(def cases [
|
||||||
nil
|
nil
|
||||||
|
|
||||||
"abc"
|
"abc"
|
||||||
|
|
||||||
:def
|
:def
|
||||||
|
|
||||||
'hij
|
'hij
|
||||||
|
|
||||||
123
|
123
|
||||||
|
|
||||||
(int/s64 123)
|
(int/s64 123)
|
||||||
|
|
||||||
"7"
|
"7"
|
||||||
@ -28,12 +28,12 @@
|
|||||||
{:a 123}
|
{:a 123}
|
||||||
|
|
||||||
@{:b 'xyz}
|
@{:b 'xyz}
|
||||||
|
|
||||||
(peg/compile
|
(peg/compile
|
||||||
'{:a (* "a" :b "a")
|
'{:a (* "a" :b "a")
|
||||||
:b (* "b" (+ :a 0) "b")
|
:b (* "b" (+ :a 0) "b")
|
||||||
:main (* "(" :b ")")})
|
:main (* "(" :b ")")})
|
||||||
|
|
||||||
(fn f [a] (fn [] {:ab a}))
|
(fn f [a] (fn [] {:ab a}))
|
||||||
|
|
||||||
(fn f [a] (print "hello world!"))
|
(fn f [a] (print "hello world!"))
|
||||||
|
Loading…
Reference in New Issue
Block a user