It is currently Fri Jul 28, 2017 2:00 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Tue Mar 25, 2008 4:03 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 12985
Location: France
Could you post the code generated by TailBite ?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Mar 25, 2008 4:13 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10278
Location: Beyond the pale...
Here's the PB source :

Code:
ProcedureDLL.s HeyHo(a)
  Protected a$
  a$=Str(a)
  ProcedureReturn a$
EndProcedure


Here's the PB generated ASM for the HeyHo function :

Code:
; :
; 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
}


and here's the tailbite generated source for the HeyHo function:

Code:
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


Here's the desc file :

Code:
ASM
;
1
KERNEL32
;
LIB
;
2
String
StringExtension
;
heyho.chm
;
HeyHo, Long (a)
String | StdCall
;
heyho_Init
InitFunction | StdCall
;

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Apr 14, 2008 10:34 pm 
Offline
Addict
Addict

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1142
Location: Germany
I think its how PB calls the TailBiten function.

Here the commented ASM output when using the TailBiten function from PB:
Code:
; 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]


Here the commented ASM output using the lib as includefile:
Code:
; 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]


and the function itself (TailBiten with PB4.20B4) :
Code:
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


Fact is : the procedure is in both cases the same, only the calling is different.
Since i am not an ASM guru like you (Fred and Freak) it would be nice if you could help get TailBite running again.

Thanks in advance.
Klaus


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 6:49 am 
Offline
Addict
Addict
User avatar

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3099
This bug is still preventing TailBite from functioning properly with PureBasic 4.20. Is this a PureBasic bug or a TailBite bug?

http://www.purebasic.fr/english/viewtopic.php?t=32585

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 12:04 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 12985
Location: France
It's definitely a tailbite bug, how could it be a PB one ?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 12:15 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
<Asks humbly> Some hint on how to fix this tailbite issue would be great !
I am no asm guru myself.

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 12:22 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 12985
Location: France
The tailbite function should change the 'Ret' line to:

Code:
RET    X+4


Only when a string is returned. It should work then.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 1:54 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10278
Location: Beyond the pale...
Fred wrote:
The tailbite function should change the 'Ret' line to:

Code:
RET    X+4


Only when a string is returned. It should work then.


Yes - it works! :) (Tested with coffIT, manually editing the ASM files and creating the DESC file by hand. Tailbite should easily follow suit.)

Thanks Fred. Looking at it, the damn solution was obvious!!!

Can I ask why PB passes an extra parameter when calling compiled user lib functions?

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 2:27 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
It seems to work yes (I only made a few tests).
1. only add 'RET X + 4' to the exported functions, not the private functions
2. don't use exported functions in the library

I have just updated the custom Tailbite for jaPBe V3 : http://freenet-homepage.de/gnozal/TailBite.zip
Source included, search for 'PB4.20 fix'. It seems to work.
Sorry, it's not the ABBKlaus source, but I am more confortable with the old ElChoni source :oops:

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Last edited by gnozal on Tue May 27, 2008 2:44 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 2:30 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10278
Location: Beyond the pale...
gnozal wrote:
2. don't use exported functions in the library


That should be fine Gnozal. I see no reason why that should be a problem.

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 2:47 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
srod wrote:
gnozal wrote:
2. don't use exported functions in the library

That should be fine Gnozal. I see no reason why that should be a problem.
I made some tests, and it crashed.
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.

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 2:52 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10278
Location: Beyond the pale...
Right, I'll have a crack at it! :)

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 3:03 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10278
Location: Beyond the pale...
gnozal wrote:
srod wrote:
gnozal wrote:
2. don't use exported functions in the library

That should be fine Gnozal. I see no reason why that should be a problem.
I made some tests, and it crashed.
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.


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.

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.

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 3:14 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
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.
Yes, that's what I did for one test library.
I will check all my libs for this before recompiling them with PB4.20 final.

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2008 11:49 pm 
Offline
Addict
Addict

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1142
Location: Germany
Thanks Fred, i´m going to donate now :D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye