Fix build with Python 3.4 (PR python/16784)
authorSimon Marchi <simon.marchi@ericsson.com>
Mon, 15 Dec 2014 16:38:03 +0000 (11:38 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Mon, 15 Dec 2014 16:40:00 +0000 (11:40 -0500)
The type of the function pointer PyOS_ReadlineFunctionPointer (part of the
Python C API), which we use, slightly changed starting with Python 3.4. The
signature went from

PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);

to

PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);

The parameter that changed is the prompt text.

This commits adjust gdb accordingly by making the prompt_arg parameter
const, as well as the fallouts of that. I needed to rework how
annotations are added to the prompt, since the it is now const. If
annotations are enabled, it will make a copy of the prompt overwrite the
prompt variable that is used throughout the function. Otherwise, no copy
is done and the original prompt_arg value is passed.

I changed the signature of deprecated_readline_hook. I would've changed any
user of it, but it seems like nothing is using it,

Built-tested with python 2.7.x, 3.3.y and 3.4.z.

gdb/ChangeLog:

* defs.h (gdb_readline): Constify argument.
(gdb_readline_wrapper): Same.
(command_line_input): Same.
(deprecated_readline_hook): Same.
* top.c (deprecated_readline_hook): Same.
(gdb_readline): Same.
(gdb_readline_wrapper): Same.
(command_line_input): Constify argument. Pass prompt to
called functions instead of local_prompt, overwriting prompt
if using annotations.
* event-top.h (display_gdb_prompt): Constify argument.
* event-top.c (display_gdb_prompt): Same.
* python/py-gdb-readline.c (gdbpy_readline_wrapper): Constify
argument if building with Python 3.4 and up.

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
gdb/ChangeLog
gdb/defs.h
gdb/event-top.c
gdb/event-top.h
gdb/python/py-gdb-readline.c
gdb/top.c

index b7ea3a690f5324c3cda95912ea9d34526b31153e..2e13df58786e72d9827af90ff83550049dc8ce96 100644 (file)
@@ -1,3 +1,19 @@
+2014-12-15  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * defs.h (gdb_readline): Constify argument.
+       (gdb_readline_wrapper): Same.
+       (command_line_input): Same.
+       (deprecated_readline_hook): Same.
+       * top.c (deprecated_readline_hook): Same.
+       (gdb_readline): Same.
+       (gdb_readline_wrapper): Same.
+       (command_line_input): Constify argument. Pass prompt_arg to called
+       functions instead of local_prompt, overwriting prompt_arg if necessary.
+       * event-top.h (display_gdb_prompt): Constify argument.
+       * event-top.c (display_gdb_prompt): Same.
+       * python/py-gdb-readline.c (gdbpy_readline_wrapper): Constify argument
+       if building with Python 3.4 and up.
+
 2014-12-15  Simon Marchi  <simon.marchi@ericsson.com>
 
        * python/lib/gdb/prompt.py (_prompt_pwd): Use os.getcwd() instead of
