[18 Feb 2008] Potential problem

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
Dwayne

[18 Feb 2008] Potential problem

Post by Dwayne »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 18 Feb 2008 01:46:01 +1100

Andreas,

Can you confirm this for me please..

Have been writing some metamethods and have come across an issue that might be a bug.

Take note of the line where dummy=0 if this is removed in either of the Object.copy or Object.union functions the system goes into a loop and does not return. You can still close using the close gadget. This line can be anything as long as it is not next which closes the for loop. The Object.tostring function did not present this symptom because it has the sep=", " statement between endif and next which stops it from stalling.

Regards,

Dwayne

Code: Select all

Object={}

function Object.copy (o)
    local ret={}
    local k, v
    local dummy
    for k, v in pairs (o)
        if (gettype (v)=#TABLE)
            ret [k]=Object.copy (v)
        else
            ret [k]=v
        endif
        dummy=0
    next
    return (ret)
endfunction

function Object.union (t1, t2)
    local ret=Object.new (object, {})
    local k, v
    local dummy

    for k, v in pairs (t1)
        if (gettype (v)=#TABLE)
            ret [k]=Object.copy (v)
        else
           ret [k]=v
        endif
        dummy=0
    next
    for k, v in pairs (t2)
        if (gettype (v)=#TABLE)
            ret [k]=Object.copy (v)
        else
           ret [k]=v
        endif
        dummy=0
    next
    return (ret)
endfunction

Function Object.tostring (o)
    local s="{"
    local sep=""
    local k, v
    for k, v in pairs (o)
        s=s .. sep .. k .. "="
        if (gettype (v)=#TABLE)
            s=s .. Object.tostring (v)
        elseif (gettype (v)=#FUNCTION)
            s=s .. "function"
        else
            s=s .. v
        endif
        sep=", "
    next
    return (s .. "}")
EndFunction

Function Object.print (o)
    nprint (Object.tostring (o))
EndFunction

Function Object.new (this, o)
    local object=o
    setmetatable (object, this)
    this.__index=this
    this.__add=this.union
    return (object)
EndFunction

a=Object.new (object, {a=1, b=2, c=3, g={1}})
b=Object.new (object, {d=4, e=5, f=6, debug=function () print ("Hello
World!") endfunction})

a.print (a)
b.print (b)

c=a + b
c.print (c)

a.g={3}
a.print (a)
c.print (c)

waitleftmouse
User avatar
airsoftsoftwair
Posts: 5833
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[21 Feb 2008] Re: Potential problem

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 21 Feb 2008 00:17:18 +0100
Andreas,

Can you confirm this for me please..

Have been writing some metamethods and have come across an issue that might be a bug.

Take note of the line where dummy=0 if this is removed in either of the Object.copy or Object.union functions the system goes into a loop and does not return. You can still close using the close gadget. This line can be anything as long as it is not next which closes the for loop. The Object.tostring function did not present this symptom because it has the sep=", " statement between endif and next which stops it from stalling.
This looks like a bug. I can confirm that removing the line "dummy=0" causes an endless loop in the virtual machine which is a behaviour that I can't currently explain.

I currently don't have the time to read through your script thoroughly to see if you are doing something wrong that causes this error. But it looks like a bug because it doesn't make any sense that removing the "dummy=0" line causes such trouble.

I've written this issue down in my notes and will try to dig deeper into it when I have more time.

By the way, I would be glad if you could cut down demonstration scripts as short as possible. This makes the bug hunt much easier. Even if I'm the author of Hollywood, it still takes me quite some time to understand these demonstration scripts... especially when they make use of complicated stuff like methods and metamethods like in your example.

Thanks for the report

Andreas --
User avatar
airsoftsoftwair
Posts: 5833
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[22 Mar 2008] Re: Potential problem

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 22 Mar 2008 00:28:57 +0100
Andreas,

Can you confirm this for me please..

Have been writing some metamethods and have come across an issue that might be a bug.

Take note of the line where dummy=0 if this is removed in either of the Object.copy or Object.union functions the system goes into a loop and does not return. You can still close using the close gadget. This line can be anything as long as it is not next which closes the for loop. The Object.tostring function did not present this symptom because it has the sep=", " statement between endif and next which stops it from stalling.
This bug has been fixed now. Bugs in the virtual machine are hard to identify and fix. This one took me almost 4 hours but now it works like it should.

I'm really thankful for this report because this is really a "first class bug" because it is inside the virtual machine which is the heart of Hollywood and thus must be stable as a rock. So thanks again for that.
Locked