-
Notifications
You must be signed in to change notification settings - Fork 146
Using loops to solve the problem of recursive stack overflow #48
Conversation
@shargon Can you take a look at this? |
Why the equal method of Struct is different of Array, is needed? |
@@ -11,33 +10,61 @@ public Struct(IEnumerable<StackItem> value) : base(value) | |||
{ | |||
} | |||
|
|||
public StackItem Clone() | |||
public Struct Clone() |
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 think that this doesn't solve this problem:
[Fact]
public void OverFlow()
{
Struct s1 = new Struct { 1 };
s1[0] = s1;
Struct s2 = s1.Clone();
}
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.
In NeoVM, it is impossible that a struct contains itself. Because SETITEM
and APPEND
will clone the struct before setting the item.
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.
Then why we need to change the clone method? when is the overflow produced?
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.
If we limit the number of global StackItem
s, it will not overflow. However, if only the number of fields of the struct is limited, stack overflow will occur as long as there are too many nested layers.
[1, [2, [3, [... //repeat 100000 times
In many high level language, whether structs are equal depends on whether their fields are equal.
Take this struct as an example: |
@shargon Do you agree to merge this PR? |
No description provided.