Skip to contentSkip to conversation

Fixes curses on msys2/mingw

PATCH Superseded Yonggang Luo 4 participants 18 messages Oct 1, 2020 – Oct 12, 2020

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Fixes curses on msys2/mingw

And also convert related configure script to meson.
V5-V6
Dropping configure: Fixes ncursesw detection under msys2/mingw by convert the= m to meson first.
That need the meson 0.56 upstream to fixes the curses detection. Add
* configure: fixes indent of $meson setup

Yonggang Luo (4):
configure: fixes indent of $meson setup
curses: Fixes compiler error that complain don't have langinfo.h on
msys2/mingw
curses: Fixes curses compiling errors.
win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE
are defined on msys2/mingw

 configure                 | 42 ++++-----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 ui/curses.c               | 14 ++++++-------
 util/oslib-win32.c        |  4 ++--
 4 files changed, 15 insertions(+), 49 deletions(-)

--=20
2.28.0.windows.1

#1 lore raw

PATCH v6 1/4 configure: fixes indent of $meson setup

convert these line from tab to space

---
 configure | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
configure +4 -4
index ca9b458ea0..8f7bdbfdd3 100755
@@ -7843,10 +7843,10 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
         -Dstrip=$(if test "$strip_opt" = yes; then echo true; else echo false; fi) \
         -Db_pie=$(if test "$pie" = yes; then echo true; else echo false; fi) \
         -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \
-	-Dmalloc=$malloc -Dmalloc_trim=$malloc_trim \
-	-Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
-	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
-	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\
+        -Dmalloc=$malloc -Dmalloc_trim=$malloc_trim \
+        -Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
+        -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
+        -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
         $cross_arg \
         "$PWD" "$source_path"
 
Signature · 1 line
2.28.0.windows.1
Reviewed-by on v6 1/4
#2 lore raw

Re: [PATCH v6 1/4] configure: fixes indent of $meson setup

Quoted 6 lines · Yonggang Luo

convert these line from tab to space

---
 configure | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#3 lore raw

PATCH v6 2/4 curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

In reply to Yonggang Luo

msys2/mingw lacks the POSIX-required langinfo.h.

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.

So we using g_get_codeset instead of nl_langinfo(CODESET)

---
 ui/curses.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
ui/curses.c +5 -5
index a59b23a9cf..12bc682cf9 100644
@@ -30,7 +30,6 @@
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@ static void font_setup(void)
     iconv_t nativecharset_to_ucs2;
     iconv_t font_conv;
     int i;
