From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix python-interactive with Python 3.6
Date: Fri, 20 Jan 2017 16:37:00 -0000 [thread overview]
Message-ID: <1b7bea3d-3044-a643-d7b9-3b11db14758f@redhat.com> (raw)
In-Reply-To: <20170120151550.24928-1-simon.marchi@ericsson.com>
On 01/20/2017 03:15 PM, Simon Marchi wrote:
> Since Python 3.4, the callback installed in PyOS_ReadlineFunctionPointer
> should return a value allocated with PyMem_RawMalloc instead of
> PyMem_Malloc. The reason is that PyMem_Malloc must be called with the
> Python Global Interpreter Lock (GIL) held, which is not the case in the
> context where this function is called. PyMem_RawMalloc was introduced
> for cases like this.
>
> +/* Starting from Python 3.4, the result of the PyOS_ReadlineFunctionPointer
> + callback must be allocated with PyMem_RawMalloc rather than PyMem_Malloc. */
> +
> +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4
This will break with PY_MAJOR_VERSION 4 (at some point :-) ).
Write:
#if PY_MAJOR_VERSION > 3
|| (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4)
?
Or add some macro that makes it a bit easier to write,
like "#if HAVE_PY_AT_LEAST(3, 4)" or
"#if GDB_PY_VERSION >= 3004" (like GCC_VERSION).
Or use Python's PY_VERSION_HEX, like
"#if PY_VERSION_HEX >= 0x03040000".
> +#define PyOS_ReadlineFunctionPointer_Malloc PyMem_RawMalloc
> +#else
> +#define PyOS_ReadlineFunctionPointer_Malloc PyMem_Malloc
> +#endif
It sounds like we'll find other cases that will need
to call PyMem_RawMalloc going forward? How about handling
this similarly to how we handle fixing up other missing
Python bits, in python-internal.h. Like:
#if python < 3.4
static inline void *
gdb_PyMem_RawMalloc (size_t n)
{
return gdb_PyMem_Malloc (n);
}
#define PyMem_RawMalloc(n) gdb_PyMem_RawMalloc (n)
#endif
> +
> /* Readline function suitable for PyOS_ReadlineFunctionPointer, which
> is used for Python's interactive parser and raw_input. In both
> cases, sys_stdin and sys_stdout are always stdin and stdout
> @@ -63,7 +73,7 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
> /* Detect EOF (Ctrl-D). */
> if (p == NULL)
> {
> - q = (char *) PyMem_Malloc (1);
> + q = (char *) PyOS_ReadlineFunctionPointer_Malloc (1);
and then write PyMem_RawMalloc here.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2017-01-20 16:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-20 15:19 Simon Marchi
2017-01-20 15:38 ` Simon Marchi
2017-01-20 16:37 ` Pedro Alves [this message]
2017-01-20 16:49 ` Simon Marchi
2017-01-20 16:51 ` Pedro Alves
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=1b7bea3d-3044-a643-d7b9-3b11db14758f@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@ericsson.com \
/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