[Gambas-user] emulated empty settings collection get a crash when write it
PICCORO McKAY Lenz
mckaygerhard at gmail.com
Wed Jul 4 22:53:20 CEST 2018
Tibiqa of course i understan the problem..
that's why i want to override the write process to detect when got
null and change to empty string at writing
again i parse the current code>
Export
Inherits Collection
Property Read {Null} As Variant '' emulacion de null para que una
lib collecion lo admita
Private $vNull As Variant '' variable null emulada para que
sea aceptada en una colleccion
Public Sub _init()
$vNull = VarPtr($vNull)
cf = New Excfg
End
Private Function Null_Read() As Variant
Return $vNull
End
' sobreescritura de get, put y next par admitir null
Public Sub _get(Key As String) As Variant
Dim vVal As Variant
vVal = Super[Key]
If TypeOf(vVal) = gb.Pointer And If vVal = me.Null Then vVal = Null
Return vVal
End
Public Sub _put(Value As Variant, Key As String)
If IsNull(Value) Then Value = me.Null
Super[Key] = Value
End
Public Sub _next() As Variant
Super._next()
If Not Enum.Stopped Then Return _get(Me.Key)
End
Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
2018-07-04 16:46 GMT-04:00 Tobias Boege <taboege at gmail.com>:
> On Wed, 04 Jul 2018, PICCORO McKAY Lenz wrote:
>> In the past I was told to emulate the "null" and I did it based on the
>> json class, but now I have the following problem
>>
>> I have my own Settings class but when I try to write, I get an error
>> and a crash because some keys instead of getting the string I get a
>> reference (as emulated in the json class)
>>
>> Of course the settings clas at write does not xpect to have any null
>> key value, so that's the problem
>>
>> how can overrite the process to do not get a crash?
>> or how to write those null keys into a empty string?
>>
>> i got at console that poutput:
>>
>> gb.settings: warning: unable to save settings:
>> /home/general/Devel/gambasex/excore/exdatabase.conf: Settings.Save.204
>> Unable to save settings: Settings.WriteValue.563 Type mismatch: wanted
>> Object, got Pointer instead
>>
>> that due emulated null value based on json class of gambas
>>
>
> Interesting, I get a segfault in addition:
>
> $ cat a.gbs3
> #!/usr/bin/env gbs3
>
> Use "gb.settings"
>
> Public Sub Main()
> Dim p As Pointer = VarPtr(p)
>
> Settings["x"] = p
> Settings.Save
> End
> $ ./a.gbs3
> Settings.Save.204: Unable to save settings: Settings.WriteValue.563 Type mismatch: wanted Object, got Pointer instead
> Settings.Save.204 MMain.Main.9
> Segmentation fault
>
> Besides this crash (which really shouldn't happen), you have to
> understand how the JSON.Null is implemented. Even if the crash
> didn't happen your code wouldn't work. This is the definition of
> JSON.Null which you supposedly copied into your thing:
>
> Property {Null} As Variant
> Private $vNull As Variant
>
> Public Sub _init()
> $vNull = VarPtr($vNull)
> End
>
> Private Function Null_Read() As Variant
> Return $vNull
> End
>
> JSON.Null is a "unique" value obtained as the pointer to the contents
> of some static variable during the loading of the JSON class. When
> you restart your program, you will get a different pointer. You can't
> store JSON.Null in a settings file because the next process reading it
> won't recognise that it was JSON.Null.
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
More information about the User
mailing list