index 7920938d18e14d4787b5b002d87713ff1394a0a7..7b5bc0628a359f022f275a1d7b50946017761606 100644 (file)
@@ -277,11 +277,11 @@ extern void print_transfer_performance (struct ui_file *stream,
 
 typedef void initialize_file_ftype (void);
 
-extern char *gdb_readline (char *);
+extern char *gdb_readline (const char *);
 
-extern char *gdb_readline_wrapper (char *);
+extern char *gdb_readline_wrapper (const char *);
 
-extern char *command_line_input (char *, int, char *);
+extern char *command_line_input (const char *, int, char *);
 
 extern void print_prompt (void);
 
@@ -664,7 +664,7 @@ extern void (*deprecated_warning_hook) (const char *, va_list)
 extern void (*deprecated_interactive_hook) (void);
 extern void (*deprecated_readline_begin_hook) (char *, ...)
      ATTRIBUTE_FPTR_PRINTF_1;
-extern char *(*deprecated_readline_hook) (char *);
+extern char *(*deprecated_readline_hook) (const char *);
 extern void (*deprecated_readline_end_hook) (void);
 extern void (*deprecated_register_changed_hook) (int regno);
 extern void (*deprecated_context_hook) (int);
index cb438acfcbebb6bdfb227a2377dc36a511e19e39..55caf72705fa879d134afef0707fc135a2e6e9b0 100644 (file)
@@ -288,7 +288,7 @@ gdb_rl_callback_handler_reinstall (void)
    3. On prompting for pagination.  */
 
 void
-display_gdb_prompt (char *new_prompt)
+display_gdb_prompt (const char *new_prompt)
 {
   char *actual_gdb_prompt = NULL;
   struct cleanup *old_chain;
index 919287e6f34e31dc18b89a84c9475144de03636c..0c8baae27808d64e0f0868efa23e9a6f65e12542 100644 (file)
@@ -27,7 +27,7 @@ struct cmd_list_element;
 /* Exported functions from event-top.c.
    FIXME: these should really go into top.h.  */
 
-extern void display_gdb_prompt (char *new_prompt);
+extern void display_gdb_prompt (const char *new_prompt);
 void gdb_setup_readline (void);
 void gdb_disable_readline (void);
 extern void async_init_signals (void);
index d98a19651c936f265885be5c9fb39999ecc09330..ab419bce15c3eee500ee876d3ac990a93945301b 100644 (file)
 
 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;
index 83d858adcfc4b184dceef249c2887fc18e2dc675..7f385628b8b7f3f913968638117951281a495c60 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -215,7 +215,7 @@ void (*deprecated_warning_hook) (const char *, va_list);
    window and it can close it.  */
 
 void (*deprecated_readline_begin_hook) (char *, ...);
-char *(*deprecated_readline_hook) (char *);
+char *(*deprecated_readline_hook) (const char *);
 void (*deprecated_readline_end_hook) (void);
 
 /* Called as appropriate to notify the interface that we have attached
@@ -620,7 +620,7 @@ prevent_dont_repeat (void)
 
    A NULL return means end of file.  */
 char *
-gdb_readline (char *prompt_arg)
+gdb_readline (const char *prompt_arg)
 {
   int c;
   char *result;
@@ -812,7 +812,7 @@ gdb_readline_wrapper_cleanup (void *arg)
 }
 
 char *
-gdb_readline_wrapper (char *prompt)
+gdb_readline_wrapper (const char *prompt)
 {
   struct cleanup *back_to;
   struct gdb_readline_wrapper_cleanup *cleanup;
@@ -912,14 +912,14 @@ gdb_rl_operate_and_get_next (int count, int key)
    simple input as the user has requested.  */
 
 char *
-command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
+command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix)
 {
   static char *linebuffer = 0;
   static unsigned linelength = 0;
+  const char *prompt = prompt_arg;
   char *p;
   char *p1;
   char *rl;
-  char *local_prompt = prompt_arg;
   char *nline;
   char got_eof = 0;
 
@@ -929,15 +929,19 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
 
   if (annotation_level > 1 && instream == stdin)
     {
-      local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
+      char *local_prompt;
+
+      local_prompt = alloca ((prompt == NULL ? 0 : strlen (prompt))
                             + strlen (annotation_suffix) + 40);
-      if (prompt_arg == NULL)
+      if (prompt == NULL)
        local_prompt[0] = '\0';
       else
-       strcpy (local_prompt, prompt_arg);
+       strcpy (local_prompt, prompt);
       strcat (local_prompt, "\n\032\032");
       strcat (local_prompt, annotation_suffix);
       strcat (local_prompt, "\n");
+
+      prompt = local_prompt;
     }
 
   if (linebuffer == 0)
@@ -979,15 +983,15 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
       /* Don't use fancy stuff if not talking to stdin.  */
       if (deprecated_readline_hook && input_from_terminal_p ())
        {
-         rl = (*deprecated_readline_hook) (local_prompt);
+         rl = (*deprecated_readline_hook) (prompt);
        }
       else if (command_editing_p && input_from_terminal_p ())
        {
-         rl = gdb_readline_wrapper (local_prompt);
+         rl = gdb_readline_wrapper (prompt);
        }
       else
        {
-         rl = gdb_readline (local_prompt);
+         rl = gdb_readline (prompt);
        }
 
       if (annotation_level > 1 && instream == stdin)
@@ -1021,7 +1025,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
        break;
 
       p--;                     /* Put on top of '\'.  */
-      local_prompt = (char *) 0;
+      prompt = NULL;
     }
 
 #ifdef STOP_SIGNAL
@@ -1064,7 +1068,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
          if (expanded < 0)
            {
              xfree (history_value);
-             return command_line_input (prompt_arg, repeat,
+             return command_line_input (prompt, repeat,
                                         annotation_suffix);
            }
          if (strlen (history_value) > linelength)
This page took 0.0414 seconds and 4 git commands to generate.