diff mbox series

configure: Fixes ncursesw detection under msys2/mingw and enable curses

Message ID 20200905204236.1508-1-luoyonggang@gmail.com (mailing list archive)
State New, archived
Headers show
Series configure: Fixes ncursesw detection under msys2/mingw and enable curses | expand

Commit Message

Yonggang Luo Sept. 5, 2020, 8:42 p.m. UTC
The mingw pkg-config are showing following absolute path and contains : as the separator,
so we must handling : properly.

-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw:-I/usr/include/ncursesw:
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -pipe -lncursesw -lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lncursesw
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lcursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lcursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -lcursesw

MINGW doesn't have langinfo.h, only exist in glic and musl

gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
test.c:4:10: fatal error: langinfo.h: No such file or directory
    4 | #include <langinfo.h>
      |          ^~~~~~~~~~~~
compilation terminated.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 configure   | 9 +++------
 ui/curses.c | 9 ++++-----
 2 files changed, 7 insertions(+), 11 deletions(-)

Comments

Richard Henderson Sept. 6, 2020, 3:28 a.m. UTC | #1
On 9/5/20 1:42 PM, Yonggang Luo wrote:
> +    nativecharset_to_ucs2 = iconv_open("UCS-2", g_get_codeset());

g_get_codeset():
"a newly allocated string containing the name of the character set. This string
must be freed with g_free()."

You need to plug the memory leak.

It's probably worth fixing the mistake in which we call this function four
times from the same function.


r~
Yonggang Luo Sept. 7, 2020, 4:20 a.m. UTC | #2
On Sun, Sep 6, 2020 at 11:28 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 9/5/20 1:42 PM, Yonggang Luo wrote:
> > +    nativecharset_to_ucs2 = iconv_open("UCS-2", g_get_codeset());
>
> g_get_codeset():
> "a newly allocated string containing the name of the character set. This
> string
> must be freed with g_free()."
>
> You need to plug the memory leak.
>
> It's probably worth fixing the mistake in which we call this function four
> times from the same function.
>
Done with autofree

>
>
> r~
>
diff mbox series

Patch

diff --git a/configure b/configure
index f8cbd2898c..2dc25bda69 100755
--- a/configure
+++ b/configure
@@ -3620,8 +3620,8 @@  if test "$iconv" = "no" ; then
 fi
 if test "$curses" != "no" ; then
   if test "$mingw32" = "yes" ; then
-    curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
-    curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
+    curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/${MSYSTEM,,}/include/ncursesw:"
+    curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw"
   else
     curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/usr/include/ncursesw:"
     curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw"
@@ -3631,17 +3631,14 @@  if test "$curses" != "no" ; then
 #include <locale.h>
 #include <curses.h>
 #include <wchar.h>
-#include <langinfo.h>
 int main(void) {
-  const char *codeset;
   wchar_t wch = L'w';
   setlocale(LC_ALL, "");
   resize_term(0, 0);
   addwstr(L"wide chars\n");
   addnwstr(&wch, 1);
   add_wch(WACS_DEGREE);
-  codeset = nl_langinfo(CODESET);
-  return codeset != 0;
+  return 0;
 }
 EOF
   IFS=:
diff --git a/ui/curses.c b/ui/curses.c
index a59b23a9cf..74b30d323c 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -30,7 +30,6 @@ 
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -566,14 +565,14 @@  static void font_setup(void)
       0x25bc
     };
 
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+    ucs2_to_nativecharset = iconv_open(g_get_codeset(), "UCS-2");
     if (ucs2_to_nativecharset == (iconv_t) -1) {
         fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n",
                         strerror(errno));
         exit(1);
     }
 
-    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
+    nativecharset_to_ucs2 = iconv_open("UCS-2", g_get_codeset());
     if (nativecharset_to_ucs2 == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n",
@@ -581,7 +580,7 @@  static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(g_get_codeset(), font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);
@@ -602,7 +601,7 @@  static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(g_get_codeset(), "UTF-8")) {
         /* Non-Unicode capable, use termcap equivalents for those available */
         for (i = 0; i <= 0xFF; i++) {
             wchar_t wch[CCHARW_MAX];