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>
This commit is contained in:
Corinna Vinschen 2016-08-25 14:18:31 +02:00
parent 988629da1d
commit e97109184a
4 changed files with 37 additions and 41 deletions

View File

@ -35,7 +35,7 @@
static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90"; static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <ctype.h> #include "ctype_.h"
#include "../locale/setlocale.h" #include "../locale/setlocale.h"
#define _CTYPE_DATA_0_127 \ #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, \
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_CAPABLE)
#if defined(_MB_EXTENDED_CHARSETS_ISO) #if defined(_MB_EXTENDED_CHARSETS_ISO)
#include "ctype_iso.h" #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 /* No static const on Cygwin since it's referenced and potentially overwritten
for compatibility with older applications. */ for compatibility with older applications. */
#ifndef __CYGWIN__ #ifndef __CYGWIN__
static _CONST _CONST
#endif #endif
char _ctype_b[128 + 256] = { char _ctype_b[128 + 256] = {
_CTYPE_DATA_128_255, _CTYPE_DATA_128_255,
@ -99,12 +95,10 @@ char _ctype_b[128 + 256] = {
_CTYPE_DATA_128_255 _CTYPE_DATA_128_255
}; };
#ifndef _MB_CAPABLE
_CONST
#endif
char __EXPORT *__ctype_ptr__ = (char *) _ctype_b + 127;
# ifdef __CYGWIN__ # ifdef __CYGWIN__
/* For backward compatibility */
char __EXPORT *__ctype_ptr__ = DEFAULT_CTYPE_PTR;
# ifdef __x86_64__ # ifdef __x86_64__
__asm__ (" \n\ __asm__ (" \n\
.data \n\ .data \n\
@ -137,11 +131,6 @@ _CONST char _ctype_[1 + 256] = {
_CTYPE_DATA_128_255 _CTYPE_DATA_128_255
}; };
#ifndef _MB_CAPABLE
_CONST
#endif
char *__ctype_ptr__ = (char *) _ctype_;
#endif /* !ALLOW_NEGATIVE_CTYPE_INDEX */ #endif /* !ALLOW_NEGATIVE_CTYPE_INDEX */
#if defined(_MB_CAPABLE) #if defined(_MB_CAPABLE)
@ -191,15 +180,9 @@ __set_ctype (struct __locale_t *loc, const char *charset)
# endif # endif
} }
# if defined(ALLOW_NEGATIVE_CTYPE_INDEX) # if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
if (loc)
loc->ctype_ptr = ctype_ptr + 127; loc->ctype_ptr = ctype_ptr + 127;
else
__ctype_ptr__ = ctype_ptr + 127;
# else # else
if (loc)
loc->ctype_ptr = ctype_ptr; loc->ctype_ptr = ctype_ptr;
else
__ctype_ptr__ = ctype_ptr;
# endif # endif
} }
#endif /* !__CYGWIN__ */ #endif /* !__CYGWIN__ */

View File

@ -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 */

View File

@ -172,13 +172,13 @@ No supporting OS subroutines are required.
#include <newlib.h> #include <newlib.h>
#include <errno.h> #include <errno.h>
#include <ctype.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <reent.h> #include <reent.h>
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h> #include <wchar.h>
#include "setlocale.h" #include "setlocale.h"
#include "../ctype/ctype_.h"
#include "../stdlib/local.h" #include "../stdlib/local.h"
#ifdef __CYGWIN__ /* Has to be kept available as exported symbol for #ifdef __CYGWIN__ /* Has to be kept available as exported symbol for
@ -225,7 +225,7 @@ const struct __locale_t __C_locale =
__ascii_wctomb, __ascii_wctomb,
__ascii_mbtowc, __ascii_mbtowc,
0, 0,
NULL, DEFAULT_CTYPE_PTR,
{ {
".", "", "", "", "", "", "", "", "", "", ".", "", "", "", "", "", "", "", "", "",
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
@ -266,7 +266,7 @@ struct __locale_t __global_locale =
__ascii_mbtowc, __ascii_mbtowc,
#endif #endif
0, 0,
NULL, DEFAULT_CTYPE_PTR,
{ {
".", "", "", "", "", "", "", "", "", "", ".", "", "", "", "", "", "", "", "", "",
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
@ -901,7 +901,7 @@ restart:
#endif #endif
loc->wctomb = l_wctomb; loc->wctomb = l_wctomb;
loc->mbtowc = l_mbtowc; 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 /* Determine the width for the "CJK Ambiguous Width" category of
characters. This is used in wcwidth(). Assume single width for characters. This is used in wcwidth(). Assume single width for
single-byte charsets, and double width for multi-byte charsets single-byte charsets, and double width for multi-byte charsets
@ -988,20 +988,15 @@ _DEFUN_VOID (__locale_mb_cur_max)
} }
const char * 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 return locale->ctype_ptr;
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__;
} }
const char * const char *
__locale_ctype_ptr_l (struct __locale_t *locale) __locale_ctype_ptr (void)
{ {
extern char *__ctype_ptr__; return __get_current_locale (_REENT)->ctype_ptr;
return locale->ctype_ptr ?: __ctype_ptr__;
} }
#ifndef _REENT_ONLY #ifndef _REENT_ONLY

View File

@ -64,10 +64,10 @@ __set_ctype (struct __locale_t *loc, const char *charset)
} }
ctype_ptr = (char *) _ctype_b; ctype_ptr = (char *) _ctype_b;
} }
if (loc)
loc->ctype_ptr = ctype_ptr + 127; loc->ctype_ptr = ctype_ptr + 127;
else /* For backward compatibilty */
__ctype_ptr__ = ctype_ptr + 127; if (loc == __get_global_locale ())
__ctype_ptr__ = loc->ctype_ptr;
} }
} /* extern "C" */ } /* extern "C" */