Linux threw this error.. Anyone see it before?

General FreeBASIC programming questions.
dodicat
Posts: 8168
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Linux threw this error.. Anyone see it before?

Post by dodicat »

I have altered your function to:

Code: Select all

function stringize_array( byref v as variable ) as string 
    locate 3,13

   if v.typ <> varType._ARRAY_ then return ""
   dim as integer length = v.array->size
   
   if length = 0 then return "[]"
   static as string s
  ' var s = "["   
  print s
  sleep
   for i as integer = 0 to length - 1
      var tmp = *v.array->items(i)
      select case tmp.typ
         case _ARRAY_    : s += stringize_array( tmp )
         case _STRING_    : 
            s += DBLQUOTE
            s += tmp.strng
            s += DBLQUOTE
         case _BOOL_      : s += tmp.toString
         case _NULL_      : s += "NULL"
         case _NUMBER_   : s &= tmp.number
         case _OBJECT_   : s += stringize_object( tmp )
      end select
      if i <> length-1 then s += "," else s += "]"
   next i 

   function=  s 
end function 
As you see, I have made s static, otherwise it does not accumulate much beyond "["
Here are some results.

Code: Select all

Building string
Initializing variable
Stringizing "NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        {
                "txt":          "word",
                "tag_tkns":     ["NN"],
                "phone_tag":    "(W ER D)",
                "nsyls":        1,
                "accent":       1,
                "tags":         ["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        },"NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        {
                "txt":          "word",
                "tag_tkns":     ["NN"],
                "phone_tag":    "(W ER D)",
                "nsyls":        1,
                "accent":       1,
                "tags":         ["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        },"NN"]"stuff","nested","array"],"more stuff"]
        {
                "txt":          "word",
                "tag_tkns":     ["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        {
                "txt":          "word",
                "tag_tkns":     ["NN"],
                "phone_tag":    "(W ER D)",
                "nsyls":        1,
                "accent":       1,
                "tags":         ["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        },"NN"],
                "phone_tag":    "(W ER D)",
                "nsyls":        1,
                "accent":       1,
                "tags":         ["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        {
                "txt":          "word",
                "tag_tkns":     ["NN"],
                "phone_tag":    "(W ER D)",
                "nsyls":        1,
                "accent":       1,
                "tags":         ["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        },"NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        {
                "txt":          "word",
                "tag_tkns":     ["NN"],
                "phone_tag":    "(W ER D)",
                "nsyls":        1,
                "accent":       1,
                "tags":         ["NN"]"stuff","nested","array"]["NN"]"stuff","nested","array"],"more stuff"]
        },"NN"]"stuff","nested","array"],"more stuff"]
        },
 
But it still pegs out if I omit sleep and don't print inside the function.
I think the recursions are causing the error.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Re: Linux threw this error.. Anyone see it before?

Post by rolliebollocks »

Could be the recursions. I have no idea. I don't think this is expected behavior.
fxm
Moderator
Posts: 12395
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Linux threw this error.. Anyone see it before?

Post by fxm »

@rolliebollocks,

I studied your program and I found the bug:
- No problem of iterations or program stack overflow.
- Your program overflows the heap memory, and that because the object destructors are badly coded, mainly the destructor in variable type (besides the destructor in varObjectField is missing).

Modify the 4 descriptors (and one type) as following:

Code: Select all

type varObjectField
    Public:
        declare Destructor()
        as string           key
        as variable_ ptr    value
end type

Destructor varArray()
    for i as integer = 0 to this.size-1
        delete items(i)
    next
    erase items
End Destructor

Destructor varObject
    for i as integer = 0 to this.size-1
        delete fields(i)
    next i
    erase fields
end Destructor

Destructor varObjectField()
    delete value
End destructor

Destructor variable()
    delete array
    delete object
end Destructor
Good continuation!


[edit]
- One destructor was also missing.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Re: Linux threw this error.. Anyone see it before?

Post by rolliebollocks »

Nice catch! Thanks!
Post Reply