Reflection: wrong values with ArrayLength()

Archives Forums/BlitzMax Bug Reports/Reflection: wrong values with ArrayLength()

Derron(Posted 2014) [#1]
Ok I narrowed a nasty crash down to reflection returning wrong values.

Where? Seems only on Mac OS - Linux and Windows do not have this issue. Reporter used OS X 10.9.5, I use an older one.

I have a type:

Type TMyType
Field xyz
...
End Type


And another Type:
Type TOtherType
field mytypes:TMyType[]
End Type

Btw I use Bruceys TPersistence module to serialize the data (the module is crashing the whole app - according to gdb it is a division-by-zero-error, which lead me to find the reflection module returning wrong values).

Ok, so when iterating over the instances of "TOtherType" the
mytypesFieldType.ArrayDimensions(f.Get(otherTypeInstance)) returns values like "3332211" as soon as the array is a 0 sized array. As soon as I have something added to the array (so "[1]") the returned values are correct.

TMyType[0] and TMyType[] then lead to this odd numbers.

ArrayLength(f.Get...) returns correctly "0" (no entries in the array)-

As this only happens on Mac (with the same input data on Windows, Linux and Mac) I am not sure how to narrow it down even more.


bye
Ron


grable(Posted 2014) [#2]
Sounds like a mismatch between the type stored in TTypeID and the actual instance type.
But could just as well be that Object Null is too different than Array Null on mac (i cant check for real, and i havent found any reason for this in the source though).
Checking for Null might help until a fix is provided...

What is the output of this snippet btw?
Local a:Object[]
Local b:Object[10]
Local c:Object
Local d:Object = New TList
Local e:Object = New TList[10]
Local f:Object = New TList[10,10]

Local t:TTypeId = TTypeId.ForName("TList[]")
Print t.ArrayDimensions(a) + " " + t.ArrayLength(a)
Print t.ArrayDimensions(b) + " " + t.ArrayLength(b)
Print t.ArrayDimensions(c) + " " + t.ArrayLength(c)
Print t.ArrayDimensions(d) + " " + t.ArrayLength(d)
Print t.ArrayDimensions(e) + " " + t.ArrayLength(e)
Print t.ArrayDimensions(f) + " " + t.ArrayLength(f)

i get this in windows:
0 0
1 10
0 0
0 -2147483648
1 10
2 100
Notice the middle one reading bogus data from wrong instance type.
They all read directly from the instance provided, so rely more on luck to get the right data on type mismatches.


Derron(Posted 2014) [#3]
Sorry, did not read your post earlier:

Building untitled2
Compiling:untitled2.bmx
Linking:untitled
Executing:untitled2
0 0
1 10
1074747 0
0 4
1 10
2 100


BUT ... the results came from a "field bla:type[]". All entered objects are from the same type, no extension or so. Exception is, if NOTHING was entered - then the "bla:type[]" is something like "null/undefined" - which then on Mac leads to that odd numbers.

So the important thing is: YOURS just gives the second one an "odd" number - but mine leads to an incorrect "ArrayDimensions" value.

The problem is: an array could have 0 entries: and therefore a length of "0", but the dimensions are something which comes from "definition" (the amount of "," in "[,,,,]".


bye
Ron