Commit Graph

107 Commits

Author SHA1 Message Date
Emmanuel Briot
140f412215 Major redesign of refcounting in the scripts API.
For the python interface, a Class_Instance is now the same object as
 the corresponding PyObject (so they share the same refcount), instead
 of having a PyObject having a reference to a Class_Instance which also
 has a reference to the PyObject. We managed to break the circle through
 complex computation in Decref, when the last reference was removed from
 Ada, but not when the last reference was removed from Python.
 This was the memory leak in M806-002.
This change required moving the handling of properties directly into the
 python or shell objects, rather than in the Class_Instance, so that the
 latter is now a simple wrapper for the underling shell object.
Previous attempts at fixing the refcounting had resulted in other
 memory leaks because of bugs in the code (M823-012 and M813-016).
The gnatlib scripts testsuite is clean with valgrind after these changes.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@214979 936e1b1b-40f2-da11-902a-00137254ae57
2013-09-02 15:12:08 +00:00
Emmanuel Briot
d0a0106c76 Fix inorrect previous check in
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@214104 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-13 20:01:42 +00:00
Emmanuel Briot
36658e4c30 (Get_CI): temporarily comment out code for M506-018
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@214103 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-13 19:55:52 +00:00
Emmanuel Briot
764745e2eb Minor fixes when using a python search provider.
We had Constraint_Error in some cases.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@214037 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-12 15:28:17 +00:00
Emmanuel Briot
13dd697e72 A Class_Instance now owns a single reference to a PyObject.
This is a minor cleanup of the code, although it doesn't fix some
 memory leaks we have been seeing in GPS.Search_Result
M806-002

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@213871 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-08 13:18:11 +00:00
Emmanuel Briot
f46f705364 Revert "Fix Storage_Error with python search providers"
Previous change was incorrect and resulted in an immediate crash at
 startup. Will need more time to review it.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@213861 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-08 10:33:53 +00:00
Emmanuel Briot
a7a82d5356 Fix Storage_Error with python search providers
A Class_Instance now owns a single reference to a PyObject.
This however does not free the memory leak for the search result, since
 we end up with a Class_Instance with a refcount of 1 (owned by python),
 which owns a PyObject with a refcount of 1, so neither are freed.
This is a general issue, but is visible in the context of the test
 because python is the last one getting a decrease in its refcount. In
 other cases (like contexts), the Class_Instance is the last one getting
 a decref, and we have a special mechanism in place that counts the
 number of internal references.
 Unfortunately, python has no callback to monitor the decrease of
 refcounts.
M806-002

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@213859 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-08 09:59:34 +00:00
Emmanuel Briot
69a687824c Add missing Py_INCREF, found when reading code for M806-002
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@213760 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-06 12:36:46 +00:00
Emmanuel Briot
97aff40b95 Add support for creating custom search providers in python (M625-006)
There is currently a memory leak with the search results, which are
 never properly freed, because a search result implemented as a python
 class owns a reference to the python instance, which is thus never
 freed and thus never frees the result.
 The leak does not exist when wrapping an Ada-implemented search
 result into a python class. This leak might result in some
 Program_Error on exit of GPS, which will be looked at in M806-002.
Added automatic test for the omni-search and the python search
 providers.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@213736 936e1b1b-40f2-da11-902a-00137254ae57
2013-08-06 08:39:42 +00:00
Emmanuel Briot
9a5485d479 Update copyright notice to 2013
M103-015

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@200402 936e1b1b-40f2-da11-902a-00137254ae57
2013-01-08 10:50:34 +00:00
Emmanuel Briot
739340cca2 Make sure the examples can be compiled with a simple "make"
git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@194175 936e1b1b-40f2-da11-902a-00137254ae57
2012-09-05 07:50:30 +00:00
Emmanuel Briot
4bbc6f8f89 (Execute_Command): fix handling of cases when __repr__ raises an
exception.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191486 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-29 13:25:15 +00:00
Emmanuel Briot
5cdd341b62 (Run_Command): do not return null without also setting an exception
message, to avoid python warning. Calling the destructor methods is
 one of the few authorized calls when python is finalized.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191217 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-21 15:57:27 +00:00
Emmanuel Briot
f8fc478441 Use execfile() with python 2.x, this might work better with 2.6
(the new version was working fine with 2.7 and 3.2)

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191211 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-21 15:28:33 +00:00
Emmanuel Briot
275a5ad29f Add support for python3
The testsuite is now clean with either python2.7 or python3.2.
 Support for older versions of python has not changed, so we should
 still be compatible with 2.6
L619-031

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191207 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-21 14:40:19 +00:00
Emmanuel Briot
e5b29006ae (Run_Command): simply typing <enter> at the prompt should display
another prompt in interactive mode.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191184 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-21 08:12:43 +00:00
Emmanuel Briot
80b041560e Fix nightly testsuite (hide some expected exception when the command
line is incomplete)

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191183 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-21 07:59:03 +00:00
Emmanuel Briot
ff775f2f56 Improve logging of exceptions
Fix some tests
Make sure commands typed in an interactive console do not expect
 an output (which allows the users to enter any command)
L620-027

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191181 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-20 20:42:11 +00:00
Emmanuel Briot
aa09c2449f (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
Emmanuel Briot
0bac96eb9e Revamp the initialization of python.
The new implementation does more work directly in C, which also makes
 it easier to add support for python 3.
(configure): new switch --with-python-exec
 to force the use of python 3
Support for python3 now compiles, but resulting executables still do not
 work properly yet.

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@191120 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-19 15:51:12 +00:00
Emmanuel Briot
793c1f7fd0 (Execute_Command): new parameter Hide_Output.
In multi-threading applications, it seems to work better when this
 parameter is set to False.
 L607-001

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@190755 936e1b1b-40f2-da11-902a-00137254ae57
2012-06-12 08:25:13 +00:00
Emmanuel Briot
82de55b012 (_gnatcoll): add support for nested calls to Run_Command.
Otherwise, the following scenario was possible:
 Cmd1 hides its output. But the python command interacts with an Ada-exported
 API, which in turn needs to execute some python code. The nested call ended
 up calling _gnatcoll.show(), and thus when we are back to the initial call
 its output would then be displayed.
L528-025

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@190172 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-29 09:28:07 +00:00
Emmanuel Briot
c5569a5a42 Improve tracing of calls to _gnatcoll (for hiding or showing
output of python commands)
Part of L528-025

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@190171 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-29 09:28:03 +00:00
Emmanuel Briot
a4bd6fffd2 Prevent link errors when the python library is compiled without support
for threads.
L521-010 and L522-013

git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@189889 936e1b1b-40f2-da11-902a-00137254ae57
2012-05-22 10:34:49 +00:00
Emmanuel Briot
d153a16130 (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