Working on TZCollection.Error ASM code

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Working on TZCollection.Error ASM code

Post by gto »

Hello!

As I'm seeing these days, people have some problems with the assembly code in TZCollection.Error, which raises an error at the calling address.

ASM code in a multi-platform component isn't the best thing in the world, so I've did some research to find how eliminate it, or at least if it's possible to do that.

As I said, I think that this code just return a pointer for some address, so the exception can be raised at the right point. The TZCollection object inherits these procedure from VCL TList. The following is defined under classes.pas (delphi7):

Code: Select all

class procedure TList.Error(const Msg: string; Data: Integer);

  function ReturnAddr: Pointer;
  asm
          MOV     EAX,[EBP+4]
  end;

begin
  raise EListError.CreateFmt(Msg, [Data]) at ReturnAddr;
end;

Yes, exactly the same code. And as TCollection in VCL inherits from TList, it was just copied.

Then, we think: There's no special classes.pas in delphi7 for CLX, and I don't have any kylix at hand. Then I moved to Lazarus. The closest I can take is:

TList.Error is now renamed to TFPList.Error, at the file /objpas/classes/lists.inc, and implemented as follows:

Code: Select all

class procedure TFPList.Error(const Msg: string; Data: PtrInt);
begin
  Raise EListError.CreateFmt(Msg,[Data]) at get_caller_addr(get_frame);
end;
Yep, no ASM, but two functions instead. I'm close, but I cannot find where these functions are implemented!!

I just found their documentation:

http://www.freepascal.org/docs-html/rtl ... _addr.html
http://www.freepascal.org/docs-html/rtl ... frame.html

When I looked at it, it says: "Source position: systemh.inc line 700", but systemh.inc is just a file that include other files, depending on the platform as I can imagine.

Anyone can help me in my "quest"?
Besides, google out there, I've found an article about porting ZeosLib to FPC64, but it's in russian! I've tried with google translator, but cannot got the right point. Anyone that can read russian, please?

Here's the article:
http://freepascal.ru/forum/viewtopic.php?f=6&t=3284

If it's done in lazarus, we can take it as basis and rework it in Zeos, then make it more compatible ;)
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Bad luck gto...

I had a look where the lazarus functions are defined.

See fpc/source/rtl/i386/i386.inc (Or other files for other platforms)

Code: Select all

function get_caller_addr(framebp:pointer):pointer;nostackframe;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
asm
{$ifndef REGCALL}
        movl    framebp,%eax
{$endif}
        orl     %eax,%eax
        jz      .Lg_a_null
        movl    4(%eax),%eax
.Lg_a_null:
end ['EAX'];


{$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
function get_caller_frame(framebp:pointer):pointer;nostackframe;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
asm
{$ifndef REGCALL}
        movl    framebp,%eax
{$endif}
        orl     %eax,%eax
        jz      .Lgnf_null
        movl    (%eax),%eax
.Lgnf_null:
end ['EAX'];
Seems like you really need this kind of tricks.
BUT we can say : if Delphi, let Delphi handle it (or keep it like it is now). If FPC -> use the fpc way, I think. That way it's fpc who takes care of the environment/processor specific way of handling this.

Mark
Image
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post by gto »

BUT we can say : if Delphi, let Delphi handle it (or keep it like it is now). If FPC -> use the fpc way, I think. That way it's fpc who takes care of the environment/processor specific way of handling this.
Hum!
Good point!

Anyone more?
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post by gto »

Well, here goes the patch.

I don't have lazarus here, then I ask someone to test it. But should be OK.

Code: Select all

Index: ZCollections.pas
===================================================================
--- ZCollections.pas	(revision 382)
+++ ZCollections.pas	(working copy)
@@ -270,13 +270,19 @@
 }
 class procedure TZCollection.Error(const Msg: string; Data: Integer);
 
+{$IFNDEF FPC}
   function ReturnAddr: Pointer;
   asm
           MOV     EAX,[EBP+4]
   end;
+{$ENDIF}
 
 begin
+  {$IFDEF FPC}
+  raise EListError.CreateFmt(Msg,[Data]) at get_caller_addr(get_frame);
+  {$ELSE}
   raise EListError.CreateFmt(Msg, [Data]) at ReturnAddr;
+  {$ENDIF FPC}
 end;
 
 {**
You do not have the required permissions to view the files attached to this post.
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Patch applied. SVN rev. 383 (Testing Branch).
Post Reply