[Gambas-user] Issues when writing and reading structures
Brian G
brian at westwoodsvcs.com
Sat Mar 25 19:07:25 CET 2023
Thank you Ben, for the all the work you have done for Structure support, they all work great!
I have been trying to encapsulate the structures within a gambas class.
I have run into an issue with the serialization using the _read/_write interface.
When doing a "write myclass as TestElevationClass"
and the class itself just does a "write value as elevation" <-- the actual structure
then the serialization process always adds a 4F as the leading byte of any output stream.
While this works well when reading and writing using the gambas serialization.
The recieving app not being gambas based goes all crazy.
Is this needed or is there a work around?
See the following script:
-------------------------------------------------------------------------------------
#!/usr/bin/env gbs3
' Gambas Script File Created 03/25/2023 10:38:24
class TestElevationClass
Public Struct elevation
a As Short
b As Long
c As Float
d As Short
e As String
End Struct
Public Value As Elevation
Property Read text As String
Public Sub _new()
value = New Elevation
value.a = 45
value.b = 98765
value.c = 67.465
value.d = 1
value.e = "hello Value ............................."
End
Public Sub _write(outfile As File)
Write #outfile, value As Elevation
End
Public Sub _read(infile As File)
value = Read #infile As Elevation
End
Private Function text_Read() As String
Return Subst("&1\t&2\t&3\t&4\t&5", Value.a, Value.b, Value.c, Value.d, Value.e)
End
end class
' Gambas module file
Public Struct elevation
a As Short
b As Long
c As Float
d As Short
e As String
End Struct
Public Sub main()
Dim ee As New TestElevationClass
Dim b, d As Object
Dim a As New Elevation
Dim aa As Elevation
Dim aaa As Elevation
Dim p As Pointer = Alloc(20000, 1)
Dim pp As Pointer = Alloc(10000, 1)
Dim ptr As Pointer = 0
b = Object.Class(a)
a.a = 45
a.b = 98765
a.c = 67.456
a.d = 1
a.e = "hello a.........."
aa = pp
aa.a = 45
aa.b = 98765
aa.c = 67.465
aa.d = 1
aa.e = "hello aa........"
Dim f As File
f = Memory p For Write
Write #f, a As Elevation
Close #f
f = Memory p For Read
aaa = Read #f As Elevation
For i As Integer = 0 To 50
Print Hex(Byte@(p + i), 2);;
Next
Print
For i As Integer = 0 To 50
Print Hex(Byte@(pp + i), 2);;
Next
Print
Print a.a, a.b, a.c, a.d, a.e
Print aaa.a, aaa.b, aaa.c, aaa.d, aaa.e
f = Memory p For Write
Write #f, ee As TestElevationClass
Close #f
For i As Integer = 0 To 50
Print Hex(Byte@(p + i), 2);;
Next
Print
f = Memory p For Read
ee = Read #f As TestElevationClass
Print ee.Text
Free(p)
Free(pp)
End
---------------------------------------------------------------
"Failure is the key to success;
each mistake teaches us something" .. Morihei Ueshiba
Brian G
----- On Mar 22, 2023, at 7:01 PM, Brian G brian at westwoodsvcs.com wrote:
> I can confirn that on openSUSE 15.4 it also segfaults.
>
> In more detail on the platforms where it segfaults, it only happens when writing
> structure and only when writing the entire structure. Any single field within
> the structure works fine.
> Reading an entire structure also works fine.
>
> And the issue seems to be on debian and openSUSE not on Ubuntu/mint systems
>
> I will investigate a little farther
>
> "Failure is the key to success;
> each mistake teaches us something" .. Morihei Ueshiba
> Brian G
>
> ----- On Mar 22, 2023, at 11:10 AM, Brian G brian at westwoodsvcs.com wrote:
>
>> I can confirm that it is issue on Debian even with latest version of gambas
>> built on the platform
>>
>> Will rebuild and test with OpenSUSE now
>>
>> "Failure is the key to success;
>> each mistake teaches us something" .. Morihei Ueshiba
>> Brian G
>>
>> ----- On Mar 22, 2023, at 10:52 AM, T Lee Davidson t.lee.davidson at gmail.com
>> wrote:
>>
>>> On 3/22/23 11:47, Brian G wrote:
>>>> Which os are you running it on?
>>>>
>>>> "Failure is the key to success;
>>>> each mistake teaches us something" .. Morihei Ueshiba
>>>> Brian G
>>>
>>> [System]
>>> Gambas=3.18.1
>>> OperatingSystem=Linux
>>> Distribution=openSUSE Leap 15.4
>>> Kernel=5.14.21-150400.24.49-default
>>> Architecture=x86_64
>>> Cores=6
>>> Memory=15921M
>>> Language=en_US.UTF-8
>>> Desktop=KDE
>>>
>>>
>>> --
>>> Lee
>>>
>>>
>>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
More information about the User
mailing list