@@ -180,7 +180,7 @@ procedure GetCodeMem(var ptr: PByte; size: integer);
180180    page:=VirtualAlloc(nil , PageSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
181181	{ $ELSE} 
182182    // page := GetMem(PageSize);
183-     page := mmap($10000000 , PageSize, PROT_NONE, MAP_PRIVATE or  MAP_ANON, -1 , 0 );
183+     page := mmap(Pointer( $10000000 ) , PageSize, PROT_NONE, MAP_PRIVATE or  MAP_ANON, -1 , 0 );
184184    mprotect(page, PageSize, PROT_READ or  PROT_WRITE or  PROT_EXEC);
185185	{ $ENDIF} 
186186    page^.next:=CodeMemPages;
@@ -505,15 +505,6 @@ function  GetCallBack( self: TObject; method: Pointer;
505505function   GetCallBack ( self: TObject; method: Pointer;
506506                       argnum: Integer; calltype: tcalltype): Pointer;
507507const 
508- //  Short handling of stdcalls:
509- S1: array  [0 ..14 ] of  byte = (
510- $5A,            // 00  pop  edx  // pop return address
511- $B8,0 ,0 ,0 ,0 ,    // 01  mov  eax, self
512- $50 ,            // 06  push eax
513- $52 ,            // 07  push edx // now push return address
514- //  call the real callback
515- $B8,0 ,0 ,0 ,0 ,    // 08  mov  eax, Method
516- $FF,$E0);       // 13  jmp  eax
517508
518509// Handling for ctCDECL:
519510C1: array  [0 ..5 ] of  byte = (
@@ -530,7 +521,7 @@ function  GetCallBack( self: TObject; method: Pointer;
530521//   end;
531522
532523//  self parameter
533- C3: array  [0 ..17 ] of  byte = (
524+ C3: array  [0 ..19 ] of  byte = (
534525$B8,0 ,0 ,0 ,0 ,    // 06+4*s  mov eax, self
535526$50 ,            // 11+4*s  push eax
536527//  call the real callback
@@ -539,35 +530,30 @@ function  GetCallBack( self: TObject; method: Pointer;
539530//  clear stack
540531$83 ,$C4,0 ,      // 20+4*s  add esp, 4+bytes+align
541532$5D,            // 23+4*s  pop  ebp
542- $C3);           // 24+4*s  ret
543- 
544- 
533+ $C2,00 ,00 );           // 24+4*s  ret   [0]
545534
546535var 
547536  bytes: Word;
548537  i: Integer;
549538  P,Q: PByte;
550539  align : integer;
551540begin 
552-   if  calltype = ctSTDCALL then  begin 
553-     GetCodeMem(Q,15 );
554-     P := Q;
555-     move(S1,P^,SizeOf(S1));
556-     Inc(P,2 );
557-     move(self,P^,SizeOf(self));
558-     Inc(P,7 );
559-     move(method,P^,SizeOf(method));
560-     { Inc(P,6); End of proc} 
561-   end  else  begin   { ctCDECL} 
541+ //  On mac FPC ctSTDCALL and ctCDECL are the same
542+     { $IFDEF FPC} 
543+     { $IFDEF MACOS32} 
544+     calltype := ctCDECL;
545+     { $ENDIF} 
546+     { $ENDIF} 
547+ 
562548    bytes := argnum * 4 ;
563- 	align :=  ($10  - (bytes + 4 { self} 4 { address} 4 { push bp} and  $f) and  $f; //  align to $10 for Mac compatibility
549+ 	   align :=  ($10  - (bytes + 4 { self} 4 { address} 4 { push bp} and  $f) and  $f; //  align to $10 for Mac compatibility
564550
565-     GetCodeMem(Q,24 + 4 *argnum);
551+     GetCodeMem(Q,sizeof(c1)+sizeof(c3)+sizeof(c2) *argnum);
566552    P := Q;
567553    move(C1,P^,SizeOf(C1));
568554    Inc(P,SizeOf(C1)-1 );
569555	  p^ := align;
570-     Inc(P);	 
556+     Inc(P);
571557    for  i:=argnum-1  downto  0  do  begin 
572558      move(C2,P^,SizeOf(C2));
573559      Inc(P,2 );
@@ -580,10 +566,19 @@ function  GetCallBack( self: TObject; method: Pointer;
580566    Inc(P,6 );
581567    move(method,P^,SizeOf(method));
582568    Inc(P,8 );
583-     P^ := 4 +bytes+align;
584-     { Inc(P,3); End of proc} 
585-   end ;
586-   result := Q;
569+     if  calltype = ctCDECL then 
570+     begin 
571+        P^ := 4 +bytes+align;
572+     end 
573+     else 
574+     begin 
575+        P^ := { 4+} 
576+        Inc(P,3 );
577+        P^ := bytes;
578+     end ;
579+ 
580+ 
581+     result := Q;
587582end ;
588583{ $ENDIF} 
589584
0 commit comments