Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

Crash when referencing free variables (v2.1.1)

Last post 05-16-2008, 6:24 AM by fagiano. 2 replies.
Sort Posts: Previous Next
  •  05-16-2008, 12:44 AM 2512

    Crash when referencing free variables (v2.1.1)

    This code causes an access violation in squirrel when run in sq.exe or prints "((null) : 0x008E3884)" when run in real project:

    --------------------------------
    function test(str)
    {
    local f = function() : (str) {
    print(str+"\n")
    return 1;
    }

    return f()
    }

    ::test("abcd");
    --------------------------------

    These versions work correct:

    1)
    --------------------------------
    function test(str)
    {
    local f = function() : (str) {
    local s = str
    print(s+"\n")
    return 1;
    }

    return f()
    }

    ::test("abcd");

    --------------------------------

    2)
    function test(str)
    {
    local f = function() : (str) {
    print(str+"\n")
    return 1;
    }

    local res = f()
    return res
    }

    ::test("abcd");
  •  05-16-2008, 4:47 AM 2513 in reply to 2512

    Re: Crash when referencing free variables (v2.1.1)

    Indeed I can reproduce it also on 2.2, I'll take a look at it as soon as I get home.

     thx for the report

    Alberto

  •  05-16-2008, 6:24 AM 2515 in reply to 2513

    Re: Crash when referencing free variables (v2.1.1)

    I found and fixed the bug, FYI the problem is caused by the fact the when 'f' is ivoked as a tailcall, the closure is delete when the caller stack is collapsed. Now I keep a strong reference of the closure in the call stack. No biggie, quite an obscure bug though.

    I'll release a 2.2.1 tonite or tomorrow as soon as I'm done with the tests.

    ciao

    Alberto

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems