Discussion:
[PATCH] localename: Port to cygwin 2.6.
(too old to reply)
Eric Blake
2017-01-19 20:30:57 UTC
Permalink
Raw Message
Cygwin 2.6 introduced uselocale() and thread-local locales in general,
but lacks any way to get at the name of each portion of a locale_t
object short of peeking behind an opaque object. I'm proposing a
patch to add NL_LOCALE_NAME() to Cygwin patterned after glibc's
extension of the same name, but we might as well work around it
in the meantime.

* lib/localename.c (gl_locale_name_thread_unsafe): Add clause for
Cygwin.

Signed-off-by: Eric Blake <***@redhat.com>
---

I won't actually push this to gnulib until I've sent the corresponding
newlib/Cygwin patch to add NL_LOCALE_NAME, and tweaked the commit
messages of both patches to refer to the appropriate mailing list
threads. But this was enough to get test-localename passing on
Cygwin again.

ChangeLog | 6 ++++++
lib/localename.c | 13 +++++++++++++
2 files changed, 19 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index e4339fc..f0e23a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-01-19 Eric Blake <***@redhat.com>
+
+ localename: Port to cygwin 2.6.
+ * lib/localename.c (gl_locale_name_thread_unsafe): Add clause for
+ Cygwin.
+
2017-01-17 Pádraig Brady <***@draigBrady.com>

parse-datetime: fix dependence on AC_PROG_SED
diff --git a/lib/localename.c b/lib/localename.c
index 33879e9..89ce889 100644
--- a/lib/localename.c
+++ b/lib/localename.c
@@ -2734,6 +2734,19 @@ gl_locale_name_thread_unsafe (int category, const char *categoryname)
# elif defined __sun && HAVE_GETLOCALENAME_L
/* Solaris >= 12. */
return getlocalename_l (category, thread_locale);
+# elif defined __CYGWIN__
+ /* Cygwin < 2.6 lacks uselocale and thread-local locales altogether.
+ Cygwin <= 2.6.1 lacks NL_LOCALE_NAME, requiring peeking inside
+ an opaque struct. */
+# ifdef NL_LOCALE_NAME
+ return nl_langinfo_l (NL_LOCALE_NAME (category), thread_locale);
+# else
+ /* FIXME: Remove when we can assume new-enough Cygwin. */
+ struct __locale_t {
+ char categories[7][32];
+ };
+ return ((struct __locale_t *) thread_locale)->categories[category];
+# endif
# elif defined __ANDROID__
return MB_CUR_MAX == 4 ? "C.UTF-8" : "C";
# endif
--
2.9.3
Eric Blake
2017-01-20 02:47:29 UTC
Permalink
Raw Message
Post by Eric Blake
Cygwin 2.6 introduced uselocale() and thread-local locales in general,
but lacks any way to get at the name of each portion of a locale_t
object short of peeking behind an opaque object. I'm proposing a
patch to add NL_LOCALE_NAME() to Cygwin patterned after glibc's
extension of the same name, but we might as well work around it
in the meantime.
* lib/localename.c (gl_locale_name_thread_unsafe): Add clause for
Cygwin.
---
I won't actually push this to gnulib until I've sent the corresponding
newlib/Cygwin patch to add NL_LOCALE_NAME, and tweaked the commit
messages of both patches to refer to the appropriate mailing list
threads. But this was enough to get test-localename passing on
Cygwin again.
+# ifdef NL_LOCALE_NAME
+ return nl_langinfo_l (NL_LOCALE_NAME (category), thread_locale);
Here's the proposed cygwin patch for adding NL_LOCALE_NAME():
https://sourceware.org/ml/newlib/2017/msg00071.html
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Eric Blake
2017-01-20 15:30:35 UTC
Permalink
Raw Message
Post by Eric Blake
Cygwin 2.6 introduced uselocale() and thread-local locales in general,
but lacks any way to get at the name of each portion of a locale_t
object short of peeking behind an opaque object. I'm proposing a
patch to add NL_LOCALE_NAME() to Cygwin patterned after glibc's
extension of the same name, but we might as well work around it
in the meantime.
* lib/localename.c (gl_locale_name_thread_unsafe): Add clause for
Cygwin.
---
I won't actually push this to gnulib until I've sent the corresponding
newlib/Cygwin patch to add NL_LOCALE_NAME, and tweaked the commit
messages of both patches to refer to the appropriate mailing list
threads. But this was enough to get test-localename passing on
Cygwin again.
Now pushed.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Bruno Haible
2017-01-23 10:47:43 UTC
Permalink
Raw Message
Hi Eric,
Post by Eric Blake
Post by Eric Blake
But this was enough to get test-localename passing on
Cygwin again.
Now pushed.
Thanks, Eric. I confirm that this fixes the 'test-localename' on 64-bit Cygwin
2.6.1. My test results with
$ ./gnulib-tool --create-testdir --dir=/tmp/testdir1 --with-tests --single-configure duplocale localename

