Add extern "C" to declarations of C symbols
authorPedro Alves <palves@redhat.com>
Mon, 9 Feb 2015 14:59:08 +0000 (14:59 +0000)
committerPedro Alves <palves@redhat.com>
Fri, 27 Feb 2015 17:26:16 +0000 (17:26 +0000)
These symbols are defined in C code, so in C++ mode we need to use
extern "C" to declare them.  As extern "C" can't be used inside a
function's scope, we move the declarations to the global scope at the
same time.

gdb/ChangeLog:
2015-02-27  Pedro Alves  <palves@redhat.com>

* cli-out.c (_rl_erase_entire_line): Move declaration out of
cli_mld_erase_entire_line, and make it extern "C".
* common/common-defs.h (EXTERN_C): New.
* completer.c (_rl_completion_prefix_display_length)
(_rl_print_completions_horizontally, QSFUNC): Move declarations
out of gdb_display_match_list_1.
(_rl_qsort_string_compare): Move declaration out of
gdb_display_match_list_1, and make it extern "C".
* defs.h (re_comp): Use EXTERN_C.
* maint.c (_mcleanup): Move declaration out of mcleanup_wrapper,
and make it extern "C".
(monstartup): Move declaration out of maintenance_set_profile_cmd,
and make it extern "C".
(main): Move declaration out of maintenance_set_profile_cmd.
* nat/linux-ptrace.c (linux_ptrace_attach_fail_reason_string): Use
EXTERN_C.

gdb/ChangeLog
gdb/cli-out.c
gdb/common/common-defs.h
gdb/completer.c
gdb/defs.h
gdb/maint.c
gdb/nat/linux-ptrace.c

index 19ecc01..aa4a614 100644 (file)
@@ -1,5 +1,24 @@
 2015-02-27  Pedro Alves  <palves@redhat.com>
 
+       * cli-out.c (_rl_erase_entire_line): Move declaration out of
+       cli_mld_erase_entire_line, and make it extern "C".
+       * common/common-defs.h (EXTERN_C): New.
+       * completer.c (_rl_completion_prefix_display_length)
+       (_rl_print_completions_horizontally, QSFUNC): Move declarations
+       out of gdb_display_match_list_1.
+       (_rl_qsort_string_compare): Move declaration out of
+       gdb_display_match_list_1, and make it extern "C".
+       * defs.h (re_comp): Use EXTERN_C.
+       * maint.c (_mcleanup): Move declaration out of mcleanup_wrapper,
+       and make it extern "C".
+       (monstartup): Move declaration out of maintenance_set_profile_cmd,
+       and make it extern "C".
+       (main): Move declaration out of maintenance_set_profile_cmd.
+       * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason_string): Use
+       EXTERN_C.
+
+2015-02-27  Pedro Alves  <palves@redhat.com>
+
        * python/python.c (GdbMethods): Rename to ...
        (python_GdbMethods): ... this and make extern.
        (GdbModuleDef): Rename to ...
index 48f2a04..2a83169 100644 (file)
@@ -452,13 +452,13 @@ cli_mld_flush (const struct match_list_displayer *displayer)
   fflush (rl_outstream);
 }
 
+EXTERN_C void _rl_erase_entire_line (void);
+
 /* CLI version of displayer.erase_entire_line.  */
 
 static void
 cli_mld_erase_entire_line (const struct match_list_displayer *displayer)
 {
-  extern void _rl_erase_entire_line (void);
-
   _rl_erase_entire_line ();
 }
 
index e80d332..3020bd8 100644 (file)
 #include "cleanups.h"
 #include "common-exceptions.h"
 
+#ifdef __cplusplus
+# define EXTERN_C extern "C"
+#else
+# define EXTERN_C extern
+#endif
+
 #endif /* COMMON_DEFS_H */
index add79cc..efcb771 100644 (file)
@@ -1548,6 +1548,12 @@ gdb_complete_get_screenwidth (const struct match_list_displayer *displayer)
   return displayer->width;
 }
 
+extern int _rl_completion_prefix_display_length;
+extern int _rl_print_completions_horizontally;
+
+EXTERN_C int _rl_qsort_string_compare (const void *, const void *);
+typedef int QSFUNC (const void *, const void *);
+
 /* GDB version of readline/complete.c:rl_display_match_list.
    See gdb_display_match_list for a description of MATCHES, LEN, MAX.
    Returns non-zero if all matches are displayed.  */
@@ -1560,10 +1566,6 @@ gdb_display_match_list_1 (char **matches, int len, int max,
   int i, j, k, l, common_length, sind;
   char *temp, *t;
   int page_completions = displayer->height != INT_MAX && pagination_enabled;
-  extern int _rl_completion_prefix_display_length;
-  extern int _rl_qsort_string_compare (const void *, const void *);
-  extern int _rl_print_completions_horizontally;
-  typedef int QSFUNC (const void *, const void *);
 
   /* Find the length of the prefix common to all items: length as displayed
      characters (common_length) and as a byte index into the matches (sind) */
index a1cd45f..72512f6 100644 (file)
@@ -249,7 +249,7 @@ extern int annotation_level;        /* in stack.c */
    "const char *" in unistd.h, so we can't declare the argument
    as "char *".  */
 
-extern char *re_comp (const char *);
+EXTERN_C char *re_comp (const char *);
 
 /* From symfile.c */
 
index be18a32..1adea2f 100644 (file)
@@ -683,15 +683,18 @@ extern char etext;
 
 static int profiling_state;
 
+EXTERN_C void _mcleanup (void);
+
 static void
 mcleanup_wrapper (void)
 {
-  extern void _mcleanup (void);
-
   if (profiling_state)
     _mcleanup ();
 }
 
+EXTERN_C void monstartup (unsigned long, unsigned long);
+extern int main ();
+
 static void
 maintenance_set_profile_cmd (char *args, int from_tty,
                             struct cmd_list_element *c)
@@ -705,9 +708,6 @@ maintenance_set_profile_cmd (char *args, int from_tty,
     {
       static int profiling_initialized;
 
-      extern void monstartup (unsigned long, unsigned long);
-      extern int main();
-
       if (!profiling_initialized)
        {
          atexit (mcleanup_wrapper);
index 1c67819..2244d9d 100644 (file)
@@ -84,7 +84,7 @@ linux_ptrace_attach_fail_reason_string (ptid_t ptid, int err)
 #if defined __i386__ || defined __x86_64__
 
 /* Address of the 'ret' instruction in asm code block below.  */
-extern void (linux_ptrace_test_ret_to_nx_instr) (void);
+EXTERN_C void linux_ptrace_test_ret_to_nx_instr (void);
 
 #include <sys/reg.h>
 #include <sys/mman.h>