Reflection - setting null array instance
Archives Forums/BlitzMax Bug Reports/Reflection - setting null array instance
| ||
| Using TField.Set() to assign Null to an field of type Array, may result in later undefined behaviour as it appears &bbNullObject is assigned to the field, and not &bbEmptyArray. Depending on compiler/memory/weather settings, results from this field's Length/Dimensions may then appear as random values, or zero, as expected. A "fix" would be to assign &bbEmptyArray to the field, instead of the generic "Null". This could be accomplished along the lines of : reflection.cpp
BBArray * bbRefArrayNull() {
return &bbEmptyArray;
}
reflection.bmx
...
Extern
...
Function bbRefArrayNull:Object()
...
End Extern
...
Function _Assign( p:Byte Ptr,typeId:TTypeId,value:Object )
...
Default
If value
...
Else
If typeId.Name().Endswith("]") Then
value = bbRefArrayNull()
EndIf
EndIf
...
End Function
|
| ||
A cooler fix would be to be able to set Null to an Array, so I don't get confused with codes like this:
Local a:String[] = Null
Print "No NullPointerException: "+a.length
If a = Null
Local b:Object = a
If b = Null
Print "This does make sense"
Else
Print "Nah... we're in BlitzMax here"
EndIf
EndIf
I understand how it works internally but working with Java in my job and programming a serialization lib for Blitzmax this was not easy and you have to go through a lot of special ifs to filter out arrays and strings that aren't really Null in many cases. |