PB 4.31 Beta - String Problem

TailBite specific forum

Moderators: gnozal, ABBKlaus, lexvictory

User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

PB 4.31 Beta - String Problem

Post by Guimauve »

Hello,

I have discovered a small problem with String manipulation.

The file to compile :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Format Integer
; File : Lib_FormatInteger.pb
; File Version : 1.0.0
; Programmation : Bugged
; Programmed by : Gnozal
; Modified by : Guimauve
; Date : 27-05-2009
; Last Update : 27-05-2009
; Coded for PureBasic V4.31 Beta
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

ProcedureDLL.s FormatInteger(Number.s)
  
  NumberLen = Len(Number)
  Start = NumberLen % 3
  FormatedNumber.s = Left(Number, Start)
  
  For i = Start + 1 To NumberLen - Start Step 3
    FormatedNumber + " " + Mid(Number, i, 3)
  Next
  
  ProcedureReturn LTrim(FormatedNumber)
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
The file see the problem :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Format Integer
; File : Lib_FormatInteger.pb
; File Version : 1.0.0
; Programmation : Bugged
; Programmed by : Gnozal
; Modified by : Guimauve
; Date : 27-05-2009
; Last Update : 27-05-2009
; Coded for PureBasic V4.31 Beta
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

ProcedureDLL.s FormatInteger2(Number.s)
  
  NumberLen = Len(Number)
  Start = NumberLen % 3
  FormatedNumber.s = Left(Number, Start)
  
  For i = Start + 1 To NumberLen - Start Step 3
    FormatedNumber + " " + Mid(Number, i, 3)
  Next
  
  ProcedureReturn LTrim(FormatedNumber)
EndProcedure

String.s = Str(12345677)
Debug FormatInteger(String)
Debug FormatInteger(Str(12345677))

Debug FormatInteger2(String)
Debug FormatInteger2(Str(12345677))

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Debugger output wrote:12 345 677
12345677
12 345 677
12 345 677

Code: Select all

12 345 677  <-- This one OK
12345677  <-- This one Not OK
12 345 677  <-- This one OK
12 345 677  <-- This one OK
Best Regards

Guimauve
Last edited by Guimauve on Thu May 28, 2009 11:39 am, edited 1 time in total.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

The ASM for the procedures is the same (apart from symbol renaming), so I don't believe this is a TailBite bug.

The only difference is in the ASM that PB generates to call the functions. (which as far as I know doesn't change what is returned)

Code: Select all

1c1
< ; PrintN(FormatInteger(Str(12345677)))
---
> ; PrintN(FormatInteger2(Str(12345677)))
8d7
<   PUSH   dword [_PB_StringBasePosition]
12d10
<   INC    dword [_PB_StringBasePosition]
15c13,17
<   CALL   PB_FormatInteger
---
>   CALL  _Procedure0
>   MOV    edx,[esp]
>   MOV    dword [_PB_StringBasePosition],edx
>   MOV    edx,eax
>   CALL  _SYS_CopyString@0
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Maybe this is evident, but PB4.30 results what expected:

Code: Select all

12 345 677
12 345 677
12 345 677
12 345 677
@Guimauve - if this is a PB4.31ß issue, you may change the threads title

Michael
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Post by mpz »

Hi,

I have a same problem.

Code: Select all

ProcedureDLL.s MP_NullTrim(String.s) ;   ; Cut all "0" from the end of the string 
  Protected Len.i = Len(String) 
  Protected *String.CHARACTER = @String + (Len-1) * SizeOf(CHARACTER) 
  Protected i.i 
  
  While *String\c = '0' 
    i + 1 
    *String - SizeOf(CHARACTER) 
  Wend 
  If *String\c = '.' 
    i + 1 
  EndIf 
  ProcedureReturn Left(String, len - i) 
EndProcedure 



Debug MP_NullTrim("0.00000") = 0 is correct

zahl.f = 0
Debug MP_NullTrim(StrF(zahl))+"!!!!!!!!!!" = 0.00000 is wrong

zahl.f = 0
a.s = StrF(zahl)
Debug MP_NullTrim(a)+"!!!!!!!!!!" = 0!!!!!!!!!! is correct

I don't know is it a Tailbite or a Purebasic 4.31 or another problem?!? Any ideas?

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

personally I would think it a PB bug, as it was only reported after 4.31.

As said before, the ASM for the procedures is the same, its simply a difference in the way they are called and the return values handled. (it appears in the incorrect cases the output of Str() is being returned)
I however do not know enough asm to discover where the problem lies.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Post by mpz »

Hi,

i have tested this problem with Purebasic 4.30 and Tailbite 1.4.0 and i have tested it with 4.20 and Tailbite 1.3 PR 1.878 but the string problem was all times the same. It is not a 4.31 problem. I thing nobody used this funktion before ?! ?

Greetings
Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

I tested the examples on PB4.31.
Output result looks ok.

It seems to be a tailbite problem.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

My guess is the parameters aren't being passed properly / return values not picked up properly by pb, as I mentioned before.
Tailbite is not doing anything funky that should disrupt this.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Post by mpz »

Hi,

I have tested a DLL Library and it seems to be Okay with a DLL one. Perhaps we find the difference with the dll and tailbite code? I think it is problem with the "function stack" of the procedure. I have tested it and if you use MP_NullTrim(StrF(zahl)) the Taibite function use the STRF Funktion twice times in Tailbite.


:) Michael


