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
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
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
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
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
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
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
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
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
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
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
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
(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