[Done] 6.0 alpha 5 x64 - Reading data doesn't work

All bugs related to new C backend
User avatar
marcoagpinto
Enthusiast
Enthusiast
Posts: 727
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

[Done] 6.0 alpha 5 x64 - Reading data doesn't work

Post by marcoagpinto »

Hello!

If I use the standard compiler, it reads a wrong result in the first line of the Data.

If I use the C compiler it doesn't run at all, it gives an error.

Code: Select all

Restore cache_files_data

time_start=ElapsedMilliseconds()
For f=1 To 10
  Read.l header
  Debug "header:"+Str(header)
  If header<>f
    Debug "Wrong header!"
    End
  EndIf
  For ff=1 To f*2+1
    Read.l left
    Read.l middle
  Next ff
Next f
time_end=ElapsedMilliseconds()
Debug "Time taken:"+Str(time_end-time_start)


cache_files_data:

DataSection
    Data.l 1
    Data.l $0,$3
    Data.l $0,$3
    Data.l $0,$3

    Data.l 2
    Data.l $1,$3
    Data.l $0,$5
    Data.l $0,$5
    Data.l $0,$5
    Data.l $1,$3

    Data.l 3
    Data.l $2,$3
    Data.l $1,$5
    Data.l $0,$7
    Data.l $0,$7
    Data.l $0,$7
    Data.l $1,$5
    Data.l $2,$3

    Data.l 4
    Data.l $3,$3
    Data.l $1,$7
    Data.l $1,$7
    Data.l $0,$9
    Data.l $0,$9
    Data.l $0,$9
    Data.l $1,$7
    Data.l $1,$7
    Data.l $3,$3

    Data.l 5
    Data.l $3,$5
    Data.l $2,$7
    Data.l $1,$9
    Data.l $0,$B
    Data.l $0,$B
    Data.l $0,$B
    Data.l $0,$B
    Data.l $0,$B
    Data.l $1,$9
    Data.l $2,$7
    Data.l $3,$5

    Data.l 6
    Data.l $4,$5
    Data.l $3,$7
    Data.l $2,$9
    Data.l $1,$B
    Data.l $0,$D
    Data.l $0,$D
    Data.l $0,$D
    Data.l $0,$D
    Data.l $0,$D
    Data.l $1,$B
    Data.l $2,$9
    Data.l $3,$7
    Data.l $4,$5

    Data.l 7
    Data.l $5,$5
    Data.l $3,$9
    Data.l $2,$B
    Data.l $1,$D
    Data.l $1,$D
    Data.l $0,$F
    Data.l $0,$F
    Data.l $0,$F
    Data.l $0,$F
    Data.l $0,$F
    Data.l $1,$D
    Data.l $1,$D
    Data.l $2,$B
    Data.l $3,$9
    Data.l $5,$5

    Data.l 8
    Data.l $6,$5
    Data.l $4,$9
    Data.l $3,$B
    Data.l $2,$D
    Data.l $1,$F
    Data.l $1,$F
    Data.l $0,$11
    Data.l $0,$11
    Data.l $0,$11
    Data.l $0,$11
    Data.l $0,$11
    Data.l $1,$F
    Data.l $1,$F
    Data.l $2,$D
    Data.l $3,$B
    Data.l $4,$9
    Data.l $6,$5

    Data.l 9
    Data.l $7,$5
    Data.l $5,$9
    Data.l $3,$D
    Data.l $2,$F
    Data.l $2,$F
    Data.l $1,$11
    Data.l $1,$11
    Data.l $0,$13
    Data.l $0,$13
    Data.l $0,$13
    Data.l $0,$13
    Data.l $0,$13
    Data.l $1,$11
    Data.l $1,$11
    Data.l $2,$F
    Data.l $2,$F
    Data.l $3,$D
    Data.l $5,$9
    Data.l $7,$5

    Data.l 10
    Data.l $7,$7
    Data.l $5,$B
    Data.l $4,$D
    Data.l $3,$F
    Data.l $2,$11
    Data.l $1,$13
    Data.l $1,$13
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $1,$13
    Data.l $1,$13
    Data.l $2,$11
    Data.l $3,$F
    Data.l $4,$D
    Data.l $5,$B
    Data.l $7,$7


EndDataSection
User_Russian
Addict
Addict
Posts: 1230
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: 6.0 alpha 5 x64 - Reading data doesn't work

Post by User_Russian »

I did not find a bug.

Code: Select all

Restore cache_files_data

time_start=ElapsedMilliseconds()
For f=1 To 10
  Read.l header
  Debug "header:"+Str(header)
  If header<>f
    Debug "Wrong header!"
    End
  EndIf
  For ff=1 To f*2+1
    Read.l left
    Read.l middle
  Next ff
Next f
time_end=ElapsedMilliseconds()
Debug "Time taken:"+Str(time_end-time_start)



