2011-12-20 09:32:09 +00:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
-- G N A T C O L L --
|
|
|
|
|
-- --
|
2013-01-08 10:50:34 +00:00
|
|
|
-- Copyright (C) 2003-2013, AdaCore --
|
2011-12-20 09:32:09 +00:00
|
|
|
-- --
|
|
|
|
|
-- This library is free software; you can redistribute it and/or modify it --
|
|
|
|
|
-- under terms of the GNU General Public License as published by the Free --
|
|
|
|
|
-- Software Foundation; either version 3, or (at your option) any later --
|
|
|
|
|
-- version. This library is distributed in the hope that it will be useful, --
|
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
|
|
|
|
|
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
|
|
|
|
|
-- --
|
|
|
|
|
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
|
|
|
|
-- additional permissions described in the GCC Runtime Library Exception, --
|
|
|
|
|
-- version 3.1, as published by the Free Software Foundation. --
|
|
|
|
|
-- --
|
|
|
|
|
-- You should have received a copy of the GNU General Public License and --
|
|
|
|
|
-- a copy of the GCC Runtime Library Exception along with this program; --
|
|
|
|
|
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
|
|
|
|
-- <http://www.gnu.org/licenses/>. --
|
|
|
|
|
-- --
|
|
|
|
|
------------------------------------------------------------------------------
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2011-03-22 14:50:49 +00:00
|
|
|
with Ada.Characters.Handling; use Ada.Characters.Handling;
|
2007-06-11 07:57:59 +00:00
|
|
|
with Ada.Unchecked_Conversion;
|
|
|
|
|
with Ada.Unchecked_Deallocation;
|
|
|
|
|
with Ada.Exceptions; use Ada.Exceptions;
|
|
|
|
|
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
|
|
|
|
with Interfaces.C.Strings; use Interfaces.C, Interfaces.C.Strings;
|
|
|
|
|
with GNAT.IO; use GNAT.IO;
|
|
|
|
|
with GNAT.Strings; use GNAT.Strings;
|
2010-11-18 13:25:46 +00:00
|
|
|
with GNATCOLL.Any_Types.Python;
|
2008-04-17 12:12:00 +00:00
|
|
|
with GNATCOLL.Scripts.Impl; use GNATCOLL.Scripts, GNATCOLL.Scripts.Impl;
|
2010-05-27 14:41:31 +00:00
|
|
|
with GNATCOLL.Traces; use GNATCOLL.Traces;
|
2007-06-11 07:57:59 +00:00
|
|
|
with System; use System;
|
|
|
|
|
|
2008-04-17 12:12:00 +00:00
|
|
|
package body GNATCOLL.Scripts.Python is
|
2010-11-15 14:56:33 +00:00
|
|
|
Me : constant Trace_Handle := Create ("PYTHON");
|
2012-06-19 15:51:12 +00:00
|
|
|
Me_Error : constant Trace_Handle := Create ("PYTHON.ERROR", On);
|
2010-06-03 09:28:56 +00:00
|
|
|
Me_Stack : constant Trace_Handle := Create ("PYTHON.TB", Off);
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Me_Log : constant Trace_Handle := Create ("SCRIPTS.LOG", Off);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2012-06-21 14:40:19 +00:00
|
|
|
Finalized : Boolean := True;
|
|
|
|
|
-- Whether Python has been finalized (or never initialized).
|
|
|
|
|
|
2012-06-19 15:51:12 +00:00
|
|
|
function Ada_Py_Builtin return Interfaces.C.Strings.chars_ptr;
|
|
|
|
|
pragma Import (C, Ada_Py_Builtin, "ada_py_builtin");
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
function Ada_Py_Builtins return Interfaces.C.Strings.chars_ptr;
|
|
|
|
|
pragma Import (C, Ada_Py_Builtins, "ada_py_builtins");
|
2012-06-19 15:51:12 +00:00
|
|
|
|
2012-06-21 15:28:33 +00:00
|
|
|
function Ada_Is_Python3 return Integer;
|
|
|
|
|
pragma Import (C, Ada_Is_Python3, "ada_is_python3");
|
|
|
|
|
|
|
|
|
|
Is_Python3 : constant Boolean := Ada_Is_Python3 = 1;
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Builtin_Name : constant String := Value (Ada_Py_Builtin);
|
|
|
|
|
Builtins_Name : constant String := Value (Ada_Py_Builtins);
|
2012-06-19 15:51:12 +00:00
|
|
|
|
2010-11-16 08:23:37 +00:00
|
|
|
procedure Set_Item (Args : PyObject; T : Integer; Item : PyObject);
|
2011-05-06 20:26:55 +00:00
|
|
|
-- Change the T-th item in Args.
|
|
|
|
|
-- This increases the refcount of Item
|
2010-11-16 08:23:37 +00:00
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
procedure Name_Parameters
|
|
|
|
|
(Data : in out Python_Callback_Data; Params : Param_Array);
|
|
|
|
|
-- Internal version of Name_Parameters
|
|
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
type Property_User_Data_Record is record
|
|
|
|
|
Script : Python_Scripting;
|
|
|
|
|
Prop : Property_Descr_Access;
|
|
|
|
|
end record;
|
|
|
|
|
type Property_User_Data is access all Property_User_Data_Record;
|
|
|
|
|
function Convert is new Ada.Unchecked_Conversion
|
|
|
|
|
(System.Address, Property_User_Data);
|
|
|
|
|
function Convert is new Ada.Unchecked_Conversion
|
|
|
|
|
(Property_User_Data, System.Address);
|
|
|
|
|
-- Subprograms needed to support the user data passed to the Property
|
|
|
|
|
-- setters and getters
|
|
|
|
|
|
|
|
|
|
procedure Run_Callback
|
|
|
|
|
(Script : Python_Scripting;
|
|
|
|
|
Cmd : Module_Command_Function;
|
|
|
|
|
Command : String;
|
|
|
|
|
Data : in out Python_Callback_Data'Class;
|
|
|
|
|
Result : out PyObject);
|
|
|
|
|
-- Return Cmd and pass (Data, Command) parameters to it.
|
|
|
|
|
-- This properly handles returned value, exceptions and python errors.
|
|
|
|
|
-- This also freed the memory used by Data
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
------------------------
|
|
|
|
|
-- Python_Subprograms --
|
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
type Python_Subprogram_Record is new Subprogram_Record with record
|
|
|
|
|
Script : Python_Scripting;
|
|
|
|
|
Subprogram : PyObject;
|
|
|
|
|
end record;
|
|
|
|
|
|
|
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return Boolean;
|
2007-06-11 07:57:59 +00:00
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return String;
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return Any_Type;
|
2010-11-19 16:03:39 +00:00
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return Class_Instance;
|
2007-06-11 07:57:59 +00:00
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean)
|
2007-06-11 07:57:59 +00:00
|
|
|
return GNAT.Strings.String_List;
|
2013-08-06 08:39:42 +00:00
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
|
|
|
|
Args : Callback_Data'Class;
|
|
|
|
|
Error : not null access Boolean) return List_Instance'Class;
|
2007-06-11 07:57:59 +00:00
|
|
|
overriding procedure Free (Subprogram : in out Python_Subprogram_Record);
|
|
|
|
|
overriding function Get_Name
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record) return String;
|
|
|
|
|
overriding function Get_Script
|
|
|
|
|
(Subprogram : Python_Subprogram_Record) return Scripting_Language;
|
|
|
|
|
-- See doc from inherited subprograms
|
|
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
|
-- Python_Callback_Data --
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
procedure Prepare_Value_Key
|
|
|
|
|
(Data : in out Python_Callback_Data'Class;
|
|
|
|
|
Key : PyObject;
|
|
|
|
|
Append : Boolean);
|
|
|
|
|
-- Internal version of Set_Return_Value_Key
|
|
|
|
|
|
|
|
|
|
---------------------------
|
|
|
|
|
-- Python_Class_Instance --
|
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
|
|
type Python_Class_Instance_Record is new Class_Instance_Record with record
|
|
|
|
|
Data : PyObject;
|
|
|
|
|
end record;
|
|
|
|
|
type Python_Class_Instance is access all Python_Class_Instance_Record'Class;
|
|
|
|
|
|
2013-09-02 15:12:08 +00:00
|
|
|
overriding procedure Incref
|
|
|
|
|
(Inst : not null access Python_Class_Instance_Record);
|
|
|
|
|
overriding procedure Decref
|
|
|
|
|
(Inst : not null access Python_Class_Instance_Record);
|
|
|
|
|
overriding function Get_User_Data
|
|
|
|
|
(Inst : not null access Python_Class_Instance_Record)
|
|
|
|
|
return access User_Data_List;
|
2007-06-11 07:57:59 +00:00
|
|
|
overriding function Print_Refcount
|
|
|
|
|
(Instance : access Python_Class_Instance_Record) return String;
|
|
|
|
|
overriding function Is_Subclass
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
2007-06-12 20:03:42 +00:00
|
|
|
Base : String) return Boolean;
|
2010-11-17 16:29:07 +00:00
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : Integer);
|
|
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : Boolean);
|
2012-09-05 07:50:30 +00:00
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : Float);
|
2010-11-17 16:29:07 +00:00
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : String);
|
2010-12-04 09:32:07 +00:00
|
|
|
overriding function Get_Method
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String) return Subprogram_Type;
|
2007-06-11 07:57:59 +00:00
|
|
|
-- See doc from inherited subprogram
|
|
|
|
|
|
|
|
|
|
function Get_CI
|
|
|
|
|
(Script : Python_Scripting; Object : PyObject) return Class_Instance;
|
2013-09-02 15:12:08 +00:00
|
|
|
-- Wraps the python object into a Class_Instance.
|
|
|
|
|
-- The refcount of the object is increased by one, owned by Class_Instance.
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Handler_Data --
|
|
|
|
|
------------------
|
|
|
|
|
|
2010-11-17 12:06:29 +00:00
|
|
|
type Handler_Data is record
|
|
|
|
|
Script : Python_Scripting;
|
|
|
|
|
Cmd : Command_Descr_Access;
|
2007-06-11 07:57:59 +00:00
|
|
|
end record;
|
|
|
|
|
type Handler_Data_Access is access Handler_Data;
|
2010-11-17 12:06:29 +00:00
|
|
|
-- Information stored with each python function to call the right Ada
|
2007-06-11 07:57:59 +00:00
|
|
|
-- subprogram.
|
|
|
|
|
|
2010-05-27 14:41:31 +00:00
|
|
|
function Command_Name (Data : Handler_Data) return String;
|
|
|
|
|
-- Return the qualified name of the command "command" or "class.command"
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
function Convert is new Ada.Unchecked_Conversion
|
|
|
|
|
(System.Address, Handler_Data_Access);
|
|
|
|
|
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
|
|
|
|
|
(Handler_Data, Handler_Data_Access);
|
|
|
|
|
|
|
|
|
|
procedure Destroy_Handler_Data (Handler : System.Address);
|
|
|
|
|
pragma Convention (C, Destroy_Handler_Data);
|
2010-12-11 10:30:33 +00:00
|
|
|
-- Called when the python object associated with Handler is destroyed
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2013-09-02 15:12:08 +00:00
|
|
|
-------------------------------
|
|
|
|
|
-- Class_Instance properties --
|
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
|
|
type PyObject_Data_Record is record
|
|
|
|
|
Props : aliased User_Data_List;
|
|
|
|
|
end record;
|
|
|
|
|
type PyObject_Data is access all PyObject_Data_Record;
|
|
|
|
|
-- Data stored in each PyObject representing a class instance, as a
|
|
|
|
|
-- __gps_data property.
|
|
|
|
|
|
|
|
|
|
function Convert is new Ada.Unchecked_Conversion
|
|
|
|
|
(System.Address, PyObject_Data);
|
|
|
|
|
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
|
|
|
|
|
(PyObject_Data_Record, PyObject_Data);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
procedure On_PyObject_Data_Destroy (Data : System.Address);
|
|
|
|
|
pragma Convention (C, On_PyObject_Data_Destroy);
|
2013-09-02 15:12:08 +00:00
|
|
|
-- Called when the __gps_data property is destroyed.
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Interpreter_View --
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
function First_Level (Self, Args, Kw : PyObject) return PyObject;
|
|
|
|
|
pragma Convention (C, First_Level);
|
|
|
|
|
-- First level handler for all functions exported to python. This function
|
|
|
|
|
-- is in charge of dispatching to the actual Ada subprogram.
|
|
|
|
|
|
|
|
|
|
procedure Setup_Return_Value (Data : in out Python_Callback_Data'Class);
|
|
|
|
|
-- Mark Data as containing a return value, and free the previous value if
|
|
|
|
|
-- there is any
|
|
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
function First_Level_Getter
|
|
|
|
|
(Obj : PyObject; Closure : System.Address) return PyObject;
|
|
|
|
|
pragma Convention (C, First_Level_Getter);
|
|
|
|
|
-- Handles getters for descriptor objects
|
|
|
|
|
|
|
|
|
|
function First_Level_Setter
|
|
|
|
|
(Obj, Value : PyObject; Closure : System.Address) return Integer;
|
|
|
|
|
pragma Convention (C, First_Level_Setter);
|
|
|
|
|
-- Handles setters for descriptor objects
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
procedure Trace_Dump (Name : String; Obj : PyObject);
|
|
|
|
|
pragma Unreferenced (Trace_Dump);
|
|
|
|
|
-- Print debug info for Obj
|
|
|
|
|
|
|
|
|
|
function Refcount_Msg
|
|
|
|
|
(Obj : PyObject) return Interfaces.C.Strings.chars_ptr;
|
|
|
|
|
pragma Import (C, Refcount_Msg, "ada_py_refcount_msg");
|
|
|
|
|
-- Print a debug message to trace the refcounting on Obj
|
|
|
|
|
|
|
|
|
|
function Run_Command
|
|
|
|
|
(Script : access Python_Scripting_Record'Class;
|
|
|
|
|
Command : String;
|
|
|
|
|
Console : Virtual_Console := null;
|
|
|
|
|
Show_Command : Boolean := False;
|
|
|
|
|
Hide_Output : Boolean := False;
|
|
|
|
|
Hide_Exceptions : Boolean := False;
|
|
|
|
|
Errors : access Boolean) return String;
|
|
|
|
|
-- Same as above, but also return the output of the command
|
|
|
|
|
|
2007-06-12 20:03:42 +00:00
|
|
|
procedure Python_Global_Command_Handler
|
|
|
|
|
(Data : in out Callback_Data'Class; Command : String);
|
|
|
|
|
-- Handles all commands pre-defined in this module
|
|
|
|
|
|
2012-06-20 20:42:11 +00:00
|
|
|
procedure Log_Python_Exception;
|
|
|
|
|
-- Log the current exception to a trace_handle
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
------------------------
|
|
|
|
|
-- Internals Nth_Arg --
|
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return String;
|
2010-12-11 10:30:40 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return Unbounded_String;
|
2007-09-04 14:01:06 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return Integer;
|
2012-09-05 07:50:30 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return Float;
|
2007-09-04 14:01:06 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return Boolean;
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return Subprogram_Type;
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Class : Class_Type;
|
|
|
|
|
Allow_Null : Boolean; Success : access Boolean)
|
|
|
|
|
return Class_Instance;
|
2007-09-04 14:53:48 +00:00
|
|
|
-- These functions are called by the overriden Nth_Arg functions. They try
|
|
|
|
|
-- to return the parameter at the location N. If no parameter is found,
|
|
|
|
|
-- Success is false, true otherwise. It's the responsibility of the
|
|
|
|
|
-- enclosing Nth_Arg to either raise a No_Such_Parameter exception or to
|
|
|
|
|
-- return a default value.
|
2007-09-04 14:01:06 +00:00
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
--------------------
|
|
|
|
|
-- Block_Commands --
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
procedure Block_Commands
|
|
|
|
|
(Script : access Python_Scripting_Record; Block : Boolean) is
|
|
|
|
|
begin
|
|
|
|
|
Script.Blocked := Block;
|
|
|
|
|
end Block_Commands;
|
|
|
|
|
|
|
|
|
|
----------------
|
|
|
|
|
-- Trace_Dump --
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
procedure Trace_Dump (Name : String; Obj : PyObject) is
|
2011-05-06 20:26:55 +00:00
|
|
|
S : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2011-05-06 10:15:31 +00:00
|
|
|
if Obj = null then
|
2007-06-11 07:57:59 +00:00
|
|
|
Put_Line (Name & "=<null>");
|
|
|
|
|
else
|
2011-05-06 20:26:55 +00:00
|
|
|
-- Special handling here, since for a string PyObject_Str returns
|
|
|
|
|
-- the string itself, thus impacting the refcounting
|
|
|
|
|
S := PyObject_Str (Obj);
|
|
|
|
|
if S = Obj then
|
|
|
|
|
Py_DECREF (Obj); -- Preserve original refcount
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Put_Line (Name & "="""
|
2011-05-06 20:26:55 +00:00
|
|
|
& PyString_AsString (S) & '"' & ASCII.LF
|
2011-05-06 10:15:31 +00:00
|
|
|
& " refcount=" & Value (Refcount_Msg (Obj)));
|
2011-05-06 20:26:55 +00:00
|
|
|
|
|
|
|
|
if S /= Obj then
|
|
|
|
|
Py_DECREF (S);
|
|
|
|
|
end if;
|
2011-05-06 10:15:31 +00:00
|
|
|
-- Other possible debug info:
|
|
|
|
|
-- repr = PyString_AsString (PyObject_Repr (Obj))
|
|
|
|
|
-- methods = PyString_AsString (PyObject_Str (PyObject_Dir (Obj)))
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end Trace_Dump;
|
|
|
|
|
|
2010-05-27 14:41:31 +00:00
|
|
|
------------------
|
|
|
|
|
-- Command_Name --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
function Command_Name (Data : Handler_Data) return String is
|
|
|
|
|
begin
|
2010-11-17 12:06:29 +00:00
|
|
|
if Data.Cmd.Class = No_Class then
|
|
|
|
|
return Data.Cmd.Command;
|
2010-05-27 14:41:31 +00:00
|
|
|
else
|
2010-11-17 12:06:29 +00:00
|
|
|
return Data.Cmd.Class.Name.all & "." & Data.Cmd.Command;
|
2010-05-27 14:41:31 +00:00
|
|
|
end if;
|
|
|
|
|
end Command_Name;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-------------
|
|
|
|
|
-- Destroy --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
procedure Destroy (Script : access Python_Scripting_Record) is
|
|
|
|
|
begin
|
2012-06-21 14:40:19 +00:00
|
|
|
if not Finalized then
|
2010-11-24 13:39:54 +00:00
|
|
|
Trace (Me, "Finalizing python");
|
2012-06-21 14:40:19 +00:00
|
|
|
Finalized := True;
|
2009-12-01 11:43:59 +00:00
|
|
|
Set_Default_Console (Script, null);
|
|
|
|
|
Free (Script.Buffer);
|
|
|
|
|
Py_Finalize;
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Destroy;
|
|
|
|
|
|
* aliases_module.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* build_command_manager.adb:
Start replacing command line handling with use of GNATCOLL.Command_Line.
* builder_module.adb:
Do not use a GNAT.OS_Lib.Argument_List to represent a command line.
* commands-builder.adb:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* commands-builder.ads:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* code_peer-module-bridge.adb:
(Add_Audit_Record): Adapt to new profile of Launch_Process.
(Inspection): Ditto.
(Review_Message): Ditto.
* code_peer-shell_commands.adb:
(Build_Target): Adapt to new profile of Execute_GPS_Shell_Command.
(Build_Target_Execute): Ditto.
(Get_Build_Mode): Ditto.
(Set_Build_Mode): Ditto.
* codefix_module.adb:
(Compilation_Finished_Cb): Adapt to new profile of Execute_GPS_Shell_Command.
* custom_module.adb:
(Parse_Entry_Node): Adapt to new profile of Execute_GPS_Shell_Command.
* expect_interface.adb:
(Interactive_Expect): Adapt to new profile of Spawn.
(Custom_Spawn_Handler): Likewise.
* xml_viewer.adb:
(On_Click): Adapt to new profile of Execute_GPS_Shell_Command.
* gnatcoll-command_lines.adb:
Initial revision.
* gnatcoll-command_lines.ads:
Initial revision.
* gnatcoll-scripts-shell.ads:
(Initialize): Remove parameter Arguments_Count, no longer needed.
(Command_Line_Treatment): Declare.
(Execute_Command): Adapt to new profile of parent.
(Execute_Command_With_Args): Likewise.
(Set_Nth_Arg): Likewise.
* gnatcoll-scripts-utils.ads:
Add ??? comment.
* gnatcoll-scripts.adb:
(Command_Line_Treatment): Declare.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts.ads:
(Command_Line_Treatment): Add new subprogram, which enables scripts to specify
how they would like their command line to be handled.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts-python-gtkada.adb:
(Init_PyGtk_Support): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.adb:
(Command_Line_Treatment): Implement.
(Set_Nth_Arg): Adapt to profile of parent.
(Execute_Command): Ditto.
(Execute_File): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.ads:
(Command_Line_Treatment): Declare.
(Execute_Command, Set_Nth_Arg): Adjust to new profiles of abstract parent.
* gps-main.adb:
(Execute_Batch): Adapt to new profile of Execute_Command.
* debugger.adb:
(General_Spawn): Adapt to new profile of Spawn.
* debugger.ads:
Add ??? comment.
* gvd-proc_utils.adb:
(Open_Processes): Adapt to new profile of Spawn.
* gvd-source_editor-gps.adb:
(Highlight_Current_Line): Adapt to new profile of Execute_GPS_Shell_Command.
(Unhighlight_Current_Line): Ditto.
(Initialize): Ditto.
(Free_Debug_Info): Ditto.
* help_module.adb:
(On_Load_HTML): Adapt to new profile of Execute_Command.
* commands-custom.adb:
Rewrite handling of command line. Use type GNATCOLL.Command_Lines.Command_Line.
* gps-kernel-macros.adb:
(Substitute): No need to protect paths.
* gps-kernel-remote.adb:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-remote.ads:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-scripts.adb:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-scripts.ads:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-timeout.adb:
(Free): No longer need to free Args.
(Execute): Ditto. Adapt to new profile for Spawn.
(Launch_Process): Use type Command_Line to represent a command line.
* gps-kernel-timeout.ads:
(Launch_Process): Use type GNATCOLL.Command_Lines.Command_Line to represent a
command line.
* gps-kernel.adb:
(Filter_Matches_Primitive): Adapt to new profile of Execute_Command.
* navigation_module.adb:
(Go_To): Adapt to new profile of Execute_Command.
* project_properties.adb:
(For_Each_Item_In_List): Adapt to new profile of Execute_Command.
* python_module.adb:
(Load_Dir): Adapt to new profile of Execute_Command.
* remote-rsync.adb:
(On_Rsync_Hook): Adapt to new profile of Launch_Process.
* clearcase.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* cvs.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* gnatpp.xml:
Remove unneeded triple quoting.
* subversion.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* shell_script.adb:
(Module_Command_Handler): Adapt to new profile of Execute_GPS_Shell_Command.
(Create): No longer need to take into account Arguments_Count.
Add ??? comment.
* commands-socket.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* casing_exceptions.adb:
(Set_Casing): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_buffer.adb:
(Edition_Timeout): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_module.adb:
(On_Print): Adapt to new profile of Execute_GPS_Shell_Command.
* log_utils.adb:
(Get_ChangeLog_From_File): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs-generic_vcs.adb:
(Parse_Annotations): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_activities_view_api.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_view_api.adb:
(Get_Location): Adapt to new profile of Execute_GPS_Shell_Command.
(On_Menu_Edit_ChangeLog): Ditto.
(On_Menu_View_Log_Rev): Ditto.
(Comparison): Ditto.
* vdiff2_command_block.adb:
(Close_Difference): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-callback.adb:
(Setup_Ref): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-utils-shell_command.adb:
(Add_Line Adapt to new profile of Execute_GPS_Shell_Command.
(Edit, Synchronize_Scrolling, Get_Chars, Get_File_Last_Line,
Get_Line_Number, Highlight_Line, Highlight_Range, Register_Highlighting,
Remove_Blank_Lines, Replace_Text, Unhighlight, Unhighlight_Range): Ditto.
* vdiff2_module-utils.adb:
(Is_Ref_Editor_Opened): Adapt to new profile of Execute_GPS_Shell_Command.
* clipboard_views.adb:
(Button_Press): Adapt to new profile of Execute_GPS_Shell_Command.
* interactive_consoles.adb:
(Default_Command_Handler): Adapt to new profile of Execute_Command.
Change the way GPS handles command lines. Introduce a new type
(GNATCOLL.Command_Lines.Command_Line) and use it in most areas where we
manipulate command lines.
For H926-007.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@152411 936e1b1b-40f2-da11-902a-00137254ae57
2009-11-17 17:51:13 +00:00
|
|
|
----------------------------
|
|
|
|
|
-- Command_Line_Treatment --
|
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
|
|
overriding function Command_Line_Treatment
|
|
|
|
|
(Script : access Python_Scripting_Record) return Command_Line_Mode is
|
|
|
|
|
pragma Unreferenced (Script);
|
|
|
|
|
begin
|
|
|
|
|
return Raw_String;
|
|
|
|
|
end Command_Line_Treatment;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-------------------------------
|
|
|
|
|
-- Register_Python_Scripting --
|
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
|
|
procedure Register_Python_Scripting
|
2010-11-12 11:54:55 +00:00
|
|
|
(Repo : access Scripts.Scripts_Repository_Record'Class;
|
2010-10-20 14:58:09 +00:00
|
|
|
Module : String;
|
|
|
|
|
Program_Name : String := "python";
|
|
|
|
|
Python_Home : String := "")
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
|
|
|
|
Script : Python_Scripting;
|
|
|
|
|
Ignored : Integer;
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
pragma Unreferenced (Ignored);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2012-06-19 15:51:12 +00:00
|
|
|
function Initialize_Py_And_Module
|
|
|
|
|
(Program, Module : String) return PyObject;
|
|
|
|
|
pragma Import (C, Initialize_Py_And_Module,
|
|
|
|
|
"ada_py_initialize_and_module");
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
Main_Module : PyObject;
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
Script := new Python_Scripting_Record;
|
2010-11-12 11:54:55 +00:00
|
|
|
Script.Repo := Scripts_Repository (Repo);
|
2007-06-11 07:57:59 +00:00
|
|
|
Register_Scripting_Language (Repo, Script);
|
|
|
|
|
|
2010-10-20 14:58:09 +00:00
|
|
|
-- Set the program name and python home
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2010-10-20 14:58:09 +00:00
|
|
|
if Python_Home /= "" then
|
|
|
|
|
Py_SetPythonHome (Python_Home);
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2012-06-19 15:51:12 +00:00
|
|
|
Script.Module := Initialize_Py_And_Module
|
|
|
|
|
(Program_Name & ASCII.NUL, Module & ASCII.NUL);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2012-06-19 15:51:12 +00:00
|
|
|
if Script.Module = null then
|
|
|
|
|
raise Program_Error with "Could not import module " & Module;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2012-06-21 14:40:19 +00:00
|
|
|
Finalized := False;
|
|
|
|
|
|
2010-05-27 14:41:31 +00:00
|
|
|
if Active (Me_Stack)
|
|
|
|
|
and then not PyRun_SimpleString ("import traceback")
|
|
|
|
|
then
|
|
|
|
|
raise Program_Error with "Could not import traceback.py";
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Main_Module := PyImport_AddModule ("__main__");
|
|
|
|
|
if Main_Module = null then
|
|
|
|
|
raise Program_Error with "Could not import module __main__";
|
|
|
|
|
end if;
|
|
|
|
|
Script.Globals := PyModule_GetDict (Main_Module);
|
|
|
|
|
|
|
|
|
|
Script.Buffer := new String'("");
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Script.Builtin := PyImport_ImportModule (Builtin_Name);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
Script.Exception_Unexpected := PyErr_NewException
|
|
|
|
|
(Module & ".Unexpected_Exception", null, null);
|
2008-02-25 10:56:26 +00:00
|
|
|
Ignored := PyModule_AddObject
|
|
|
|
|
(Script.Module, "Unexpected_Exception" & ASCII.NUL,
|
|
|
|
|
Script.Exception_Unexpected);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Script.Exception_Misc := PyErr_NewException
|
|
|
|
|
(Module & ".Exception", null, null);
|
2008-02-25 10:56:26 +00:00
|
|
|
Ignored := PyModule_AddObject
|
|
|
|
|
(Script.Module, "Exception" & ASCII.NUL, Script.Exception_Misc);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Script.Exception_Missing_Args := PyErr_NewException
|
|
|
|
|
(Module & ".Missing_Arguments", null, null);
|
2008-02-25 10:56:26 +00:00
|
|
|
Ignored := PyModule_AddObject
|
|
|
|
|
(Script.Module, "Missing_Arguments" & ASCII.NUL,
|
|
|
|
|
Script.Exception_Missing_Args);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Script.Exception_Invalid_Arg := PyErr_NewException
|
|
|
|
|
(Module & ".Invalid_Argument", null, null);
|
2008-02-25 10:56:26 +00:00
|
|
|
Ignored := PyModule_AddObject
|
|
|
|
|
(Script.Module, "Invalid_Argument" & ASCII.NUL,
|
|
|
|
|
Script.Exception_Invalid_Arg);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
-- PyGTK prints its error messages using sys.argv, which doesn't
|
|
|
|
|
-- exist in non-interactive mode. We therefore define it here
|
2007-06-12 20:03:42 +00:00
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if not PyRun_SimpleString ("sys.argv=['" & Module & "']") then
|
|
|
|
|
Trace (Me_Error, "Could not initialize sys.argv");
|
|
|
|
|
end if;
|
2007-06-12 20:03:42 +00:00
|
|
|
|
|
|
|
|
-- This function is required for support of the Python menu (F120-025),
|
|
|
|
|
-- so that we can execute python commands in the context of the global
|
|
|
|
|
-- interpreter instead of the current context (for the menu, that would
|
|
|
|
|
-- be python_support.py, and thus would have no impact on the
|
|
|
|
|
-- interpreter itself)
|
|
|
|
|
|
|
|
|
|
Register_Command
|
2010-11-17 12:06:29 +00:00
|
|
|
(Repo,
|
2007-06-12 20:03:42 +00:00
|
|
|
Command => "exec_in_console",
|
|
|
|
|
Handler => Python_Global_Command_Handler'Access,
|
|
|
|
|
Minimum_Args => 1,
|
2010-11-17 12:06:29 +00:00
|
|
|
Maximum_Args => 1,
|
|
|
|
|
Language => Python_Name);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Register_Python_Scripting;
|
|
|
|
|
|
2007-06-12 20:03:42 +00:00
|
|
|
-----------------------------------
|
|
|
|
|
-- Python_Global_Command_Handler --
|
|
|
|
|
-----------------------------------
|
|
|
|
|
|
|
|
|
|
procedure Python_Global_Command_Handler
|
|
|
|
|
(Data : in out Callback_Data'Class; Command : String)
|
|
|
|
|
is
|
|
|
|
|
Result : PyObject;
|
|
|
|
|
Errors : aliased Boolean;
|
|
|
|
|
begin
|
|
|
|
|
if Command = "exec_in_console" then
|
|
|
|
|
Result := Run_Command
|
|
|
|
|
(Python_Scripting (Get_Script (Data)),
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Command => Nth_Arg (Data, 1),
|
|
|
|
|
Need_Output => False,
|
|
|
|
|
Show_Command => True,
|
|
|
|
|
Errors => Errors'Unchecked_Access);
|
|
|
|
|
Py_XDECREF (Result);
|
2007-06-12 20:03:42 +00:00
|
|
|
end if;
|
|
|
|
|
end Python_Global_Command_Handler;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
--------------------------
|
|
|
|
|
-- Destroy_Handler_Data --
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
procedure Destroy_Handler_Data (Handler : System.Address) is
|
|
|
|
|
H : Handler_Data_Access := Convert (Handler);
|
|
|
|
|
begin
|
|
|
|
|
Unchecked_Free (H);
|
|
|
|
|
end Destroy_Handler_Data;
|
|
|
|
|
|
|
|
|
|
----------
|
|
|
|
|
-- Free --
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
|
|
procedure Free (Data : in out Python_Callback_Data) is
|
|
|
|
|
begin
|
|
|
|
|
if Data.Args /= null then
|
|
|
|
|
Py_DECREF (Data.Args);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Data.Kw /= null then
|
|
|
|
|
Py_DECREF (Data.Kw);
|
|
|
|
|
end if;
|
|
|
|
|
|
2011-05-09 14:21:32 +00:00
|
|
|
if Data.Return_Value /= null then
|
|
|
|
|
Py_DECREF (Data.Return_Value);
|
|
|
|
|
Data.Return_Value := null;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Data.Return_Dict /= null then
|
|
|
|
|
Py_DECREF (Data.Return_Dict);
|
|
|
|
|
Data.Return_Dict := null;
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Free;
|
|
|
|
|
|
2010-11-16 08:23:37 +00:00
|
|
|
--------------
|
|
|
|
|
-- Set_Item --
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Item (Args : PyObject; T : Integer; Item : PyObject) is
|
2010-11-16 13:13:47 +00:00
|
|
|
N : Integer;
|
|
|
|
|
pragma Unreferenced (N);
|
2010-11-16 08:23:37 +00:00
|
|
|
begin
|
|
|
|
|
-- Special case tuples, since they are immutable through
|
|
|
|
|
-- PyObject_SetItem
|
|
|
|
|
if PyTuple_Check (Args) then
|
2011-05-06 20:26:55 +00:00
|
|
|
PyTuple_SetItem (Args, T, Item); -- Doesn't modify refcount
|
|
|
|
|
Py_INCREF (Item);
|
2010-11-16 13:13:47 +00:00
|
|
|
|
|
|
|
|
-- Also special case lists, since we want to append if the index is
|
|
|
|
|
-- too big
|
|
|
|
|
|
|
|
|
|
elsif PyList_Check (Args) then
|
|
|
|
|
if T < PyList_Size (Args) then
|
|
|
|
|
PyObject_SetItem (Args, T, Item);
|
|
|
|
|
else
|
|
|
|
|
N := PyList_Append (Args, Item);
|
|
|
|
|
end if;
|
|
|
|
|
|
2010-11-16 08:23:37 +00:00
|
|
|
else
|
|
|
|
|
PyObject_SetItem (Args, T, Item);
|
|
|
|
|
end if;
|
|
|
|
|
end Set_Item;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-----------
|
|
|
|
|
-- Clone --
|
|
|
|
|
-----------
|
|
|
|
|
|
|
|
|
|
function Clone (Data : Python_Callback_Data) return Callback_Data'Class is
|
|
|
|
|
D : Python_Callback_Data := Data;
|
|
|
|
|
Item : PyObject;
|
2010-11-15 17:33:14 +00:00
|
|
|
Size : Integer;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
if D.Args /= null then
|
2010-11-15 17:33:14 +00:00
|
|
|
Size := PyObject_Size (D.Args);
|
|
|
|
|
D.Args := PyTuple_New (Size);
|
|
|
|
|
for T in 0 .. Size - 1 loop
|
|
|
|
|
Item := PyObject_GetItem (Data.Args, T);
|
2010-11-16 08:23:37 +00:00
|
|
|
Set_Item (D.Args, T, Item);
|
2011-05-06 20:26:55 +00:00
|
|
|
Py_DECREF (Item);
|
2007-06-11 07:57:59 +00:00
|
|
|
end loop;
|
|
|
|
|
end if;
|
|
|
|
|
if D.Kw /= null then
|
|
|
|
|
Py_INCREF (D.Kw);
|
|
|
|
|
end if;
|
|
|
|
|
D.Return_Value := null;
|
|
|
|
|
D.Return_Dict := null;
|
|
|
|
|
return D;
|
|
|
|
|
end Clone;
|
|
|
|
|
|
|
|
|
|
------------
|
|
|
|
|
-- Create --
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
function Create
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Arguments_Count : Natural) return Callback_Data'Class
|
|
|
|
|
is
|
|
|
|
|
Callback : constant Python_Callback_Data :=
|
|
|
|
|
(Callback_Data with
|
|
|
|
|
Script => Python_Scripting (Script),
|
|
|
|
|
Args => PyTuple_New (Arguments_Count),
|
|
|
|
|
Kw => Py_None,
|
|
|
|
|
Return_Value => null,
|
|
|
|
|
Return_Dict => null,
|
|
|
|
|
Has_Return_Value => False,
|
|
|
|
|
Return_As_List => False,
|
2010-11-17 10:00:16 +00:00
|
|
|
First_Arg_Is_Self => False);
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
Py_INCREF (Callback.Kw);
|
|
|
|
|
return Callback;
|
|
|
|
|
end Create;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Nth_Arg
|
* aliases_module.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* build_command_manager.adb:
Start replacing command line handling with use of GNATCOLL.Command_Line.
* builder_module.adb:
Do not use a GNAT.OS_Lib.Argument_List to represent a command line.
* commands-builder.adb:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* commands-builder.ads:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* code_peer-module-bridge.adb:
(Add_Audit_Record): Adapt to new profile of Launch_Process.
(Inspection): Ditto.
(Review_Message): Ditto.
* code_peer-shell_commands.adb:
(Build_Target): Adapt to new profile of Execute_GPS_Shell_Command.
(Build_Target_Execute): Ditto.
(Get_Build_Mode): Ditto.
(Set_Build_Mode): Ditto.
* codefix_module.adb:
(Compilation_Finished_Cb): Adapt to new profile of Execute_GPS_Shell_Command.
* custom_module.adb:
(Parse_Entry_Node): Adapt to new profile of Execute_GPS_Shell_Command.
* expect_interface.adb:
(Interactive_Expect): Adapt to new profile of Spawn.
(Custom_Spawn_Handler): Likewise.
* xml_viewer.adb:
(On_Click): Adapt to new profile of Execute_GPS_Shell_Command.
* gnatcoll-command_lines.adb:
Initial revision.
* gnatcoll-command_lines.ads:
Initial revision.
* gnatcoll-scripts-shell.ads:
(Initialize): Remove parameter Arguments_Count, no longer needed.
(Command_Line_Treatment): Declare.
(Execute_Command): Adapt to new profile of parent.
(Execute_Command_With_Args): Likewise.
(Set_Nth_Arg): Likewise.
* gnatcoll-scripts-utils.ads:
Add ??? comment.
* gnatcoll-scripts.adb:
(Command_Line_Treatment): Declare.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts.ads:
(Command_Line_Treatment): Add new subprogram, which enables scripts to specify
how they would like their command line to be handled.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts-python-gtkada.adb:
(Init_PyGtk_Support): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.adb:
(Command_Line_Treatment): Implement.
(Set_Nth_Arg): Adapt to profile of parent.
(Execute_Command): Ditto.
(Execute_File): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.ads:
(Command_Line_Treatment): Declare.
(Execute_Command, Set_Nth_Arg): Adjust to new profiles of abstract parent.
* gps-main.adb:
(Execute_Batch): Adapt to new profile of Execute_Command.
* debugger.adb:
(General_Spawn): Adapt to new profile of Spawn.
* debugger.ads:
Add ??? comment.
* gvd-proc_utils.adb:
(Open_Processes): Adapt to new profile of Spawn.
* gvd-source_editor-gps.adb:
(Highlight_Current_Line): Adapt to new profile of Execute_GPS_Shell_Command.
(Unhighlight_Current_Line): Ditto.
(Initialize): Ditto.
(Free_Debug_Info): Ditto.
* help_module.adb:
(On_Load_HTML): Adapt to new profile of Execute_Command.
* commands-custom.adb:
Rewrite handling of command line. Use type GNATCOLL.Command_Lines.Command_Line.
* gps-kernel-macros.adb:
(Substitute): No need to protect paths.
* gps-kernel-remote.adb:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-remote.ads:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-scripts.adb:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-scripts.ads:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-timeout.adb:
(Free): No longer need to free Args.
(Execute): Ditto. Adapt to new profile for Spawn.
(Launch_Process): Use type Command_Line to represent a command line.
* gps-kernel-timeout.ads:
(Launch_Process): Use type GNATCOLL.Command_Lines.Command_Line to represent a
command line.
* gps-kernel.adb:
(Filter_Matches_Primitive): Adapt to new profile of Execute_Command.
* navigation_module.adb:
(Go_To): Adapt to new profile of Execute_Command.
* project_properties.adb:
(For_Each_Item_In_List): Adapt to new profile of Execute_Command.
* python_module.adb:
(Load_Dir): Adapt to new profile of Execute_Command.
* remote-rsync.adb:
(On_Rsync_Hook): Adapt to new profile of Launch_Process.
* clearcase.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* cvs.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* gnatpp.xml:
Remove unneeded triple quoting.
* subversion.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* shell_script.adb:
(Module_Command_Handler): Adapt to new profile of Execute_GPS_Shell_Command.
(Create): No longer need to take into account Arguments_Count.
Add ??? comment.
* commands-socket.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* casing_exceptions.adb:
(Set_Casing): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_buffer.adb:
(Edition_Timeout): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_module.adb:
(On_Print): Adapt to new profile of Execute_GPS_Shell_Command.
* log_utils.adb:
(Get_ChangeLog_From_File): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs-generic_vcs.adb:
(Parse_Annotations): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_activities_view_api.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_view_api.adb:
(Get_Location): Adapt to new profile of Execute_GPS_Shell_Command.
(On_Menu_Edit_ChangeLog): Ditto.
(On_Menu_View_Log_Rev): Ditto.
(Comparison): Ditto.
* vdiff2_command_block.adb:
(Close_Difference): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-callback.adb:
(Setup_Ref): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-utils-shell_command.adb:
(Add_Line Adapt to new profile of Execute_GPS_Shell_Command.
(Edit, Synchronize_Scrolling, Get_Chars, Get_File_Last_Line,
Get_Line_Number, Highlight_Line, Highlight_Range, Register_Highlighting,
Remove_Blank_Lines, Replace_Text, Unhighlight, Unhighlight_Range): Ditto.
* vdiff2_module-utils.adb:
(Is_Ref_Editor_Opened): Adapt to new profile of Execute_GPS_Shell_Command.
* clipboard_views.adb:
(Button_Press): Adapt to new profile of Execute_GPS_Shell_Command.
* interactive_consoles.adb:
(Default_Command_Handler): Adapt to new profile of Execute_Command.
Change the way GPS handles command lines. Introduce a new type
(GNATCOLL.Command_Lines.Command_Line) and use it in most areas where we
manipulate command lines.
For H926-007.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@152411 936e1b1b-40f2-da11-902a-00137254ae57
2009-11-17 17:51:13 +00:00
|
|
|
(Data : in out Python_Callback_Data;
|
2012-01-17 12:07:00 +00:00
|
|
|
N : Positive; Value : PyObject) is
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2012-01-17 12:07:00 +00:00
|
|
|
Set_Item (Data.Args, N - 1, Value);
|
|
|
|
|
Py_DECREF (Value);
|
|
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Nth_Arg
|
|
|
|
|
(Data : in out Python_Callback_Data;
|
|
|
|
|
N : Positive; Value : Subprogram_Type)
|
|
|
|
|
is
|
|
|
|
|
Subp : constant PyObject :=
|
|
|
|
|
Python_Subprogram_Record (Value.all).Subprogram;
|
|
|
|
|
begin
|
|
|
|
|
Set_Item (Data.Args, N - 1, Subp);
|
|
|
|
|
Py_DECREF (Subp);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Nth_Arg
|
2011-05-06 20:26:55 +00:00
|
|
|
(Data : in out Python_Callback_Data; N : Positive; Value : String)
|
|
|
|
|
is
|
|
|
|
|
Item : constant PyObject := PyString_FromString (Value);
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2011-05-06 20:26:55 +00:00
|
|
|
Set_Item (Data.Args, N - 1, Item);
|
|
|
|
|
Py_DECREF (Item);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Nth_Arg
|
2011-05-06 20:26:55 +00:00
|
|
|
(Data : in out Python_Callback_Data; N : Positive; Value : Integer)
|
|
|
|
|
is
|
|
|
|
|
Item : constant PyObject := PyInt_FromLong (Interfaces.C.long (Value));
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2011-05-06 20:26:55 +00:00
|
|
|
Set_Item (Data.Args, N - 1, Item);
|
|
|
|
|
Py_DECREF (Item);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
2012-09-05 07:50:30 +00:00
|
|
|
procedure Set_Nth_Arg
|
|
|
|
|
(Data : in out Python_Callback_Data; N : Positive; Value : Float)
|
|
|
|
|
is
|
|
|
|
|
Item : constant PyObject := PyFloat_FromDouble
|
|
|
|
|
(Interfaces.C.double (Value));
|
|
|
|
|
begin
|
|
|
|
|
Set_Item (Data.Args, N - 1, Item);
|
|
|
|
|
Py_DECREF (Item);
|
|
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
procedure Set_Nth_Arg
|
2011-05-06 20:26:55 +00:00
|
|
|
(Data : in out Python_Callback_Data; N : Positive; Value : Boolean)
|
|
|
|
|
is
|
|
|
|
|
Item : constant PyObject := PyInt_FromLong (Boolean'Pos (Value));
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2011-05-06 20:26:55 +00:00
|
|
|
Set_Item (Data.Args, N - 1, Item);
|
|
|
|
|
Py_DECREF (Item);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Nth_Arg
|
* aliases_module.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* build_command_manager.adb:
Start replacing command line handling with use of GNATCOLL.Command_Line.
* builder_module.adb:
Do not use a GNAT.OS_Lib.Argument_List to represent a command line.
* commands-builder.adb:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* commands-builder.ads:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* code_peer-module-bridge.adb:
(Add_Audit_Record): Adapt to new profile of Launch_Process.
(Inspection): Ditto.
(Review_Message): Ditto.
* code_peer-shell_commands.adb:
(Build_Target): Adapt to new profile of Execute_GPS_Shell_Command.
(Build_Target_Execute): Ditto.
(Get_Build_Mode): Ditto.
(Set_Build_Mode): Ditto.
* codefix_module.adb:
(Compilation_Finished_Cb): Adapt to new profile of Execute_GPS_Shell_Command.
* custom_module.adb:
(Parse_Entry_Node): Adapt to new profile of Execute_GPS_Shell_Command.
* expect_interface.adb:
(Interactive_Expect): Adapt to new profile of Spawn.
(Custom_Spawn_Handler): Likewise.
* xml_viewer.adb:
(On_Click): Adapt to new profile of Execute_GPS_Shell_Command.
* gnatcoll-command_lines.adb:
Initial revision.
* gnatcoll-command_lines.ads:
Initial revision.
* gnatcoll-scripts-shell.ads:
(Initialize): Remove parameter Arguments_Count, no longer needed.
(Command_Line_Treatment): Declare.
(Execute_Command): Adapt to new profile of parent.
(Execute_Command_With_Args): Likewise.
(Set_Nth_Arg): Likewise.
* gnatcoll-scripts-utils.ads:
Add ??? comment.
* gnatcoll-scripts.adb:
(Command_Line_Treatment): Declare.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts.ads:
(Command_Line_Treatment): Add new subprogram, which enables scripts to specify
how they would like their command line to be handled.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts-python-gtkada.adb:
(Init_PyGtk_Support): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.adb:
(Command_Line_Treatment): Implement.
(Set_Nth_Arg): Adapt to profile of parent.
(Execute_Command): Ditto.
(Execute_File): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.ads:
(Command_Line_Treatment): Declare.
(Execute_Command, Set_Nth_Arg): Adjust to new profiles of abstract parent.
* gps-main.adb:
(Execute_Batch): Adapt to new profile of Execute_Command.
* debugger.adb:
(General_Spawn): Adapt to new profile of Spawn.
* debugger.ads:
Add ??? comment.
* gvd-proc_utils.adb:
(Open_Processes): Adapt to new profile of Spawn.
* gvd-source_editor-gps.adb:
(Highlight_Current_Line): Adapt to new profile of Execute_GPS_Shell_Command.
(Unhighlight_Current_Line): Ditto.
(Initialize): Ditto.
(Free_Debug_Info): Ditto.
* help_module.adb:
(On_Load_HTML): Adapt to new profile of Execute_Command.
* commands-custom.adb:
Rewrite handling of command line. Use type GNATCOLL.Command_Lines.Command_Line.
* gps-kernel-macros.adb:
(Substitute): No need to protect paths.
* gps-kernel-remote.adb:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-remote.ads:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-scripts.adb:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-scripts.ads:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-timeout.adb:
(Free): No longer need to free Args.
(Execute): Ditto. Adapt to new profile for Spawn.
(Launch_Process): Use type Command_Line to represent a command line.
* gps-kernel-timeout.ads:
(Launch_Process): Use type GNATCOLL.Command_Lines.Command_Line to represent a
command line.
* gps-kernel.adb:
(Filter_Matches_Primitive): Adapt to new profile of Execute_Command.
* navigation_module.adb:
(Go_To): Adapt to new profile of Execute_Command.
* project_properties.adb:
(For_Each_Item_In_List): Adapt to new profile of Execute_Command.
* python_module.adb:
(Load_Dir): Adapt to new profile of Execute_Command.
* remote-rsync.adb:
(On_Rsync_Hook): Adapt to new profile of Launch_Process.
* clearcase.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* cvs.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* gnatpp.xml:
Remove unneeded triple quoting.
* subversion.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* shell_script.adb:
(Module_Command_Handler): Adapt to new profile of Execute_GPS_Shell_Command.
(Create): No longer need to take into account Arguments_Count.
Add ??? comment.
* commands-socket.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* casing_exceptions.adb:
(Set_Casing): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_buffer.adb:
(Edition_Timeout): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_module.adb:
(On_Print): Adapt to new profile of Execute_GPS_Shell_Command.
* log_utils.adb:
(Get_ChangeLog_From_File): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs-generic_vcs.adb:
(Parse_Annotations): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_activities_view_api.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_view_api.adb:
(Get_Location): Adapt to new profile of Execute_GPS_Shell_Command.
(On_Menu_Edit_ChangeLog): Ditto.
(On_Menu_View_Log_Rev): Ditto.
(Comparison): Ditto.
* vdiff2_command_block.adb:
(Close_Difference): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-callback.adb:
(Setup_Ref): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-utils-shell_command.adb:
(Add_Line Adapt to new profile of Execute_GPS_Shell_Command.
(Edit, Synchronize_Scrolling, Get_Chars, Get_File_Last_Line,
Get_Line_Number, Highlight_Line, Highlight_Range, Register_Highlighting,
Remove_Blank_Lines, Replace_Text, Unhighlight, Unhighlight_Range): Ditto.
* vdiff2_module-utils.adb:
(Is_Ref_Editor_Opened): Adapt to new profile of Execute_GPS_Shell_Command.
* clipboard_views.adb:
(Button_Press): Adapt to new profile of Execute_GPS_Shell_Command.
* interactive_consoles.adb:
(Default_Command_Handler): Adapt to new profile of Execute_Command.
Change the way GPS handles command lines. Introduce a new type
(GNATCOLL.Command_Lines.Command_Line) and use it in most areas where we
manipulate command lines.
For H926-007.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@152411 936e1b1b-40f2-da11-902a-00137254ae57
2009-11-17 17:51:13 +00:00
|
|
|
(Data : in out Python_Callback_Data; N : Positive; Value : Class_Instance)
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
2012-02-09 14:13:19 +00:00
|
|
|
Inst : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2012-02-09 14:13:19 +00:00
|
|
|
if Value = No_Class_Instance then
|
|
|
|
|
Set_Item (Data.Args, N - 1, Py_None); -- Increments refcount
|
|
|
|
|
else
|
|
|
|
|
Inst := Python_Class_Instance (Get_CIR (Value)).Data;
|
|
|
|
|
Set_Item (Data.Args, N - 1, Inst); -- Increments refcount
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
2010-11-16 13:13:47 +00:00
|
|
|
-----------------
|
|
|
|
|
-- Set_Nth_Arg --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Nth_Arg
|
|
|
|
|
(Data : in out Python_Callback_Data; N : Positive; Value : List_Instance)
|
|
|
|
|
is
|
|
|
|
|
V : constant PyObject := Python_Callback_Data (Value).Args;
|
|
|
|
|
begin
|
2011-05-06 20:26:55 +00:00
|
|
|
Set_Item (Data.Args, N - 1, V); -- Increments refcount
|
2010-11-16 13:13:47 +00:00
|
|
|
end Set_Nth_Arg;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-----------------
|
|
|
|
|
-- First_Level --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
function First_Level (Self, Args, Kw : PyObject) return PyObject is
|
2008-08-29 09:57:28 +00:00
|
|
|
-- Args and Kw could both be null, as called from PyCFunction_Call
|
|
|
|
|
|
2012-06-21 14:40:19 +00:00
|
|
|
Handler : Handler_Data_Access;
|
2008-08-29 09:57:28 +00:00
|
|
|
Size : Integer := 0;
|
2007-06-11 07:57:59 +00:00
|
|
|
Callback : Python_Callback_Data;
|
2010-11-17 12:06:29 +00:00
|
|
|
First_Arg_Is_Self : Boolean;
|
2010-11-18 11:20:51 +00:00
|
|
|
Result : PyObject;
|
2012-06-21 14:40:19 +00:00
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2012-06-21 15:57:27 +00:00
|
|
|
Handler := Convert (PyCObject_AsVoidPtr (Self));
|
|
|
|
|
|
|
|
|
|
if Finalized
|
|
|
|
|
and then Handler.Cmd.Command /= Destructor_Method
|
|
|
|
|
then
|
|
|
|
|
PyErr_SetString (Handler.Script.Exception_Unexpected,
|
|
|
|
|
"Application was already finalized");
|
2012-06-21 14:40:19 +00:00
|
|
|
return null;
|
|
|
|
|
end if;
|
|
|
|
|
|
2010-05-27 14:41:31 +00:00
|
|
|
if Active (Me_Stack) then
|
|
|
|
|
declare
|
|
|
|
|
Module : constant PyObject := PyImport_ImportModule ("traceback");
|
|
|
|
|
Newline, List, Join : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
if Module /= null then
|
|
|
|
|
List := PyObject_CallMethod (Module, "format_stack");
|
|
|
|
|
|
|
|
|
|
if List /= null then
|
|
|
|
|
Newline := PyString_FromString ("");
|
|
|
|
|
Join := PyObject_CallMethod (Newline, "join", List);
|
|
|
|
|
|
2011-01-05 09:59:51 +00:00
|
|
|
Trace (Me_Stack, "Exec " & Command_Name (Handler.all)
|
2010-05-27 14:41:31 +00:00
|
|
|
& ASCII.LF & PyString_AsString (Join));
|
|
|
|
|
Py_DECREF (Newline);
|
|
|
|
|
Py_DECREF (List);
|
|
|
|
|
Py_DECREF (Join);
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
exception
|
|
|
|
|
when E : others =>
|
|
|
|
|
Trace (Me_Stack, E);
|
|
|
|
|
end;
|
|
|
|
|
end if;
|
|
|
|
|
|
2008-08-29 09:57:28 +00:00
|
|
|
if Args /= null then
|
2010-11-15 17:33:14 +00:00
|
|
|
Size := PyObject_Size (Args);
|
2008-08-29 09:57:28 +00:00
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
if Kw /= null then
|
2010-11-15 14:56:33 +00:00
|
|
|
declare
|
|
|
|
|
S : constant Integer := PyDict_Size (Kw);
|
|
|
|
|
begin
|
|
|
|
|
if S < 0 then
|
|
|
|
|
raise Program_Error with
|
|
|
|
|
"Incorrect dictionary when calling function "
|
2010-11-17 12:06:29 +00:00
|
|
|
& Handler.Cmd.Command;
|
2010-11-15 14:56:33 +00:00
|
|
|
end if;
|
|
|
|
|
Size := S + Size;
|
|
|
|
|
end;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 12:06:29 +00:00
|
|
|
First_Arg_Is_Self :=
|
|
|
|
|
Handler.Cmd.Class /= No_Class and then not Handler.Cmd.Static_Method;
|
|
|
|
|
|
|
|
|
|
if First_Arg_Is_Self then
|
2007-06-11 07:57:59 +00:00
|
|
|
Size := Size - 1; -- First param is always the instance
|
|
|
|
|
end if;
|
|
|
|
|
|
2010-11-15 14:56:33 +00:00
|
|
|
-- Special case for constructors:
|
|
|
|
|
-- when we were using old-style classes, New_Instance was not calling
|
|
|
|
|
-- __init__. With new-style classes, however, __init__ is already called
|
|
|
|
|
-- when we call the metatype(). In particular, this means that the
|
|
|
|
|
-- profile of New_Instance should allow passing custom parameters,
|
|
|
|
|
-- otherwise the call to __init__ fails.
|
|
|
|
|
-- So for now we simply allow a call to the constructor with no
|
|
|
|
|
-- parameter, which does nothing.
|
|
|
|
|
-- This is not very elegant, since from python's point of view, this
|
|
|
|
|
-- relies on the user calling New_Instance and immediately initializing
|
|
|
|
|
-- the Class_Instance as done in the Constructor_Method handler.
|
|
|
|
|
|
2010-11-17 08:13:52 +00:00
|
|
|
if Handler.Script.Ignore_Constructor
|
2010-11-17 12:06:29 +00:00
|
|
|
and then Handler.Cmd.Command = Constructor_Method
|
2010-11-15 14:56:33 +00:00
|
|
|
then
|
2010-11-15 15:34:28 +00:00
|
|
|
Py_INCREF (Py_None);
|
2010-11-15 14:56:33 +00:00
|
|
|
return Py_None;
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-- Check number of arguments
|
2010-11-17 12:06:29 +00:00
|
|
|
if Handler.Cmd.Minimum_Args > Size
|
|
|
|
|
or else Size > Handler.Cmd.Maximum_Args
|
2007-06-11 07:57:59 +00:00
|
|
|
then
|
2010-11-17 12:06:29 +00:00
|
|
|
if Handler.Cmd.Minimum_Args > Size then
|
2007-06-11 07:57:59 +00:00
|
|
|
PyErr_SetString (Handler.Script.Exception_Missing_Args,
|
|
|
|
|
"Wrong number of parameters, expecting at least"
|
2010-11-17 12:06:29 +00:00
|
|
|
& Handler.Cmd.Minimum_Args'Img & ", received"
|
2010-11-15 14:56:33 +00:00
|
|
|
& Size'Img);
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
PyErr_SetString (Handler.Script.Exception_Missing_Args,
|
|
|
|
|
"Wrong number of parameters, expecting at most"
|
2010-11-17 12:06:29 +00:00
|
|
|
& Handler.Cmd.Maximum_Args'Img & ", received"
|
2010-11-15 14:56:33 +00:00
|
|
|
& Size'Img);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
return null;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Callback.Args := Args;
|
2011-05-11 09:26:12 +00:00
|
|
|
Py_XINCREF (Callback.Args);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Callback.Kw := Kw;
|
2011-05-11 09:26:12 +00:00
|
|
|
Py_XINCREF (Callback.Kw);
|
|
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
Callback.Return_Value := null;
|
2007-06-11 07:57:59 +00:00
|
|
|
Callback.Return_Dict := null;
|
|
|
|
|
Callback.Script := Handler.Script;
|
2010-11-17 12:06:29 +00:00
|
|
|
Callback.First_Arg_Is_Self := First_Arg_Is_Self;
|
2008-08-29 09:57:28 +00:00
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
if Handler.Cmd.Params /= null then
|
|
|
|
|
Name_Parameters (Callback, Handler.Cmd.Params.all);
|
|
|
|
|
end if;
|
|
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
Run_Callback
|
|
|
|
|
(Handler.Script, Handler.Cmd.Handler, Handler.Cmd.Command, Callback,
|
|
|
|
|
Result);
|
|
|
|
|
return Result;
|
|
|
|
|
end First_Level;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
------------------
|
|
|
|
|
-- Run_Callback --
|
|
|
|
|
------------------
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
procedure Run_Callback
|
|
|
|
|
(Script : Python_Scripting;
|
|
|
|
|
Cmd : Module_Command_Function;
|
|
|
|
|
Command : String;
|
|
|
|
|
Data : in out Python_Callback_Data'Class;
|
|
|
|
|
Result : out PyObject)
|
|
|
|
|
is
|
|
|
|
|
begin
|
2010-11-18 13:25:46 +00:00
|
|
|
-- Return_Value will be set to null in case of error
|
|
|
|
|
Data.Return_Value := Py_None;
|
|
|
|
|
Py_INCREF (Py_None);
|
|
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
Cmd.all (Data, Command);
|
|
|
|
|
|
|
|
|
|
if Data.Return_Dict /= null then
|
|
|
|
|
Result := Data.Return_Dict;
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
2010-11-18 13:25:46 +00:00
|
|
|
Result := Data.Return_Value; -- might be null for an exception
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2011-05-10 09:17:19 +00:00
|
|
|
Py_XINCREF (Result);
|
2011-05-09 14:21:32 +00:00
|
|
|
Free (Data);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
exception
|
|
|
|
|
when E : Invalid_Parameter =>
|
2010-11-18 11:20:51 +00:00
|
|
|
if not Data.Has_Return_Value
|
|
|
|
|
or else Data.Return_Value /= null
|
2007-06-11 07:57:59 +00:00
|
|
|
then
|
|
|
|
|
PyErr_SetString
|
2010-11-18 11:20:51 +00:00
|
|
|
(Script.Exception_Invalid_Arg, Exception_Message (E));
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
Free (Data);
|
|
|
|
|
Result := null;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2007-06-12 20:03:42 +00:00
|
|
|
when E : others =>
|
2010-11-18 11:20:51 +00:00
|
|
|
if not Data.Has_Return_Value
|
|
|
|
|
or else Data.Return_Value /= null
|
2007-06-11 07:57:59 +00:00
|
|
|
then
|
2007-06-12 20:03:42 +00:00
|
|
|
PyErr_SetString
|
2010-11-18 11:20:51 +00:00
|
|
|
(Script.Exception_Unexpected,
|
2007-06-12 20:03:42 +00:00
|
|
|
"unexpected internal exception "
|
|
|
|
|
& Exception_Information (E));
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-18 11:20:51 +00:00
|
|
|
Free (Data);
|
|
|
|
|
Result := null;
|
|
|
|
|
end Run_Callback;
|
|
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
|
-- First_Level_Getter --
|
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
function First_Level_Getter
|
|
|
|
|
(Obj : PyObject; Closure : System.Address) return PyObject
|
|
|
|
|
is
|
|
|
|
|
Prop : constant Property_User_Data := Convert (Closure);
|
|
|
|
|
Callback : Python_Callback_Data;
|
|
|
|
|
Args : PyObject;
|
|
|
|
|
Result : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
Args := PyTuple_New (1);
|
|
|
|
|
|
|
|
|
|
Py_INCREF (Obj);
|
|
|
|
|
PyTuple_SetItem (Args, 0, Obj);
|
|
|
|
|
|
|
|
|
|
Callback :=
|
|
|
|
|
(Script => Prop.Script,
|
|
|
|
|
Args => Args, -- Now owned by Callback
|
|
|
|
|
Kw => null,
|
|
|
|
|
Return_Value => null,
|
|
|
|
|
Return_Dict => null,
|
|
|
|
|
Has_Return_Value => False,
|
|
|
|
|
Return_As_List => False,
|
|
|
|
|
First_Arg_Is_Self => False);
|
|
|
|
|
|
|
|
|
|
Run_Callback (Prop.Script, Prop.Prop.Getter, Prop.Prop.Name, Callback,
|
|
|
|
|
Result);
|
|
|
|
|
return Result;
|
|
|
|
|
end First_Level_Getter;
|
|
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
|
-- First_Level_Setter --
|
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
function First_Level_Setter
|
|
|
|
|
(Obj, Value : PyObject; Closure : System.Address) return Integer
|
|
|
|
|
is
|
|
|
|
|
Prop : constant Property_User_Data := Convert (Closure);
|
|
|
|
|
Callback : Python_Callback_Data;
|
|
|
|
|
Args : PyObject;
|
|
|
|
|
Result : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
Args := PyTuple_New (2);
|
|
|
|
|
|
|
|
|
|
Py_INCREF (Obj);
|
|
|
|
|
PyTuple_SetItem (Args, 0, Obj);
|
|
|
|
|
|
|
|
|
|
Py_INCREF (Value);
|
|
|
|
|
PyTuple_SetItem (Args, 1, Value);
|
|
|
|
|
|
|
|
|
|
Callback :=
|
|
|
|
|
(Script => Prop.Script,
|
|
|
|
|
Args => Args, -- Now owned by Callback
|
|
|
|
|
Kw => null,
|
|
|
|
|
Return_Value => null,
|
|
|
|
|
Return_Dict => null,
|
|
|
|
|
Has_Return_Value => False,
|
|
|
|
|
Return_As_List => False,
|
|
|
|
|
First_Arg_Is_Self => False);
|
|
|
|
|
Run_Callback
|
2011-07-28 13:19:43 +00:00
|
|
|
(Prop.Script, Prop.Prop.Setter, Prop.Prop.Name, Callback, Result);
|
2010-11-18 11:20:51 +00:00
|
|
|
|
|
|
|
|
if Result = null then
|
2011-07-28 13:59:22 +00:00
|
|
|
return -1;
|
2010-11-18 11:20:51 +00:00
|
|
|
else
|
|
|
|
|
Py_DECREF (Result);
|
2011-07-29 09:13:31 +00:00
|
|
|
return 0;
|
2010-11-18 11:20:51 +00:00
|
|
|
end if;
|
|
|
|
|
end First_Level_Setter;
|
|
|
|
|
|
|
|
|
|
-----------------------
|
|
|
|
|
-- Register_Property --
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
overriding procedure Register_Property
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Prop : Property_Descr_Access)
|
|
|
|
|
is
|
|
|
|
|
Klass : PyObject;
|
|
|
|
|
Ignored : Boolean;
|
|
|
|
|
pragma Unreferenced (Ignored);
|
|
|
|
|
|
|
|
|
|
Setter : C_Setter := First_Level_Setter'Access;
|
|
|
|
|
Getter : C_Getter := First_Level_Getter'Access;
|
|
|
|
|
|
|
|
|
|
H : constant Property_User_Data := new Property_User_Data_Record'
|
|
|
|
|
(Script => Python_Scripting (Script),
|
|
|
|
|
Prop => Prop);
|
|
|
|
|
-- ??? Memory leak. We do not know when H is no longer needed
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
if Prop.Setter = null then
|
|
|
|
|
Setter := null;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Prop.Getter = null then
|
|
|
|
|
Getter := null;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Klass := Lookup_Object (Script.Module, Get_Name (Prop.Class));
|
|
|
|
|
Ignored := PyDescr_NewGetSet
|
|
|
|
|
(Typ => Klass,
|
|
|
|
|
Name => Prop.Name,
|
|
|
|
|
Setter => Setter,
|
|
|
|
|
Getter => Getter,
|
|
|
|
|
Closure => Convert (H));
|
|
|
|
|
end Register_Property;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Register_Command --
|
|
|
|
|
----------------------
|
|
|
|
|
|
2010-11-17 12:06:29 +00:00
|
|
|
overriding procedure Register_Command
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Cmd : Command_Descr_Access)
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
|
|
|
|
H : constant Handler_Data_Access := new Handler_Data'
|
2010-11-17 12:06:29 +00:00
|
|
|
(Cmd => Cmd,
|
|
|
|
|
Script => Python_Scripting (Script));
|
2007-06-11 07:57:59 +00:00
|
|
|
User_Data : constant PyObject := PyCObject_FromVoidPtr
|
|
|
|
|
(H.all'Address, Destroy_Handler_Data'Access);
|
|
|
|
|
Klass : PyObject;
|
|
|
|
|
Def : PyMethodDef;
|
|
|
|
|
begin
|
2010-11-17 12:06:29 +00:00
|
|
|
if Cmd.Class = No_Class then
|
2007-06-11 07:57:59 +00:00
|
|
|
Add_Function
|
|
|
|
|
(Module => Script.Module,
|
2010-11-17 12:06:29 +00:00
|
|
|
Func => Create_Method_Def (Cmd.Command, First_Level'Access),
|
2007-06-11 07:57:59 +00:00
|
|
|
Self => User_Data);
|
|
|
|
|
|
|
|
|
|
else
|
2010-11-17 12:06:29 +00:00
|
|
|
if Cmd.Command = Constructor_Method then
|
2007-06-11 07:57:59 +00:00
|
|
|
Def := Create_Method_Def ("__init__", First_Level'Access);
|
2010-11-17 12:06:29 +00:00
|
|
|
elsif Cmd.Command = Addition_Method then
|
2007-06-11 07:57:59 +00:00
|
|
|
Def := Create_Method_Def ("__add__", First_Level'Access);
|
2010-11-17 12:06:29 +00:00
|
|
|
elsif Cmd.Command = Substraction_Method then
|
2007-06-11 07:57:59 +00:00
|
|
|
Def := Create_Method_Def ("__sub__", First_Level'Access);
|
2010-11-17 12:06:29 +00:00
|
|
|
elsif Cmd.Command = Comparison_Method then
|
2007-06-11 07:57:59 +00:00
|
|
|
Def := Create_Method_Def ("__cmp__", First_Level'Access);
|
2010-11-19 13:01:42 +00:00
|
|
|
elsif Cmd.Command = Equal_Method then
|
|
|
|
|
Def := Create_Method_Def ("__eq__", First_Level'Access);
|
2010-11-17 12:06:29 +00:00
|
|
|
elsif Cmd.Command = Destructor_Method then
|
2007-06-11 07:57:59 +00:00
|
|
|
Def := Create_Method_Def ("__del__", First_Level'Access);
|
|
|
|
|
else
|
2010-11-17 12:06:29 +00:00
|
|
|
Def := Create_Method_Def (Cmd.Command, First_Level'Access);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 12:06:29 +00:00
|
|
|
Klass := Lookup_Object (Script.Module, Get_Name (Cmd.Class));
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2010-11-17 12:06:29 +00:00
|
|
|
if Cmd.Static_Method then
|
2007-06-11 07:57:59 +00:00
|
|
|
Add_Static_Method
|
2010-11-15 14:56:33 +00:00
|
|
|
(Class => Klass, Func => Def, Self => User_Data,
|
|
|
|
|
Module => Script.Module);
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
2010-11-15 14:56:33 +00:00
|
|
|
Add_Method (Class => Klass, Func => Def, Self => User_Data,
|
|
|
|
|
Module => Script.Module);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
end Register_Command;
|
|
|
|
|
|
|
|
|
|
--------------------
|
|
|
|
|
-- Register_Class --
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
procedure Register_Class
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Name : String;
|
|
|
|
|
Base : Class_Type := No_Class)
|
|
|
|
|
is
|
|
|
|
|
Dict : constant PyDictObject := PyDict_New;
|
2010-11-15 14:56:33 +00:00
|
|
|
Class : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
Ignored : Integer;
|
|
|
|
|
Bases : PyObject := null;
|
|
|
|
|
S : Interfaces.C.Strings.chars_ptr;
|
|
|
|
|
pragma Unreferenced (Ignored);
|
|
|
|
|
begin
|
|
|
|
|
PyDict_SetItemString
|
|
|
|
|
(Dict, "__module__",
|
|
|
|
|
PyObject_GetAttrString (Script.Module, "__name__"));
|
|
|
|
|
|
|
|
|
|
if Base /= No_Class then
|
2010-11-15 14:56:33 +00:00
|
|
|
declare
|
|
|
|
|
N : constant String := Get_Name (Base);
|
|
|
|
|
B : PyObject := Lookup_Object (Script.Module, N);
|
|
|
|
|
begin
|
2010-11-15 15:34:25 +00:00
|
|
|
if B = null and then not Base.Exists then
|
2010-11-15 14:56:33 +00:00
|
|
|
B := Lookup_Object (Script.Builtin, N);
|
|
|
|
|
end if;
|
|
|
|
|
Bases := Create_Tuple ((1 => B));
|
|
|
|
|
end;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-15 14:56:33 +00:00
|
|
|
Class := Type_New
|
|
|
|
|
(Name => Name,
|
|
|
|
|
Bases => Bases,
|
|
|
|
|
Dict => Dict);
|
|
|
|
|
if Class = null then
|
|
|
|
|
PyErr_Print;
|
|
|
|
|
raise Program_Error
|
|
|
|
|
with "Could not register class " & Name;
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
S := New_String (Name);
|
|
|
|
|
Ignored := PyModule_AddObject (Script.Module, S, Class);
|
|
|
|
|
Free (S);
|
|
|
|
|
end Register_Class;
|
|
|
|
|
|
|
|
|
|
---------------
|
|
|
|
|
-- Interrupt --
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
function Interrupt
|
|
|
|
|
(Script : access Python_Scripting_Record) return Boolean is
|
|
|
|
|
begin
|
|
|
|
|
if Script.In_Process then
|
|
|
|
|
PyErr_SetInterrupt;
|
|
|
|
|
return True;
|
|
|
|
|
else
|
|
|
|
|
return False;
|
|
|
|
|
end if;
|
|
|
|
|
end Interrupt;
|
|
|
|
|
|
|
|
|
|
--------------
|
|
|
|
|
-- Complete --
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
|
|
procedure Complete
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Input : String;
|
|
|
|
|
Completions : out String_Lists.List)
|
|
|
|
|
is
|
|
|
|
|
Start : Natural := Input'First - 1;
|
|
|
|
|
Last : Natural := Input'Last + 1;
|
|
|
|
|
Obj, Item : PyObject;
|
|
|
|
|
Errors : aliased Boolean;
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
Completions := String_Lists.Empty_List;
|
|
|
|
|
|
|
|
|
|
for N in reverse Input'Range loop
|
|
|
|
|
if Input (N) = ' ' or else Input (N) = ASCII.HT then
|
|
|
|
|
Start := N;
|
|
|
|
|
exit;
|
|
|
|
|
elsif Input (N) = '.' and then Last > Input'Last then
|
|
|
|
|
Last := N;
|
|
|
|
|
end if;
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
|
|
if Start < Input'Last then
|
|
|
|
|
Obj := Run_Command
|
|
|
|
|
(Script,
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Builtins_Name
|
2012-06-19 15:51:12 +00:00
|
|
|
& ".dir(" & Input (Start + 1 .. Last - 1) & ")",
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Need_Output => True,
|
2007-06-11 07:57:59 +00:00
|
|
|
Hide_Output => True,
|
|
|
|
|
Hide_Exceptions => True,
|
|
|
|
|
Errors => Errors'Unchecked_Access);
|
|
|
|
|
|
|
|
|
|
if Obj /= null then
|
|
|
|
|
for Index in 0 .. PyList_Size (Obj) - 1 loop
|
|
|
|
|
Item := PyList_GetItem (Obj, Index);
|
|
|
|
|
|
|
|
|
|
declare
|
|
|
|
|
S : constant String := PyString_AsString (Item);
|
|
|
|
|
begin
|
|
|
|
|
if S'First + Input'Last - Last - 1 <= S'Last
|
|
|
|
|
and then
|
|
|
|
|
(Last >= Input'Last
|
|
|
|
|
or else Input (Last + 1 .. Input'Last)
|
|
|
|
|
= S (S'First .. S'First + Input'Last - Last - 1))
|
|
|
|
|
then
|
|
|
|
|
String_Lists.Append
|
|
|
|
|
(Completions,
|
|
|
|
|
Input (Input'First .. Last - 1) & '.' & S);
|
|
|
|
|
end if;
|
|
|
|
|
end;
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
end Complete;
|
|
|
|
|
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
----------------
|
|
|
|
|
-- Get_Prompt --
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
overriding function Get_Prompt
|
|
|
|
|
(Script : access Python_Scripting_Record) return String
|
|
|
|
|
is
|
|
|
|
|
Ps : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
if Script.Use_Secondary_Prompt then
|
|
|
|
|
Ps := PySys_GetObject ("ps2");
|
|
|
|
|
if Ps = null then
|
|
|
|
|
return "... ";
|
|
|
|
|
end if;
|
|
|
|
|
else
|
|
|
|
|
Ps := PySys_GetObject ("ps1");
|
|
|
|
|
if Ps = null then
|
|
|
|
|
return ">>> ";
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
return PyString_AsString (Ps);
|
|
|
|
|
end Get_Prompt;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
--------------------
|
|
|
|
|
-- Display_Prompt --
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
procedure Display_Prompt
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
Console : Virtual_Console := null) is
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
Insert_Prompt
|
|
|
|
|
(Script, Console, Get_Prompt (Scripting_Language (Script)));
|
2007-06-11 07:57:59 +00:00
|
|
|
end Display_Prompt;
|
|
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
|
-- Run_Command --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
function Run_Command
|
|
|
|
|
(Script : access Python_Scripting_Record'Class;
|
|
|
|
|
Command : String;
|
|
|
|
|
Console : Virtual_Console := null;
|
|
|
|
|
Show_Command : Boolean := False;
|
|
|
|
|
Hide_Output : Boolean := False;
|
|
|
|
|
Hide_Exceptions : Boolean := False;
|
|
|
|
|
Errors : access Boolean) return String
|
|
|
|
|
is
|
|
|
|
|
Result : PyObject;
|
|
|
|
|
Str : PyObject;
|
|
|
|
|
begin
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Result := Run_Command
|
|
|
|
|
(Script, Command,
|
|
|
|
|
Console => Console,
|
|
|
|
|
Need_Output => True,
|
|
|
|
|
Show_Command => Show_Command,
|
|
|
|
|
Hide_Output => Hide_Output,
|
|
|
|
|
Hide_Exceptions => Hide_Exceptions,
|
|
|
|
|
Errors => Errors);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
if Result /= null and then not Errors.all then
|
|
|
|
|
Str := PyObject_Str (Result);
|
2012-06-29 13:25:15 +00:00
|
|
|
if Str = null then
|
|
|
|
|
Py_DECREF (Result);
|
|
|
|
|
return "Error calling __repr__ on the result of the script";
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
declare
|
|
|
|
|
S : constant String := PyString_AsString (Str);
|
|
|
|
|
begin
|
2012-06-29 13:25:15 +00:00
|
|
|
Py_DECREF (Result);
|
2007-06-11 07:57:59 +00:00
|
|
|
Py_DECREF (Str);
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
|
|
|
|
|
if Active (Me_Log) then
|
|
|
|
|
Trace (Me_Log, "output is: " & S);
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
return S;
|
|
|
|
|
end;
|
|
|
|
|
else
|
|
|
|
|
Py_XDECREF (Result);
|
|
|
|
|
return "";
|
|
|
|
|
end if;
|
|
|
|
|
end Run_Command;
|
|
|
|
|
|
2012-06-20 20:42:11 +00:00
|
|
|
--------------------------
|
|
|
|
|
-- Log_Python_Exception --
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
procedure Log_Python_Exception is
|
|
|
|
|
Typ, Occurrence, Traceback, S : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
if Active (Me_Error) then
|
|
|
|
|
PyErr_Fetch (Typ, Occurrence, Traceback);
|
|
|
|
|
PyErr_NormalizeException (Typ, Occurrence, Traceback);
|
|
|
|
|
|
|
|
|
|
S := PyObject_Repr (Occurrence);
|
|
|
|
|
if S /= null then
|
|
|
|
|
Trace (Me_Error, "Exception "& PyString_AsString (S));
|
|
|
|
|
Py_DECREF (S);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
PyErr_Restore (Typ, Occurrence, Traceback);
|
|
|
|
|
end if;
|
|
|
|
|
end Log_Python_Exception;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-----------------
|
|
|
|
|
-- Run_Command --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
function Run_Command
|
|
|
|
|
(Script : access Python_Scripting_Record'Class;
|
|
|
|
|
Command : String;
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Need_Output : Boolean;
|
2007-06-11 07:57:59 +00:00
|
|
|
Console : Virtual_Console := null;
|
|
|
|
|
Show_Command : Boolean := False;
|
|
|
|
|
Hide_Output : Boolean := False;
|
|
|
|
|
Hide_Exceptions : Boolean := False;
|
|
|
|
|
Errors : access Boolean) return PyObject
|
|
|
|
|
is
|
|
|
|
|
Result : PyObject := null;
|
|
|
|
|
Code : PyCodeObject;
|
|
|
|
|
Indented_Input : constant Boolean := Command'Length > 0
|
2012-04-25 19:59:00 +00:00
|
|
|
and then (Command (Command'First) = ASCII.HT
|
|
|
|
|
or else Command (Command'First) = ' ');
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Cmd : constant String := Script.Buffer.all & Command & ASCII.LF;
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Typ, Occurrence, Traceback, S : PyObject;
|
2008-10-21 22:09:20 +00:00
|
|
|
Default_Console_Refed : Boolean := False;
|
2007-06-11 07:57:59 +00:00
|
|
|
Default_Console : constant Virtual_Console :=
|
|
|
|
|
Get_Default_Console (Script);
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
State : Interpreter_State;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
begin
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if Active (Me_Log) then
|
2012-06-20 20:42:11 +00:00
|
|
|
Trace (Me_Log, "command: " & Script.Buffer.all & Command);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Errors.all := False;
|
|
|
|
|
|
2012-06-21 14:40:19 +00:00
|
|
|
if Finalized or else Cmd = "" & ASCII.LF then
|
2012-06-21 08:12:43 +00:00
|
|
|
if not Hide_Output then
|
|
|
|
|
Display_Prompt (Script);
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
return null;
|
|
|
|
|
end if;
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if Show_Command and not Hide_Output then
|
|
|
|
|
Insert_Text (Script, Console, Command & ASCII.LF);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
-- The following code will not work correctly in multitasking mode if
|
|
|
|
|
-- each thread is redirecting to a different console. One might argue
|
|
|
|
|
-- this is up to the user to fix.
|
2007-06-11 07:57:59 +00:00
|
|
|
if Console /= null then
|
|
|
|
|
if Default_Console /= null then
|
2008-10-21 22:09:20 +00:00
|
|
|
Default_Console_Refed := True;
|
2007-06-11 07:57:59 +00:00
|
|
|
Ref (Default_Console);
|
|
|
|
|
end if;
|
|
|
|
|
Set_Default_Console (Script, Console);
|
|
|
|
|
end if;
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
-- If we want to have sys.displayhook called, we should use
|
|
|
|
|
-- <stdin> as the filename, otherwise <string> will ensure this is not
|
|
|
|
|
-- an interactive session.
|
|
|
|
|
-- For interactive code, python generates addition opcode PRINT_EXPR
|
|
|
|
|
-- which will call displayhook.
|
|
|
|
|
--
|
|
|
|
|
-- We cannot use Py_Eval_Input, although it would properly return the
|
|
|
|
|
-- result of evaluating the expression, but it would not support multi
|
|
|
|
|
-- line input, in particular function defintion.
|
|
|
|
|
-- So we need to use Py_Single_Input, but then the result of evaluating
|
|
|
|
|
-- the code is always None.
|
|
|
|
|
|
|
|
|
|
if Need_Output then
|
|
|
|
|
State := Py_Eval_Input;
|
|
|
|
|
else
|
|
|
|
|
State := Py_Single_Input;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if Hide_Output then
|
|
|
|
|
Code := Py_CompileString (Cmd, "<string>", State);
|
|
|
|
|
else
|
|
|
|
|
Code := Py_CompileString (Cmd, "<stdin>", State);
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
-- If code compiled just fine
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
if Code /= null and then not Indented_Input then
|
|
|
|
|
Script.Use_Secondary_Prompt := False;
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Free (Script.Buffer);
|
|
|
|
|
Script.Buffer := new String'("");
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if Get_Default_Console (Script) /= null then
|
|
|
|
|
Grab_Events (Get_Default_Console (Script), True);
|
|
|
|
|
Result := PyEval_EvalCode (Code, Script.Globals, Script.Globals);
|
|
|
|
|
Grab_Events (Get_Default_Console (Script), False);
|
|
|
|
|
else
|
|
|
|
|
Result := PyEval_EvalCode (Code, Script.Globals, Script.Globals);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Py_XDECREF (PyObject (Code));
|
|
|
|
|
|
|
|
|
|
if Result = null then
|
|
|
|
|
if Active (Me_Error) then
|
|
|
|
|
PyErr_Fetch (Typ, Occurrence, Traceback);
|
|
|
|
|
PyErr_NormalizeException (Typ, Occurrence, Traceback);
|
|
|
|
|
S := PyObject_Repr (Occurrence);
|
|
|
|
|
if S /= null then
|
2012-06-20 20:42:11 +00:00
|
|
|
Trace (Me_Error, "Exception "& PyString_AsString (S));
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Py_DECREF (S);
|
2012-06-20 20:42:11 +00:00
|
|
|
else
|
|
|
|
|
Trace
|
|
|
|
|
(Me_Error, "Python raised an exception with no __repr__");
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
-- Do not DECREF Typ, Occurrence or Traceback after this
|
|
|
|
|
PyErr_Restore (Typ, Occurrence, Traceback);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if not Hide_Exceptions then
|
|
|
|
|
PyErr_Print;
|
|
|
|
|
else
|
|
|
|
|
PyErr_Clear;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Errors.all := True;
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-- Do we have compilation error because input was incomplete ?
|
|
|
|
|
|
|
|
|
|
elsif not Hide_Output then
|
|
|
|
|
Script.Use_Secondary_Prompt := Indented_Input;
|
|
|
|
|
|
|
|
|
|
if not Script.Use_Secondary_Prompt then
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if PyErr_Occurred /= null then
|
|
|
|
|
PyErr_Fetch (Typ, Occurrence, Traceback);
|
|
|
|
|
PyErr_NormalizeException (Typ, Occurrence, Traceback);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if PyTuple_Check (Occurrence) then
|
|
|
|
|
-- Old style exceptions
|
|
|
|
|
S := PyTuple_GetItem (Occurrence, 0);
|
|
|
|
|
else
|
|
|
|
|
-- New style: occurrence is an instance
|
|
|
|
|
-- S is null if the exception is not a syntax_error
|
|
|
|
|
S := PyObject_GetAttrString (Occurrence, "msg");
|
|
|
|
|
end if;
|
|
|
|
|
|
2012-06-21 07:59:03 +00:00
|
|
|
PyErr_Restore (Typ, Occurrence, Traceback);
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if S = null then
|
|
|
|
|
Script.Use_Secondary_Prompt := False;
|
|
|
|
|
else
|
|
|
|
|
declare
|
|
|
|
|
Msg : constant String := PyString_AsString (S);
|
|
|
|
|
begin
|
|
|
|
|
Py_DECREF (S);
|
|
|
|
|
|
|
|
|
|
-- Second message appears when typing:
|
|
|
|
|
-- >>> if 1:
|
|
|
|
|
-- ... pass
|
|
|
|
|
-- ... else:
|
|
|
|
|
if Msg = "unexpected EOF while parsing" then
|
|
|
|
|
Script.Use_Secondary_Prompt := Command'Length > 0
|
|
|
|
|
and then Command (Command'Last) = ':';
|
|
|
|
|
|
|
|
|
|
elsif Msg = "expected an indented block" then
|
|
|
|
|
Script.Use_Secondary_Prompt := Command'Length /= 0
|
|
|
|
|
and then Command (Command'Last) /= ASCII.LF;
|
2012-06-21 07:59:03 +00:00
|
|
|
|
|
|
|
|
else
|
|
|
|
|
Log_Python_Exception;
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
end if;
|
|
|
|
|
end;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if not Script.Use_Secondary_Prompt then
|
|
|
|
|
PyErr_Print;
|
|
|
|
|
Errors.all := True;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
PyErr_Clear;
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
PyErr_Clear;
|
|
|
|
|
end if;
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Free (Script.Buffer);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
if Script.Use_Secondary_Prompt then
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Script.Buffer := new String'(Cmd);
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
Script.Buffer := new String'("");
|
|
|
|
|
end if;
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
2012-06-20 20:42:11 +00:00
|
|
|
if Active (Me_Error) then
|
|
|
|
|
PyErr_Fetch (Typ, Occurrence, Traceback);
|
|
|
|
|
PyErr_NormalizeException (Typ, Occurrence, Traceback);
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
|
2012-06-20 20:42:11 +00:00
|
|
|
S := PyObject_Repr (Occurrence);
|
|
|
|
|
if S /= null then
|
|
|
|
|
Trace (Me_Error, "Exception "& PyString_AsString (S));
|
|
|
|
|
Py_DECREF (S);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
PyErr_Restore (Typ, Occurrence, Traceback);
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
PyErr_Print;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if not Hide_Output then
|
2007-06-11 07:57:59 +00:00
|
|
|
Display_Prompt (Script);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Console /= null then
|
|
|
|
|
Set_Default_Console (Script, Default_Console);
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
if Default_Console_Refed then
|
|
|
|
|
Unref (Default_Console);
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
|
|
exception
|
2012-06-20 20:42:11 +00:00
|
|
|
when E : others =>
|
|
|
|
|
Trace (Me_Error, E);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Errors.all := True;
|
|
|
|
|
|
2008-10-21 22:09:20 +00:00
|
|
|
if Default_Console_Refed then
|
|
|
|
|
Unref (Default_Console);
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
return Result;
|
|
|
|
|
end Run_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
procedure Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
2009-11-23 17:31:43 +00:00
|
|
|
CL : Arg_List;
|
2007-06-11 07:57:59 +00:00
|
|
|
Console : Virtual_Console := null;
|
|
|
|
|
Hide_Output : Boolean := False;
|
|
|
|
|
Show_Command : Boolean := True;
|
|
|
|
|
Errors : out Boolean)
|
|
|
|
|
is
|
|
|
|
|
E : aliased Boolean;
|
|
|
|
|
Result : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
if Script.Blocked then
|
|
|
|
|
Errors := True;
|
|
|
|
|
Insert_Error (Script, Console, "A command is already executing");
|
|
|
|
|
else
|
|
|
|
|
Result := Run_Command
|
* aliases_module.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* build_command_manager.adb:
Start replacing command line handling with use of GNATCOLL.Command_Line.
* builder_module.adb:
Do not use a GNAT.OS_Lib.Argument_List to represent a command line.
* commands-builder.adb:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* commands-builder.ads:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* code_peer-module-bridge.adb:
(Add_Audit_Record): Adapt to new profile of Launch_Process.
(Inspection): Ditto.
(Review_Message): Ditto.
* code_peer-shell_commands.adb:
(Build_Target): Adapt to new profile of Execute_GPS_Shell_Command.
(Build_Target_Execute): Ditto.
(Get_Build_Mode): Ditto.
(Set_Build_Mode): Ditto.
* codefix_module.adb:
(Compilation_Finished_Cb): Adapt to new profile of Execute_GPS_Shell_Command.
* custom_module.adb:
(Parse_Entry_Node): Adapt to new profile of Execute_GPS_Shell_Command.
* expect_interface.adb:
(Interactive_Expect): Adapt to new profile of Spawn.
(Custom_Spawn_Handler): Likewise.
* xml_viewer.adb:
(On_Click): Adapt to new profile of Execute_GPS_Shell_Command.
* gnatcoll-command_lines.adb:
Initial revision.
* gnatcoll-command_lines.ads:
Initial revision.
* gnatcoll-scripts-shell.ads:
(Initialize): Remove parameter Arguments_Count, no longer needed.
(Command_Line_Treatment): Declare.
(Execute_Command): Adapt to new profile of parent.
(Execute_Command_With_Args): Likewise.
(Set_Nth_Arg): Likewise.
* gnatcoll-scripts-utils.ads:
Add ??? comment.
* gnatcoll-scripts.adb:
(Command_Line_Treatment): Declare.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts.ads:
(Command_Line_Treatment): Add new subprogram, which enables scripts to specify
how they would like their command line to be handled.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts-python-gtkada.adb:
(Init_PyGtk_Support): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.adb:
(Command_Line_Treatment): Implement.
(Set_Nth_Arg): Adapt to profile of parent.
(Execute_Command): Ditto.
(Execute_File): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.ads:
(Command_Line_Treatment): Declare.
(Execute_Command, Set_Nth_Arg): Adjust to new profiles of abstract parent.
* gps-main.adb:
(Execute_Batch): Adapt to new profile of Execute_Command.
* debugger.adb:
(General_Spawn): Adapt to new profile of Spawn.
* debugger.ads:
Add ??? comment.
* gvd-proc_utils.adb:
(Open_Processes): Adapt to new profile of Spawn.
* gvd-source_editor-gps.adb:
(Highlight_Current_Line): Adapt to new profile of Execute_GPS_Shell_Command.
(Unhighlight_Current_Line): Ditto.
(Initialize): Ditto.
(Free_Debug_Info): Ditto.
* help_module.adb:
(On_Load_HTML): Adapt to new profile of Execute_Command.
* commands-custom.adb:
Rewrite handling of command line. Use type GNATCOLL.Command_Lines.Command_Line.
* gps-kernel-macros.adb:
(Substitute): No need to protect paths.
* gps-kernel-remote.adb:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-remote.ads:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-scripts.adb:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-scripts.ads:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-timeout.adb:
(Free): No longer need to free Args.
(Execute): Ditto. Adapt to new profile for Spawn.
(Launch_Process): Use type Command_Line to represent a command line.
* gps-kernel-timeout.ads:
(Launch_Process): Use type GNATCOLL.Command_Lines.Command_Line to represent a
command line.
* gps-kernel.adb:
(Filter_Matches_Primitive): Adapt to new profile of Execute_Command.
* navigation_module.adb:
(Go_To): Adapt to new profile of Execute_Command.
* project_properties.adb:
(For_Each_Item_In_List): Adapt to new profile of Execute_Command.
* python_module.adb:
(Load_Dir): Adapt to new profile of Execute_Command.
* remote-rsync.adb:
(On_Rsync_Hook): Adapt to new profile of Launch_Process.
* clearcase.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* cvs.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* gnatpp.xml:
Remove unneeded triple quoting.
* subversion.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* shell_script.adb:
(Module_Command_Handler): Adapt to new profile of Execute_GPS_Shell_Command.
(Create): No longer need to take into account Arguments_Count.
Add ??? comment.
* commands-socket.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* casing_exceptions.adb:
(Set_Casing): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_buffer.adb:
(Edition_Timeout): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_module.adb:
(On_Print): Adapt to new profile of Execute_GPS_Shell_Command.
* log_utils.adb:
(Get_ChangeLog_From_File): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs-generic_vcs.adb:
(Parse_Annotations): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_activities_view_api.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_view_api.adb:
(Get_Location): Adapt to new profile of Execute_GPS_Shell_Command.
(On_Menu_Edit_ChangeLog): Ditto.
(On_Menu_View_Log_Rev): Ditto.
(Comparison): Ditto.
* vdiff2_command_block.adb:
(Close_Difference): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-callback.adb:
(Setup_Ref): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-utils-shell_command.adb:
(Add_Line Adapt to new profile of Execute_GPS_Shell_Command.
(Edit, Synchronize_Scrolling, Get_Chars, Get_File_Last_Line,
Get_Line_Number, Highlight_Line, Highlight_Range, Register_Highlighting,
Remove_Blank_Lines, Replace_Text, Unhighlight, Unhighlight_Range): Ditto.
* vdiff2_module-utils.adb:
(Is_Ref_Editor_Opened): Adapt to new profile of Execute_GPS_Shell_Command.
* clipboard_views.adb:
(Button_Press): Adapt to new profile of Execute_GPS_Shell_Command.
* interactive_consoles.adb:
(Default_Command_Handler): Adapt to new profile of Execute_Command.
Change the way GPS handles command lines. Introduce a new type
(GNATCOLL.Command_Lines.Command_Line) and use it in most areas where we
manipulate command lines.
For H926-007.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@152411 936e1b1b-40f2-da11-902a-00137254ae57
2009-11-17 17:51:13 +00:00
|
|
|
(Script, Get_Command (CL),
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Console => Console,
|
|
|
|
|
Need_Output => False,
|
|
|
|
|
Hide_Output => Hide_Output,
|
|
|
|
|
Show_Command => Show_Command,
|
|
|
|
|
Errors => E'Unchecked_Access);
|
2007-06-11 07:57:59 +00:00
|
|
|
Py_XDECREF (Result);
|
|
|
|
|
Errors := E;
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
function Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
2009-11-23 17:31:43 +00:00
|
|
|
CL : Arg_List;
|
2007-06-11 07:57:59 +00:00
|
|
|
Console : Virtual_Console := null;
|
|
|
|
|
Hide_Output : Boolean := False;
|
|
|
|
|
Show_Command : Boolean := True;
|
|
|
|
|
Errors : access Boolean) return String
|
|
|
|
|
is
|
|
|
|
|
pragma Unreferenced (Show_Command);
|
|
|
|
|
begin
|
|
|
|
|
if Script.Blocked then
|
|
|
|
|
Errors.all := True;
|
|
|
|
|
Insert_Error (Script, Console, "A command is already executing");
|
|
|
|
|
return "";
|
|
|
|
|
else
|
|
|
|
|
return Run_Command
|
* aliases_module.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* build_command_manager.adb:
Start replacing command line handling with use of GNATCOLL.Command_Line.
* builder_module.adb:
Do not use a GNAT.OS_Lib.Argument_List to represent a command line.
* commands-builder.adb:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* commands-builder.ads:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* code_peer-module-bridge.adb:
(Add_Audit_Record): Adapt to new profile of Launch_Process.
(Inspection): Ditto.
(Review_Message): Ditto.
* code_peer-shell_commands.adb:
(Build_Target): Adapt to new profile of Execute_GPS_Shell_Command.
(Build_Target_Execute): Ditto.
(Get_Build_Mode): Ditto.
(Set_Build_Mode): Ditto.
* codefix_module.adb:
(Compilation_Finished_Cb): Adapt to new profile of Execute_GPS_Shell_Command.
* custom_module.adb:
(Parse_Entry_Node): Adapt to new profile of Execute_GPS_Shell_Command.
* expect_interface.adb:
(Interactive_Expect): Adapt to new profile of Spawn.
(Custom_Spawn_Handler): Likewise.
* xml_viewer.adb:
(On_Click): Adapt to new profile of Execute_GPS_Shell_Command.
* gnatcoll-command_lines.adb:
Initial revision.
* gnatcoll-command_lines.ads:
Initial revision.
* gnatcoll-scripts-shell.ads:
(Initialize): Remove parameter Arguments_Count, no longer needed.
(Command_Line_Treatment): Declare.
(Execute_Command): Adapt to new profile of parent.
(Execute_Command_With_Args): Likewise.
(Set_Nth_Arg): Likewise.
* gnatcoll-scripts-utils.ads:
Add ??? comment.
* gnatcoll-scripts.adb:
(Command_Line_Treatment): Declare.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts.ads:
(Command_Line_Treatment): Add new subprogram, which enables scripts to specify
how they would like their command line to be handled.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts-python-gtkada.adb:
(Init_PyGtk_Support): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.adb:
(Command_Line_Treatment): Implement.
(Set_Nth_Arg): Adapt to profile of parent.
(Execute_Command): Ditto.
(Execute_File): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.ads:
(Command_Line_Treatment): Declare.
(Execute_Command, Set_Nth_Arg): Adjust to new profiles of abstract parent.
* gps-main.adb:
(Execute_Batch): Adapt to new profile of Execute_Command.
* debugger.adb:
(General_Spawn): Adapt to new profile of Spawn.
* debugger.ads:
Add ??? comment.
* gvd-proc_utils.adb:
(Open_Processes): Adapt to new profile of Spawn.
* gvd-source_editor-gps.adb:
(Highlight_Current_Line): Adapt to new profile of Execute_GPS_Shell_Command.
(Unhighlight_Current_Line): Ditto.
(Initialize): Ditto.
(Free_Debug_Info): Ditto.
* help_module.adb:
(On_Load_HTML): Adapt to new profile of Execute_Command.
* commands-custom.adb:
Rewrite handling of command line. Use type GNATCOLL.Command_Lines.Command_Line.
* gps-kernel-macros.adb:
(Substitute): No need to protect paths.
* gps-kernel-remote.adb:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-remote.ads:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-scripts.adb:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-scripts.ads:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-timeout.adb:
(Free): No longer need to free Args.
(Execute): Ditto. Adapt to new profile for Spawn.
(Launch_Process): Use type Command_Line to represent a command line.
* gps-kernel-timeout.ads:
(Launch_Process): Use type GNATCOLL.Command_Lines.Command_Line to represent a
command line.
* gps-kernel.adb:
(Filter_Matches_Primitive): Adapt to new profile of Execute_Command.
* navigation_module.adb:
(Go_To): Adapt to new profile of Execute_Command.
* project_properties.adb:
(For_Each_Item_In_List): Adapt to new profile of Execute_Command.
* python_module.adb:
(Load_Dir): Adapt to new profile of Execute_Command.
* remote-rsync.adb:
(On_Rsync_Hook): Adapt to new profile of Launch_Process.
* clearcase.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* cvs.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* gnatpp.xml:
Remove unneeded triple quoting.
* subversion.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* shell_script.adb:
(Module_Command_Handler): Adapt to new profile of Execute_GPS_Shell_Command.
(Create): No longer need to take into account Arguments_Count.
Add ??? comment.
* commands-socket.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* casing_exceptions.adb:
(Set_Casing): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_buffer.adb:
(Edition_Timeout): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_module.adb:
(On_Print): Adapt to new profile of Execute_GPS_Shell_Command.
* log_utils.adb:
(Get_ChangeLog_From_File): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs-generic_vcs.adb:
(Parse_Annotations): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_activities_view_api.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_view_api.adb:
(Get_Location): Adapt to new profile of Execute_GPS_Shell_Command.
(On_Menu_Edit_ChangeLog): Ditto.
(On_Menu_View_Log_Rev): Ditto.
(Comparison): Ditto.
* vdiff2_command_block.adb:
(Close_Difference): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-callback.adb:
(Setup_Ref): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-utils-shell_command.adb:
(Add_Line Adapt to new profile of Execute_GPS_Shell_Command.
(Edit, Synchronize_Scrolling, Get_Chars, Get_File_Last_Line,
Get_Line_Number, Highlight_Line, Highlight_Range, Register_Highlighting,
Remove_Blank_Lines, Replace_Text, Unhighlight, Unhighlight_Range): Ditto.
* vdiff2_module-utils.adb:
(Is_Ref_Editor_Opened): Adapt to new profile of Execute_GPS_Shell_Command.
* clipboard_views.adb:
(Button_Press): Adapt to new profile of Execute_GPS_Shell_Command.
* interactive_consoles.adb:
(Default_Command_Handler): Adapt to new profile of Execute_Command.
Change the way GPS handles command lines. Introduce a new type
(GNATCOLL.Command_Lines.Command_Line) and use it in most areas where we
manipulate command lines.
For H926-007.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@152411 936e1b1b-40f2-da11-902a-00137254ae57
2009-11-17 17:51:13 +00:00
|
|
|
(Script, Get_Command (CL),
|
2007-06-11 07:57:59 +00:00
|
|
|
Console => Console,
|
|
|
|
|
Hide_Output => Hide_Output,
|
|
|
|
|
Errors => Errors);
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
function Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
2009-11-23 17:31:43 +00:00
|
|
|
CL : Arg_List;
|
* aliases_module.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* build_command_manager.adb:
Start replacing command line handling with use of GNATCOLL.Command_Line.
* builder_module.adb:
Do not use a GNAT.OS_Lib.Argument_List to represent a command line.
* commands-builder.adb:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* commands-builder.ads:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* code_peer-module-bridge.adb:
(Add_Audit_Record): Adapt to new profile of Launch_Process.
(Inspection): Ditto.
(Review_Message): Ditto.
* code_peer-shell_commands.adb:
(Build_Target): Adapt to new profile of Execute_GPS_Shell_Command.
(Build_Target_Execute): Ditto.
(Get_Build_Mode): Ditto.
(Set_Build_Mode): Ditto.
* codefix_module.adb:
(Compilation_Finished_Cb): Adapt to new profile of Execute_GPS_Shell_Command.
* custom_module.adb:
(Parse_Entry_Node): Adapt to new profile of Execute_GPS_Shell_Command.
* expect_interface.adb:
(Interactive_Expect): Adapt to new profile of Spawn.
(Custom_Spawn_Handler): Likewise.
* xml_viewer.adb:
(On_Click): Adapt to new profile of Execute_GPS_Shell_Command.
* gnatcoll-command_lines.adb:
Initial revision.
* gnatcoll-command_lines.ads:
Initial revision.
* gnatcoll-scripts-shell.ads:
(Initialize): Remove parameter Arguments_Count, no longer needed.
(Command_Line_Treatment): Declare.
(Execute_Command): Adapt to new profile of parent.
(Execute_Command_With_Args): Likewise.
(Set_Nth_Arg): Likewise.
* gnatcoll-scripts-utils.ads:
Add ??? comment.
* gnatcoll-scripts.adb:
(Command_Line_Treatment): Declare.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts.ads:
(Command_Line_Treatment): Add new subprogram, which enables scripts to specify
how they would like their command line to be handled.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts-python-gtkada.adb:
(Init_PyGtk_Support): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.adb:
(Command_Line_Treatment): Implement.
(Set_Nth_Arg): Adapt to profile of parent.
(Execute_Command): Ditto.
(Execute_File): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.ads:
(Command_Line_Treatment): Declare.
(Execute_Command, Set_Nth_Arg): Adjust to new profiles of abstract parent.
* gps-main.adb:
(Execute_Batch): Adapt to new profile of Execute_Command.
* debugger.adb:
(General_Spawn): Adapt to new profile of Spawn.
* debugger.ads:
Add ??? comment.
* gvd-proc_utils.adb:
(Open_Processes): Adapt to new profile of Spawn.
* gvd-source_editor-gps.adb:
(Highlight_Current_Line): Adapt to new profile of Execute_GPS_Shell_Command.
(Unhighlight_Current_Line): Ditto.
(Initialize): Ditto.
(Free_Debug_Info): Ditto.
* help_module.adb:
(On_Load_HTML): Adapt to new profile of Execute_Command.
* commands-custom.adb:
Rewrite handling of command line. Use type GNATCOLL.Command_Lines.Command_Line.
* gps-kernel-macros.adb:
(Substitute): No need to protect paths.
* gps-kernel-remote.adb:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-remote.ads:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-scripts.adb:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-scripts.ads:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-timeout.adb:
(Free): No longer need to free Args.
(Execute): Ditto. Adapt to new profile for Spawn.
(Launch_Process): Use type Command_Line to represent a command line.
* gps-kernel-timeout.ads:
(Launch_Process): Use type GNATCOLL.Command_Lines.Command_Line to represent a
command line.
* gps-kernel.adb:
(Filter_Matches_Primitive): Adapt to new profile of Execute_Command.
* navigation_module.adb:
(Go_To): Adapt to new profile of Execute_Command.
* project_properties.adb:
(For_Each_Item_In_List): Adapt to new profile of Execute_Command.
* python_module.adb:
(Load_Dir): Adapt to new profile of Execute_Command.
* remote-rsync.adb:
(On_Rsync_Hook): Adapt to new profile of Launch_Process.
* clearcase.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* cvs.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* gnatpp.xml:
Remove unneeded triple quoting.
* subversion.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* shell_script.adb:
(Module_Command_Handler): Adapt to new profile of Execute_GPS_Shell_Command.
(Create): No longer need to take into account Arguments_Count.
Add ??? comment.
* commands-socket.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* casing_exceptions.adb:
(Set_Casing): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_buffer.adb:
(Edition_Timeout): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_module.adb:
(On_Print): Adapt to new profile of Execute_GPS_Shell_Command.
* log_utils.adb:
(Get_ChangeLog_From_File): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs-generic_vcs.adb:
(Parse_Annotations): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_activities_view_api.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_view_api.adb:
(Get_Location): Adapt to new profile of Execute_GPS_Shell_Command.
(On_Menu_Edit_ChangeLog): Ditto.
(On_Menu_View_Log_Rev): Ditto.
(Comparison): Ditto.
* vdiff2_command_block.adb:
(Close_Difference): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-callback.adb:
(Setup_Ref): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-utils-shell_command.adb:
(Add_Line Adapt to new profile of Execute_GPS_Shell_Command.
(Edit, Synchronize_Scrolling, Get_Chars, Get_File_Last_Line,
Get_Line_Number, Highlight_Line, Highlight_Range, Register_Highlighting,
Remove_Blank_Lines, Replace_Text, Unhighlight, Unhighlight_Range): Ditto.
* vdiff2_module-utils.adb:
(Is_Ref_Editor_Opened): Adapt to new profile of Execute_GPS_Shell_Command.
* clipboard_views.adb:
(Button_Press): Adapt to new profile of Execute_GPS_Shell_Command.
* interactive_consoles.adb:
(Default_Command_Handler): Adapt to new profile of Execute_Command.
Change the way GPS handles command lines. Introduce a new type
(GNATCOLL.Command_Lines.Command_Line) and use it in most areas where we
manipulate command lines.
For H926-007.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@152411 936e1b1b-40f2-da11-902a-00137254ae57
2009-11-17 17:51:13 +00:00
|
|
|
Console : Virtual_Console := null;
|
2007-06-11 07:57:59 +00:00
|
|
|
Hide_Output : Boolean := False;
|
|
|
|
|
Errors : access Boolean) return Boolean
|
|
|
|
|
is
|
|
|
|
|
Obj : PyObject;
|
|
|
|
|
Result : Boolean;
|
|
|
|
|
begin
|
|
|
|
|
if Script.Blocked then
|
|
|
|
|
Errors.all := True;
|
|
|
|
|
Insert_Error (Script, Console, "A command is already executing");
|
|
|
|
|
return False;
|
|
|
|
|
else
|
|
|
|
|
Obj := Run_Command
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
(Script, Get_Command (CL),
|
|
|
|
|
Need_Output => True,
|
|
|
|
|
Console => Console,
|
|
|
|
|
Hide_Output => Hide_Output,
|
|
|
|
|
Errors => Errors);
|
2007-06-11 07:57:59 +00:00
|
|
|
Result := Obj /= null
|
|
|
|
|
and then ((PyInt_Check (Obj) and then PyInt_AsLong (Obj) = 1)
|
2009-11-18 08:34:44 +00:00
|
|
|
or else (PyBool_Check (Obj) and then PyBool_Is_True (Obj))
|
2007-06-11 07:57:59 +00:00
|
|
|
or else
|
|
|
|
|
(PyString_Check (Obj)
|
2011-06-20 11:12:55 +00:00
|
|
|
and then PyString_AsString (Obj) = "true")
|
|
|
|
|
or else
|
|
|
|
|
(PyUnicode_Check (Obj)
|
|
|
|
|
and then Unicode_AsString (Obj) = "true"));
|
2007-06-11 07:57:59 +00:00
|
|
|
Py_XDECREF (Obj);
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
function Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Command : String;
|
|
|
|
|
Args : Callback_Data'Class) return Boolean
|
|
|
|
|
is
|
|
|
|
|
Obj : PyObject;
|
|
|
|
|
Errors : aliased Boolean;
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
if Script.Blocked then
|
|
|
|
|
return False;
|
|
|
|
|
else
|
|
|
|
|
Obj := Run_Command
|
|
|
|
|
(Script,
|
|
|
|
|
Command => Command,
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Need_Output => True,
|
2007-06-11 07:57:59 +00:00
|
|
|
Console => null,
|
|
|
|
|
Errors => Errors'Unchecked_Access);
|
|
|
|
|
|
|
|
|
|
if Obj /= null and then PyFunction_Check (Obj) then
|
2011-02-02 08:09:03 +00:00
|
|
|
return Execute_Command (Script, Obj, Args, Errors'Access);
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
return False;
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
function Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record'Class;
|
|
|
|
|
Command : PyObject;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
|
|
|
|
Error : access Boolean) return PyObject
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
|
|
|
|
Obj : PyObject;
|
2012-03-23 15:59:32 +00:00
|
|
|
Old, Args2, Item : PyObject;
|
|
|
|
|
Size : Integer;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
begin
|
2011-02-02 08:09:03 +00:00
|
|
|
Error.all := False;
|
|
|
|
|
|
2012-06-20 20:42:11 +00:00
|
|
|
if Command = null then
|
|
|
|
|
Trace (Me_Error, "Trying to execute 'null'");
|
|
|
|
|
return null;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Active (Me_Log) then
|
|
|
|
|
Obj := PyObject_Repr (Command);
|
|
|
|
|
if Obj /= null then
|
|
|
|
|
Trace (Me_Log, "Execute " & PyString_AsString (Obj));
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
if Script.Blocked then
|
2011-02-02 08:09:03 +00:00
|
|
|
Error.all := True;
|
2012-06-19 15:51:12 +00:00
|
|
|
Trace (Me_Error, "A python command is already executing");
|
2007-06-11 07:57:59 +00:00
|
|
|
return null;
|
|
|
|
|
end if;
|
|
|
|
|
|
2012-03-23 15:59:32 +00:00
|
|
|
-- If we are calling a bound method whose self is the same as the
|
|
|
|
|
-- first parameter in Args, we remove the first parameter to avoid
|
|
|
|
|
-- a duplicate. This allows registering callbacks as:
|
|
|
|
|
-- class MyClass(object):
|
|
|
|
|
-- def my_callback(self, arg1):
|
|
|
|
|
-- pass
|
|
|
|
|
-- def __init__(self):
|
|
|
|
|
-- register_callback(self, self.my_callback)
|
|
|
|
|
-- register_callback(self, MyClass.my_callback)
|
|
|
|
|
-- If Ada calls the registered callback by passing the instance as
|
|
|
|
|
-- the first parameter in the Callback_Data, both the calls above
|
|
|
|
|
-- have the same effect when we remove the duplication. Otherwise,
|
|
|
|
|
-- the first one will result in an error since my_callback will be
|
|
|
|
|
-- called with three arguments (self, self, arg1).
|
|
|
|
|
-- Note that the second call does not provide dynamic dispatching when
|
|
|
|
|
-- MyClass is subclassed and my_callback overridden.
|
|
|
|
|
|
|
|
|
|
Old := Python_Callback_Data (Args).Args;
|
|
|
|
|
Size := PyTuple_Size (Old);
|
|
|
|
|
|
|
|
|
|
if PyMethod_Check (Command)
|
|
|
|
|
and then PyMethod_Self (Command) /= null
|
|
|
|
|
and then Size > 0
|
|
|
|
|
and then PyMethod_Self (Command) = PyTuple_GetItem (Old, 0)
|
|
|
|
|
then
|
|
|
|
|
if Size = 1 then
|
|
|
|
|
Args2 := Py_None;
|
|
|
|
|
Py_INCREF (Args2);
|
|
|
|
|
else
|
|
|
|
|
Args2 := PyTuple_New (Size => Size - 1);
|
|
|
|
|
for T in 1 .. Size - 1 loop -- Remove arg 0
|
|
|
|
|
Item := PyTuple_GetItem (Old, T); -- same refcount
|
|
|
|
|
Py_INCREF (Item);
|
|
|
|
|
PyTuple_SetItem (Args2, T - 1, Item); -- same refcount
|
|
|
|
|
end loop;
|
|
|
|
|
end if;
|
|
|
|
|
else
|
|
|
|
|
Args2 := Old;
|
|
|
|
|
Py_INCREF (Args2);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Obj := PyObject_Call (Command, Args2, Python_Callback_Data (Args).Kw);
|
|
|
|
|
Py_DECREF (Args2);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
if Obj = null then
|
2011-02-02 08:09:03 +00:00
|
|
|
Error.all := True;
|
2012-06-20 20:42:11 +00:00
|
|
|
Trace (Me_Error, "Calling object raised an exception");
|
|
|
|
|
Log_Python_Exception;
|
2007-06-11 07:57:59 +00:00
|
|
|
PyErr_Print;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
return Obj;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
function Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record'Class;
|
|
|
|
|
Command : PyObject;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
|
|
|
|
Error : access Boolean) return String
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
2011-02-02 08:09:03 +00:00
|
|
|
Obj : constant PyObject :=
|
|
|
|
|
Execute_Command (Script, Command, Args, Error);
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
if Obj /= null
|
|
|
|
|
and then PyString_Check (Obj)
|
|
|
|
|
then
|
|
|
|
|
declare
|
|
|
|
|
Str : constant String := PyString_AsString (Obj);
|
|
|
|
|
begin
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return Str;
|
|
|
|
|
end;
|
2011-06-20 11:12:55 +00:00
|
|
|
|
|
|
|
|
elsif Obj /= null
|
|
|
|
|
and then PyUnicode_Check (Obj)
|
|
|
|
|
then
|
|
|
|
|
declare
|
|
|
|
|
Str : constant String := Unicode_AsString (Obj, "utf-8");
|
|
|
|
|
begin
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return Str;
|
|
|
|
|
end;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
if Obj /= null then
|
|
|
|
|
Py_DECREF (Obj);
|
2011-02-02 08:09:03 +00:00
|
|
|
else
|
|
|
|
|
Error.all := True;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
return "";
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
function Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record'Class;
|
|
|
|
|
Command : PyObject;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
|
|
|
|
Error : access Boolean) return Any_Type
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
is
|
2011-02-02 08:09:03 +00:00
|
|
|
Obj : constant PyObject :=
|
|
|
|
|
Execute_Command (Script, Command, Args, Error);
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
begin
|
|
|
|
|
if Obj /= null then
|
|
|
|
|
declare
|
2009-05-26 22:12:26 +00:00
|
|
|
Any : constant Any_Type :=
|
|
|
|
|
GNATCOLL.Any_Types.Python.From_PyObject (Obj);
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
begin
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return Any;
|
|
|
|
|
end;
|
|
|
|
|
else
|
|
|
|
|
return Empty_Any_Type;
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
function Execute_Command
|
|
|
|
|
(Script : access Python_Scripting_Record'Class;
|
|
|
|
|
Command : PyObject;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
|
|
|
|
Error : access Boolean) return Boolean
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
2011-02-02 08:09:03 +00:00
|
|
|
Obj : constant PyObject :=
|
|
|
|
|
Execute_Command (Script, Command, Args, Error);
|
2007-06-11 07:57:59 +00:00
|
|
|
Result : Boolean;
|
|
|
|
|
begin
|
|
|
|
|
if Obj = null then
|
|
|
|
|
return False;
|
|
|
|
|
else
|
|
|
|
|
Result := ((PyInt_Check (Obj) and then PyInt_AsLong (Obj) = 1)
|
2009-11-18 08:34:44 +00:00
|
|
|
or else (PyBool_Check (Obj) and then PyBool_Is_True (Obj))
|
2007-06-11 07:57:59 +00:00
|
|
|
or else
|
2011-06-20 11:12:55 +00:00
|
|
|
(PyString_Check (Obj)
|
|
|
|
|
and then PyString_AsString (Obj) = "true")
|
|
|
|
|
or else
|
|
|
|
|
(PyUnicode_Check (Obj)
|
|
|
|
|
and then Unicode_AsString (Obj) = "true"));
|
2007-06-11 07:57:59 +00:00
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Execute_File --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
procedure Execute_File
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Filename : String;
|
* aliases_module.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* build_command_manager.adb:
Start replacing command line handling with use of GNATCOLL.Command_Line.
* builder_module.adb:
Do not use a GNAT.OS_Lib.Argument_List to represent a command line.
* commands-builder.adb:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* commands-builder.ads:
(Launch_Build_Command): Use type GNATCOLL.Command_Lines.Command_Line.
* code_peer-module-bridge.adb:
(Add_Audit_Record): Adapt to new profile of Launch_Process.
(Inspection): Ditto.
(Review_Message): Ditto.
* code_peer-shell_commands.adb:
(Build_Target): Adapt to new profile of Execute_GPS_Shell_Command.
(Build_Target_Execute): Ditto.
(Get_Build_Mode): Ditto.
(Set_Build_Mode): Ditto.
* codefix_module.adb:
(Compilation_Finished_Cb): Adapt to new profile of Execute_GPS_Shell_Command.
* custom_module.adb:
(Parse_Entry_Node): Adapt to new profile of Execute_GPS_Shell_Command.
* expect_interface.adb:
(Interactive_Expect): Adapt to new profile of Spawn.
(Custom_Spawn_Handler): Likewise.
* xml_viewer.adb:
(On_Click): Adapt to new profile of Execute_GPS_Shell_Command.
* gnatcoll-command_lines.adb:
Initial revision.
* gnatcoll-command_lines.ads:
Initial revision.
* gnatcoll-scripts-shell.ads:
(Initialize): Remove parameter Arguments_Count, no longer needed.
(Command_Line_Treatment): Declare.
(Execute_Command): Adapt to new profile of parent.
(Execute_Command_With_Args): Likewise.
(Set_Nth_Arg): Likewise.
* gnatcoll-scripts-utils.ads:
Add ??? comment.
* gnatcoll-scripts.adb:
(Command_Line_Treatment): Declare.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts.ads:
(Command_Line_Treatment): Add new subprogram, which enables scripts to specify
how they would like their command line to be handled.
(Set_Nth_Arg): Adapt to new parameters of parent.
(Execute_Command): Likewise.
(Execute_Command_With_Args): Likewise.
* gnatcoll-scripts-python-gtkada.adb:
(Init_PyGtk_Support): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.adb:
(Command_Line_Treatment): Implement.
(Set_Nth_Arg): Adapt to profile of parent.
(Execute_Command): Ditto.
(Execute_File): Adapt to new profile of Execute_Command.
* gnatcoll-scripts-python.ads:
(Command_Line_Treatment): Declare.
(Execute_Command, Set_Nth_Arg): Adjust to new profiles of abstract parent.
* gps-main.adb:
(Execute_Batch): Adapt to new profile of Execute_Command.
* debugger.adb:
(General_Spawn): Adapt to new profile of Spawn.
* debugger.ads:
Add ??? comment.
* gvd-proc_utils.adb:
(Open_Processes): Adapt to new profile of Spawn.
* gvd-source_editor-gps.adb:
(Highlight_Current_Line): Adapt to new profile of Execute_GPS_Shell_Command.
(Unhighlight_Current_Line): Ditto.
(Initialize): Ditto.
(Free_Debug_Info): Ditto.
* help_module.adb:
(On_Load_HTML): Adapt to new profile of Execute_Command.
* commands-custom.adb:
Rewrite handling of command line. Use type GNATCOLL.Command_Lines.Command_Line.
* gps-kernel-macros.adb:
(Substitute): No need to protect paths.
* gps-kernel-remote.adb:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-remote.ads:
(Spawn): Use type Command_Line rather than GNAT.OS_Lib.Argument_List to
represent command lines.
* gps-kernel-scripts.adb:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-scripts.ads:
(Execute_GPS_Shell_Command): Remove versions based on String + GNAT.OS_Lib.
Argument_List. Replace all by use of type Command_Line.
(Set_Nth_Arg): Adjust mode of Callback_Data.
* gps-kernel-timeout.adb:
(Free): No longer need to free Args.
(Execute): Ditto. Adapt to new profile for Spawn.
(Launch_Process): Use type Command_Line to represent a command line.
* gps-kernel-timeout.ads:
(Launch_Process): Use type GNATCOLL.Command_Lines.Command_Line to represent a
command line.
* gps-kernel.adb:
(Filter_Matches_Primitive): Adapt to new profile of Execute_Command.
* navigation_module.adb:
(Go_To): Adapt to new profile of Execute_Command.
* project_properties.adb:
(For_Each_Item_In_List): Adapt to new profile of Execute_Command.
* python_module.adb:
(Load_Dir): Adapt to new profile of Execute_Command.
* remote-rsync.adb:
(On_Rsync_Hook): Adapt to new profile of Launch_Process.
* clearcase.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* cvs.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* gnatpp.xml:
Remove unneeded triple quoting.
* subversion.xml:
Conform to the command line API design: parameters such as "$2-" and "$*" need
to not be surrounded by quotes, so that they expand into multiple arguments.
* shell_script.adb:
(Module_Command_Handler): Adapt to new profile of Execute_GPS_Shell_Command.
(Create): No longer need to take into account Arguments_Count.
Add ??? comment.
* commands-socket.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* casing_exceptions.adb:
(Set_Casing): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_buffer.adb:
(Edition_Timeout): Adapt to new profile of Execute_GPS_Shell_Command.
* src_editor_module.adb:
(On_Print): Adapt to new profile of Execute_GPS_Shell_Command.
* log_utils.adb:
(Get_ChangeLog_From_File): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs-generic_vcs.adb:
(Parse_Annotations): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_activities_view_api.adb:
(Execute): Adapt to new profile of Execute_GPS_Shell_Command.
* vcs_view_api.adb:
(Get_Location): Adapt to new profile of Execute_GPS_Shell_Command.
(On_Menu_Edit_ChangeLog): Ditto.
(On_Menu_View_Log_Rev): Ditto.
(Comparison): Ditto.
* vdiff2_command_block.adb:
(Close_Difference): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-callback.adb:
(Setup_Ref): Adapt to new profile of Execute_GPS_Shell_Command.
* vdiff2_module-utils-shell_command.adb:
(Add_Line Adapt to new profile of Execute_GPS_Shell_Command.
(Edit, Synchronize_Scrolling, Get_Chars, Get_File_Last_Line,
Get_Line_Number, Highlight_Line, Highlight_Range, Register_Highlighting,
Remove_Blank_Lines, Replace_Text, Unhighlight, Unhighlight_Range): Ditto.
* vdiff2_module-utils.adb:
(Is_Ref_Editor_Opened): Adapt to new profile of Execute_GPS_Shell_Command.
* clipboard_views.adb:
(Button_Press): Adapt to new profile of Execute_GPS_Shell_Command.
* interactive_consoles.adb:
(Default_Command_Handler): Adapt to new profile of Execute_Command.
Change the way GPS handles command lines. Introduce a new type
(GNATCOLL.Command_Lines.Command_Line) and use it in most areas where we
manipulate command lines.
For H926-007.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@152411 936e1b1b-40f2-da11-902a-00137254ae57
2009-11-17 17:51:13 +00:00
|
|
|
Console : Virtual_Console := null;
|
2007-06-11 07:57:59 +00:00
|
|
|
Hide_Output : Boolean := False;
|
|
|
|
|
Show_Command : Boolean := True;
|
|
|
|
|
Errors : out Boolean) is
|
|
|
|
|
begin
|
|
|
|
|
Script.Current_File := To_Unbounded_String (Filename);
|
2012-06-21 14:40:19 +00:00
|
|
|
|
|
|
|
|
-- The call to compile is only necessary to get an error message
|
|
|
|
|
-- pointing back to Filename
|
|
|
|
|
|
2012-06-21 15:28:33 +00:00
|
|
|
if Is_Python3 then
|
|
|
|
|
Execute_Command
|
|
|
|
|
(Script, Create ("exec(compile(open(r'" & Filename
|
|
|
|
|
& "').read(),r'" & Filename & "','exec'))"),
|
|
|
|
|
Console, Hide_Output, Show_Command, Errors);
|
|
|
|
|
else
|
|
|
|
|
Execute_Command
|
|
|
|
|
(Script, Create ("execfile(r'" & Filename & "')"),
|
|
|
|
|
Console, Hide_Output, Show_Command, Errors);
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Script.Current_File := Null_Unbounded_String;
|
|
|
|
|
end Execute_File;
|
|
|
|
|
|
|
|
|
|
--------------
|
|
|
|
|
-- Get_Name --
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
|
|
function Get_Name (Script : access Python_Scripting_Record) return String is
|
|
|
|
|
pragma Unreferenced (Script);
|
|
|
|
|
begin
|
|
|
|
|
return Python_Name;
|
|
|
|
|
end Get_Name;
|
|
|
|
|
|
|
|
|
|
----------------
|
|
|
|
|
-- Get_Script --
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
function Get_Script (Data : Python_Callback_Data)
|
|
|
|
|
return Scripting_Language
|
|
|
|
|
is
|
|
|
|
|
begin
|
|
|
|
|
return Scripting_Language (Data.Script);
|
|
|
|
|
end Get_Script;
|
|
|
|
|
|
|
|
|
|
--------------------
|
|
|
|
|
-- Get_Repository --
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
function Get_Repository (Script : access Python_Scripting_Record)
|
|
|
|
|
return Scripts_Repository is
|
|
|
|
|
begin
|
|
|
|
|
return Script.Repo;
|
|
|
|
|
end Get_Repository;
|
|
|
|
|
|
|
|
|
|
--------------------
|
|
|
|
|
-- Current_Script --
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
function Current_Script
|
|
|
|
|
(Script : access Python_Scripting_Record) return String
|
|
|
|
|
is
|
|
|
|
|
begin
|
|
|
|
|
if Script.Current_File = Null_Unbounded_String then
|
|
|
|
|
return "<python script>";
|
|
|
|
|
else
|
|
|
|
|
return To_String (Script.Current_File);
|
|
|
|
|
end if;
|
|
|
|
|
end Current_Script;
|
|
|
|
|
|
|
|
|
|
-------------------------
|
|
|
|
|
-- Number_Of_Arguments --
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
function Number_Of_Arguments (Data : Python_Callback_Data) return Natural is
|
|
|
|
|
begin
|
|
|
|
|
if Data.Kw /= null then
|
2010-11-15 17:33:14 +00:00
|
|
|
return PyDict_Size (Data.Kw) + PyObject_Size (Data.Args);
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
2010-11-15 17:33:14 +00:00
|
|
|
return PyObject_Size (Data.Args);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end Number_Of_Arguments;
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
|
-- Name_Parameters --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
procedure Name_Parameters
|
2010-11-17 13:28:17 +00:00
|
|
|
(Data : in out Python_Callback_Data; Params : Param_Array)
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
2010-11-17 10:00:16 +00:00
|
|
|
First : Integer := 0;
|
|
|
|
|
Old_Args : constant PyObject := Data.Args;
|
|
|
|
|
Item : PyObject;
|
|
|
|
|
Nargs : Natural := 0; -- Number of entries in Data.Args
|
|
|
|
|
Nkeywords : Integer; -- Number of unhandled entries in Data.Kw
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
if Data.Kw = null then
|
|
|
|
|
return;
|
|
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 10:00:16 +00:00
|
|
|
Nkeywords := PyDict_Size (Data.Kw);
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
if Data.Args /= null then
|
2010-11-17 10:00:16 +00:00
|
|
|
Nargs := PyObject_Size (Data.Args);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 10:00:16 +00:00
|
|
|
-- Modify Data.Args in place, so we need to resize it appropriately.
|
|
|
|
|
-- Then, through a single loop, we fill it.
|
|
|
|
|
|
|
|
|
|
if Data.First_Arg_Is_Self then
|
|
|
|
|
First := 1;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
Data.Args := PyTuple_New (Params'Length + First);
|
2010-11-17 10:00:16 +00:00
|
|
|
if First > 0 then
|
|
|
|
|
-- Copy "self"
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2010-11-17 10:00:16 +00:00
|
|
|
if Old_Args /= null then
|
|
|
|
|
Item := PyObject_GetItem (Old_Args, 0);
|
2010-11-24 13:39:54 +00:00
|
|
|
Py_DECREF (Item);
|
2010-11-17 10:00:16 +00:00
|
|
|
else
|
|
|
|
|
Item := PyDict_GetItemString (Data.Kw, "self");
|
|
|
|
|
if Item = null then
|
|
|
|
|
First := 0; -- Unbound method ?
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 10:00:16 +00:00
|
|
|
if Item /= null then
|
|
|
|
|
PyTuple_SetItem (Data.Args, 0, Item);
|
|
|
|
|
Py_INCREF (Item);
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
for N in Params'Range loop
|
2010-11-17 10:00:16 +00:00
|
|
|
-- Do we have a corresponding keyword parameter ?
|
2010-11-17 13:28:17 +00:00
|
|
|
Item := PyDict_GetItemString (Data.Kw, Params (N).Name.all);
|
2010-11-17 10:00:16 +00:00
|
|
|
|
|
|
|
|
if Item /= null then
|
|
|
|
|
Nkeywords := Nkeywords - 1;
|
|
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
if N - Params'First + First < Nargs then
|
2010-11-17 10:00:16 +00:00
|
|
|
Set_Error_Msg
|
|
|
|
|
(Data, "Parameter cannot be both positional ("
|
2010-11-17 13:28:17 +00:00
|
|
|
& Image (N - Params'First + 1 + First, 0) & Nargs'Img
|
|
|
|
|
& Params'First'Img
|
|
|
|
|
& ") and named: " & Params (N).Name.all);
|
2010-11-17 10:00:16 +00:00
|
|
|
Py_DECREF (Old_Args);
|
|
|
|
|
raise Invalid_Parameter;
|
|
|
|
|
end if;
|
|
|
|
|
|
2010-11-24 13:39:54 +00:00
|
|
|
Py_INCREF (Item);
|
|
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
elsif N - Params'First + First < Nargs then
|
|
|
|
|
Item := PyObject_GetItem (Old_Args, N - Params'First + First);
|
2010-11-17 10:00:16 +00:00
|
|
|
|
|
|
|
|
else
|
|
|
|
|
Item := Py_None;
|
2010-11-24 13:39:54 +00:00
|
|
|
Py_INCREF (Item);
|
2010-11-17 10:00:16 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
PyTuple_SetItem (Data.Args, N - Params'First + First, Item);
|
2007-06-11 07:57:59 +00:00
|
|
|
end loop;
|
2010-11-17 10:00:16 +00:00
|
|
|
|
|
|
|
|
Py_DECREF (Old_Args);
|
|
|
|
|
|
|
|
|
|
-- Are there unused keyword arguments ?
|
|
|
|
|
|
|
|
|
|
if Nkeywords > 0 then
|
|
|
|
|
declare
|
|
|
|
|
Pos : Integer := 0;
|
|
|
|
|
Key, Value : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
loop
|
|
|
|
|
PyDict_Next (Data.Kw, Pos, Key, Value);
|
|
|
|
|
exit when Pos = 1;
|
|
|
|
|
|
|
|
|
|
declare
|
|
|
|
|
K : constant String := PyString_AsString (Key);
|
|
|
|
|
Found : Boolean := False;
|
|
|
|
|
begin
|
2010-11-17 13:28:17 +00:00
|
|
|
for N in Params'Range loop
|
|
|
|
|
if Params (N).Name.all = K then
|
2010-11-17 10:00:16 +00:00
|
|
|
Found := True;
|
|
|
|
|
exit;
|
|
|
|
|
end if;
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
|
|
if not Found then
|
|
|
|
|
Set_Error_Msg (Data, "Invalid keyword parameter: " & K);
|
|
|
|
|
raise Invalid_Parameter;
|
|
|
|
|
end if;
|
|
|
|
|
end;
|
|
|
|
|
end loop;
|
|
|
|
|
end;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
-- Get rid of the old arguments
|
|
|
|
|
|
|
|
|
|
Py_DECREF (Data.Kw);
|
|
|
|
|
Data.Kw := null;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Name_Parameters;
|
|
|
|
|
|
2010-11-17 13:28:17 +00:00
|
|
|
---------------------
|
|
|
|
|
-- Name_Parameters --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
procedure Name_Parameters
|
|
|
|
|
(Data : in out Python_Callback_Data; Names : Cst_Argument_List)
|
|
|
|
|
is
|
2010-11-24 13:39:54 +00:00
|
|
|
function Convert is new Ada.Unchecked_Conversion
|
|
|
|
|
(Cst_String_Access, GNAT.Strings.String_Access);
|
2010-11-17 13:28:17 +00:00
|
|
|
Params : Param_Array (Names'Range);
|
|
|
|
|
begin
|
|
|
|
|
for N in Names'Range loop
|
2010-11-24 13:39:54 +00:00
|
|
|
-- The conversion here is safe: Name_Parameters does not modify the
|
|
|
|
|
-- string, nor does it try to free it
|
|
|
|
|
Params (N) := (Name => Convert (Names (N)),
|
2010-11-17 13:28:17 +00:00
|
|
|
Optional => True);
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
|
|
Name_Parameters (Data, Params);
|
|
|
|
|
end Name_Parameters;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
---------------
|
|
|
|
|
-- Get_Param --
|
|
|
|
|
---------------
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
function Get_Param
|
|
|
|
|
(Data : Python_Callback_Data'Class; N : Positive)
|
2007-06-11 07:57:59 +00:00
|
|
|
return PyObject
|
|
|
|
|
is
|
|
|
|
|
Obj : PyObject := null;
|
|
|
|
|
begin
|
2010-11-17 10:00:16 +00:00
|
|
|
if Data.Args /= null and then N <= PyObject_Size (Data.Args) then
|
2010-11-15 17:33:14 +00:00
|
|
|
Obj := PyObject_GetItem (Data.Args, N - 1);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 10:00:16 +00:00
|
|
|
if Obj = null and then Data.Kw /= null then
|
|
|
|
|
-- We haven't called Name_Parameters
|
|
|
|
|
PyErr_SetString
|
|
|
|
|
(Data.Script.Exception_Misc, "Keyword parameters not supported");
|
|
|
|
|
raise Invalid_Parameter;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Obj = null or else Obj = Py_None then
|
2007-06-11 07:57:59 +00:00
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
end if;
|
2010-11-24 13:39:54 +00:00
|
|
|
|
|
|
|
|
Py_DECREF (Obj); -- Return a borrowed reference
|
2007-06-11 07:57:59 +00:00
|
|
|
return Obj;
|
|
|
|
|
end Get_Param;
|
|
|
|
|
|
2010-11-24 13:39:54 +00:00
|
|
|
---------------
|
|
|
|
|
-- Get_Param --
|
|
|
|
|
---------------
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
procedure Get_Param
|
|
|
|
|
(Data : Python_Callback_Data'Class;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Result : out PyObject;
|
|
|
|
|
Success : out Boolean)
|
|
|
|
|
is
|
|
|
|
|
begin
|
2010-11-17 10:00:16 +00:00
|
|
|
Result := null;
|
|
|
|
|
|
|
|
|
|
if Data.Args /= null and then N <= PyObject_Size (Data.Args) then
|
2010-11-15 17:33:14 +00:00
|
|
|
Result := PyObject_GetItem (Data.Args, N - 1);
|
2010-11-24 13:39:54 +00:00
|
|
|
Py_DECREF (Result); -- We want to return a borrowed reference
|
2007-09-04 14:01:06 +00:00
|
|
|
end if;
|
|
|
|
|
|
2010-11-17 10:00:16 +00:00
|
|
|
if Result = null and then Data.Kw /= null then
|
|
|
|
|
-- We haven't called Name_Parameters
|
|
|
|
|
PyErr_SetString
|
|
|
|
|
(Data.Script.Exception_Misc, "Keyword parameters not supported");
|
|
|
|
|
raise Invalid_Parameter;
|
2007-09-04 14:01:06 +00:00
|
|
|
end if;
|
2010-11-17 10:00:16 +00:00
|
|
|
|
|
|
|
|
Success := Result /= null and then Result /= Py_None;
|
2007-09-04 14:01:06 +00:00
|
|
|
end Get_Param;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2010-11-15 17:33:14 +00:00
|
|
|
overriding function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive)
|
|
|
|
|
return List_Instance'Class
|
|
|
|
|
is
|
|
|
|
|
Item : PyObject;
|
|
|
|
|
Success : Boolean;
|
|
|
|
|
List : Python_Callback_Data;
|
|
|
|
|
Iter : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
List.Script := Data.Script;
|
2010-11-17 10:00:16 +00:00
|
|
|
List.First_Arg_Is_Self := False;
|
2010-11-15 17:33:14 +00:00
|
|
|
|
|
|
|
|
Get_Param (Data, N, Item, Success);
|
|
|
|
|
if not Success then
|
|
|
|
|
List.Args := PyTuple_New (0); -- An empty list
|
|
|
|
|
else
|
|
|
|
|
Iter := PyObject_GetIter (Item);
|
|
|
|
|
if Iter = null then
|
|
|
|
|
Raise_Exception
|
|
|
|
|
(Invalid_Parameter'Identity,
|
|
|
|
|
"Parameter" & Integer'Image (N) & " should be iterable");
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (Iter);
|
2013-08-06 12:36:46 +00:00
|
|
|
List.Args := Item; -- Item is a borrowed reference ?
|
|
|
|
|
Py_INCREF (Item); -- so we just increase the refcount
|
2010-11-15 17:33:14 +00:00
|
|
|
end if;
|
|
|
|
|
return List;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Success : access Boolean)
|
|
|
|
|
return String
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
2007-09-04 14:01:06 +00:00
|
|
|
Item : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2007-09-04 14:01:06 +00:00
|
|
|
Get_Param (Data, N, Item, Success.all);
|
|
|
|
|
|
|
|
|
|
if not Success.all then
|
|
|
|
|
return "";
|
|
|
|
|
end if;
|
|
|
|
|
|
2011-06-20 11:12:55 +00:00
|
|
|
if PyString_Check (Item) then
|
|
|
|
|
return PyString_AsString (Item);
|
|
|
|
|
elsif PyUnicode_Check (Item) then
|
|
|
|
|
return Unicode_AsString (Item, "utf-8");
|
|
|
|
|
else
|
2007-06-11 07:57:59 +00:00
|
|
|
Raise_Exception
|
|
|
|
|
(Invalid_Parameter'Identity,
|
2011-06-20 11:12:55 +00:00
|
|
|
"Parameter"
|
|
|
|
|
& Integer'Image (N) & " should be a string or unicode");
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2010-12-11 10:30:40 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Success : access Boolean)
|
|
|
|
|
return Unbounded_String
|
|
|
|
|
is
|
|
|
|
|
Item : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
Get_Param (Data, N, Item, Success.all);
|
|
|
|
|
|
|
|
|
|
if not Success.all then
|
|
|
|
|
return Null_Unbounded_String;
|
|
|
|
|
end if;
|
|
|
|
|
|
2011-06-20 11:12:55 +00:00
|
|
|
return To_Unbounded_String (String'(Nth_Arg (Data, N, Success)));
|
2010-12-11 10:30:40 +00:00
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Success : access Boolean)
|
2007-06-11 07:57:59 +00:00
|
|
|
return Integer
|
|
|
|
|
is
|
2007-09-04 14:01:06 +00:00
|
|
|
Item : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2007-09-04 14:01:06 +00:00
|
|
|
Get_Param
|
|
|
|
|
(Data, N, Item, Success.all);
|
|
|
|
|
|
|
|
|
|
if not Success.all then
|
|
|
|
|
return 0;
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
if not PyInt_Check (Item) then
|
|
|
|
|
Raise_Exception
|
|
|
|
|
(Invalid_Parameter'Identity,
|
|
|
|
|
"Parameter" & Integer'Image (N) & " should be an integer");
|
|
|
|
|
else
|
|
|
|
|
return Integer (PyInt_AsLong (Item));
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2012-09-05 07:50:30 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Success : access Boolean)
|
|
|
|
|
return Float
|
|
|
|
|
is
|
|
|
|
|
Item : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
Get_Param
|
|
|
|
|
(Data, N, Item, Success.all);
|
|
|
|
|
|
|
|
|
|
if not Success.all then
|
|
|
|
|
return 0.0;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if not PyFloat_Check (Item) then
|
|
|
|
|
Raise_Exception
|
|
|
|
|
(Invalid_Parameter'Identity,
|
|
|
|
|
"Parameter" & Integer'Image (N) & " should be a float");
|
|
|
|
|
else
|
|
|
|
|
return Float (PyFloat_AsDouble (Item));
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
function Nth_Arg
|
2007-09-04 14:01:06 +00:00
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return Boolean
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
2007-09-04 14:01:06 +00:00
|
|
|
Item : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2007-09-04 14:01:06 +00:00
|
|
|
Get_Param (Data, N, Item, Success.all);
|
|
|
|
|
|
|
|
|
|
if not Success.all then
|
|
|
|
|
return False;
|
|
|
|
|
end if;
|
|
|
|
|
|
2011-03-22 14:50:49 +00:00
|
|
|
-- For backward compatibility, accept these as "False" values.
|
2011-06-20 11:12:55 +00:00
|
|
|
-- Don't check for unicode here, which was never supported anyway.
|
2011-03-22 14:50:49 +00:00
|
|
|
|
|
|
|
|
if PyString_Check (Item)
|
|
|
|
|
and then (To_Lower (PyString_AsString (Item)) = "false"
|
|
|
|
|
or else PyString_AsString (Item) = "0")
|
|
|
|
|
then
|
|
|
|
|
Insert_Text
|
|
|
|
|
(Get_Script (Data), null,
|
|
|
|
|
"Warning: using string 'false' instead of"
|
|
|
|
|
& " boolean False is obsolescent");
|
|
|
|
|
return False;
|
|
|
|
|
else
|
|
|
|
|
-- Use standard python behavior
|
|
|
|
|
return PyObject_IsTrue (Item);
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Success : access Boolean) return Subprogram_Type
|
|
|
|
|
is
|
|
|
|
|
Item : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
Get_Param (Data, N, Item, Success.all);
|
|
|
|
|
|
|
|
|
|
if not Success.all then
|
|
|
|
|
return null;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Item /= null
|
|
|
|
|
and then (PyFunction_Check (Item) or else PyMethod_Check (Item))
|
|
|
|
|
then
|
|
|
|
|
Py_INCREF (Item);
|
|
|
|
|
return new Python_Subprogram_Record'
|
|
|
|
|
(Subprogram_Record with
|
|
|
|
|
Script => Python_Scripting (Get_Script (Data)),
|
|
|
|
|
Subprogram => Item);
|
|
|
|
|
else
|
|
|
|
|
raise Invalid_Parameter;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Class : Class_Type;
|
2007-09-04 14:01:06 +00:00
|
|
|
Allow_Null : Boolean; Success : access Boolean)
|
2007-06-11 07:57:59 +00:00
|
|
|
return Class_Instance
|
|
|
|
|
is
|
|
|
|
|
Item : PyObject;
|
|
|
|
|
C : PyObject;
|
|
|
|
|
Item_Class : PyObject;
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
if Class /= Any_Class then
|
2010-11-15 14:56:33 +00:00
|
|
|
C := Lookup_Object (Data.Script.Module, Get_Name (Class));
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
Get_Param (Data, N, Item, Success.all); -- Item is a borrowed reference
|
|
|
|
|
|
|
|
|
|
if not Success.all then
|
|
|
|
|
return No_Class_Instance;
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2010-11-15 14:56:33 +00:00
|
|
|
if Class /= Any_Class
|
|
|
|
|
and then not PyObject_IsInstance (Item, C)
|
|
|
|
|
then
|
|
|
|
|
Raise_Exception
|
|
|
|
|
(Invalid_Parameter'Identity,
|
|
|
|
|
"Parameter" & Integer'Image (N) & " should be an instance of "
|
|
|
|
|
& Get_Name (Class));
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Item_Class := PyObject_GetAttrString (Item, "__class__");
|
|
|
|
|
-- Item_Class must be DECREF'd
|
|
|
|
|
|
|
|
|
|
if Item_Class = null then
|
|
|
|
|
Raise_Exception
|
|
|
|
|
(Invalid_Parameter'Identity,
|
|
|
|
|
"Parameter" & Integer'Image (N) & " should be an instance of "
|
|
|
|
|
& Get_Name (Class) & " but has no __class__");
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (Item_Class);
|
|
|
|
|
return Get_CI (Python_Scripting (Get_Script (Data)), Item);
|
|
|
|
|
|
|
|
|
|
exception
|
|
|
|
|
when No_Such_Parameter =>
|
|
|
|
|
if Allow_Null then
|
|
|
|
|
return No_Class_Instance;
|
|
|
|
|
else
|
|
|
|
|
raise;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive) return String
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant String := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2010-12-11 10:30:40 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive) return Unbounded_String
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Unbounded_String := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive) return Integer
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Integer := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2012-09-05 07:50:30 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive) return Float
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Float := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-09-04 14:01:06 +00:00
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive) return Boolean
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Boolean := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive) return Subprogram_Type
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Subprogram_Type := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Class : Class_Type;
|
|
|
|
|
Allow_Null : Boolean := False)
|
|
|
|
|
return Class_Instance
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Class_Instance :=
|
|
|
|
|
Nth_Arg (Data, N, Class, Allow_Null, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
if Allow_Null then
|
|
|
|
|
return No_Class_Instance;
|
|
|
|
|
else
|
|
|
|
|
raise No_Such_Parameter;
|
|
|
|
|
end if;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Default : String)
|
|
|
|
|
return String
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant String := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
return Default;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Default : Integer)
|
|
|
|
|
return Integer
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Integer := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
return Default;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data; N : Positive; Default : Boolean)
|
|
|
|
|
return Boolean
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Boolean := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
return Default;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Class : Class_Type := Any_Class;
|
|
|
|
|
Default : Class_Instance;
|
|
|
|
|
Allow_Null : Boolean := False) return Class_Instance
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Class_Instance :=
|
|
|
|
|
Nth_Arg (Data, N, Class, Allow_Null, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
return Default;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Nth_Arg --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function Nth_Arg
|
|
|
|
|
(Data : Python_Callback_Data;
|
|
|
|
|
N : Positive;
|
|
|
|
|
Default : Subprogram_Type) return Subprogram_Type
|
|
|
|
|
is
|
|
|
|
|
Success : aliased Boolean;
|
|
|
|
|
Result : constant Subprogram_Type := Nth_Arg (Data, N, Success'Access);
|
|
|
|
|
begin
|
|
|
|
|
if not Success then
|
|
|
|
|
return Default;
|
|
|
|
|
else
|
|
|
|
|
return Result;
|
|
|
|
|
end if;
|
|
|
|
|
end Nth_Arg;
|
|
|
|
|
|
2013-09-02 15:12:08 +00:00
|
|
|
------------
|
|
|
|
|
-- Incref --
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
overriding procedure Incref
|
|
|
|
|
(Inst : not null access Python_Class_Instance_Record) is
|
|
|
|
|
begin
|
|
|
|
|
if Inst.Data /= null and then not Finalized then
|
|
|
|
|
Py_INCREF (Inst.Data);
|
|
|
|
|
end if;
|
|
|
|
|
end Incref;
|
|
|
|
|
|
|
|
|
|
------------
|
|
|
|
|
-- Decref --
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
overriding procedure Decref
|
|
|
|
|
(Inst : not null access Python_Class_Instance_Record) is
|
|
|
|
|
begin
|
|
|
|
|
if Inst.Data /= null and then not Finalized then
|
|
|
|
|
Py_DECREF (Inst.Data);
|
|
|
|
|
end if;
|
|
|
|
|
end Decref;
|
|
|
|
|
|
|
|
|
|
-------------------
|
|
|
|
|
-- Get_User_Data --
|
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
|
|
overriding function Get_User_Data
|
|
|
|
|
(Inst : not null access Python_Class_Instance_Record)
|
|
|
|
|
return access User_Data_List
|
|
|
|
|
is
|
|
|
|
|
Item : constant PyObject :=
|
|
|
|
|
PyObject_GetAttrString (Inst.Data, "__gps_data");
|
|
|
|
|
Data : PyObject;
|
|
|
|
|
Tmp : PyObject_Data;
|
|
|
|
|
Tmp_Addr : System.Address;
|
|
|
|
|
begin
|
|
|
|
|
if Item = null then
|
|
|
|
|
PyErr_Clear; -- error about "no such attribute"
|
|
|
|
|
|
|
|
|
|
Tmp := new PyObject_Data_Record;
|
|
|
|
|
Data := PyCObject_FromVoidPtr
|
|
|
|
|
(Tmp.all'Address, On_PyObject_Data_Destroy'Access);
|
|
|
|
|
if PyObject_GenericSetAttrString (Inst.Data, "__gps_data", Data) /=
|
|
|
|
|
0
|
|
|
|
|
then
|
|
|
|
|
Trace (Me, "Error creating __gps_data");
|
|
|
|
|
PyErr_Clear;
|
|
|
|
|
Py_DECREF (Data);
|
|
|
|
|
Unchecked_Free (Tmp);
|
|
|
|
|
return null;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (Data);
|
|
|
|
|
|
|
|
|
|
return Tmp.Props'Access;
|
|
|
|
|
else
|
|
|
|
|
Tmp_Addr := PyCObject_AsVoidPtr (Item);
|
|
|
|
|
Tmp := Convert (Tmp_Addr);
|
|
|
|
|
Py_DECREF (Item);
|
|
|
|
|
return Tmp.Props'Access;
|
|
|
|
|
end if;
|
|
|
|
|
end Get_User_Data;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
------------------------------
|
|
|
|
|
-- On_PyObject_Data_Destroy --
|
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
|
|
procedure On_PyObject_Data_Destroy (Data : System.Address) is
|
2013-09-02 15:12:08 +00:00
|
|
|
D : constant PyObject_Data := Convert (Data);
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2013-09-02 15:12:08 +00:00
|
|
|
Free_User_Data_List (D.Props);
|
2007-06-11 07:57:59 +00:00
|
|
|
end On_PyObject_Data_Destroy;
|
|
|
|
|
|
2007-06-12 20:03:42 +00:00
|
|
|
---------------------------------
|
|
|
|
|
-- Unregister_Python_Scripting --
|
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
|
|
procedure Unregister_Python_Scripting
|
2010-11-12 11:54:55 +00:00
|
|
|
(Repo : access Scripts.Scripts_Repository_Record'Class)
|
2007-06-12 20:03:42 +00:00
|
|
|
is
|
|
|
|
|
Script : constant Scripting_Language := Lookup_Scripting_Language
|
|
|
|
|
(Repo, Python_Name);
|
|
|
|
|
begin
|
|
|
|
|
if Script /= null then
|
2009-12-01 11:43:59 +00:00
|
|
|
Destroy (Script);
|
2007-06-12 20:03:42 +00:00
|
|
|
end if;
|
|
|
|
|
end Unregister_Python_Scripting;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
------------
|
|
|
|
|
-- Get_CI --
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
function Get_CI
|
|
|
|
|
(Script : Python_Scripting; Object : PyObject) return Class_Instance
|
|
|
|
|
is
|
|
|
|
|
CI : Python_Class_Instance;
|
2013-08-08 13:18:11 +00:00
|
|
|
Result : Class_Instance := No_Class_Instance;
|
2013-09-02 15:12:08 +00:00
|
|
|
Old_Refcount : Natural := Natural'Last;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2013-09-02 15:12:08 +00:00
|
|
|
if Active (Me) then
|
|
|
|
|
Old_Refcount := Get_Refcount (Object);
|
|
|
|
|
end if;
|
2013-08-08 13:18:11 +00:00
|
|
|
|
2013-09-02 15:12:08 +00:00
|
|
|
PyErr_Clear;
|
|
|
|
|
-- If there was no instance, avoid a python exception later
|
2007-06-11 07:57:59 +00:00
|
|
|
|
2013-09-02 15:12:08 +00:00
|
|
|
CI := new Python_Class_Instance_Record;
|
|
|
|
|
CI.Data := Object; -- adopts the object
|
|
|
|
|
Py_INCREF (Object); -- the class_instance needs to own one ref
|
2013-08-08 13:18:11 +00:00
|
|
|
|
2013-09-02 15:12:08 +00:00
|
|
|
Result := From_Instance (Script, CI);
|
2010-11-19 16:03:39 +00:00
|
|
|
|
2013-09-02 15:12:08 +00:00
|
|
|
if Active (Me) then
|
|
|
|
|
Assert (Me,
|
|
|
|
|
Get_Refcount (Object) = Old_Refcount + 1,
|
|
|
|
|
"Get_CI should own a reference,"
|
|
|
|
|
& Print_Refcount (Get_CIR (Result)) & " !="
|
|
|
|
|
& Integer'Image (Old_Refcount + 1),
|
2013-08-08 13:18:11 +00:00
|
|
|
Raise_Exception => False);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
2013-08-08 13:18:11 +00:00
|
|
|
|
|
|
|
|
return Result;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Get_CI;
|
|
|
|
|
|
2012-01-17 12:07:00 +00:00
|
|
|
------------------
|
|
|
|
|
-- Get_PyObject --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
function Get_PyObject (Instance : Class_Instance) return PyObject is
|
|
|
|
|
begin
|
|
|
|
|
return Python_Class_Instance (Get_CIR (Instance)).Data;
|
|
|
|
|
end Get_PyObject;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
-----------------
|
|
|
|
|
-- Is_Subclass --
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
function Is_Subclass
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
2007-06-12 20:03:42 +00:00
|
|
|
Base : String) return Boolean
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
2010-11-19 16:03:39 +00:00
|
|
|
C, B : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2010-11-19 16:03:39 +00:00
|
|
|
if Instance.Data = null then
|
|
|
|
|
raise Program_Error;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
C := PyObject_GetAttrString (Instance.Data, "__class__");
|
|
|
|
|
B := Lookup_Object (Python_Scripting (Instance.Script).Module, Base);
|
2012-06-19 15:51:12 +00:00
|
|
|
return Py_IsSubclass (C, Base => B);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Is_Subclass;
|
|
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
|
-- Setup_Return_Value --
|
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
procedure Setup_Return_Value (Data : in out Python_Callback_Data'Class) is
|
|
|
|
|
begin
|
2010-11-18 13:25:46 +00:00
|
|
|
Py_XDECREF (Data.Return_Value);
|
2007-06-11 07:57:59 +00:00
|
|
|
Data.Has_Return_Value := True;
|
2011-05-11 09:26:12 +00:00
|
|
|
Data.Return_As_List := False;
|
2007-06-11 07:57:59 +00:00
|
|
|
Data.Return_Value := null;
|
|
|
|
|
end Setup_Return_Value;
|
|
|
|
|
|
|
|
|
|
-------------------
|
|
|
|
|
-- Set_Error_Msg --
|
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Error_Msg
|
|
|
|
|
(Data : in out Python_Callback_Data; Msg : String) is
|
|
|
|
|
begin
|
|
|
|
|
Setup_Return_Value (Data);
|
|
|
|
|
if Msg /= "" then
|
|
|
|
|
PyErr_SetString (Data.Script.Exception_Misc, Msg);
|
|
|
|
|
end if;
|
|
|
|
|
end Set_Error_Msg;
|
|
|
|
|
|
|
|
|
|
-----------------------
|
|
|
|
|
-- Prepare_Value_Key --
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
procedure Prepare_Value_Key
|
|
|
|
|
(Data : in out Python_Callback_Data'Class;
|
|
|
|
|
Key : PyObject;
|
|
|
|
|
Append : Boolean)
|
|
|
|
|
is
|
|
|
|
|
Obj, List : PyObject;
|
|
|
|
|
Tmp : Integer;
|
|
|
|
|
pragma Unreferenced (Tmp);
|
2007-09-26 14:16:56 +00:00
|
|
|
Created_List : Boolean := False;
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
if Data.Return_Dict = null then
|
|
|
|
|
Data.Return_Dict := PyDict_New;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Append then
|
|
|
|
|
Obj := PyDict_GetItem (Data.Return_Dict, Key);
|
|
|
|
|
|
|
|
|
|
if Obj /= null then
|
|
|
|
|
if PyList_Check (Obj) then
|
|
|
|
|
List := Obj;
|
|
|
|
|
else
|
|
|
|
|
List := PyList_New;
|
|
|
|
|
Tmp := PyList_Append (List, Obj);
|
2007-09-26 14:16:56 +00:00
|
|
|
Created_List := True;
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Tmp := PyList_Append (List, Data.Return_Value);
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
List := Data.Return_Value;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
List := Data.Return_Value;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Tmp := PyDict_SetItem (Data.Return_Dict, Key, List);
|
|
|
|
|
|
2007-09-26 14:16:56 +00:00
|
|
|
if Created_List then
|
|
|
|
|
Py_DECREF (List);
|
|
|
|
|
-- The only reference is now owned by the dictionary
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
-- Return_Value was either added to the value or directly to the
|
|
|
|
|
-- dictionary. In both cases, its refcount was increased by one.
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Py_DECREF (Data.Return_Value);
|
|
|
|
|
Data.Return_Value := Py_None;
|
|
|
|
|
Py_INCREF (Data.Return_Value);
|
2011-05-09 14:21:32 +00:00
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
Data.Return_As_List := False;
|
|
|
|
|
end Prepare_Value_Key;
|
|
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
|
-- Set_Return_Value_Key --
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value_Key
|
|
|
|
|
(Data : in out Python_Callback_Data;
|
|
|
|
|
Key : Integer;
|
|
|
|
|
Append : Boolean := False)
|
|
|
|
|
is
|
|
|
|
|
K : constant PyObject := PyInt_FromLong (long (Key));
|
|
|
|
|
begin
|
|
|
|
|
Prepare_Value_Key (Data, K, Append);
|
|
|
|
|
Py_DECREF (K);
|
|
|
|
|
end Set_Return_Value_Key;
|
|
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
|
-- Set_Return_Value_Key --
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value_Key
|
|
|
|
|
(Data : in out Python_Callback_Data;
|
|
|
|
|
Key : String;
|
|
|
|
|
Append : Boolean := False)
|
|
|
|
|
is
|
|
|
|
|
K : constant PyObject := PyString_FromString (Key);
|
|
|
|
|
begin
|
|
|
|
|
Prepare_Value_Key (Data, K, Append);
|
|
|
|
|
Py_DECREF (K);
|
|
|
|
|
end Set_Return_Value_Key;
|
|
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
|
-- Set_Return_Value_Key --
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value_Key
|
|
|
|
|
(Data : in out Python_Callback_Data;
|
|
|
|
|
Key : Class_Instance;
|
2009-01-28 03:39:19 +00:00
|
|
|
Append : Boolean := False)
|
|
|
|
|
is
|
|
|
|
|
K : constant PyObject := Python_Class_Instance (Get_CIR (Key)).Data;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2009-01-28 03:39:19 +00:00
|
|
|
Prepare_Value_Key (Data, K, Append);
|
|
|
|
|
|
|
|
|
|
-- Do not decrease the reference counting here (even though the key has
|
|
|
|
|
-- now one more reference owned by Data.Return_Dict), since a
|
|
|
|
|
-- Class_Instance is refcounted as well, and will automatically decrease
|
|
|
|
|
-- the reference counting when no longer in use
|
|
|
|
|
-- Py_DECREF (K);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Return_Value_Key;
|
|
|
|
|
|
|
|
|
|
------------------------------
|
|
|
|
|
-- Set_Return_Value_As_List --
|
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value_As_List
|
2010-11-15 15:51:10 +00:00
|
|
|
(Data : in out Python_Callback_Data;
|
|
|
|
|
Size : Natural := 0;
|
|
|
|
|
Class : Class_Type := No_Class)
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
|
|
|
|
pragma Unreferenced (Size);
|
|
|
|
|
begin
|
|
|
|
|
Setup_Return_Value (Data);
|
|
|
|
|
Data.Return_As_List := True;
|
|
|
|
|
Data.Has_Return_Value := True;
|
2010-11-15 15:51:10 +00:00
|
|
|
|
|
|
|
|
if Class = No_Class then
|
|
|
|
|
Data.Return_Value := PyList_New;
|
|
|
|
|
else
|
|
|
|
|
declare
|
|
|
|
|
C : constant Class_Instance := New_Instance (Data.Script, Class);
|
|
|
|
|
begin
|
|
|
|
|
if C = No_Class_Instance then
|
|
|
|
|
raise Program_Error;
|
|
|
|
|
end if;
|
|
|
|
|
Data.Return_Value := Python_Class_Instance (Get_CIR (C)).Data;
|
|
|
|
|
Py_INCREF (Data.Return_Value);
|
|
|
|
|
end;
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Return_Value_As_List;
|
|
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Set_Return_Value --
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value
|
2012-01-17 12:07:00 +00:00
|
|
|
(Data : in out Python_Callback_Data; Value : PyObject)
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
|
|
|
|
Num : Integer;
|
|
|
|
|
pragma Unreferenced (Num);
|
|
|
|
|
begin
|
|
|
|
|
if Data.Return_As_List then
|
2012-01-17 12:07:00 +00:00
|
|
|
Num := PyList_Append (Data.Return_Value, Value);
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
Setup_Return_Value (Data);
|
2012-01-17 12:07:00 +00:00
|
|
|
Data.Return_Value := Value;
|
|
|
|
|
Py_INCREF (Value);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end Set_Return_Value;
|
|
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Set_Return_Value --
|
|
|
|
|
----------------------
|
|
|
|
|
|
2012-01-17 12:07:00 +00:00
|
|
|
procedure Set_Return_Value
|
|
|
|
|
(Data : in out Python_Callback_Data; Value : Integer)
|
|
|
|
|
is
|
|
|
|
|
Val : constant PyObject := PyInt_FromLong (long (Value));
|
|
|
|
|
begin
|
|
|
|
|
Set_Return_Value (Data, Val);
|
|
|
|
|
Py_DECREF (Val);
|
|
|
|
|
end Set_Return_Value;
|
|
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Set_Return_Value --
|
|
|
|
|
----------------------
|
|
|
|
|
|
2012-09-05 07:50:30 +00:00
|
|
|
procedure Set_Return_Value
|
|
|
|
|
(Data : in out Python_Callback_Data; Value : Float)
|
|
|
|
|
is
|
|
|
|
|
Val : constant PyObject := PyFloat_FromDouble (double (Value));
|
|
|
|
|
begin
|
|
|
|
|
Set_Return_Value (Data, Val);
|
|
|
|
|
Py_DECREF (Val);
|
|
|
|
|
end Set_Return_Value;
|
|
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Set_Return_Value --
|
|
|
|
|
----------------------
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
procedure Set_Return_Value
|
|
|
|
|
(Data : in out Python_Callback_Data; Value : String)
|
|
|
|
|
is
|
2012-01-17 12:07:00 +00:00
|
|
|
Val : constant PyObject := PyString_FromString (Value);
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2012-01-17 12:07:00 +00:00
|
|
|
Set_Return_Value (Data, Val);
|
|
|
|
|
Py_DECREF (Val);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Return_Value;
|
|
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Set_Return_Value --
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value
|
2011-05-09 14:21:32 +00:00
|
|
|
(Data : in out Python_Callback_Data; Value : Boolean)
|
|
|
|
|
is
|
2012-01-17 12:07:00 +00:00
|
|
|
Val : constant PyObject := PyBool_FromBoolean (Value);
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
2012-01-17 12:07:00 +00:00
|
|
|
Set_Return_Value (Data, Val);
|
|
|
|
|
Py_DECREF (Val);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Set_Return_Value;
|
|
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
|
-- Set_Return_Value --
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value
|
|
|
|
|
(Data : in out Python_Callback_Data; Value : Class_Instance)
|
|
|
|
|
is
|
|
|
|
|
V : constant Python_Class_Instance :=
|
|
|
|
|
Python_Class_Instance (Get_CIR (Value));
|
|
|
|
|
Obj : PyObject;
|
|
|
|
|
Num : Integer;
|
|
|
|
|
pragma Unreferenced (Num);
|
|
|
|
|
begin
|
|
|
|
|
if V /= null then
|
|
|
|
|
Obj := V.Data;
|
2013-08-08 13:18:11 +00:00
|
|
|
if Active (Me) then
|
|
|
|
|
Assert (Me, V.Data /= null, "A Class_Instance has no PyObject");
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
Obj := Py_None;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
if Data.Return_As_List then
|
2011-05-09 14:21:32 +00:00
|
|
|
Num := PyList_Append (Data.Return_Value, Obj); -- Increase refcount
|
2011-05-11 09:46:39 +00:00
|
|
|
-- Py_DECREF (Obj); -- The reference to Object is adopted by the result
|
2007-06-11 07:57:59 +00:00
|
|
|
else
|
|
|
|
|
Setup_Return_Value (Data);
|
|
|
|
|
Data.Return_Value := Obj;
|
2013-09-02 15:12:08 +00:00
|
|
|
Py_INCREF (Obj);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end Set_Return_Value;
|
|
|
|
|
|
2010-11-16 13:13:47 +00:00
|
|
|
----------------------
|
|
|
|
|
-- Set_Return_Value --
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Return_Value
|
|
|
|
|
(Data : in out Python_Callback_Data; Value : List_Instance)
|
|
|
|
|
is
|
|
|
|
|
V : constant PyObject := Python_Callback_Data (Value).Args;
|
|
|
|
|
Num : Integer;
|
|
|
|
|
pragma Unreferenced (Num);
|
|
|
|
|
begin
|
|
|
|
|
if Data.Return_As_List then
|
2011-05-09 14:21:32 +00:00
|
|
|
Num := PyList_Append (Data.Return_Value, V); -- Increase refcount
|
2010-11-16 13:13:47 +00:00
|
|
|
else
|
|
|
|
|
Py_INCREF (V);
|
|
|
|
|
Setup_Return_Value (Data);
|
|
|
|
|
Data.Return_Value := V;
|
|
|
|
|
end if;
|
|
|
|
|
end Set_Return_Value;
|
|
|
|
|
|
|
|
|
|
--------------
|
|
|
|
|
-- New_List --
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
|
|
overriding function New_List
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Class : Class_Type := No_Class)
|
|
|
|
|
return List_Instance'Class
|
|
|
|
|
is
|
|
|
|
|
List : Python_Callback_Data;
|
|
|
|
|
begin
|
|
|
|
|
List.Script := Python_Scripting (Script);
|
2010-11-17 10:00:16 +00:00
|
|
|
List.First_Arg_Is_Self := False;
|
2010-11-16 13:13:47 +00:00
|
|
|
|
|
|
|
|
if Class = No_Class then
|
|
|
|
|
List.Args := PyList_New;
|
|
|
|
|
else
|
|
|
|
|
declare
|
|
|
|
|
C : constant Class_Instance := New_Instance (Script, Class);
|
|
|
|
|
begin
|
|
|
|
|
if C = No_Class_Instance then
|
|
|
|
|
raise Program_Error;
|
|
|
|
|
end if;
|
|
|
|
|
List.Args := Python_Class_Instance (Get_CIR (C)).Data;
|
|
|
|
|
Py_INCREF (List.Args);
|
|
|
|
|
end;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
return List;
|
|
|
|
|
end New_List;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
------------------
|
|
|
|
|
-- New_Instance --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
function New_Instance
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Class : Class_Type) return Class_Instance
|
|
|
|
|
is
|
2010-11-15 14:56:33 +00:00
|
|
|
Klass : constant PyObject := Lookup_Object
|
2007-06-11 07:57:59 +00:00
|
|
|
(Script.Module, Get_Name (Class));
|
|
|
|
|
Inst : Class_Instance;
|
2009-01-28 03:39:19 +00:00
|
|
|
Obj : PyObject;
|
2010-11-15 14:56:33 +00:00
|
|
|
Args : PyObject;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
if Klass = null then
|
|
|
|
|
return No_Class_Instance;
|
|
|
|
|
end if;
|
|
|
|
|
|
2010-11-15 14:56:33 +00:00
|
|
|
-- Creating a new instance is equivalent to calling its metaclass. This
|
|
|
|
|
-- is true for both new-style classes and old-style classes (for which
|
|
|
|
|
-- the tp_call slot is set to PyInstance_New.
|
|
|
|
|
-- Here, we are in fact calling Class.__new__ (cls, *args, **kwargs).
|
|
|
|
|
-- After allocating memory, this in turns automatically tp_init in the
|
|
|
|
|
-- type definition, which in the case of GNATCOLL cases is often set to
|
|
|
|
|
-- slot_tp_init. The latter in turn calls __init__
|
|
|
|
|
--
|
|
|
|
|
-- ??? This API does not permit passing extra parameters to the call
|
|
|
|
|
|
|
|
|
|
Args := PyTuple_New (0);
|
2010-11-17 08:13:52 +00:00
|
|
|
Script.Ignore_Constructor := True;
|
2010-11-15 14:56:33 +00:00
|
|
|
Obj := PyObject_Call
|
|
|
|
|
(Object => Klass,
|
|
|
|
|
Args => Args,
|
|
|
|
|
Kw => null); -- NOT: Py_None, which is not a valid dictionary
|
2010-11-17 08:13:52 +00:00
|
|
|
Script.Ignore_Constructor := False;
|
2010-11-15 14:56:33 +00:00
|
|
|
Py_DECREF (Args);
|
|
|
|
|
|
|
|
|
|
if Obj = null then
|
|
|
|
|
if Active (Me) then
|
|
|
|
|
Trace (Me, "Could not create instance");
|
|
|
|
|
PyErr_Print; -- debugging only
|
|
|
|
|
end if;
|
|
|
|
|
return No_Class_Instance;
|
|
|
|
|
end if;
|
|
|
|
|
|
2013-08-08 13:18:11 +00:00
|
|
|
if Active (Me) then
|
|
|
|
|
Assert
|
|
|
|
|
(Me, Get_Refcount (Obj) = 1,
|
|
|
|
|
"Object's refcount should be 1, got "
|
|
|
|
|
& Get_Refcount (Obj)'Img,
|
|
|
|
|
Raise_Exception => False);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Inst := Get_CI (Python_Scripting (Script), Obj); -- increases refcount
|
|
|
|
|
Py_DECREF (Obj);
|
2007-06-11 07:57:59 +00:00
|
|
|
|
|
|
|
|
-- The PyObject should have a single reference in the end, owned by
|
|
|
|
|
-- the class instance itself.
|
|
|
|
|
|
2013-08-08 13:18:11 +00:00
|
|
|
if Active (Me) then
|
|
|
|
|
Assert
|
|
|
|
|
(Me,
|
|
|
|
|
Get_Refcount (Python_Class_Instance (Get_CIR (Inst)).Data) = 1,
|
|
|
|
|
"New_Instance should own a single refcount of PyObject, got "
|
|
|
|
|
& Print_Refcount (Get_CIR (Inst)),
|
|
|
|
|
Raise_Exception => False);
|
|
|
|
|
end if;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
return Inst;
|
2010-11-15 14:56:33 +00:00
|
|
|
|
|
|
|
|
exception
|
|
|
|
|
when others =>
|
2010-11-17 08:13:52 +00:00
|
|
|
Script.Ignore_Constructor := False;
|
2010-11-15 14:56:33 +00:00
|
|
|
raise;
|
2007-06-11 07:57:59 +00:00
|
|
|
end New_Instance;
|
|
|
|
|
|
2010-12-04 09:32:07 +00:00
|
|
|
----------------
|
|
|
|
|
-- Get_Method --
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
overriding function Get_Method
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String) return Subprogram_Type
|
|
|
|
|
is
|
|
|
|
|
Inst : constant PyObject := Instance.Data;
|
|
|
|
|
Subp : constant PyObject := PyObject_GetAttrString (Inst, Name => Name);
|
|
|
|
|
begin
|
2012-01-17 12:07:00 +00:00
|
|
|
if Subp = null then
|
|
|
|
|
return null;
|
|
|
|
|
else
|
|
|
|
|
return new Python_Subprogram_Record'
|
|
|
|
|
(Script => Python_Scripting (Instance.Script),
|
|
|
|
|
Subprogram => Subp);
|
|
|
|
|
end if;
|
2010-12-04 09:32:07 +00:00
|
|
|
end Get_Method;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
--------------------
|
|
|
|
|
-- Print_Refcount --
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
function Print_Refcount
|
|
|
|
|
(Instance : access Python_Class_Instance_Record) return String is
|
|
|
|
|
begin
|
|
|
|
|
if Instance.Data /= null then
|
|
|
|
|
return Print_Refcount (Class_Instance_Record (Instance.all)'Access)
|
|
|
|
|
& " Py=" & Value (Refcount_Msg (Instance.Data));
|
|
|
|
|
else
|
|
|
|
|
return Print_Refcount (Class_Instance_Record (Instance.all)'Access)
|
|
|
|
|
& " Py=<None>";
|
|
|
|
|
end if;
|
|
|
|
|
end Print_Refcount;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Execute --
|
|
|
|
|
-------------
|
|
|
|
|
|
2011-02-02 08:09:03 +00:00
|
|
|
overriding function Execute
|
2007-06-11 07:57:59 +00:00
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return Boolean is
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
return Execute_Command
|
|
|
|
|
(Script => Subprogram.Script,
|
|
|
|
|
Command => Subprogram.Subprogram,
|
2011-02-02 08:09:03 +00:00
|
|
|
Args => Args,
|
|
|
|
|
Error => Error);
|
2007-06-11 07:57:59 +00:00
|
|
|
end Execute;
|
|
|
|
|
|
|
|
|
|
-------------
|
2010-11-19 16:03:39 +00:00
|
|
|
-- Execute --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return String is
|
2011-02-02 08:09:03 +00:00
|
|
|
begin
|
|
|
|
|
return Execute_Command
|
|
|
|
|
(Script => Subprogram.Script,
|
|
|
|
|
Command => Subprogram.Subprogram,
|
|
|
|
|
Args => Args,
|
|
|
|
|
Error => Error);
|
|
|
|
|
end Execute;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Execute --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
|
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return Class_Instance
|
2010-11-19 16:03:39 +00:00
|
|
|
is
|
|
|
|
|
Obj : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
Obj := Execute_Command
|
|
|
|
|
(Script => Subprogram.Script,
|
|
|
|
|
Command => Subprogram.Subprogram,
|
2011-02-02 08:09:03 +00:00
|
|
|
Args => Args,
|
|
|
|
|
Error => Error);
|
2010-11-19 16:03:39 +00:00
|
|
|
if Obj = null then
|
|
|
|
|
return No_Class_Instance;
|
|
|
|
|
else
|
|
|
|
|
return Get_CI (Subprogram.Script, Obj);
|
|
|
|
|
end if;
|
|
|
|
|
end Execute;
|
|
|
|
|
|
|
|
|
|
-------------
|
2007-06-11 07:57:59 +00:00
|
|
|
-- Execute --
|
|
|
|
|
-------------
|
|
|
|
|
|
2013-08-06 08:39:42 +00:00
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
|
|
|
|
Args : Callback_Data'Class;
|
|
|
|
|
Error : not null access Boolean) return List_Instance'Class
|
|
|
|
|
is
|
|
|
|
|
Obj : PyObject;
|
|
|
|
|
List : Python_Callback_Data;
|
|
|
|
|
begin
|
|
|
|
|
Obj := Execute_Command
|
|
|
|
|
(Script => Subprogram.Script,
|
|
|
|
|
Command => Subprogram.Subprogram,
|
|
|
|
|
Args => Args,
|
|
|
|
|
Error => Error);
|
|
|
|
|
|
|
|
|
|
List.Script := Subprogram.Script;
|
|
|
|
|
List.First_Arg_Is_Self := False;
|
|
|
|
|
List.Args := Obj; -- now owns the reference to Obj
|
|
|
|
|
|
|
|
|
|
return List;
|
|
|
|
|
end Execute;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Execute --
|
|
|
|
|
-------------
|
|
|
|
|
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
overriding function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return Any_Type
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
is
|
|
|
|
|
begin
|
|
|
|
|
return Execute_Command
|
|
|
|
|
(Script => Subprogram.Script,
|
|
|
|
|
Command => Subprogram.Subprogram,
|
2011-02-02 08:09:03 +00:00
|
|
|
Args => Args,
|
|
|
|
|
Error => Error);
|
* build_command_manager.adb:
(Execute): The hook for Compute_Build_Targets_Hook now returns an Any_Type.
* builder_facility_module.adb:
(On_Compute_Build_Targets): This now returns an Any_Type. The structure of this
Any_Type is described in shell_commands.xml.
(Install_Button_For_Target): The hook for Compute_Build_Targets_Hook now
returns an Any_Type, adapt.
(Add_Menu_For_Target): Likewise.
* gnatcoll-any_types.adb:
Initial revision.
* gnatcoll-any_types.ads:
Initial revision.
* gnatcoll-scripts-shell.adb:
Implement overriding subprogram Execute [Any_Type].
* gnatcoll-scripts-shell.ads:
Declare overriding subprogram Execute [Any_Type].
* gnatcoll-scripts.ads:
(Execute): New abstract subprogram, returning an Any_Type.
* gnatcoll-any_types-python.adb:
Initial revision.
* gnatcoll-any_types-python.ads:
Initial revision.
* gnatcoll-scripts-python.adb:
(Execute): Declare overriding subprogram. Implement.
(Execute_Command): New subprogram.
* gnatcoll-scripts-python.ads:
(Execute_Command): New subprogram.
* gps-kernel-hooks.adb:
(Command_Handler_Return_Any): New subprogram.
(Wrapper_Return_Any): New type.
(Execute): Implement wrappers.
(Destroy): Implement.
(Run_Hook_Until_Not_Empty): New subprogram.
(Register_Standard_Hooks): The hook Compute_Build_Targets_Hook now returns an
Any_Type.
* gps-kernel-hooks.ads:
Add functions allowing to launch hooks that return Any_Types.
Add documentation.
* Makefile.py:
Adapt to new return types of compute_build_targets hook.
* shell_commands.xml:
Document new return type of compute_build_targets hook.
Follow-up on I302-024.
We want to display the base names of "main" targets in the Build menu, and we
also want the hook to contain the full path to the main file in order to
support "%TT".
We cannot do a simple "base_name" on the target when it comes to adding it to
the menu, because this suppresses useful information coming from targets from
Makefile.py.
To solve this, the hook "compute_build_targets" now returns a list of targets,
with, for each target, the name to display in the menu, and the full name.
In order to implement this, we introduce a way for hooks to return complex
information, mapping a subset of the Python types.
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@143141 936e1b1b-40f2-da11-902a-00137254ae57
2009-04-22 13:16:40 +00:00
|
|
|
end Execute;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- Execute --
|
|
|
|
|
-------------
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
function Execute
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record;
|
2011-02-02 08:09:03 +00:00
|
|
|
Args : Callback_Data'Class;
|
2011-02-02 15:29:10 +00:00
|
|
|
Error : not null access Boolean) return GNAT.Strings.String_List
|
2007-06-11 07:57:59 +00:00
|
|
|
is
|
|
|
|
|
Obj : constant PyObject := Execute_Command
|
|
|
|
|
(Script => Subprogram.Script,
|
|
|
|
|
Command => Subprogram.Subprogram,
|
2011-02-02 08:09:03 +00:00
|
|
|
Args => Args,
|
|
|
|
|
Error => Error);
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
if Obj = null then
|
|
|
|
|
return (1 .. 0 => null);
|
|
|
|
|
|
|
|
|
|
elsif Obj = Py_None then
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return (1 .. 0 => null);
|
|
|
|
|
|
|
|
|
|
elsif PyString_Check (Obj) then
|
|
|
|
|
declare
|
|
|
|
|
Str : constant String := PyString_AsString (Obj);
|
|
|
|
|
begin
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return (1 .. 1 => new String'(Str));
|
|
|
|
|
end;
|
|
|
|
|
|
2011-06-20 11:12:55 +00:00
|
|
|
elsif PyUnicode_Check (Obj) then
|
|
|
|
|
declare
|
|
|
|
|
Str : constant String := Unicode_AsString (Obj);
|
|
|
|
|
begin
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return (1 .. 1 => new String'(Str));
|
|
|
|
|
end;
|
|
|
|
|
|
2007-06-11 07:57:59 +00:00
|
|
|
elsif PyList_Check (Obj) then
|
|
|
|
|
declare
|
|
|
|
|
Result : GNAT.Strings.String_List (1 .. PyList_Size (Obj));
|
|
|
|
|
Item : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
for J in 0 .. PyList_Size (Obj) - 1 loop
|
|
|
|
|
Item := PyList_GetItem (Obj, J);
|
|
|
|
|
if PyString_Check (Item) then
|
|
|
|
|
Result (J + 1) := new String'(PyString_AsString (Item));
|
2011-06-20 11:12:55 +00:00
|
|
|
elsif PyUnicode_Check (Item) then
|
|
|
|
|
Result (J + 1) := new String'(Unicode_AsString (Item));
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end loop;
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return Result;
|
|
|
|
|
end;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Py_DECREF (Obj);
|
|
|
|
|
return (1 .. 0 => null);
|
|
|
|
|
end Execute;
|
|
|
|
|
|
|
|
|
|
----------
|
|
|
|
|
-- Free --
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
|
|
procedure Free (Subprogram : in out Python_Subprogram_Record) is
|
|
|
|
|
begin
|
2012-06-21 14:40:19 +00:00
|
|
|
if not Finalized then
|
2009-12-01 11:43:59 +00:00
|
|
|
Py_DECREF (Subprogram.Subprogram);
|
|
|
|
|
end if;
|
2007-06-11 07:57:59 +00:00
|
|
|
end Free;
|
|
|
|
|
|
|
|
|
|
--------------
|
|
|
|
|
-- Get_Name --
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
|
|
function Get_Name
|
|
|
|
|
(Subprogram : access Python_Subprogram_Record) return String
|
|
|
|
|
is
|
|
|
|
|
S : constant PyObject := PyObject_Str (Subprogram.Subprogram);
|
|
|
|
|
Name : constant String := PyString_AsString (S);
|
|
|
|
|
begin
|
|
|
|
|
Py_DECREF (S);
|
|
|
|
|
return Name;
|
|
|
|
|
end Get_Name;
|
|
|
|
|
|
|
|
|
|
----------------
|
|
|
|
|
-- Get_Script --
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
function Get_Script
|
|
|
|
|
(Subprogram : Python_Subprogram_Record) return Scripting_Language
|
|
|
|
|
is
|
|
|
|
|
begin
|
|
|
|
|
return Scripting_Language (Subprogram.Script);
|
|
|
|
|
end Get_Script;
|
|
|
|
|
|
|
|
|
|
-------------------------
|
|
|
|
|
-- Set_Default_Console --
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
procedure Set_Default_Console
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Console : Virtual_Console)
|
|
|
|
|
is
|
|
|
|
|
Inst : Class_Instance;
|
|
|
|
|
Cons : PyObject := Py_None;
|
2008-10-21 22:09:20 +00:00
|
|
|
Errors : aliased Boolean;
|
2007-06-11 07:57:59 +00:00
|
|
|
begin
|
|
|
|
|
Set_Default_Console
|
|
|
|
|
(Scripting_Language_Record (Script.all)'Access, Console);
|
|
|
|
|
|
|
|
|
|
if Console /= null
|
|
|
|
|
and then Get_Console_Class (Get_Repository (Script)) /= No_Class
|
|
|
|
|
then
|
|
|
|
|
Inst := Get_Instance (Script, Console);
|
|
|
|
|
if Inst = No_Class_Instance then
|
|
|
|
|
Inst := New_Instance
|
|
|
|
|
(Script, Get_Console_Class (Get_Repository (Script)));
|
|
|
|
|
Set_Data (Inst, Console => Console);
|
|
|
|
|
end if;
|
|
|
|
|
Cons := Python_Class_Instance (Get_CIR (Inst)).Data;
|
|
|
|
|
|
|
|
|
|
PyDict_SetItemString
|
|
|
|
|
(PyModule_GetDict (PyImport_ImportModule ("sys")), "stdout", Cons);
|
|
|
|
|
PyDict_SetItemString
|
|
|
|
|
(PyModule_GetDict (PyImport_ImportModule ("sys")), "stderr", Cons);
|
|
|
|
|
PyDict_SetItemString
|
|
|
|
|
(PyModule_GetDict (PyImport_ImportModule ("sys")), "stdin", Cons);
|
2008-10-21 22:09:20 +00:00
|
|
|
|
|
|
|
|
else
|
|
|
|
|
Cons := Run_Command
|
|
|
|
|
(Script,
|
|
|
|
|
"sys.stdout = sys.__stdout__" & ASCII.LF
|
|
|
|
|
& "sys.stdin = sys.__stdin__" & ASCII.LF
|
|
|
|
|
& "sys.stderr = sys.__stderr__",
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Hide_Output => True,
|
|
|
|
|
Need_Output => False,
|
|
|
|
|
Errors => Errors'Access);
|
|
|
|
|
Py_XDECREF (Cons);
|
2007-06-11 07:57:59 +00:00
|
|
|
end if;
|
|
|
|
|
end Set_Default_Console;
|
|
|
|
|
|
2010-11-17 16:29:07 +00:00
|
|
|
------------------
|
|
|
|
|
-- Set_Property --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : Integer)
|
|
|
|
|
is
|
|
|
|
|
Val : PyObject;
|
2012-02-15 17:31:18 +00:00
|
|
|
Result : Integer;
|
|
|
|
|
pragma Unreferenced (Result);
|
2010-11-17 16:29:07 +00:00
|
|
|
begin
|
|
|
|
|
Val := PyInt_FromLong (long (Value));
|
2012-02-15 17:31:18 +00:00
|
|
|
Result := PyObject_GenericSetAttrString (Instance.Data, Name, Val);
|
2010-11-17 16:29:07 +00:00
|
|
|
Py_DECREF (Val);
|
|
|
|
|
end Set_Property;
|
|
|
|
|
|
2012-09-05 07:50:30 +00:00
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : Float)
|
|
|
|
|
is
|
|
|
|
|
Val : PyObject;
|
|
|
|
|
Result : Integer;
|
|
|
|
|
pragma Unreferenced (Result);
|
|
|
|
|
begin
|
|
|
|
|
Val := PyFloat_FromDouble (double (Value));
|
|
|
|
|
Result := PyObject_GenericSetAttrString (Instance.Data, Name, Val);
|
|
|
|
|
Py_DECREF (Val);
|
|
|
|
|
end Set_Property;
|
|
|
|
|
|
2010-11-17 16:29:07 +00:00
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : Boolean)
|
|
|
|
|
is
|
|
|
|
|
Val : PyObject;
|
2012-02-15 17:31:18 +00:00
|
|
|
Result : Integer;
|
|
|
|
|
pragma Unreferenced (Result);
|
2010-11-17 16:29:07 +00:00
|
|
|
begin
|
|
|
|
|
Val := PyBool_FromBoolean (Value);
|
2012-02-15 17:31:18 +00:00
|
|
|
Result := PyObject_GenericSetAttrString (Instance.Data, Name, Val);
|
2010-11-17 16:29:07 +00:00
|
|
|
Py_DECREF (Val);
|
|
|
|
|
end Set_Property;
|
|
|
|
|
|
|
|
|
|
overriding procedure Set_Property
|
|
|
|
|
(Instance : access Python_Class_Instance_Record;
|
|
|
|
|
Name : String; Value : String)
|
|
|
|
|
is
|
|
|
|
|
Val : PyObject;
|
2012-02-15 17:31:18 +00:00
|
|
|
Result : Integer;
|
|
|
|
|
pragma Unreferenced (Result);
|
2010-11-17 16:29:07 +00:00
|
|
|
begin
|
|
|
|
|
Val := PyString_FromString (Value);
|
2012-02-15 17:31:18 +00:00
|
|
|
Result := PyObject_GenericSetAttrString (Instance.Data, Name, Val);
|
2010-11-17 16:29:07 +00:00
|
|
|
Py_DECREF (Val);
|
|
|
|
|
end Set_Property;
|
|
|
|
|
|
2010-12-23 09:23:54 +00:00
|
|
|
--------------------
|
|
|
|
|
-- Load_Directory --
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
overriding procedure Load_Directory
|
|
|
|
|
(Script : access Python_Scripting_Record;
|
|
|
|
|
Directory : GNATCOLL.VFS.Virtual_File;
|
|
|
|
|
To_Load : Script_Loader := Load_All'Access)
|
|
|
|
|
is
|
|
|
|
|
Files : File_Array_Access;
|
|
|
|
|
Path : constant String := +Directory.Full_Name (True);
|
|
|
|
|
Last : Integer := Path'Last;
|
|
|
|
|
Errors : Boolean;
|
|
|
|
|
begin
|
|
|
|
|
if not Directory.Is_Directory then
|
|
|
|
|
return;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Trace (Me, "Load python files from " & Path);
|
|
|
|
|
|
|
|
|
|
-- Add the directory to the default python search path.
|
|
|
|
|
-- Python requires no trailing dir separator (at least on Windows)
|
|
|
|
|
|
|
|
|
|
if Is_Directory_Separator (Path (Last)) then
|
|
|
|
|
Last := Last - 1;
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
Execute_Command
|
|
|
|
|
(Script,
|
|
|
|
|
Create ("sys.path=[r'" & Path (Path'First .. Last) & "']+sys.path"),
|
|
|
|
|
Show_Command => False,
|
|
|
|
|
Hide_Output => True,
|
|
|
|
|
Errors => Errors);
|
|
|
|
|
|
|
|
|
|
-- ??? Should also check for python modules (ie subdirectories that
|
|
|
|
|
-- contain a __init__.py file
|
|
|
|
|
|
|
|
|
|
Files := Directory.Read_Dir;
|
|
|
|
|
|
|
|
|
|
for J in Files'Range loop
|
|
|
|
|
if Equal (Files (J).File_Extension, ".py") then
|
|
|
|
|
if To_Load (Files (J)) then
|
2011-01-05 09:59:51 +00:00
|
|
|
Trace (Me, "Load " & Files (J).Display_Full_Name);
|
2010-12-23 09:23:54 +00:00
|
|
|
Execute_Command
|
|
|
|
|
(Script,
|
|
|
|
|
Create ("import " & (+Base_Name (Files (J), ".py"))),
|
|
|
|
|
Show_Command => False,
|
2010-12-23 10:27:17 +00:00
|
|
|
Hide_Output => True,
|
2010-12-23 09:23:54 +00:00
|
|
|
Errors => Errors);
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
elsif Is_Regular_File (Create_From_Dir (Files (J), "__init__.py"))
|
|
|
|
|
and then To_Load (Files (J))
|
|
|
|
|
then
|
2011-01-05 09:59:51 +00:00
|
|
|
Trace (Me, "Load " & (+Base_Dir_Name (Files (J))) & "/");
|
2010-12-23 09:23:54 +00:00
|
|
|
Execute_Command
|
|
|
|
|
(Script,
|
|
|
|
|
Create ("import " & (+Base_Dir_Name (Files (J)))),
|
|
|
|
|
Show_Command => False,
|
2010-12-23 10:27:17 +00:00
|
|
|
Hide_Output => True,
|
2010-12-23 09:23:54 +00:00
|
|
|
Errors => Errors);
|
|
|
|
|
end if;
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
|
|
Unchecked_Free (Files);
|
|
|
|
|
end Load_Directory;
|
|
|
|
|
|
2011-03-21 16:14:36 +00:00
|
|
|
---------------------
|
|
|
|
|
-- Execute_Command --
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
overriding procedure Execute_Command
|
|
|
|
|
(Args : in out Python_Callback_Data;
|
2012-06-12 08:25:13 +00:00
|
|
|
Command : String;
|
|
|
|
|
Hide_Output : Boolean := True)
|
2011-03-21 16:14:36 +00:00
|
|
|
is
|
|
|
|
|
Script : constant Python_Scripting :=
|
|
|
|
|
Python_Scripting (Get_Script (Args));
|
|
|
|
|
Func : PyObject;
|
|
|
|
|
Errors : aliased Boolean;
|
|
|
|
|
Result : PyObject;
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
if Script.Blocked then
|
|
|
|
|
Set_Error_Msg (Args, "A command is already executing");
|
|
|
|
|
else
|
|
|
|
|
-- Fetch a handle on the function to execute. What we want to execute
|
|
|
|
|
-- is:
|
|
|
|
|
-- func = module.function_name
|
|
|
|
|
-- func(args)
|
|
|
|
|
Func := Run_Command
|
|
|
|
|
(Script,
|
|
|
|
|
Command => Command,
|
2012-06-12 08:25:13 +00:00
|
|
|
Hide_Output => Hide_Output,
|
(Run_Command): cleanup handling of Hide_Output.
We now longer create and call our custom _gnatcoll class to redirect
sys.stdout, sys.stderr and sys.displayhook. This method was fragile
in the face of multi-tasking (L607-001). It was also hiding too
much in fact, since it was often confusing for users that their
"print" statements did not generate any output (L620-027).
Instead, we now compile with special flags with Py_CompileString,
so that python does not generate the call to displayhook.
Because of this, we cannot use __builtins__._ to look at the result
of the previous command, but we get this output directly from
PyEval_EvalCode when the code is an expression.
One of the changes for users is that we can no longer execute a
string containing a class or function definition or import statement,
and expect to get its output (but in fact there is none, so the code
was suspicious in the first place).
A few other optimizations in Run_Command (logging directly using the
traces module, rather than through the console class), and avoid
string manipulation when possible.
Provide support for logging exception messages in the log file, to
help debug scripts.
Finally, this code is in preparation for support of python3 (L619-031)
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191180 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 19:23:03 +00:00
|
|
|
Need_Output => True,
|
2012-06-21 07:59:03 +00:00
|
|
|
Errors => Errors'Access);
|
2011-03-21 16:14:36 +00:00
|
|
|
|
2011-11-16 11:55:29 +00:00
|
|
|
if Func /= null and then PyCallable_Check (Func) then
|
2011-03-21 16:14:36 +00:00
|
|
|
Setup_Return_Value (Args);
|
|
|
|
|
Result := Execute_Command (Script, Func, Args, Errors'Access);
|
|
|
|
|
|
|
|
|
|
if Errors then
|
2011-05-09 14:21:32 +00:00
|
|
|
Py_XDECREF (Result);
|
2011-03-21 16:14:36 +00:00
|
|
|
PyErr_Clear;
|
2012-06-21 07:59:03 +00:00
|
|
|
raise Error_In_Command with "Error in '" & Command & "()'";
|
2011-03-21 16:14:36 +00:00
|
|
|
else
|
2011-05-09 14:21:32 +00:00
|
|
|
Args.Return_Value := Result; -- Adopts a reference
|
2011-03-21 16:14:36 +00:00
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
else
|
2011-11-07 16:39:27 +00:00
|
|
|
raise Error_In_Command with Command & " is not a function";
|
2011-03-21 16:14:36 +00:00
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
end Execute_Command;
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Return_Value --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
overriding function Return_Value
|
|
|
|
|
(Data : Python_Callback_Data) return String is
|
|
|
|
|
begin
|
2011-11-07 16:39:27 +00:00
|
|
|
if Data.Return_Value = null then
|
|
|
|
|
raise Invalid_Parameter
|
|
|
|
|
with "Returned value is null (a python exception ?)";
|
|
|
|
|
elsif PyString_Check (Data.Return_Value) then
|
2011-03-21 16:14:36 +00:00
|
|
|
return PyString_AsString (Data.Return_Value);
|
2011-06-20 11:12:55 +00:00
|
|
|
elsif PyUnicode_Check (Data.Return_Value) then
|
|
|
|
|
return Unicode_AsString (Data.Return_Value);
|
|
|
|
|
else
|
|
|
|
|
raise Invalid_Parameter with "Returned value is not a string";
|
2011-03-21 16:14:36 +00:00
|
|
|
end if;
|
|
|
|
|
end Return_Value;
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Return_Value --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
overriding function Return_Value
|
|
|
|
|
(Data : Python_Callback_Data) return Integer is
|
|
|
|
|
begin
|
|
|
|
|
if not PyInt_Check (Data.Return_Value) then
|
|
|
|
|
raise Invalid_Parameter with "Returned value is not an integer";
|
|
|
|
|
else
|
|
|
|
|
return Integer (PyInt_AsLong (Data.Return_Value));
|
|
|
|
|
end if;
|
|
|
|
|
end Return_Value;
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Return_Value --
|
|
|
|
|
------------------
|
|
|
|
|
|
2012-09-05 07:50:30 +00:00
|
|
|
overriding function Return_Value
|
|
|
|
|
(Data : Python_Callback_Data) return Float is
|
|
|
|
|
begin
|
|
|
|
|
if not PyFloat_Check (Data.Return_Value) then
|
|
|
|
|
raise Invalid_Parameter with "Returned value is not a float";
|
|
|
|
|
else
|
|
|
|
|
return Float (PyFloat_AsDouble (Data.Return_Value));
|
|
|
|
|
end if;
|
|
|
|
|
end Return_Value;
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Return_Value --
|
|
|
|
|
------------------
|
|
|
|
|
|
2011-03-21 16:14:36 +00:00
|
|
|
overriding function Return_Value
|
|
|
|
|
(Data : Python_Callback_Data) return Boolean is
|
|
|
|
|
begin
|
|
|
|
|
return PyObject_IsTrue (Data.Return_Value);
|
|
|
|
|
end Return_Value;
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Return_Value --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
overriding function Return_Value
|
2011-05-09 14:21:32 +00:00
|
|
|
(Data : Python_Callback_Data) return Class_Instance
|
|
|
|
|
is
|
2011-03-21 16:14:36 +00:00
|
|
|
begin
|
|
|
|
|
if Data.Return_Value = Py_None then
|
|
|
|
|
return No_Class_Instance;
|
|
|
|
|
else
|
|
|
|
|
return Get_CI
|
|
|
|
|
(Python_Scripting (Get_Script (Data)), Data.Return_Value);
|
|
|
|
|
end if;
|
|
|
|
|
end Return_Value;
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
-- Return_Value --
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
overriding function Return_Value
|
|
|
|
|
(Data : Python_Callback_Data) return List_Instance'Class
|
|
|
|
|
is
|
|
|
|
|
List : Python_Callback_Data;
|
|
|
|
|
Iter : PyObject;
|
|
|
|
|
begin
|
|
|
|
|
List.Script := Data.Script;
|
|
|
|
|
List.First_Arg_Is_Self := False;
|
|
|
|
|
|
|
|
|
|
Iter := PyObject_GetIter (Data.Return_Value);
|
|
|
|
|
if Iter = null then
|
|
|
|
|
raise Invalid_Parameter with "Return value is not an iterable";
|
|
|
|
|
end if;
|
|
|
|
|
Py_DECREF (Iter);
|
2011-05-09 14:21:32 +00:00
|
|
|
|
2011-03-21 16:14:36 +00:00
|
|
|
List.Args := Data.Return_Value;
|
2011-05-09 14:21:32 +00:00
|
|
|
Py_INCREF (List.Args);
|
2011-03-21 16:14:36 +00:00
|
|
|
|
|
|
|
|
return List;
|
|
|
|
|
end Return_Value;
|
|
|
|
|
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
-------------------------
|
|
|
|
|
-- Begin_Allow_Threads --
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
function Begin_Allow_Threads return PyThreadState is
|
2012-05-22 10:34:49 +00:00
|
|
|
-- Import only if the function exists in python, otherwise
|
|
|
|
|
-- we can undefined symbols error at link time.
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
function PyEval_SaveThread return PyThreadState;
|
2012-05-22 10:34:49 +00:00
|
|
|
pragma Import (C, PyEval_SaveThread, "ada_PyEval_SaveThread");
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
begin
|
|
|
|
|
return PyEval_SaveThread;
|
|
|
|
|
end Begin_Allow_Threads;
|
|
|
|
|
|
|
|
|
|
-------------------------
|
|
|
|
|
-- Begin_Allow_Threads --
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
procedure Begin_Allow_Threads is
|
|
|
|
|
State : PyThreadState;
|
|
|
|
|
pragma Unreferenced (State);
|
|
|
|
|
begin
|
|
|
|
|
State := Begin_Allow_Threads;
|
|
|
|
|
end Begin_Allow_Threads;
|
|
|
|
|
|
|
|
|
|
-----------------------
|
|
|
|
|
-- End_Allow_Threads --
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
procedure End_Allow_Threads (State : PyThreadState) is
|
|
|
|
|
procedure PyEval_RestoreThread (State : PyThreadState);
|
2012-05-22 10:34:49 +00:00
|
|
|
pragma Import (C, PyEval_RestoreThread, "ada_PyEval_RestoreThread");
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
begin
|
|
|
|
|
PyEval_RestoreThread (State);
|
|
|
|
|
end End_Allow_Threads;
|
|
|
|
|
|
|
|
|
|
---------------------------
|
|
|
|
|
-- Get_This_Thread_State --
|
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
|
|
function Get_This_Thread_State return PyThreadState is
|
|
|
|
|
function PyGILState_GetThisThreadState return PyThreadState;
|
|
|
|
|
pragma Import
|
2012-05-22 10:34:49 +00:00
|
|
|
(C, PyGILState_GetThisThreadState,
|
|
|
|
|
"ada_PyGILState_GetThisThreadState");
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
begin
|
|
|
|
|
return PyGILState_GetThisThreadState;
|
|
|
|
|
end Get_This_Thread_State;
|
|
|
|
|
|
|
|
|
|
-------------------------
|
|
|
|
|
-- Ensure_Thread_State --
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
procedure Ensure_Thread_State is
|
|
|
|
|
function PyGILState_Ensure return Integer;
|
2012-05-22 10:34:49 +00:00
|
|
|
pragma Import (C, PyGILState_Ensure, "ada_PyGILState_Ensure");
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
Ignored : Integer;
|
|
|
|
|
pragma Unreferenced (Ignored);
|
|
|
|
|
begin
|
|
|
|
|
Ignored := PyGILState_Ensure;
|
|
|
|
|
end Ensure_Thread_State;
|
|
|
|
|
|
|
|
|
|
--------------------------------
|
|
|
|
|
-- Initialize_Threads_Support --
|
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
|
|
procedure Initialize_Threads_Support is
|
|
|
|
|
procedure PyEval_InitThreads;
|
2012-05-22 10:34:49 +00:00
|
|
|
pragma Import (C, PyEval_InitThreads, "ada_PyEval_InitThreads");
|
(Get_Prompt): new subprogram
(Read): second version of this subprogram, that takes the prompt as
parameter. This is useful when implementing interactive consoles based
on readline, since the latter needs to know about the prompt otherwise
using the history key will hide the prompt.
(Register_Python_Scripting): cleanup the python functions that are used to
temporarily hide the output of internal commands. In some cases, it was
possible that setting sys.stdout.write would result in an exception, and
then we were never reseting sys.displayhook properly; also, we now use a
class to provide a cleaner namespace usage.
(Run_Command): no longer explicitly display the output through Insert_Text,
since it was in fact already displayed automatically via sys.displayhook.
This resulted in duplicate output in interactive consoles in some cases.
(Begin_Allow_Threads, End_Allow_Threads, Get_This_Thread_State,
Ensure_Thread_State, Initialize_Threads_Support): new subprograms required
for proper support of multitasking applications interacting with python.
L509-021
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189488 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-10 14:48:51 +00:00
|
|
|
begin
|
|
|
|
|
PyEval_InitThreads;
|
|
|
|
|
end Initialize_Threads_Support;
|
|
|
|
|
|
2008-04-17 12:12:00 +00:00
|
|
|
end GNATCOLL.Scripts.Python;
|