testdir before your change
- cygwin32 OK
- cygwin64 test-duplocale crashes, test-localename fails

testdir after your change
- cygwin32 OK
- cygwin64 test-duplocale crashes

There still is a crash in test-duplocale. It occurs in
main (test-duplocale.c:100)
-> get_locale_dependent_values (test-duplocale.c:45)
-> strfmon

I'm using Cygwin 2.6.1(0.305/5/3) 2016-12-16 11:55.

By the way, is it normal that gdb is so unhelpful on Cygwin?
$ gdb test-duplocale
(gdb) run
Starting program: ...
[New thread]
[New thread]
[New thread]
[New thread]
2 [main] test-duplocale 4668 cygwin_exception::open_stackdumpfile: Dumping stack trace to test-duplocale.exe.stackdump
[Thread exited]
[Thread exited]
[Inferior 1 (process 4668) exited with code 0105400]
(gdb) where
No stack.

Bruno
Eric Blake
2017-01-23 14:23:10 UTC
Permalink
Raw Message
Post by Bruno Haible
testdir before your change
- cygwin32 OK
- cygwin64 test-duplocale crashes, test-localename fails
testdir after your change
- cygwin32 OK
- cygwin64 test-duplocale crashes
I'll see if I can figure that one out.
Post by Bruno Haible
There still is a crash in test-duplocale. It occurs in
main (test-duplocale.c:100)
-> get_locale_dependent_values (test-duplocale.c:45)
-> strfmon
I'm using Cygwin 2.6.1(0.305/5/3) 2016-12-16 11:55.
By the way, is it normal that gdb is so unhelpful on Cygwin?
Are you using CFLAGS=-g? Without debugging symbols, there's not much to
debug.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Bruno Haible
2017-01-23 14:36:58 UTC
Permalink
Raw Message
Post by Eric Blake
Post by Bruno Haible
There still is a crash in test-duplocale. It occurs in
main (test-duplocale.c:100)
-> get_locale_dependent_values (test-duplocale.c:45)
-> strfmon
I'm using Cygwin 2.6.1(0.305/5/3) 2016-12-16 11:55.
By the way, is it normal that gdb is so unhelpful on Cygwin?
Are you using CFLAGS=-g? Without debugging symbols, there's not much to
debug.
Of course I'm using "-g -O0" when I want to debug something.
I'm complaining about the facts that
1. gdb doesn't stop the process before it's about to crash,
2. the testduplocale.exe.stackdump file contains a list of addresses
(from the stack), and it would be useful if gdb showed this
as a stack trace. But it doesn't.

Bruno
Bruno Haible
2017-05-18 22:51:01 UTC
Permalink
Raw Message
Post by Eric Blake
* lib/localename.c (gl_locale_name_thread_unsafe): Add clause for
Cygwin.
It relies on the NL_LOCALE_NAME macro, which is defined in <langinfo.h>.
Better than to hope that it gets included by chance, include it explicitly.


2017-05-18 Bruno Haible <***@clisp.org>

localename: Include necessary header files on Cygwin.
* lib/localename.c [__CYGWIN__]: Include <langinfo.h>, since this is
where NL_LOCALE_NAME is defined.

diff --git a/lib/localename.c b/lib/localename.c
index 3ba9d08..eb0755c 100644
--- a/lib/localename.c
+++ b/lib/localename.c
@@ -40,7 +40,7 @@
# if defined __APPLE__ && defined __MACH__
# include <xlocale.h>
# endif
-# if __GLIBC__ >= 2 && !defined __UCLIBC__
+# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || defined __CYGWIN__
# include <langinfo.h>
# endif
# if !defined IN_LIBINTL

Loading...