Skip to content

Commit

Permalink
Fix locale_t under macOS 10.10
Browse files Browse the repository at this point in the history
`xlocale.h` is not available on Linux, so we can't just universally
include it.

`HAVE_XLOCALE_H` was already being tested/set in the CMake script as a
possible requirement for `wcstod_l` support, this just adds it to
`config_cmake_h.in` and uses it in `wutil.h` to gate the include.
  • Loading branch information
mqudsi committed Jan 11, 2019
1 parent b402b63 commit 2bb53f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config_cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
/* The size of wchar_t in bits. */
#define WCHAR_T_BITS ${WCHAR_T_BITS}

/* Define if xlocale.h is required for locale_t or wide character support */
#cmakedefine HAVE_XLOCALE_H 1

/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
Expand Down
4 changes: 4 additions & 0 deletions src/wutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <locale.h>
#include <string>

#ifdef HAVE_XLOCALE_H
#include <xlocale.h>
#endif

#include "common.h"
#include "maybe.h"

Expand Down

5 comments on commit 2bb53f7

@zanchey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using xlocale is almost always wrong, as far as I can tell. I haven't got 10.10 running anywhere still; what's the compilation error you're getting without this?

@mqudsi
Copy link
Contributor Author

@mqudsi mqudsi commented on 2bb53f7 Jan 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locale_t is undefined without it. Note that xlocale.h was also required to get wcstod_l under FreeBSD.

@zanchey
Copy link
Member

@zanchey zanchey commented on 2bb53f7 Jan 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting; POSIX requires locale.h to define locale_t, although I suppose 10.10 might have predated that requirement (added in issue 7).

Anyway pulling in <sstream> pulls in <xlocale.h> on 10.11, which I guess is why this just worked beforehand.

@mqudsi
Copy link
Contributor Author

@mqudsi mqudsi commented on 2bb53f7 Jan 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into it and for that info.

@floam
Copy link
Member

@floam floam commented on 2bb53f7 Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can define _USE_EXTENDED_LOCALES_ and then stdlib.h includes xlocale.h itself on Darwin and FreeBSD.

Please sign in to comment.