--------------Working DLL FUNKTION----------------
test.dll

Code: Select all

Global Stringback.s

ProcedureDLL.s MP_NullTrim(String.s) ;   ; Cut all "0" from the end of the string 
  Protected Len.i = Len(String) 
  Protected *String.CHARACTER = @String + (Len-1) * SizeOf(CHARACTER) 
  Protected i.i 
  
  While *String\c = '0' 
    i + 1 
    *String - SizeOf(CHARACTER) 
  Wend 
  If *String\c = '.' 
    i + 1 
  EndIf
  Stringback =  Left(String, len - i) 
  ProcedureReturn  Stringback 
EndProcedure 
Testprocedure

Code: Select all


  If OpenLibrary(0, "test.dll")
     *MP_NullTrim = GetFunction(0, "MP_NullTrim")
  EndIf

Debug PeekS(CallFunctionFast(*MP_NullTrim,"0.00000")) ; = 0 Okay
;Debug MP_NullTrim("0.00000") ;= 0 Okay


;zahl.f = 0 
;Debug MP_NullTrim(StrF(zahl))+"!!!!!!!!!!" ;= 0.00000 is wrong 

zahl.f = 0 
Debug PeekS(CallFunctionFast(*MP_NullTrim,StrF(zahl)))+"!!!!!!!!!!" ; -> Works fine

CloseLibrary(0)


--------------Working DLL FUNKTION end----------------


--------------TaiBite Funktion----------------

Code: Select all

Global Stringback.s

ProcedureDLL.s MP_NullTrim(String.s,*Pointer) ;   ; Cut all "0" from the end of the string 

  MessageRequester("Information", "<"+string+"> + Peeki "+Str(@String), 0)

  Protected Len.i = Len(String) 
  Protected *String.CHARACTER = @String + (Len-1) * SizeOf(CHARACTER) 
  Protected i.i 
  
  While *String\c = '0' 
    i + 1 
    *String - SizeOf(CHARACTER) 
  Wend 
  If *String\c = '.' 
    i + 1 
  EndIf
  Stringback =  Left(String, len - i)  

  MessageRequester("Information", "<"+stringback+"> + Peeki "+Str(@Stringback), 0)

  PokeI(*Pointer,@Stringback)
  ProcedureReturn  Stringback 

EndProcedure 

Testprocedure

Code: Select all


zahl.f = 0.1

*pointer
Debug MP_NullTrim(StrF(zahl),@*pointer)+"!!!!!!!!!!" ;= 0.10000 is wrong and where is "!!!!!!!!!!"?

Debug PeekS(*pointer) ; = 0.1 is Okay

Working on - MP3D Library - PB 5.73 version ready for download
Post Reply