Page 1 of 1

Solved, no Bug! Probably a Bug with Stringoperations in PB6.21

Posted: Wed Jul 30, 2025 12:28 pm
by SMaag
I tried to solve the GetExtentionPart with Spaces with my FindCharReverse() Function.

But PB6.21 failed

Code: Select all

EnableExplicit 

Enumeration ReturnMode
  #FStr_ReturnCharNo
  #FStr_ReturnPointer
EndEnumeration

Prototype.i FindCharReverse(String$, cSearch.c, cfgReturnValue = #FStr_ReturnCharNo)
Global FindCharReverse.FindCharReverse                  ; define Prototype-Handler for FindCharReverse


Procedure.i _FindCharReverse(*String, cSearch.c, cfgReturnValue = #FStr_ReturnCharNo, *outEndOfString.Integer=0)
; ============================================================================
; NAME: FindCharReverse
; DESC: !PointerVersion! use it as ProtoType FindCharReverse()
; DESC: Finds the first psoition of Char from reverse
; DESC: 
; VAR(*String) : Pointer to the String
; VAR(cSearch) : Character to find
; VAR(cfgReturnValue) : #FStr_ReturnCharNo=0 => Returns Charposition 1..n or 0
;                       #FStr_ReturnPointer=1 => Returns address of Char or 0
; VAR(*outEndOfString=0) : Optional Pointer to return the address of EndOfString/NullChar
; RET.i : Character Position 1..n of cSearch or Pointer to cSearch  
; ============================================================================
  
  Protected *LastChar
  Protected *pChar.Character = *String
  
    
    If Not *String
      ProcedureReturn 0
    EndIf
    
    While *pChar\c
      If *pChar\c = cSearch
        *LastChar = *pChar
      EndIf
      *pChar + SizeOf(Character)
    Wend
    
    If *outEndOfString
      *outEndOfString\i = *pChar
    EndIf
    
    If cfgReturnValue =  #FStr_ReturnPointer Or *LastChar = 0
      ProcedureReturn *LastChar
    Else
      ProcedureReturn (*LastChar - *pChar) / SizeOf(Character) + 1
    EndIf
EndProcedure
FindCharReverse = @_FindCharReverse()   ; Bind ProcedureAddress to the PrototypeHandler
  
Define File$ = "c:\test\file.john doe"
Define File$ = "c:\test\file.dat"

Define Ext$, Full$
Define *Dot

*Dot = FindCharReverse(File$, '.', #FStr_ReturnPointer)
Ext$ = PeekS(*Dot+SizeOf(Character))
Full$ = PeekS(@File$)
Debug Ext$
Debug Full$
Debug File$
  
PB6.21 x64 With C-Backend optimize Code off
=> Debugger quitt

PB6.21 x64 With C-Backend optimize Code ON
datࢠ鵀Ǻ
c:\test\file.datࢠ鵀Ǻ
c:\test\file.datࢠ鵀Ǻ

PB6.21 x64 ASM-Backend optimize Code OFF
datࢠ梕Dz
c:\test\file.datࢠ梕Dz
c:\test\file.datࢠ梕Dz

PB6.21 x64 ASM Backen optimize Code ON
datࢠﲙɹ
c:\test\file.datࢠﲙɹ
c:\test\file.datࢠﲙɹ

If I do not call
*Dot = FindCharReverse(File$, '.', #FStr_ReturnPointer)

c:\test\file.dat
c:\test\file.dat


In PB6.04 x32 ASM Backend it works correct!
dat
c:\test\file.dat
c:\test\file.dat


THE PROBLEM SEEMS TO BE THE PROTOTYPE


if I call the _FindCharReverse() direct - not over the Prototype, It works correct!

Code: Select all

*Dot = _FindCharReverse(@File$, '.', #FStr_ReturnPointer)
Output in ASM and C-Backend is same and correct
dat
c:\test\file.dat
c:\test\file.dat

Re: Probably a Bug with Stringoperations in PB6.21

Posted: Wed Jul 30, 2025 12:49 pm
by SMaag
Solved! Last Parameter in Prototype definition was missing! That problem we had a few times here in the Forum!
Now it works!

Code: Select all

Prototype.i FindCharReverse(String$, cSearch.c, cfgReturnValue = #FStr_ReturnCharNo,) ; wrong
Prototype.i FindCharReverse(String$, cSearch.c, cfgReturnValue = #FStr_ReturnCharNo, *outEndOfString.Integer=0) ; correct!

Re: Probably a Bug with Stringoperations in PB6.21

Posted: Wed Jul 30, 2025 1:05 pm
by Little John
SMaag wrote: Wed Jul 30, 2025 12:49 pm Solved! Last Parameter in Prototype definition was missing!
So please correct the title of this thread (at least remove the word „bug“)!