1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
with Ada.Text_IO; use Ada.Text_IO;
with GNATCOLL.Scripts; use GNATCOLL.Scripts;
with GNATCOLL.Scripts.Python; use GNATCOLL.Scripts.Python;
with GNATCOLL.Traces; use GNATCOLL.Traces;
with TestConsole; use TestConsole;
with Support; use Support;
procedure Leaks is
procedure MyClass_Handler
(Data : in out Callback_Data'Class; Command : String);
procedure Cache_Handler
(Data : in out Callback_Data'Class; Command : String);
Class_MyClass, Class_Cache : Class_Type;
procedure MyClass_Handler
(Data : in out Callback_Data'Class; Command : String)
is
CI : Class_Instance;
begin
if Command = Constructor_Method then
Put_Line ("MyClass.__init__");
Flush;
elsif Command = Destructor_Method then
Put_Line ("MyClass.__del__");
Flush;
elsif Command = "get" then
CI := New_Instance (Get_Script (Data), Class_MyClass);
Set_Return_Value (Data, CI);
end if;
end MyClass_Handler;
procedure Cache_Handler
(Data : in out Callback_Data'Class; Command : String)
is
CI : Class_Instance;
Tmp : Cache_Data_Access;
begin
if Command = Constructor_Method then
raise Program_Error;
elsif Command = Destructor_Method then
Put_Line ("Cache.__del__");
Flush;
elsif Command = "value" then
CI := Nth_Arg (Data, 1);
Tmp := Get_Data (CI);
if Tmp /= null then
Set_Return_Value (Data, Tmp.Data);
else
Set_Return_Value (Data, -1);
end if;
elsif Command = "get" then
Tmp := Lookup;
CI := Get (Tmp.Inst.all, Get_Script (Data));
if CI = No_Class_Instance then
CI := New_Instance (Get_Script (Data), Class_Cache);
Set_Data (CI, Tmp);
end if;
Set_Return_Value (Data, CI);
elsif Command = "destroy" then
Tmp := Lookup;
Destroy (Tmp);
end if;
end Cache_Handler;
Repo : Scripts_Repository := new Scripts_Repository_Record;
Console : aliased Test_Console;
Errors : Boolean;
begin
GNATCOLL.Traces.Parse_Config_File;
-- Set_Active (Create ("SCRIPTS"), True);
-- Set_Active (Create ("PYTHON"), True);
Register_Python_Scripting (Repo, "GPS");
Set_Default_Console
(Lookup_Scripting_Language (Repo, "python"), Console'Unchecked_Access);
Class_MyClass := New_Class (Repo, "MyClass");
Register_Command
(Repo, Constructor_Method, Class => Class_MyClass,
Handler => MyClass_Handler'Unrestricted_Access);
Register_Command
(Repo, Destructor_Method, Class => Class_MyClass,
Handler => MyClass_Handler'Unrestricted_Access);
Register_Command
(Repo, "get", Class => Class_MyClass, Static_Method => True,
Handler => MyClass_Handler'Unrestricted_Access);
Class_Cache := New_Class (Repo, "Cache");
Register_Command
(Repo, Constructor_Method, Class => Class_Cache,
Handler => Cache_Handler'Unrestricted_Access);
Register_Command
(Repo, Destructor_Method, Class => Class_Cache,
Handler => Cache_Handler'Unrestricted_Access);
Register_Command
(Repo, "get", Class => Class_Cache, Static_Method => True,
Handler => Cache_Handler'Unrestricted_Access);
Register_Command
(Repo, "value", Class => Class_Cache,
Handler => Cache_Handler'Unrestricted_Access);
Register_Command
(Repo, "destroy", Class => Class_Cache,
Handler => Cache_Handler'Unrestricted_Access);
Execute_File
(Script => Lookup_Scripting_Language (Repo, "python"),
Filename => "test.py",
Show_Command => True,
Errors => Errors);
Free (Console);
Destroy (Repo);
end Leaks;
|