+    g_autofree gchar *local_codeset = g_get_codeset();
 
     /*
      * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@ static void font_setup(void)
       0x25bc
     };
 
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+    ucs2_to_nativecharset = iconv_open(local_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", local_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 +581,7 @@ static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(local_codeset, font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);
@@ -602,7 +602,7 @@ static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(local_codeset, "UTF-8")) {
         /* Non-Unicode capable, use termcap equivalents for those available */
         for (i = 0; i <= 0xFF; i++) {
             wchar_t wch[CCHARW_MAX];
Signature · 1 line
2.28.0.windows.1
#4 lore raw

Re: [PATCH v6 2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

Quoted 63 lines · Yonggang Luo

msys2/mingw lacks the POSIX-required langinfo.h.

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.

So we using g_get_codeset instead of nl_langinfo(CODESET)

---
 ui/curses.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
ui/curses.c +4 -4
index a59b23a9cf..12bc682cf9 100644
@@ -30,7 +30,6 @@
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@ static void font_setup(void)
     iconv_t nativecharset_to_ucs2;
     iconv_t font_conv;
     int i;
+    g_autofree gchar *local_codeset = g_get_codeset();
 
     /*
      * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@ static void font_setup(void)
       0x25bc
     };
 
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+    ucs2_to_nativecharset = iconv_open(local_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", local_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 +581,7 @@ static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(local_codeset, font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);

ui/curses.c static void font_setup(void) · line 605

Quoted 5 lines
ui/curses.c +1 -1
@@ -602,7 +602,7 @@ static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(local_codeset, "UTF-8")) {

If you're removing use of nl_langinfo / langinfo.h then you need to also update configure, because it is checking for this function and header file when validating curses library support.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw

Re: [PATCH v6 2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

Quoted 5 lines · Daniel P. Berrangé
Quoted 3 lines · Yonggang Luo

msys2/mingw lacks the POSIX-required langinfo.h.

gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe

-lncursesw -lgnurx -ltre -lintl -liconv

Quoted 37 lines
Quoted 37 lines

test.c:4:10: fatal error: langinfo.h: No such file or directory
4 | #include <langinfo.h>
| ^~~~~~~~~~~~
compilation terminated.

So we using g_get_codeset instead of nl_langinfo(CODESET)

---
 ui/curses.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
ui/curses.c +1 -1
index a59b23a9cf..12bc682cf9 100644
@@ -30,7 +30,6 @@
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@ static void font_setup(void)
     iconv_t nativecharset_to_ucs2;
     iconv_t font_conv;
     int i;
+    g_autofree gchar *local_codeset = g_get_codeset();
 
     /*
      * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@ static void font_setup(void)
       0x25bc
     };
 
Quoted 4 lines

ui/curses.c static void font_setup(void)

Quoted 4 lines
ui/curses.c +1 -1
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
     if (ucs2_to_nativecharset == (iconv_t) -1) {
         fprintf(stderr, "Could not convert font glyphs from UCS-2:

'%s'\n",

Quoted 9 lines

ui/curses.c static void font_setup(void)

Quoted 9 lines
ui/curses.c +1 -1
                         strerror(errno));
         exit(1);
     }
 
-    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
+    nativecharset_to_ucs2 = iconv_open("UCS-2", local_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",

Quoted 13 lines
Quoted 13 lines
ui/curses.c +1 -1
@@ -581,7 +581,7 @@ static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(local_codeset, font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);
@@ -602,7 +602,7 @@ static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
Quoted 6 lines

ui/curses.c static void font_setup(void) · line 605

Quoted 2 lines
ui/curses.c +1 -1
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(local_codeset, "UTF-8")) {

If you're removing use of nl_langinfo / langinfo.h then you need to also update configure, because it is checking for this function and header file when validating curses library support.

The change of configure are waiting for meson 0.56, so I didn't post that yet And this patch
is a pre-request for msys2/mingw support and won't hurt other platform

We are converting everything to meson, so I am not willing to change configure this time

Quoted 6 lines

Regards,
Daniel
--
|: https://berrange.com -o-

https://www.flickr.com/photos/dberrange :|

Quoted 1 line

|: https://libvirt.org -o-

https://fstop138.berrange.com :|

Quoted 1 line

|: https://entangle-photo.org -o-

https://www.instagram.com/dberrange :|

Quoted 1 line

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

#6 lore raw

Re: [PATCH v6 2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

Quoted 79 lines · 罗勇刚(Yonggang Luo)
Quoted 5 lines · Daniel P. Berrangé
Quoted 3 lines · Yonggang Luo

msys2/mingw lacks the POSIX-required langinfo.h.

gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe

-lncursesw -lgnurx -ltre -lintl -liconv

Quoted 37 lines
Quoted 37 lines

test.c:4:10: fatal error: langinfo.h: No such file or directory
4 | #include <langinfo.h>
| ^~~~~~~~~~~~
compilation terminated.

So we using g_get_codeset instead of nl_langinfo(CODESET)

---
 ui/curses.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
ui/curses.c +1 -1
index a59b23a9cf..12bc682cf9 100644
@@ -30,7 +30,6 @@
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@ static void font_setup(void)
     iconv_t nativecharset_to_ucs2;
     iconv_t font_conv;
     int i;
+    g_autofree gchar *local_codeset = g_get_codeset();
 
     /*
      * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@ static void font_setup(void)
       0x25bc
     };
 
Quoted 4 lines

ui/curses.c static void font_setup(void)

Quoted 4 lines
ui/curses.c +1 -1
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
     if (ucs2_to_nativecharset == (iconv_t) -1) {
         fprintf(stderr, "Could not convert font glyphs from UCS-2:

'%s'\n",

Quoted 9 lines

ui/curses.c static void font_setup(void)

Quoted 9 lines
ui/curses.c +1 -1
                         strerror(errno));
         exit(1);
     }
 
-    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
+    nativecharset_to_ucs2 = iconv_open("UCS-2", local_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",

Quoted 13 lines
Quoted 13 lines
ui/curses.c +1 -1
@@ -581,7 +581,7 @@ static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(local_codeset, font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);
@@ -602,7 +602,7 @@ static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
Quoted 6 lines

ui/curses.c static void font_setup(void) · line 605

Quoted 2 lines
ui/curses.c +1 -1
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(local_codeset, "UTF-8")) {

If you're removing use of nl_langinfo / langinfo.h then you need to also update configure, because it is checking for this function and header file when validating curses library support.

Quoted 6 lines

The change of configure are waiting for meson 0.56, so I didn't post that yet And this patch
is a pre-request for msys2/mingw support and won't hurt other platform

We are converting everything to meson, so I am not willing to change configure this time

I don't see why the configure change has any dependancy on meson 0.56. It just requires you to remove the mentioned header file and function from the configure check. This patch needs to include that or it is incomplete IMHO

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

Re: [PATCH v6 2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

Quoted 4 lines · Daniel P. Berrangé

I don't see why the configure change has any dependancy on meson 0.56. It just requires you to remove the mentioned header file and function from the configure check. This patch needs to include that or it is incomplete IMHO

I agree, moving the check to Meson is waiting for 0.56 but for now the configure check needs to be maintained.

Paolo

#8 lore raw

Re: [PATCH v6 2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

In reply to Daniel P. Berrangé
Quoted 41 lines · Daniel P. Berrangé
Quoted 39 lines · 罗勇刚(Yonggang Luo)
Quoted 5 lines · Daniel P. Berrangé
Quoted 3 lines · Yonggang Luo

msys2/mingw lacks the POSIX-required langinfo.h.

gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe

-lncursesw -lgnurx -ltre -lintl -liconv

Quoted 31 lines
Quoted 31 lines

test.c:4:10: fatal error: langinfo.h: No such file or directory
4 | #include <langinfo.h>
| ^~~~~~~~~~~~
compilation terminated.

So we using g_get_codeset instead of nl_langinfo(CODESET)

---
 ui/curses.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
ui/curses.c +1 -1
index a59b23a9cf..12bc682cf9 100644
@@ -30,7 +30,6 @@
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@ static void font_setup(void)
     iconv_t nativecharset_to_ucs2;
     iconv_t font_conv;
     int i;
+    g_autofree gchar *local_codeset = g_get_codeset();
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

ui/curses.c static void font_setup(void) · line 531

Quoted 2 lines
ui/curses.c +0 -0
     /*
      * Control characters are normally non-printable, but VGA does

have

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

ui/curses.c static void font_setup(void) · line 569

Quoted 5 lines
ui/curses.c +0 -1
@@ -566,14 +566,14 @@ static void font_setup(void)
       0x25bc
     };
 
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET),

"UCS-2");

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

ui/curses.c static void font_setup(void)

Quoted 3 lines
ui/curses.c +1 -0
+    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
     if (ucs2_to_nativecharset == (iconv_t) -1) {
         fprintf(stderr, "Could not convert font glyphs from UCS-2:

'%s'\n",

Quoted 5 lines
Quoted 5 lines
ui/curses.c +0 -1
                         strerror(errno));
         exit(1);
     }
 
-    nativecharset_to_ucs2 = iconv_open("UCS-2",

nl_langinfo(CODESET));

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

ui/curses.c static void font_setup(void)

Quoted 4 lines
ui/curses.c +1 -0
+    nativecharset_to_ucs2 = iconv_open("UCS-2", local_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",

Quoted 13 lines
Quoted 13 lines
ui/curses.c +1 -1
@@ -581,7 +581,7 @@ static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(local_codeset, font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);
@@ -602,7 +602,7 @@ static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

ui/curses.c static void font_setup(void) · line 605

Quoted 2 lines
ui/curses.c +1 -1
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(local_codeset, "UTF-8")) {

If you're removing use of nl_langinfo / langinfo.h then you need to also update configure, because it is checking for this function and header file when validating curses library support.

The change of configure are waiting for meson 0.56, so I didn't post

that

Quoted 11 lines
Quoted 5 lines

yet And this patch
is a pre-request for msys2/mingw support and won't hurt other platform

We are converting everything to meson, so I am not willing to change configure this time

I don't see why the configure change has any dependancy on meson 0.56. It just requires you to remove the mentioned header file and function from the configure check. This patch needs to include that or it is incomplete IMHO

Because the configure script change far more complicated than you imgaine. And I post that before

Quoted 4 lines

Regards,
Daniel
--
|: https://berrange.com -o-

https://www.flickr.com/photos/dberrange :|

Quoted 1 line

|: https://libvirt.org -o-

https://fstop138.berrange.com :|

Quoted 1 line

|: https://entangle-photo.org -o-

https://www.instagram.com/dberrange :|

Quoted 1 line

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

#9 lore raw

Re: [PATCH v6 2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

Quoted 2 lines · 罗勇刚(Yonggang Luo)

Because the configure script change far more complicated than you imgaine. And I post that before

Daniel is literally asking for a two-line change:

configure +0 -2
index fee5faa054..ffd72b571d 100755
@@ -3671,7 +3671,6 @@ 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';
@@ -3680,7 +3679,6 @@ int main(void) {
   addwstr(L"wide chars\n");
   addnwstr(&wch, 1);
   add_wch(WACS_DEGREE);
-  codeset = nl_langinfo(CODESET);
   return codeset != 0;
 }
 EOF

Paolo

#10 lore raw

Re: [PATCH v6 2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

gotcha

Quoted 28 lines · Paolo Bonzini
Quoted 2 lines · 罗勇刚(Yonggang Luo)

Because the configure script change far more complicated than you imgaine. And I post that before

Daniel is literally asking for a two-line change:

configure +0 -2
index fee5faa054..ffd72b571d 100755
@@ -3671,7 +3671,6 @@ 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';
@@ -3680,7 +3679,6 @@ int main(void) {
   addwstr(L"wide chars\n");
   addnwstr(&wch, 1);
   add_wch(WACS_DEGREE);
-  codeset = nl_langinfo(CODESET);
   return codeset != 0;
 }
 EOF
Quoted 2 lines

Paolo

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

#11 lore raw

PATCH v6 3/4 curses: Fixes curses compiling errors.

In reply to Yonggang Luo

This is the compiling error:
../ui/curses.c: In function 'curses_refresh':
../ui/curses.c:256:5: error: 'next_maybe_keycode' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  256 |     curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
      |     ^~~~~~~~~~
../ui/curses.c:302:32: note: 'next_maybe_keycode' was declared here
  302 |             enum maybe_keycode next_maybe_keycode;
      |                                ^~~~~~~~~~~~~~~~~~
../ui/curses.c:256:5: error: 'maybe_keycode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  256 |     curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
      |     ^~~~~~~~~~
../ui/curses.c:265:24: note: 'maybe_keycode' was declared here
  265 |     enum maybe_keycode maybe_keycode;
      |                        ^~~~~~~~~~~~~

cc1.exe: all warnings being treated as errors

gcc version 10.2.0 (Rev1, Built by MSYS2 project)

---
 ui/curses.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ui/curses.c +2 -2
index 12bc682cf9..e4f9588c3e 100644
@@ -262,7 +262,7 @@ static int curses2foo(const int _curses2foo[], const int _curseskey2foo[],
 static void curses_refresh(DisplayChangeListener *dcl)
 {
     int chr, keysym, keycode, keycode_alt;
-    enum maybe_keycode maybe_keycode;
+    enum maybe_keycode maybe_keycode = CURSES_KEYCODE;
 
     curses_winch_check();
 
@@ -299,7 +299,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
 
         /* alt or esc key */
         if (keycode == 1) {
-            enum maybe_keycode next_maybe_keycode;
+            enum maybe_keycode next_maybe_keycode = CURSES_KEYCODE;
             int nextchr = console_getch(&next_maybe_keycode);
 
             if (nextchr != -1) {
Signature · 1 line
2.28.0.windows.1
#12 lore raw

PATCH v6 4/4 win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE are defined on msys2/mingw

In reply to Yonggang Luo

We remove the CONFIG_LOCALTIME_R detection option in configure, and move the check existence of gmtime_r from configure into C header and source directly by using macro _POSIX_THREAD_SAFE_FUNCTIONS.
Before this patch, the configure script are always assume the compiler doesn't define _POSIX_C_SOURCE macro at all, but that's not true, because thirdparty library such as ncursesw may define -D_POSIX_C_SOURCE in it's pkg-config file. And that C Flags will added -D_POSIX_C_SOURCE into each QEMU_CFLAGS. And that's causing the following compiling error:
n file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../softmmu/main.c:25:
C:/work/xemu/qemu/include/sysemu/os-win32.h:53:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-decls]
   53 | struct tm *gmtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../softmmu/main.c:25:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:284:36: note: previous definition of 'gmtime_r' was here
284 | __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../softmmu/main.c:25:
C:/work/xemu/qemu/include/sysemu/os-win32.h:55:12: error: redundant redeclaration of 'localtime_r' [-Werror=redundant-decls]
   55 | struct tm *localtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../softmmu/main.c:25:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:281:36: note: previous definition of 'localtime_r' was here
281 | __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~~~~
Compiling C object libcommon.fa.p/hw_gpio_zaurus.c.obj
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../hw/i2c/smbus_slave.c:16:
C:/work/xemu/qemu/include/sysemu/os-win32.h:53:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-decls]
   53 | struct tm *gmtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../hw/i2c/smbus_slave.c:16:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:284:36: note: previous definition of 'gmtime_r' was here
284 | __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../hw/i2c/smbus_slave.c:16:
C:/work/xemu/qemu/include/sysemu/os-win32.h:55:12: error: redundant redeclaration of 'localtime_r' [-Werror=redundant-decls]
   55 | struct tm *localtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../hw/i2c/smbus_slave.c:16:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:281:36: note: previous definition of 'localtime_r' was here
281 | __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~~~~
Compiling C object libcommon.fa.p/hw_dma_xilinx_axidma.c.obj

After this patch, whenever ncursesw or other thirdparty libraries tried to define or not define _POSIX_C_SOURCE, the source will building properly. Because now, we don't make any assumption if _POSIX_C_SOURCE are defined. We solely relied on if the macro _POSIX_THREAD_SAFE_FUNCTIONS are defined in msys2/mingw header.

The _POSIX_THREAD_SAFE_FUNCTIONS are defined in mingw header like this:

```
#if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
#endif

#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
__forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
  return localtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
  return gmtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {
  return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;
}
__forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {
  return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;
}
#endif
```
---
 configure                 | 34 ----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 util/oslib-win32.c        |  4 ++--
 3 files changed, 4 insertions(+), 38 deletions(-)
configure +0 -34
index 8f7bdbfdd3..d6dd147235 100755
@@ -2500,37 +2500,6 @@ if test "$vhost_net" = ""; then
   test "$vhost_kernel" = "yes" && vhost_net=yes
 fi
 
-##########################################
-# MinGW / Mingw-w64 localtime_r/gmtime_r check
-
-if test "$mingw32" = "yes"; then
-    # Some versions of MinGW / Mingw-w64 lack localtime_r
-    # and gmtime_r entirely.
-    #
-    # Some versions of Mingw-w64 define a macro for
-    # localtime_r/gmtime_r.
-    #
-    # Some versions of Mingw-w64 will define functions
-    # for localtime_r/gmtime_r, but only if you have
-    # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun
-    # though, unistd.h and pthread.h both define
-    # that for you.
-    #
-    # So this #undef localtime_r and #include <unistd.h>
-    # are not in fact redundant.
-cat > $TMPC << EOF
-#include <unistd.h>
-#include <time.h>
-#undef localtime_r
-int main(void) { localtime_r(NULL, NULL); return 0; }
-EOF
-    if compile_prog "" "" ; then
-        localtime_r="yes"
-    else
-        localtime_r="no"
-    fi
-fi
-
 ##########################################
 # pkg-config probe
 
@@ -6937,9 +6906,6 @@ if [ "$bsd" = "yes" ] ; then
   echo "CONFIG_BSD=y" >> $config_host_mak
 fi
 
-if test "$localtime_r" = "yes" ; then
-  echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak
-fi
 if test "$qom_cast_debug" = "yes" ; then
   echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
 fi
include/sysemu/os-win32.h +2 -2
index d8978e28c0..5346d51e89 100644
@@ -48,12 +48,12 @@
 #define siglongjmp(env, val) longjmp(env, val)
 
 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
-#ifndef CONFIG_LOCALTIME_R
+#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 #undef gmtime_r
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
 #undef localtime_r
 struct tm *localtime_r(const time_t *timep, struct tm *result);
-#endif /* CONFIG_LOCALTIME_R */
+#endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
 
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
util/oslib-win32.c +2 -2
index 051afb217b..e99debfb8d 100644
@@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size)
     }
 }
 
