Page 1 of 1

SUGGESTION designers PB on the management of strings between

Posted: Tue Sep 07, 2010 10:22 pm
by PAPIPP
SUGGESTION designers PB on the management of strings between a main prg and a procedure prg
The value or string address is passed by procedurereturn as example below

Code: Select all

Macro __HT(__HQ)
  "$"+RSet(Hex(PeekQ(@__HQ+2),#PB_Quad),16,"0")+RSet(Hex(PeekC(@__HQ+1),#PB_Byte),2,"0")+RSet(Hex(PeekC(@__HQ),#PB_Byte),2,"0")
EndMacro
Structure stt
  StructureUnion
    st.s{1}[10]
    st10.s{10}
  EndStructureUnion
EndStructure
Global s1.stt
s1\st10="1234506789"
s1\st[5]=Chr(0)
Debug " st10="+__ht(S1\st10)+" @st10="+Str(@S1\st10)

Procedure.s procs()
  s.s=Space(10)
  CopyMemory(@s1,@s,10)
  Debug "s="+__ht(s)+" @s="+Str(@s)
  ProcedureReturn s
EndProcedure
Procedure.s procsf()
  sf.s{10}=Space(10)
  CopyMemory(@s1,@sf,10)
  Debug "sf="+__ht(sf)+" @sf="+Str(@sf)
  ProcedureReturn sf
EndProcedure
Ss.s=procs()
Debug "ss="+__ht(ss)+" @ss="+Str(@ss)
sfp.s{10}=procsf()
Debug "sfp="+__ht(sfp)+" @sfp="+Str(@sfp)

1) Of the non-fixed type strings: cS or ch $
One can notice that a non-fixed created or copied to a subroutine has the same address as the one passed to the main prg
It can therefore be modified in the main prg while we can not control his creation.
This means that if we change the string it will be sent in the first state if the appeal under PRG
Furthermore we can notice that the chain of length 10 has not been truncated which is normal since the address is the same

2) on fixed type strings cS (10)
This string is copied and truncated which is consistent with the management of strings
Notes: whereas in the chain not fixed can access the information after null chr (0) which is not the case in a fixed string. Apart from the above observation work on both strings will be identical

3) In conclusion
ASM routines that affect both strings are different
For non-fixed string :

Code: Select all

Ss.s=procs()
	PUSH	 dword [_PB_StringBasePosition]
	CALL	 _Procedure0
	PUSH	 dword v_Ss
	CALL	 _SYS_AllocateString4@8
For fixed string :

Code: Select all

sfp.s{10}=procsf()
	PUSH	 dword [_PB_StringBasePosition]
	CALL	 _Procedure2
	LEA	 eax,[v_sfp]
	PUSH	 dword 10
	CALL	 _SYS_AssignFixedString@8
Imagine the routine fixed string passes all characters in the given length without truncation that does not affect the result of the treatment since it already exists on the non-fixed strings
One could spend between complex structures and main prg / sub prg example

Code: Select all

Structure lf
ww.w
qq.q
enstructure
Structure xx
Structureunion
 Ch.s{10]
Zone_str_complex.lf
Endstructureunion
Endstructure

Can you change the routine _SYS_AssignFixedString@8 so what can pass all characters on the given length?
This would give a strong potential to PB

Re: SUGGESTION designers PB on the management of strings bet

Posted: Wed Sep 08, 2010 9:36 am
by Fred
I don't understand what is your point.

Re: SUGGESTION designers PB on the management of strings bet

Posted: Wed Sep 08, 2010 12:18 pm
by PAPIPP
OK let me explain
Suppose the routine sets the output string can pass all characters in $ 00 to $ FF

We could make a routine type conversion W L I F D Q or T for copy value Float 80 bits INTEL
That is to say, a sub / prg passing a complex structure of output as follows
While the routine work currently works by address and not by value
The routine would operate with perfect information passed by value easier
Here the two routines :

Code: Select all

Macro __HT(__HQ)
  "$"+RSet(Hex(PeekQ(@__HQ+2),#PB_Quad),16,"0")+RSet(Hex(PeekC(@__HQ+1),#PB_Byte),2,"0")+RSet(Hex(PeekC(@__HQ),#PB_Byte),2,"0")
EndMacro
Structure ten
  vq.q
  vw.w
EndStructure
Structure lf
  StructureUnion
    fword.w[5]
    tbyte.b[10]
    vw.w[5]
    vu.u[5]
    vc.c[10]
    vb.b[10]
    vs10.s{10}
    vs.s{1}[10]
    vt.ten
  EndStructureUnion
EndStructure

; Routine classique en passage par adresse difficile pour imbriquer  comme F(G(H(j)))

Procedure convx2lf(*x.lf, *y.q, typ.s = "quad")
  ; avec Word, Integer, Long, Float simple, D flot double ,Quad, Ten routine de conversion entre une forme W,L,F,D,I,Q,T en Lf 
  ; forme flottant Intel sur 80 bits 10 Bytes ou 10 octets
  tp.s{1} = Mid(UCase(Trim(typ)), 1, 1)
  FINIT
  MOV ebx, *y
  Select tp
    Case "W" ;en 16 bits
      FILD word[ebx]
    Case "L" ; en 32 bits
      FILD dword[ebx]
    Case "I" ; en 32 bits
      FILD dword[ebx]
    Case "F" ; en float simple précision 32 bits
      FLD dword[ebx]
    Case "Q" ; en 64 bits
      FILD qword[ebx]
    Case "D" ; en 64 bits
      FLD qword[ebx]
    Case "T" ; en 80 bits
      FLD tword[ebx]
  EndSelect
  MOV ebx, *x
  FSTP tword[ebx]
EndProcedure

; Routine révée en passage pour des valeurs > 8 bytes dans une structure complexe trés facile pour imbriquer  comme F(G(H(j)))

Procedure.s conv_x2lf(y.q, typ.s = "quad")
  ; avec Word, Integer, Long, Float simple, D flot double ,Quad, Ten routine de conversion entre une forme W,L,F,D,I,Q,T en Lf 
  ; forme flottant Intel sur 80 bits 10 Byte ou 10 octets
  Define x.lf
  tp.s{1} = Mid(UCase(Trim(typ)), 1, 1)
  FINIT
  LEA ebx,dword[p.v_y]
  Select tp
    Case "W" ;en 16 bits
      FILD word[ebx]
    Case "L" ; en 32 bits
      FILD dword[ebx]
    Case "I" ; en 32 bits
      FILD dword[ebx]
    Case "F" ; en float simple précision 32 bits
      FLD dword[ebx]
    Case "Q" ; en 64 bits
      FILD qword[ebx]
    Case "D" ; en 64 bits
      FLD qword[ebx]
    Case "T" ; en 80 bits
      FLD tword[ebx]
  EndSelect
  LEA ebx,dword[p.v_x]
  FSTP tword[ebx]
  ProcedureReturn x\vs10
EndProcedure

Define sortie.lf
qq.q=1234567890

sortie\vs10=conv_x2lf(qq)
Debug "sortie type lf="+__ht(sortie\vs10)+" @sortie\vs10="+Str(@sortie\vs10)

;POUR LA ROUTINE QUI FONCTIONNE ACTUELLEMENT

convx2lf(@sortie\vs10, @qq, "quad")
Debug "sortie type lf="+__ht(sortie\vs10)+" @sortie\vs10="+Str(@sortie\vs10)

; la routine en passage par valeur est plus simple d'utilisation et il y a moins de risque d'effet de bord écrasement par un autre programme