-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore!: split ValidationError
from MaxSizeError
; validate
and max_serialized_size
made BorshSchemaContainer
's methods
#219
Conversation
f579ad4
to
e51873a
Compare
a valid alternative might be to remove second commit and newly added module |
e51873a
to
d950b87
Compare
…ze` a container method
… method to `BorshSchemaContainer`
89b781c
to
d790ba4
Compare
|
||
let schema = BorshSchemaContainer::for_type::<RecursiveNoExitStructUnnamed>(); | ||
assert_eq!(Err(()), is_zero_size(schema.declaration(), &schema)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a similar test in current master was causing stack overflow
#[test]
fn test_is_zero_size_recursive_check_err() {
use crate as borsh;
#[derive(::borsh_derive::BorshSchema)]
struct RecursiveNoExitStructUnnamed(Box<RecursiveNoExitStructUnnamed>);
let schema = BorshSchemaContainer::for_type::<RecursiveNoExitStructUnnamed>();
assert_eq!(false, is_zero_size(schema.declaration(), &schema));
}
thread 'schema_helpers::tests::test_is_zero_size_recursive_check_err' has overflowed its stack
fatal runtime error: stack overflow
Though rustc prevents from constructing a type, which would hit a branch with recursing indefinetely into is_zero_size
inside of max_serialized_size_impl
:
error: values of the type `[[[RecursiveNoExitStructUnnamed2; 4294967295]; 2]; 4294967295]` are too big for the current architecture
// can be defined without error
// cannot be used as the value of type parameter in a function
struct RecursiveNoExitStructUnnamed2(Box<[[[RecursiveNoExitStructUnnamed2; u32::MAX as usize]; 2]; u32::MAX as usize]>);
…emaMaxSerializedSizeError::MissingDefinition`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
max_serialized_size
code moved fromborsh/src/schema_helpers.rs
toborsh/src/schema/container_ext/max_size.rs
max_serialized_size
made a method ofBorshSchemaContainer
borsh::MaxSizeError
moved toborsh::schema::SchemaMaxSerializedSizeError
SchemaMaxSerializedSizeError::MissingDefinition
->SchemaMaxSerializedSizeError::MissingDefinition(Declaration)
is_zero_size
private function tries to detect recursion too, its return type changed toResult<bool, ()>
(Err
on recursive call)MaxSizeError::ZSTSequenceNotArray
check and enum variant split into separate types and moduleborsh/src/schema/container_ext/validate.rs
validate
method ofBorshSchemaContainer
split
into
and