-#ifndef CONFIG_LOCALTIME_R
+#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 /* FIXME: add proper locking */
 struct tm *gmtime_r(const time_t *timep, struct tm *result)
 {
@@ -130,7 +130,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
     }
     return p;
 }
-#endif /* CONFIG_LOCALTIME_R */
+#endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
 
 static int socket_error(void)
 {
Signature · 1 line
2.28.0.windows.1
Reviewed-by on v6 4/4
#13 lore raw

Re: [PATCH v6 4/4] win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE are defined on msys2/mingw

Quoted 78 lines · Yonggang Luo

We remove the CONFIG_LOCALTIME_R detection option in configure, and move the check existence of gmtime_r from configure into C header and source directly by using macro _POSIX_THREAD_SAFE_FUNCTIONS.
Before this patch, the configure script are always assume the compiler doesn't define _POSIX_C_SOURCE macro at all, but that's not true, because thirdparty library such as ncursesw may define -D_POSIX_C_SOURCE in it's pkg-config file. And that C Flags will added -D_POSIX_C_SOURCE into each QEMU_CFLAGS. And that's causing the following compiling error:
n file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../softmmu/main.c:25:
C:/work/xemu/qemu/include/sysemu/os-win32.h:53:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-decls]
   53 | struct tm *gmtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../softmmu/main.c:25:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:284:36: note: previous definition of 'gmtime_r' was here
284 | __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../softmmu/main.c:25:
C:/work/xemu/qemu/include/sysemu/os-win32.h:55:12: error: redundant redeclaration of 'localtime_r' [-Werror=redundant-decls]
   55 | struct tm *localtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../softmmu/main.c:25:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:281:36: note: previous definition of 'localtime_r' was here
281 | __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~~~~
Compiling C object libcommon.fa.p/hw_gpio_zaurus.c.obj
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../hw/i2c/smbus_slave.c:16:
C:/work/xemu/qemu/include/sysemu/os-win32.h:53:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-decls]
   53 | struct tm *gmtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../hw/i2c/smbus_slave.c:16:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:284:36: note: previous definition of 'gmtime_r' was here
284 | __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119,

                 from ../hw/i2c/smbus_slave.c:16:
C:/work/xemu/qemu/include/sysemu/os-win32.h:55:12: error: redundant redeclaration of 'localtime_r' [-Werror=redundant-decls]
   55 | struct tm *localtime_r(const time_t *timep, struct tm *result);
      |            ^~~~~~~~~~~
In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94,
                 from ../hw/i2c/smbus_slave.c:16:

C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:281:36: note: previous definition of 'localtime_r' was here
281 | __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
| ^~~~~~~~~~~
Compiling C object libcommon.fa.p/hw_dma_xilinx_axidma.c.obj

After this patch, whenever ncursesw or other thirdparty libraries tried to define or not define _POSIX_C_SOURCE, the source will building properly. Because now, we don't make any assumption if _POSIX_C_SOURCE are defined. We solely relied on if the macro _POSIX_THREAD_SAFE_FUNCTIONS are defined in msys2/mingw header.

The _POSIX_THREAD_SAFE_FUNCTIONS are defined in mingw header like this:

```
#if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
#endif

#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
__forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
  return localtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
  return gmtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {
  return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;
}
__forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {
  return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;
}
#endif
```
Quoted 6 lines
---
 configure                 | 34 ----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 util/oslib-win32.c        |  4 ++--
 3 files changed, 4 insertions(+), 38 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#14 lore raw
In reply to Yonggang Luo
Quoted 16 lines · Yonggang Luo

And also convert related configure script to meson.
V5-V6
Dropping configure: Fixes ncursesw detection under msys2/mingw by convert the= m to meson first.
That need the meson 0.56 upstream to fixes the curses detection. Add
* configure: fixes indent of $meson setup

Yonggang Luo (4):
configure: fixes indent of $meson setup
curses: Fixes compiler error that complain don't have langinfo.h on
msys2/mingw
curses: Fixes curses compiling errors.
win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE
are defined on msys2/mingw

Quoted 10 lines
 configure                 | 42 ++++-----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 ui/curses.c               | 14 ++++++-------
 util/oslib-win32.c        |  4 ++--
 4 files changed, 15 insertions(+), 49 deletions(-)

--=20
2.28.0.windows.1

Looks good (though there is no conversion to meson yet in this version).

Not trivial, but perhaps Gerd can take it?

Paolo

#15 lore raw
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Yonggang Luo

And also convert related configure script to meson.
V5-V6
Dropping configure: Fixes ncursesw detection under msys2/mingw by convert the= m to meson first.
That need the meson 0.56 upstream to fixes the curses detection. Add
* configure: fixes indent of $meson setup

Yonggang Luo (4):
configure: fixes indent of $meson setup
curses: Fixes compiler error that complain don't have langinfo.h on
msys2/mingw
curses: Fixes curses compiling errors.
win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE
are defined on msys2/mingw

 configure                 | 42 ++++-----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 ui/curses.c               | 14 ++++++-------
 util/oslib-win32.c        |  4 ++--
 4 files changed, 15 insertions(+), 49 deletions(-)
Quoted 8 lines
Quoted 4 lines

--=20
2.28.0.windows.1

Looks good (though there is no conversion to meson yet in this version).

Not trivial, but perhaps Gerd can take it?

Sure, series looks good.

Can't finish this today due to -ENOTIME and I'm offline next week so this has to wait a bit in the UI patch queue ...

take care,
Gerd

#16 lore raw
Quoted 29 lines · Gerd Hoffmann
Quoted 28 lines · Paolo Bonzini
Quoted 26 lines · Yonggang Luo

And also convert related configure script to meson.
V5-V6
Dropping configure: Fixes ncursesw detection under msys2/mingw by convert the= m to meson first.
That need the meson 0.56 upstream to fixes the curses detection. Add
* configure: fixes indent of $meson setup

Yonggang Luo (4):
configure: fixes indent of $meson setup
curses: Fixes compiler error that complain don't have langinfo.h on
msys2/mingw
curses: Fixes curses compiling errors.
win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE
are defined on msys2/mingw

 configure                 | 42 ++++-----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 ui/curses.c               | 14 ++++++-------
 util/oslib-win32.c        |  4 ++--
 4 files changed, 15 insertions(+), 49 deletions(-)

--=20
2.28.0.windows.1

Quoted 8 lines
Quoted 3 lines

Looks good (though there is no conversion to meson yet in this version).

Not trivial, but perhaps Gerd can take it?

Sure, series looks good.

Can't finish this today due to -ENOTIME and I'm offline next week so this has to wait a bit in the UI patch queue ...

Patch 2 needs more work I think, as its missing the corresponding configure change.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#17 lore raw
Quoted 34 lines · Daniel P. Berrangé
Quoted 33 lines · Gerd Hoffmann
Quoted 31 lines · Paolo Bonzini
Quoted 16 lines · Yonggang Luo

And also convert related configure script to meson.
V5-V6
Dropping configure: Fixes ncursesw detection under msys2/mingw by convert the= m to meson first.
That need the meson 0.56 upstream to fixes the curses detection. Add
* configure: fixes indent of $meson setup

Yonggang Luo (4):
configure: fixes indent of $meson setup
curses: Fixes compiler error that complain don't have langinfo.h on
msys2/mingw
curses: Fixes curses compiling errors.
win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE
are defined on msys2/mingw

Quoted 10 lines
 configure                 | 42 ++++-----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 ui/curses.c               | 14 ++++++-------
 util/oslib-win32.c        |  4 ++--
 4 files changed, 15 insertions(+), 49 deletions(-)

--=20
2.28.0.windows.1

Looks good (though there is no conversion to meson yet in this version).

Not trivial, but perhaps Gerd can take it?

Quoted 7 lines
Quoted 4 lines

Sure, series looks good.

Can't finish this today due to -ENOTIME and I'm offline next week so this has to wait a bit in the UI patch queue ...

Patch 2 needs more work I think, as its missing the corresponding configure change.

Also the series must be adapted to latest master, auto-rebase didn't work ...

take care,
Gerd