Browse Source

pastojs: fixed calling conventions

git-svn-id: trunk@43147 -
Mattias Gaertner 5 years ago
parent
commit
ff90306588
1 changed files with 29 additions and 25 deletions
  1. 29 25
      packages/pastojs/src/pas2jslibcompiler.pp

+ 29 - 25
packages/pastojs/src/pas2jslibcompiler.pp

@@ -18,6 +18,10 @@ unit pas2jslibcompiler;
 {$mode objfpc}
 {$H+}
 
+{$IFDEF darwin}
+{$DEFINE UseCDecl}
+{$ENDIF}
+
 interface
 
 uses
@@ -34,15 +38,15 @@ Const
 Type
   PDirectoryCache = Pointer;
 
-  TLibLogCallBack = Procedure (Data : Pointer; Msg : PAnsiChar; MsgLen : Integer); stdcall;
+  TLibLogCallBack = Procedure (Data : Pointer; Msg : PAnsiChar; MsgLen : Integer); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
   TWriteJSCallBack = Procedure (Data : Pointer;
     AFileName: PAnsiChar; AFileNameLen : Integer;
-    AFileData : PAnsiChar; AFileDataLen: Int32); stdcall;
+    AFileData : PAnsiChar; AFileDataLen: Int32); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
   TReadPasCallBack = Procedure (Data : Pointer;
     AFileName: PAnsiChar; AFileNameLen : Integer;
-    AFileData : PAnsiChar; Var AFileDataLen: Int32); stdcall;
+    AFileData : PAnsiChar; Var AFileDataLen: Int32); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
   TReadDirCallBack = Function (Data : Pointer;
-    P : PDirectoryCache; ADirPath: PAnsiChar): boolean; stdcall;
+    P : PDirectoryCache; ADirPath: PAnsiChar): boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
   { TLibraryPas2JSCompiler }
 
@@ -68,7 +72,7 @@ Type
   Public
     Constructor Create; override;
     Procedure DoLibraryLog(Sender : TObject; Const Msg : String);
-    Function LibraryRun(ACompilerExe, AWorkingDir : PAnsiChar; CommandLine : PPAnsiChar; DoReset : Boolean) :Boolean; stdcall;
+    Function LibraryRun(ACompilerExe, AWorkingDir : PAnsiChar; CommandLine : PPAnsiChar; DoReset : Boolean) :Boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
     Property LastError : String Read FLastError Write FLastError;
     Property LastErrorClass : String Read FLastErrorClass Write FLastErrorClass;
     Property OnLibLogCallBack : TLibLogCallBack Read FOnLibLogCallBack Write FOnLibLogCallBack;
@@ -85,16 +89,16 @@ Type
 Type
   PPas2JSCompiler = Pointer;
 
-Procedure SetPas2JSWriteJSCallBack(P : PPas2JSCompiler; ACallBack : TWriteJSCallBack; CallBackData : Pointer); stdcall;
-Procedure SetPas2JSCompilerLogCallBack(P : PPas2JSCompiler; ACallBack : TLibLogCallBack; CallBackData : Pointer); stdcall;
-Procedure SetPas2JSReadPasCallBack(P : PPas2JSCompiler; ACallBack : TReadPasCallBack; CallBackData : Pointer; ABufferSize : Cardinal); stdcall;
-Procedure SetPas2JSReadDirCallBack(P : PPas2JSCompiler; ACallBack : TReadDirCallBack; CallBackData : Pointer); stdcall;
+Procedure SetPas2JSWriteJSCallBack(P : PPas2JSCompiler; ACallBack : TWriteJSCallBack; CallBackData : Pointer); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+Procedure SetPas2JSCompilerLogCallBack(P : PPas2JSCompiler; ACallBack : TLibLogCallBack; CallBackData : Pointer); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+Procedure SetPas2JSReadPasCallBack(P : PPas2JSCompiler; ACallBack : TReadPasCallBack; CallBackData : Pointer; ABufferSize : Cardinal); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+Procedure SetPas2JSReadDirCallBack(P : PPas2JSCompiler; ACallBack : TReadDirCallBack; CallBackData : Pointer); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 Procedure AddPas2JSDirectoryEntry(P: PDirectoryCache; AFilename: PAnsiChar;
-  AAge: TPas2jsFileAgeTime; AAttr: TPas2jsFileAttr; ASize: TPas2jsFileSize); stdcall;
-Function RunPas2JSCompiler(P : PPas2JSCompiler; ACompilerExe, AWorkingDir : PAnsiChar; CommandLine : PPAnsiChar; DoReset : Boolean) : Boolean; stdcall;
-Procedure FreePas2JSCompiler(P : PPas2JSCompiler); stdcall;
-Function GetPas2JSCompiler : PPas2JSCompiler; stdcall;
-Procedure GetPas2JSCompilerLastError(P : PPas2JSCompiler; AError : PAnsiChar; Var AErrorLength : Longint; AErrorClass : PAnsiChar; Var AErrorClassLength : Longint); stdcall;
+  AAge: TPas2jsFileAgeTime; AAttr: TPas2jsFileAttr; ASize: TPas2jsFileSize); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+Function RunPas2JSCompiler(P : PPas2JSCompiler; ACompilerExe, AWorkingDir : PAnsiChar; CommandLine : PPAnsiChar; DoReset : Boolean) : Boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+Procedure FreePas2JSCompiler(P : PPas2JSCompiler); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+Function GetPas2JSCompiler : PPas2JSCompiler; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+Procedure GetPas2JSCompilerLastError(P : PPas2JSCompiler; AError : PAnsiChar; Var AErrorLength : Longint; AErrorClass : PAnsiChar; Var AErrorClassLength : Longint); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 implementation
 
@@ -117,7 +121,7 @@ begin
   Result:=Assigned(OnWriteJSCallBack);
   if Result then
     try
-      Src:=aWriter.AsAnsistring;
+      Src:=aWriter.{$IF FPC_FULLVERSION>30300}AsString{$ELSE}AsAnsistring{$ENDIF};
       OnWriteJSCallBack(OnWriteJSData,PAnsiChar(DestFileName),Length(DestFileName),PAnsiChar(Src),Length(Src));
     except
       Result:=False;
@@ -197,7 +201,7 @@ begin
 end;
 
 function TLibraryPas2JSCompiler.LibraryRun(ACompilerExe, AWorkingDir: PAnsiChar;
-  CommandLine: PPAnsiChar; DoReset: Boolean): Boolean; stdcall;
+  CommandLine: PPAnsiChar; DoReset: Boolean): Boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 Var
   C,W : AnsiString;
@@ -241,7 +245,7 @@ end;
   ---------------------------------------------------------------------}
 
 procedure SetPas2JSWriteJSCallBack(P: PPas2JSCompiler;
-  ACallBack: TWriteJSCallBack; CallBackData: Pointer); stdcall;
+  ACallBack: TWriteJSCallBack; CallBackData: Pointer); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 begin
   TLibraryPas2JSCompiler(P).OnWriteJSCallBack:=ACallBack;
@@ -249,7 +253,7 @@ begin
 end;
 
 procedure SetPas2JSCompilerLogCallBack(P: PPas2JSCompiler;
-  ACallBack: TLibLogCallBack; CallBackData: Pointer); stdcall;
+  ACallBack: TLibLogCallBack; CallBackData: Pointer); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 begin
   TLibraryPas2JSCompiler(P).OnLibLogCallBack:=ACallBack;
@@ -258,7 +262,7 @@ end;
 
 procedure SetPas2JSReadPasCallBack(P: PPas2JSCompiler;
   ACallBack: TReadPasCallBack; CallBackData: Pointer; ABufferSize: Cardinal);
-  stdcall;
+  {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 begin
   TLibraryPas2JSCompiler(P).OnReadPasData:=CallBackData;
@@ -269,7 +273,7 @@ begin
 end;
 
 procedure SetPas2JSReadDirCallBack(P: PPas2JSCompiler;
-  ACallBack: TReadDirCallBack; CallBackData: Pointer); stdcall;
+  ACallBack: TReadDirCallBack; CallBackData: Pointer); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 begin
   TLibraryPas2JSCompiler(P).OnReadDir:=ACallBack;
   TLibraryPas2JSCompiler(P).OnReadDirData:=CallBackData;
@@ -277,26 +281,26 @@ end;
 
 procedure AddPas2JSDirectoryEntry(P: PDirectoryCache; AFilename: PAnsiChar;
   AAge: TPas2jsFileAgeTime; AAttr: TPas2jsFileAttr; ASize: TPas2jsFileSize);
-  stdcall;
+  {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 begin
   TPas2jsCachedDirectory(P).Add(AFilename,AAge,AAttr,ASize);
 end;
 
 function RunPas2JSCompiler(P: PPas2JSCompiler; ACompilerExe,
   AWorkingDir: PAnsiChar; CommandLine: PPAnsiChar; DoReset: Boolean): Boolean;
-  stdcall;
+  {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 begin
   Result:=TLibraryPas2JSCompiler(P).LibraryRun(ACompilerExe,AWorkingDir,CommandLine,DoReset)
 end;
 
-procedure FreePas2JSCompiler(P: PPas2JSCompiler); stdcall;
+procedure FreePas2JSCompiler(P: PPas2JSCompiler); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 begin
   TLibraryPas2JSCompiler(P).Free;
 end;
 
-function GetPas2JSCompiler: PPas2JSCompiler; stdcall;
+function GetPas2JSCompiler: PPas2JSCompiler; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 begin
   Result:=TLibraryPas2JSCompiler.Create;
@@ -304,7 +308,7 @@ end;
 
 procedure GetPas2JSCompilerLastError(P: PPas2JSCompiler; AError: PAnsiChar;
   Var AErrorLength: Longint; AErrorClass: PAnsiChar;
-  Var AErrorClassLength: Longint); stdcall;
+  Var AErrorClassLength: Longint); {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
 begin
   TLibraryPas2JSCompiler(P).GetLastError(AError,AErrorLength,AErrorClass,AErrorClassLength);