/* Readline support for Python.
- Copyright (C) 2012-2013 Free Software Foundation, Inc.
+ Copyright (C) 2012-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "python-internal.h"
-#include "exceptions.h"
#include "top.h"
#include "cli/cli-utils.h"
-#include "gdb_string.h"
-
-#include <stddef.h>
/* Readline function suitable for PyOS_ReadlineFunctionPointer, which
is used for Python's interactive parser and raw_input. In both
static char *
gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
+#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4
+ const char *prompt)
+#else
char *prompt)
+#endif
{
int n;
- char *p = NULL, *q;
- volatile struct gdb_exception except;
-
- TRY_CATCH (except, RETURN_MASK_ALL)
- p = command_line_input (prompt, 0, "python");
-
- /* Detect user interrupt (Ctrl-C). */
- if (except.reason == RETURN_QUIT)
- return NULL;
+ const char *p = NULL;
+ char *q;
+ try
+ {
+ p = command_line_input (prompt, "python");
+ }
/* Handle errors by raising Python exceptions. */
- if (except.reason < 0)
+ catch (const gdb_exception &except)
{
+ /* Detect user interrupt (Ctrl-C). */
+ if (except.reason == RETURN_QUIT)
+ return NULL;
+
/* The thread state is nulled during gdbpy_readline_wrapper,
with the original value saved in the following undocumented
variable (see Python's Parser/myreadline.c and
/* Detect EOF (Ctrl-D). */
if (p == NULL)
{
- q = PyMem_Malloc (1);
+ q = (char *) PyMem_RawMalloc (1);
if (q != NULL)
q[0] = '\0';
return q;
n = strlen (p);
/* Copy the line to Python and return. */
- q = PyMem_Malloc (n + 2);
+ q = (char *) PyMem_RawMalloc (n + 2);
if (q != NULL)
{
- strncpy (q, p, n);
+ strcpy (q, p);
q[n] = '\n';
q[n + 1] = '\0';
}
and prevent conflicts. For now, this file implements a
sys.meta_path finder that simply fails to import the readline
module. */
- PyRun_SimpleString ("\
+ if (PyRun_SimpleString ("\
import sys\n\
\n\
class GdbRemoveReadlineFinder:\n\
raise ImportError('readline module disabled under GDB')\n\
\n\
sys.meta_path.append(GdbRemoveReadlineFinder())\n\
-");
-
- PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
+") == 0)
+ PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
}