[pushed] stub termcap, add extern "C" (Re: [all pushed] Re: [PATCH 00/36] Support building GDB as a C++ program)

Pedro Alves
2015-03-16T11:46:43Z

On 03/16/2015 08:26 AM, asmwarrior wrote:
> diff --git a/gdb/gdb_curses.h b/gdb/gdb_curses.h
> index 9b3707a..d02cab3 100644
> --- a/gdb/gdb_curses.h
> +++ b/gdb/gdb_curses.h
> @@ -51,7 +51,7 @@
> of the termcap functions will be built from stub-termcap.c. Readline
> provides its own extern declarations when there's no termcap.h; do the
> same here for the termcap functions used in GDB. */
> -extern int tgetnum (const char *);
> +extern "C" int tgetnum (const char *);

This still needs to be plain "extern" in C mode. We can use EXTERN_C
for this.

> #endif
>
> /* SunOS's curses.h has a '#define reg register' in it. Thank you Sun. */
> diff --git a/gdb/stub-termcap.c b/gdb/stub-termcap.c
> index cc8632c..a2e833a 100644
> --- a/gdb/stub-termcap.c
> +++ b/gdb/stub-termcap.c
> @@ -23,14 +23,20 @@
> #include "defs.h"
>
> #include <stdlib.h>
> -
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> /* -Wmissing-prototypes */
> -extern int tgetent (char *buffer, char *termtype);
> -extern int tgetnum (char *name);
> -extern int tgetflag (char *name);
> -extern char* tgetstr (char *name, char **area);
> -extern int tputs (char *string, int nlines, int (*outfun) ());
> -extern char *tgoto (const char *cap, int col, int row);
> +int tgetent (char *buffer, char *termtype);
> +int tgetnum (char *name);
> +int tgetflag (char *name);
> +char* tgetstr (char *name, char **area);
> +int tputs (char *string, int nlines, int (*outfun) (char *));
> +char *tgoto (const char *cap, int col, int row);
> +#ifdef __cplusplus
> +}
> +#endif
> +

We can keep the externs.

Here's what I pushed.

Thanks!

---
From d053f6be557fa3bedd4ccbd969103dbb51a37439 Mon Sep 17 00:00:00 2001
From: Yuanhui Zhang <asmwarrior@gmail.com>
Date: Mon, 16 Mar 2015 11:28:24 +0000
Subject: [PATCH 3/3] stub termcap, add extern "C"

Fixes linking an --enable-build-with-cxx build on mingw:

../readline/terminal.c:278: undefined reference to `tgetnum'
../readline/terminal.c:297: undefined reference to `tgetnum'
../readline/libreadline.a(terminal.o): In function `get_term_capabilities':
../readline/terminal.c:427: undefined reference to `tgetstr'
../readline/libreadline.a(terminal.o): In function `_rl_init_terminal_io':
[etc.]

gdb/ChangeLog:
2015-03-16 Yuanhui Zhang <asmwarrior@gmail.com>
Pedro Alves <palves@redhat.com>

* gdb_curses.h (tgetnum): Mark with EXTERN_C.
* stub-termcap.c (tgetent, tgetnum, tgetflag, tgetstr, tputs)
(tgoto): Wrap with extern "C".
---
gdb/ChangeLog | 7 +++++++
gdb/gdb_curses.h | 2 +-
gdb/stub-termcap.c | 8 ++++++++
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 54cb0b2..eb8ef87 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2015-03-16 Yuanhui Zhang <asmwarrior@gmail.com>
+ Pedro Alves <palves@redhat.com>
+
+ * gdb_curses.h (tgetnum): Mark with EXTERN_C.
+ * stub-termcap.c (tgetent, tgetnum, tgetflag, tgetstr, tputs)
+ (tgoto): Wrap with extern "C".
+
2015-03-16 Pedro Alves <palves@redhat.com>
Yuanhui Zhang <asmwarrior@gmail.com>

diff --git a/gdb/gdb_curses.h b/gdb/gdb_curses.h
index 9b3707a..a89383f 100644
--- a/gdb/gdb_curses.h
+++ b/gdb/gdb_curses.h
@@ -51,7 +51,7 @@
of the termcap functions will be built from stub-termcap.c. Readline
provides its own extern declarations when there's no termcap.h; do the
same here for the termcap functions used in GDB. */
-extern int tgetnum (const char *);
+EXTERN_C int tgetnum (const char *);
#endif

/* SunOS's curses.h has a '#define reg register' in it. Thank you Sun. */
diff --git a/gdb/stub-termcap.c b/gdb/stub-termcap.c
index cecb3fb..5897d89 100644
--- a/gdb/stub-termcap.c
+++ b/gdb/stub-termcap.c
@@ -24,6 +24,10 @@

#include <stdlib.h>

+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* -Wmissing-prototypes */
extern int tgetent (char *buffer, char *termtype);
extern int tgetnum (char *name);
@@ -32,6 +36,10 @@ extern char* tgetstr (char *name, char **area);
extern int tputs (char *string, int nlines, int (*outfun) (int));
extern char *tgoto (const char *cap, int col, int row);

+#ifdef __cplusplus
+}
+#endif
+
/* Each of the files below is a minimal implementation of the standard
termcap function with the same name, suitable for use in a Windows
console window. */
--
1.9.3