Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2016-08-25 15:18:31 +0300
committerCorinna Vinschen <corinna@vinschen.de>2016-08-25 15:18:31 +0300
commite97109184ab0a2de680a90a432d94f86e5be7b0f (patch)
tree5185755b1866aeaeb18c89c12daa813053625308 /newlib
parent988629da1d299cfef7023e07ad900dd047b9fc63 (diff)
Drop global __ctype_ptr__ entirely in favor of using locale_t::ctype_ptr
Keep __ctype_ptr__ available on Cygwin only, for backward compatibility with existing apps referencing it via the ctype macros. Otherwise initialize __global_locale.ctype_ptr and __C_locale.ctype_ptr and use them throughout. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'newlib')
-rw-r--r--newlib/libc/ctype/ctype_.c31
-rw-r--r--newlib/libc/ctype/ctype_.h18
-rw-r--r--newlib/libc/locale/locale.c21
3 files changed, 33 insertions, 37 deletions
diff --git a/newlib/libc/ctype/ctype_.c b/newlib/libc/ctype/ctype_.c
index 8945c5631..9e3cdcf05 100644
--- a/newlib/libc/ctype/ctype_.c
+++ b/newlib/libc/ctype/ctype_.c
@@ -35,7 +35,7 @@
static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90";
#endif /* LIBC_SCCS and not lint */
-#include <ctype.h>
+#include "ctype_.h"
#include "../locale/setlocale.h"
#define _CTYPE_DATA_0_127 \
@@ -74,10 +74,6 @@ static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90";
0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0
-#if (defined(__GNUC__) && !defined(__CHAR_UNSIGNED__) && !defined(COMPACT_CTYPE)) || defined (__CYGWIN__)
-#define ALLOW_NEGATIVE_CTYPE_INDEX
-#endif
-
#if defined(_MB_CAPABLE)
#if defined(_MB_EXTENDED_CHARSETS_ISO)
#include "ctype_iso.h"
@@ -91,7 +87,7 @@ static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90";
/* No static const on Cygwin since it's referenced and potentially overwritten
for compatibility with older applications. */
#ifndef __CYGWIN__
-static _CONST
+_CONST
#endif
char _ctype_b[128 + 256] = {
_CTYPE_DATA_128_255,
@@ -99,12 +95,10 @@ char _ctype_b[128 + 256] = {
_CTYPE_DATA_128_255
};
-#ifndef _MB_CAPABLE
-_CONST
-#endif
-char __EXPORT *__ctype_ptr__ = (char *) _ctype_b + 127;
-
# ifdef __CYGWIN__
+/* For backward compatibility */
+char __EXPORT *__ctype_ptr__ = DEFAULT_CTYPE_PTR;
+
# ifdef __x86_64__
__asm__ (" \n\
.data \n\
@@ -137,11 +131,6 @@ _CONST char _ctype_[1 + 256] = {
_CTYPE_DATA_128_255
};
-#ifndef _MB_CAPABLE
-_CONST
-#endif
-char *__ctype_ptr__ = (char *) _ctype_;
-
#endif /* !ALLOW_NEGATIVE_CTYPE_INDEX */
#if defined(_MB_CAPABLE)
@@ -191,15 +180,9 @@ __set_ctype (struct __locale_t *loc, const char *charset)
# endif
}
# if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
- if (loc)
- loc->ctype_ptr = ctype_ptr + 127;
- else
- __ctype_ptr__ = ctype_ptr + 127;
+ loc->ctype_ptr = ctype_ptr + 127;
# else
- if (loc)
- loc->ctype_ptr = ctype_ptr;
- else
- __ctype_ptr__ = ctype_ptr;
+ loc->ctype_ptr = ctype_ptr;
# endif
}
#endif /* !__CYGWIN__ */
diff --git a/newlib/libc/ctype/ctype_.h b/newlib/libc/ctype/ctype_.h
new file mode 100644
index 000000000..3b59a27d5
--- /dev/null
+++ b/newlib/libc/ctype/ctype_.h
@@ -0,0 +1,18 @@
+#include <ctype.h>
+
+#if (defined(__GNUC__) && !defined(__CHAR_UNSIGNED__) && !defined(COMPACT_CTYPE)) || defined (__CYGWIN__)
+#define ALLOW_NEGATIVE_CTYPE_INDEX
+#endif
+
+#ifdef ALLOW_NEGATIVE_CTYPE_INDEX
+
+ extern char _ctype_b[];
+# define DEFAULT_CTYPE_PTR ((char *) _ctype_b + 127)
+
+#else /* !ALLOW_NEGATIVE_CTYPE_INDEX */
+
+ extern char _ctype_[];
+# define DEFAULT_CTYPE_PTR ((char *) _ctype_)
+
+#endif /* !ALLOW_NEGATIVE_CTYPE_INDEX */
+
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index fe04395b6..b7ced4d40 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -172,13 +172,13 @@ No supporting OS subroutines are required.
#include <newlib.h>
#include <errno.h>
-#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <reent.h>
#include <stdlib.h>
#include <wchar.h>
#include "setlocale.h"
+#include "../ctype/ctype_.h"
#include "../stdlib/local.h"
#ifdef __CYGWIN__ /* Has to be kept available as exported symbol for
@@ -225,7 +225,7 @@ const struct __locale_t __C_locale =
__ascii_wctomb,
__ascii_mbtowc,
0,
- NULL,
+ DEFAULT_CTYPE_PTR,
{
".", "", "", "", "", "", "", "", "", "",
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
@@ -266,7 +266,7 @@ struct __locale_t __global_locale =
__ascii_mbtowc,
#endif
0,
- NULL,
+ DEFAULT_CTYPE_PTR,
{
".", "", "", "", "", "", "", "", "", "",
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
@@ -901,7 +901,7 @@ restart:
#endif
loc->wctomb = l_wctomb;
loc->mbtowc = l_mbtowc;
- __set_ctype (loc == __get_global_locale () ? NULL : loc, charset);
+ __set_ctype (loc, charset);
/* Determine the width for the "CJK Ambiguous Width" category of
characters. This is used in wcwidth(). Assume single width for
single-byte charsets, and double width for multi-byte charsets
@@ -988,20 +988,15 @@ _DEFUN_VOID (__locale_mb_cur_max)
}
const char *
-__locale_ctype_ptr (void)
+__locale_ctype_ptr_l (struct __locale_t *locale)
{
- /* Only check if the current thread/reent has a locale. ctype_ptr is unused
- in __global_locale, rather the global variable __ctype_ptr__ is used. */
- extern char *__ctype_ptr__;
- return __get_locale_r (_REENT) ? __get_locale_r (_REENT)->ctype_ptr
- : __ctype_ptr__;
+ return locale->ctype_ptr;
}
const char *
-__locale_ctype_ptr_l (struct __locale_t *locale)
+__locale_ctype_ptr (void)
{
- extern char *__ctype_ptr__;
- return locale->ctype_ptr ?: __ctype_ptr__;
+ return __get_current_locale (_REENT)->ctype_ptr;
}
#ifndef _REENT_ONLY