Posted: Tue Mar 25, 2008 4:03 pm
Could you post the code generated by TailBite ?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
ProcedureDLL.s HeyHo(a)
Protected a$
a$=Str(a)
ProcedureReturn a$
EndProcedure
Code: Select all
; :
; ProcedureDLL.s HeyHo(a)
macro MP0{
_Procedure0:
PS0=8
XOR eax,eax
PUSH eax
; Protected a$
; a$=Str(a)
PUSH dword [_PB_StringBasePosition]
PUSH dword [_PB_StringBasePosition]
PUSH dword [esp+PS0+8]
CALL _PB_Str@8
LEA ecx,[esp+4]
POP edx
CALL SYS_AllocateString
; ProcedureReturn a$
MOV edx,dword [esp]
PUSH dword [_PB_StringBasePosition]
CALL _SYS_CopyString@0
POP eax
ADD eax,[PB_StringBase]
JMP _EndProcedure1
; EndProcedure
MOV eax,[_PB_StringBasePosition]
ADD eax,[PB_StringBase]
MOV byte [eax],0
_EndProcedure1:
PUSH dword [esp]
CALL _SYS_FreeString@4
ADD esp,4
RET 4
}
Code: Select all
format MS COFF
Public PB_HeyHo
Extrn _PB_Str@8
Extrn SYS_AllocateString
Extrn _SYS_CopyString@0
Extrn _SYS_FreeString@4
Extrn _PB_StringBasePosition
Extrn PB_StringBase
section '.text' code readable executable
PB_HeyHo:
PS0=8
XOR eax,eax
PUSH eax
; Protected a$
; a$=Str(a)
PUSH dword [_PB_StringBasePosition]
PUSH dword [_PB_StringBasePosition]
PUSH dword [esp+PS0+8]
CALL _PB_Str@8
LEA ecx,[esp+4]
POP edx
CALL SYS_AllocateString
; ProcedureReturn a$
MOV edx,dword [esp]
PUSH dword [_PB_StringBasePosition]
CALL _SYS_CopyString@0
POP eax
ADD eax,[PB_StringBase]
JMP _EndProcedure1
; EndProcedure
MOV eax,[_PB_StringBasePosition]
ADD eax,[PB_StringBase]
MOV byte [eax],0
_EndProcedure1:
PUSH dword [esp]
CALL _SYS_FreeString@4
ADD esp,4
RET 4
Code: Select all
ASM
;
1
KERNEL32
;
LIB
;
2
String
StringExtension
;
heyho.chm
;
HeyHo, Long (a)
String | StdCall
;
heyho_Init
InitFunction | StdCall
;
Code: Select all
; MessageRequester("",HeyHo(1))
MOV eax,[_PB_StringBasePosition]
PUSH eax
PUSH eax
PUSH dword [_PB_StringBasePosition]
PUSH dword 1
CALL PB_HeyHo
INC dword [_PB_StringBasePosition]
PUSH dword _S1
MOV edx,[PB_StringBase]
ADD [esp+4],edx
CALL _PB_MessageRequester@8
POP dword [_PB_StringBasePosition]
Code: Select all
; XIncludeFile("Srod_String_Bug_1.pb")
; ProcedureDLL.s HeyHo(a)
macro MP0{
_Procedure0:
PS0=8
XOR eax,eax
PUSH eax
; Protected a$
; a$=Str(a)
MOV eax,[_PB_StringBasePosition]
PUSH eax
PUSH eax
PUSH dword [esp+PS0+8]
CALL _PB_Str@8
LEA ecx,[esp+4]
POP edx
CALL SYS_AllocateString
; ProcedureReturn a$
MOV edx,dword [esp]
PUSH dword [_PB_StringBasePosition]
CALL _SYS_CopyString@0
POP eax
ADD eax,[PB_StringBase]
JMP _EndProcedure1
; EndProcedure
MOV eax,[_PB_StringBasePosition]
ADD eax,[PB_StringBase]
MOV byte [eax],0
_EndProcedure1:
PUSH dword [esp]
CALL _SYS_FreeString@4
ADD esp,4
RET 4
}
;
; MessageRequester("",HeyHo(1))
MOV eax,[_PB_StringBasePosition]
PUSH eax
PUSH eax
PUSH dword 1
CALL _Procedure0
MOV edx,[esp]
MOV dword [_PB_StringBasePosition],edx
MOV edx,eax
CALL _SYS_CopyString@0
INC dword [_PB_StringBasePosition]
PUSH dword _S1
MOV edx,[PB_StringBase]
ADD [esp+4],edx
CALL _PB_MessageRequester@8
POP dword [_PB_StringBasePosition]
Code: Select all
format MS COFF
Public PB_HeyHo
Extrn _PB_Str@8
Extrn SYS_AllocateString
Extrn _SYS_CopyString@0
Extrn _SYS_FreeString@4
Extrn _PB_StringBasePosition
Extrn PB_StringBase
section '.text' code readable executable
PB_HeyHo:
PS0=8
XOR eax,eax
PUSH eax
; Protected a$
; a$=Str(a)
MOV eax,[_PB_StringBasePosition]
PUSH eax
PUSH eax
PUSH dword [esp+PS0+8]
CALL _PB_Str@8
LEA ecx,[esp+4]
POP edx
CALL SYS_AllocateString
; ProcedureReturn a$
MOV edx,dword [esp]
PUSH dword [_PB_StringBasePosition]
CALL _SYS_CopyString@0
POP eax
ADD eax,[PB_StringBase]
JMP _EndProcedure1
; EndProcedure
MOV eax,[_PB_StringBasePosition]
ADD eax,[PB_StringBase]
MOV byte [eax],0
_EndProcedure1:
PUSH dword [esp]
CALL _SYS_FreeString@4
ADD esp,4
RET 4
Code: Select all
RET X+4
Yes - it works! (Tested with coffIT, manually editing the ASM files and creating the DESC file by hand. Tailbite should easily follow suit.)Fred wrote:The tailbite function should change the 'Ret' line to:
Only when a string is returned. It should work then.Code: Select all
RET X+4
That should be fine Gnozal. I see no reason why that should be a problem.gnozal wrote:2. don't use exported functions in the library
I made some tests, and it crashed.srod wrote:That should be fine Gnozal. I see no reason why that should be a problem.gnozal wrote:2. don't use exported functions in the library
Confirmed. Crashes if one exported string function calls another! Yes, thinking about it -and considering the code posted by Klaus above, it's obvious now.gnozal wrote:I made some tests, and it crashed.srod wrote:That should be fine Gnozal. I see no reason why that should be a problem.gnozal wrote:2. don't use exported functions in the library
I am probably doing something wrong, but imho the '+ 4' fix is only for the exported functions when called from the outside (PB), it's not right if the function is called from the library itself.
But then again, I am no asm guru.
Yes, that's what I did for one test library.srod wrote:Mind you, in this case you'll just have to ensure that no function within a library calls a string function from the same library which is to be exported. Just add a 'dummy' function through which the exported string function operates.