-
Notifications
You must be signed in to change notification settings - Fork 220
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
Fix recursive struct issue #1522
Conversation
b351eef
to
373e3b0
Compare
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.
LGTM!
373e3b0
to
c3aeba6
Compare
Type::Array(_, dims) if dims.contains(&ArrayLength::Dynamic) => { | ||
let size = dynamic_array_size(dims); | ||
// A pointer is four bytes on Solana | ||
size * 4 |
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.
Wouldn't this be the size + 4 times the number of dynamic arrays?
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.
As I understand, an array uint8 [2][][3]
means a fixed-length array of pointers that contains three elements. Each pointer points to uint8[2]
. The size will only be 3*pointer_size
. Now if the type was uint8 [2][][][3]
, we'll still have a fixed-array of pointers that contains three elements. Each pointer points to a uint8[2][]
. The size will continue to be 3*pointer_size
.
The function calculates the minimum size we need for storage. As soon as we allocate elements, more space will be necessary.
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.
I see, thanks.
What you explained here would look good in a comment to the source code (or even in the doc comment of this function)
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.
This is explained right above dynamic_array_size
between lines 2172 and 2176.
c3aeba6
to
ebf2056
Compare
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.
There ar so many issues with struct
Type::Array(_, dims) if dims.contains(&ArrayLength::Dynamic) => { | ||
let size = dynamic_array_size(dims); | ||
// A pointer is four bytes on Solana | ||
size * 4 |
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.
I see, thanks.
What you explained here would look good in a comment to the source code (or even in the doc comment of this function)
Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
ebf2056
to
9c9ddb9
Compare
Structs that contains themselves in a dynamic array are not recursive and do not have infinite size, as in the example below: