public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Drop global __ctype_ptr__ entirely in favor of using locale_t::ctype_ptr
@ 2016-08-25 12:18 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2016-08-25 12:18 UTC (permalink / raw)
To: cygwin-cvs, newlib-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e97109184ab0a2de680a90a432d94f86e5be7b0f
commit e97109184ab0a2de680a90a432d94f86e5be7b0f
Author: Corinna Vinschen <corinna@vinschen.de>
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 <corinna@vinschen.de>
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 <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 0000000..3b59a27
--- /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 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 <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
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" */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-08-25 12:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-25 12:18 [newlib-cygwin] Drop global __ctype_ptr__ entirely in favor of using locale_t::ctype_ptr Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).