DataSection
    cache_files_data:
    Data.l 1
    Data.l $0,$3
    Data.l $0,$3
    Data.l $0,$3

    Data.l 2
    Data.l $1,$3
    Data.l $0,$5
    Data.l $0,$5
    Data.l $0,$5
    Data.l $1,$3

    Data.l 3
    Data.l $2,$3
    Data.l $1,$5
    Data.l $0,$7
    Data.l $0,$7
    Data.l $0,$7
    Data.l $1,$5
    Data.l $2,$3

    Data.l 4
    Data.l $3,$3
    Data.l $1,$7
    Data.l $1,$7
    Data.l $0,$9
    Data.l $0,$9
    Data.l $0,$9
    Data.l $1,$7
    Data.l $1,$7
    Data.l $3,$3

    Data.l 5
    Data.l $3,$5
    Data.l $2,$7
    Data.l $1,$9
    Data.l $0,$B
    Data.l $0,$B
    Data.l $0,$B
    Data.l $0,$B
    Data.l $0,$B
    Data.l $1,$9
    Data.l $2,$7
    Data.l $3,$5

    Data.l 6
    Data.l $4,$5
    Data.l $3,$7
    Data.l $2,$9
    Data.l $1,$B
    Data.l $0,$D
    Data.l $0,$D
    Data.l $0,$D
    Data.l $0,$D
    Data.l $0,$D
    Data.l $1,$B
    Data.l $2,$9
    Data.l $3,$7
    Data.l $4,$5

    Data.l 7
    Data.l $5,$5
    Data.l $3,$9
    Data.l $2,$B
    Data.l $1,$D
    Data.l $1,$D
    Data.l $0,$F
    Data.l $0,$F
    Data.l $0,$F
    Data.l $0,$F
    Data.l $0,$F
    Data.l $1,$D
    Data.l $1,$D
    Data.l $2,$B
    Data.l $3,$9
    Data.l $5,$5

    Data.l 8
    Data.l $6,$5
    Data.l $4,$9
    Data.l $3,$B
    Data.l $2,$D
    Data.l $1,$F
    Data.l $1,$F
    Data.l $0,$11
    Data.l $0,$11
    Data.l $0,$11
    Data.l $0,$11
    Data.l $0,$11
    Data.l $1,$F
    Data.l $1,$F
    Data.l $2,$D
    Data.l $3,$B
    Data.l $4,$9
    Data.l $6,$5

    Data.l 9
    Data.l $7,$5
    Data.l $5,$9
    Data.l $3,$D
    Data.l $2,$F
    Data.l $2,$F
    Data.l $1,$11
    Data.l $1,$11
    Data.l $0,$13
    Data.l $0,$13
    Data.l $0,$13
    Data.l $0,$13
    Data.l $0,$13
    Data.l $1,$11
    Data.l $1,$11
    Data.l $2,$F
    Data.l $2,$F
    Data.l $3,$D
    Data.l $5,$9
    Data.l $7,$5

    Data.l 10
    Data.l $7,$7
    Data.l $5,$B
    Data.l $4,$D
    Data.l $3,$F
    Data.l $2,$11
    Data.l $1,$13
    Data.l $1,$13
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $0,$15
    Data.l $1,$13
    Data.l $1,$13
    Data.l $2,$11
    Data.l $3,$F
    Data.l $4,$D
    Data.l $5,$B
    Data.l $7,$7
EndDataSection 
User avatar
marcoagpinto
Enthusiast
Enthusiast
Posts: 727
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: 6.0 alpha 5 x64 - Reading data doesn't work

Post by marcoagpinto »

Buaaaaaaaaaa...

It is a bug in PureBasic help, in the example it places the label before the data section, at least twice.

Image
User_Russian
Addict
Addict
Posts: 1230
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: 6.0 alpha 5 x64 - Reading data doesn't work

Post by User_Russian »

There is no bug in the help.

Code: Select all

Debug "Start"
CallFunctionFast(PeekI(?m1))
Debug "End"
End

Label:
Debug "sub routine"
Return

DataSection
  m1:
  Data.i ?Label
EndDataSection
User avatar
spikey
Enthusiast
Enthusiast
Posts: 406
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: 6.0 alpha 5 x64 - Reading data doesn't work

Post by spikey »

I agree with Marco on this one. Although the example is technically correct (the address of 'Label' is being included in a section as a data item), the DataSection itself should have a label so that it can be addressed, by Restore for example. The example as shown doesn't do this. The examples are ambiguous and could be taken to mean that the DataSection's label should preceed the DataSection directive - and this does indeed cause a bug (in the ASM backend at least, I haven't tested the C backend). They could and should be re-written to avoid this ambiguity.
User avatar
mk-soft
Addict
Addict
Posts: 3269
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: 6.0 alpha 5 x64 - Reading data doesn't work

Post by mk-soft »

I spikey agree.

The example of User_Russian also already leads Stack Corruption
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
juergenkulow
User
User
Posts: 91
Joined: Wed Sep 25, 2019 10:18 am

Re: 6.0 alpha 5 x64 - Reading data doesn't work

Post by juergenkulow »

Code: Select all

; Restore Label not in Datasection - Do you understand this error message?
; error: 'l_label' undeclared (first use in this function); did you mean 'la_l_label'?
;  pb_datapointer=&pb_data[l_label];
;                          ^~~~~~~
;                          la_l_label
; purebasic.c:93:25: note: each undeclared identifier is reported only once for each function it appears in

Macro myRestore(myLabel) 
  If ?myLabel<?DataSectionLabel Or ?myLabel>?EndDataSectionLabel
    MessageRequester("PureBasic Error","Restore Label not in Datasection.") ; [Errorcodes] 306 
  Else 
    Debug "pb_datapointer=&pb_data[l_label];"
  EndIf 
EndMacro  
  
myRestore(label) ; Restore label  

label: 

DataSection
  DataSectionLabel:
  Data.i 4711
  EndDataSectionLabel:
EndDataSection  
User_Russian
Addict
Addict
Posts: 1230
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: 6.0 alpha 5 x64 - Reading data doesn't work

Post by User_Russian »

mk-soft wrote: Sat Nov 20, 2021 7:58 pmThe example of User_Russian also already leads Stack Corruption
I did not find stack corruption.
I added the procedure and works fine.

Code: Select all

Procedure Test()
  Debug "Start"
  CallFunctionFast(PeekI(?m1))
  Debug "End"
EndProcedure

Test()
End

Label:
Debug "sub routine"
Return

DataSection
  m1:
  Data.i ?Label
EndDataSection
Why do you think that there is a stack corruption?
Post Reply