[Gambas-user] emulated empty settings collection get a crash when write it
Tobias Boege
taboege at gmail.com
Wed Jul 4 22:46:15 CEST 2018
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
More information about the User
mailing list