Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: Discrepancy between Python and Guile wrt exiting the interpreter
Date: Sun, 19 Jan 2020 17:20:00 -0000	[thread overview]
Message-ID: <7a3aa41f-367f-aa51-9b39-342874d9205e@simark.ca> (raw)
In-Reply-To: <83tv4rxuut.fsf@gnu.org>

On 2020-01-19 11:40 a.m., Eli Zaretskii wrote:
>> From: Simon Marchi <simark@simark.ca>
>> Date: Sun, 19 Jan 2020 11:07:14 -0500
>>
>> I looked into it, but didn't find a way to exit the Python interpreter and
>> come back in GDB by typing a Python command.  That command would somehow
>> have to fool the Python interpreter in thinking that its input stream, which
>> we pass here:
>>
>> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/python/python.c;h=d6f7f99c457300cba8e6dbe590ac15b4b2e2b110;hb=HEAD#l302
>>
>> has reached EOF.
> 
> Ctrl-d does that, but it is not a command.
> 
> Is there any reason why quit() exits from GDB as well?  Doesn't the
> Python interpreter support invocation from some other 'main' program?
> It's strange.

Yes, it does (we use it).  It's just the way it works.  From [1]:

    Read and execute statements from a file associated with an interactive device
    until EOF is reached.

The quit() and exit() functions are aliases of the same thing.  They raise a
"SystemExit" exception.  According to the SystemExit exception [2]:

    When it is not handled, the Python interpreter exits; no stack traceback is printed.

When using the various PyRun_Interactive* functions, it seems like the interpreter is
catching the SystemExit exception and calling the C exit() function before returning
to our code, so we don't have a chance to do handle it from the caller of
PyRun_Interactive* function.

[1] https://docs.python.org/3/c-api/veryhigh.html#c.PyRun_InteractiveLoopFlags
[2] https://docs.python.org/3/library/exceptions.html#SystemExit


  reply	other threads:[~2020-01-19 17:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-18 14:46 Eli Zaretskii
2020-01-19 16:11 ` Simon Marchi
2020-01-19 16:42   ` Eli Zaretskii
2020-01-19 17:20     ` Simon Marchi [this message]
2020-01-19 19:13       ` Eli Zaretskii
2020-01-21 19:53         ` Tom Tromey
2020-01-21 19:57           ` Eli Zaretskii
2020-01-23 17:21 ` Pedro Alves
2020-01-23 17:37   ` Simon Marchi
2020-01-23 17:50     ` Pedro Alves
2020-01-23 17:39       ` Pedro Alves
2020-01-24 10:26         ` Eli Zaretskii
2020-01-23 18:20   ` Eli Zaretskii
2020-01-23 18:30     ` Pedro Alves
2020-01-23 18:46       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a3aa41f-367f-aa51-9b39-342874d9205e@simark.ca \
    --to=simark@simark.ca \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox