On Sun, Jul 12, 2015 at 03:51:14PM +0200, Sebastien Marie wrote:
> ctype.h header define MB_CUR_MAX macro to be the maximum number of bytes
> in a character specified by the current locale (category LC_CTYPE).
>
> Switch the implementation from global variable to function, in order to
> get the value from the current locale state (global or per-thread).
>
Updated patch:
- as __mb_cur_max is now a function, it should be between __BEGIN_DECLS
and __END_DECLS else C++ don't see it.
--
Sebastien Marie
Index: b/include/stdlib.h
===================================================================
--- a/include/stdlib.h 2015-07-09 09:38:57.743213873 +0200
+++ b/include/stdlib.h 2015-07-14 11:47:29.235163404 +0200
@@ -92,8 +92,7 @@
#define RAND_MAX 0x7fffffff
-extern size_t __mb_cur_max;
-#define MB_CUR_MAX __mb_cur_max
+#define MB_CUR_MAX __mb_cur_max()
#include <sys/cdefs.h>
@@ -107,6 +106,7 @@
#endif
__BEGIN_DECLS
+size_t __mb_cur_max(void);
__dead void abort(void);
int abs(int);
int atexit(void (*)(void));
Index: b/lib/libc/locale/__mb_cur_max.c
===================================================================
--- a/lib/libc/locale/__mb_cur_max.c 2015-07-09 09:38:57.743213873 +0200
+++ b/lib/libc/locale/__mb_cur_max.c 2015-07-09 09:50:46.178175455 +0200
@@ -30,6 +30,19 @@
#include <sys/types.h>
#include <limits.h>
-size_t __mb_cur_max = 1;
+#include "rune.h"
+#include "citrus/citrus_ctype_local.h"
+#include "xlocale_private.h"
+
size_t __mb_len_max_runtime = MB_LEN_MAX;
+size_t
+__mb_cur_max()
+{
+ locale_t loc = _current_locale();
+
+ if (loc->lc_ctype->rl_citrus_ctype != NULL)
+ return (loc->lc_ctype->rl_citrus_ctype->cc_mb_cur_max);
+ else
+ return (1);
+}
Index: b/lib/libc/locale/setrunelocale.c
===================================================================
--- a/lib/libc/locale/setrunelocale.c 2015-07-09 09:48:35.757157373 +0200
+++ b/lib/libc/locale/setrunelocale.c 2015-07-09 09:50:46.178175455 +0200
@@ -218,7 +218,6 @@
found:
locale->lc_ctype = rl;
- __mb_cur_max = rl->rl_citrus_ctype->cc_mb_cur_max;
return 0;
}