Couple of random facts...
- the code functions as expected in a windows 32 bit environment, building with pb 5.43
- according to checkinstall.sh 'Everything seems correctly setup for PureBasic !'
- Create Unicode executable is off in compiler options
- Rolled back PB to 5.31, and 5.22 on the 64 bit Linux... results are the same (invalid memory access)
- Ran pb as root... results are the same (invalid memory access)
- all combinations of the debugger and purifier on/and off... results are the same (invalid memory access)
- various combinations of forcing the procedures to #PB_Ascii where available... results are the same (invalid memory access)
a functional (as in it will error on the linux side, and not windows 7 32 bit )snippit and test bed of the code...
Code: Select all
;Linux Mint 18 - Cinnamon 3.0.7
;
;uname -a
;Linux J-LINUX 4.4.0-43-generic #63-Ubuntu SMP Wed Oct 12 13:48:03 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
;
;lshw -short
; H/W path Device Class Description
; =============================================================
; system K30AD_M31AD_M51AD (All)
; /0 bus K30AD_M31AD_M51AD_M32AD
; /0/0 memory 64KiB BIOS
; /0/1 memory
; /0/1/0 memory 8GiB DIMM DDR3 Synchronous 1600 MHz (0.6 ns)
; /0/39 memory System Memory
; /0/39/0 memory DIMM [empty]
; /0/3d memory 256KiB L1 cache
; /0/3e memory 1MiB L2 cache
; /0/3f memory 6MiB L3 cache
; /0/43 processor Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz
; /0/2 memory
; /0/3 memory
; /0/100 bridge 4th Gen Core Processor DRAM Controller
; /0/100/1 bridge Xeon E3-1200 v3/4th Gen Core Processor PCI Express x16 Controller
; /0/100/1/0 display GK104 [GeForce GTX 760 OEM]
; /0/4/0.0.0 /dev/sda disk 1TB TOSHIBA DT01ACA1
EnableExplicit
Global.l gInputBufferStart, gInputBufferEnd
Global.l gInputBufferSave
Global.l gInputBufferSize
Global *MemoryID_Input
Global.s delimiterSegment
Global.s rawFileData
Global.l currentSegmentStart
Global.l segmentState
Enumeration
#SEG_STATE_NONE = 0
#SEG_STATE_NEXT = 1
#SEG_STATE_PREVIOUS = 2
#SEG_STATE_FIRST = 3
#SEG_STATE_LAST = 4
EndEnumeration
Procedure.S nextSegment()
Define.L DelimiterPos
Define.b AscSegSep
Define.S Segment
DelimiterPos.L = gInputBufferStart
Debug gInputBufferStart
AscSegSep = Asc(delimiterSegment)
Repeat
;- HERE - [ERROR] Invalid memory access.
If PeekB(DelimiterPos) = AscSegSep
;MessageRequester ("In There?","yep")
; found end of segment
currentSegmentStart = gInputBufferStart
Segment.S = PeekS(gInputBufferStart, DelimiterPos - gInputBufferStart)
; increment segment pointer
gInputBufferStart = DelimiterPos + 1
; done - return next segment
Break
Else
; next character
DelimiterPos + 1
; done if past end of input file buffer
If DelimiterPos > gInputBufferEnd
Break
EndIf
EndIf
ForEver
segmentState = #SEG_STATE_NEXT
; return next segment
ProcedureReturn Segment
EndProcedure
Procedure.S firstSegment()
;reset buffer pointer
gInputBufferStart= gInputBufferSave
segmentState = #SEG_STATE_FIRST
ProcedureReturn NextSegment()
EndProcedure
Procedure.l loadTheFile(fileToRead.s)
Define.l fH
Define.l bytes, length
Define.L hasReturnFile, originalLen, hasTrailingSpaces
Define.l CR_isDelimiter, LF_isDelimiter
fH = ReadFile(#PB_Any , fileToRead);,#PB_Ascii)
If fH
; allocate memory buffer
; entire file
length = Lof(fH)
*MemoryID_Input = AllocateMemory(length)
If *MemoryID_Input
; read file
bytes.L = ReadData(fH, *MemoryID_Input, length)
; convert data to string
CompilerIf #PB_Compiler_Version >= 540
rawfileData = PeekS(*MemoryID_Input, length,#PB_Ascii )
CompilerElse
rawfileData = PeekS(*MemoryID_Input, length)
CompilerEndIf
FreeMemory(*MemoryID_Input)
gInputBufferStart = @rawFileData
gInputBufferSave = @rawFileData
gInputBufferEnd = @rawFileData + length - 1
EndIf
CloseFile(fh)
EndIf
ProcedureReturn fh
EndProcedure
;- === TESTBED EXECUTION STARTS HERE
Define.s theFileName
;theFileName ="/mnt/data/work/1200100000001938FF-GS101461227-JJ-REQ.TXT"
;Pick a text file, any text file
theFileName = OpenFileRequester("Select a file","","Text (.txt)|*.txt|All files (*.*)|*.*",0)
If loadTheFile(theFileName)
delimiterSegment= "~"
Debug firstSegment()
Debug nextSegment()
Debug nextSegment()
CallDebugger
EndIf