From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8428 invoked by alias); 25 Aug 2016 12:18:42 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 8349 invoked by uid 9078); 25 Aug 2016 12:18:42 -0000 Date: Thu, 25 Aug 2016 12:18:00 -0000 Message-ID: <20160825121842.8346.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org, newlib-cvs@sourceware.org Subject: [newlib-cygwin] Drop global __ctype_ptr__ entirely in favor of using locale_t::ctype_ptr X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 988629da1d299cfef7023e07ad900dd047b9fc63 X-Git-Newrev: e97109184ab0a2de680a90a432d94f86e5be7b0f X-SW-Source: 2016-q3/txt/msg00074.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e97109184ab0a2de680a90a432d94f86e5be7b0f commit e97109184ab0a2de680a90a432d94f86e5be7b0f Author: Corinna Vinschen Date: Thu Aug 25 14:18:31 2016 +0200 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 Diff: --- newlib/libc/ctype/ctype_.c | 31 +++++++------------------------ newlib/libc/ctype/ctype_.h | 18 ++++++++++++++++++ newlib/libc/locale/locale.c | 21 ++++++++------------- winsup/cygwin/ctype.cc | 8 ++++---- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/newlib/libc/ctype/ctype_.c b/newlib/libc/ctype/ctype_.c index 8945c56..9e3cdcf 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 +#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 0000000..3b59a27 --- /dev/null +++ b/newlib/libc/ctype/ctype_.h @@ -0,0 +1,18 @@ +#include + +#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 fe04395..b7ced4d 100644 --- a/newlib/libc/locale/locale.c +++ b/newlib/libc/locale/locale.c @@ -172,13 +172,13 @@ No supporting OS subroutines are required. #include #include -#include #include #include #include #include #include #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 diff --git a/winsup/cygwin/ctype.cc b/winsup/cygwin/ctype.cc index 3eb6b34..0fe243b 100644 --- a/winsup/cygwin/ctype.cc +++ b/winsup/cygwin/ctype.cc @@ -64,10 +64,10 @@ __set_ctype (struct __locale_t *loc, const char *charset) } ctype_ptr = (char *) _ctype_b; } - if (loc) - loc->ctype_ptr = ctype_ptr + 127; - else - __ctype_ptr__ = ctype_ptr + 127; + loc->ctype_ptr = ctype_ptr + 127; + /* For backward compatibilty */ + if (loc == __get_global_locale ()) + __ctype_ptr__ = loc->ctype_ptr; } } /* extern "C" */