Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Using loops to solve the problem of recursive stack overflow #48

Merged
merged 3 commits into from
Aug 27, 2018

Conversation

erikzhang
Copy link
Member

No description provided.

@erikzhang
Copy link
Member Author

@shargon Can you take a look at this?

@shargon
Copy link
Member

shargon commented Aug 22, 2018

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()
Copy link
Member

@shargon shargon Aug 22, 2018

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();
        }

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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 StackItems, 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

@erikzhang
Copy link
Member Author

Why the equal method of Struct is different of Array, is needed?

In many high level language, whether structs are equal depends on whether their fields are equal.

struct point
{
    int x;
    int y;
}

Take this struct as an example: (1, 2) is equal to another (1, 2).

@erikzhang
Copy link
Member Author

@shargon Do you agree to merge this PR?

@erikzhang erikzhang merged commit 1874219 into master Aug 27, 2018
@erikzhang erikzhang deleted the fixes/stackoverflow branch August 27, 2018 07:59
erikzhang added a commit that referenced this pull request Sep 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants