Janilabo

leak

Sep 12th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.47 KB | None | 0 0
  1. { Example based upon the SPS Plugin }
  2. library test;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. {$macro on}
  7. {$define callconv:=
  8.     {$IFDEF WINDOWS}{$IFDEF CPU32}cdecl;{$ELSE}{$ENDIF}{$ENDIF}
  9.     {$IFDEF LINUX}{$IFDEF CPU32}cdecl;{$ELSE}{$ENDIF}{$ENDIF}
  10. }
  11.  
  12. uses
  13.   classes, sysutils, math
  14.   { you can add units after this };
  15.  
  16. var
  17.   OldMemoryManager: TMemoryManager;
  18.   memisset: Boolean = False;
  19.  
  20. type
  21.   TIntegerArray = array of Integer;
  22.  
  23. function Leak: TIntegerArray; callconv
  24. var
  25.   i: Integer;
  26. begin
  27.   SetLength(Result, 1000000);
  28.   for i := 0 to 999999 do
  29.     Result[i] := i;
  30. end;
  31.  
  32. function GetPluginABIVersion: Integer; callconv export;
  33. begin
  34.   Result := 2;
  35. end;
  36.  
  37. procedure SetPluginMemManager(MemMgr : TMemoryManager); callconv export;
  38. begin
  39.   if memisset then
  40.     Exit;
  41.   GetMemoryManager(OldMemoryManager);
  42.   SetMemoryManager(MemMgr);
  43.   memisset := True;
  44. end;
  45.  
  46. procedure OnDetach; callconv export;
  47. begin
  48.   SetMemoryManager(OldMemoryManager);
  49. end;
  50.  
  51. function GetFunctionCount(): Integer; callconv export;
  52. begin
  53.   Result := 1;
  54. end;
  55.  
  56. function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; callconv export;
  57. begin
  58.   case x of
  59.     0:
  60.     begin
  61.       ProcAddr := @Leak;
  62.       StrPCopy(ProcDef, 'function Leak: TIntegerArray;');
  63.     end;
  64.   else
  65.     x := -1;
  66.   end;
  67.   Result := x;
  68. end;
  69.  
  70. exports GetPluginABIVersion;
  71. exports SetPluginMemManager;
  72. exports GetFunctionCount;
  73. exports GetFunctionInfo;
  74. exports OnDetach;
  75.  
  76. begin
  77. end.
Advertisement
Add Comment
Please, Sign In to add comment