Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / python / py-gdb-readline.c
index d6576a32cccd99923ac47b4d335d2cfa43dcffa8..1162687ccf70a89d332da18b73f7717de7111280 100644 (file)
@@ -1,6 +1,6 @@
 /* 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
@@ -63,7 +64,7 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
   /* Detect EOF (Ctrl-D).  */
   if (p == NULL)
     {
-      q = PyMem_Malloc (1);
+      q = (char *) PyMem_RawMalloc (1);
       if (q != NULL)
        q[0] = '\0';
       return q;
@@ -72,10 +73,10 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
   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';
     }
This page took 0.026432 seconds and 4 git commands to generate.