Skip to content

Commit

Permalink
* ctype/ctype.h (__ctype_b, __ctype_toupper, __ctype_tolower):
Browse files Browse the repository at this point in the history
	Variable declarations removed.
	(__ctype_b_loc, __ctype_toupper_loc, __ctype_tolower_loc): Declare
	these functions to replace them.
	(__isctype, tolower, toupper, _tolower, _toupper): Use those accessor
	functions plus an indirection rather than the old global variables.
	* include/ctype.h (__isctype, tolower, _tolower, toupper, _toupper):
	Macros removed.
	(__ctype_b_loc, __ctype_toupper_loc, __ctype_tolower_loc): New extern
	inline functions.
	* ctype/ctype-info.c: Revert last reversion back the other way.
	Define tsd vars CTYPE_B, CTYPE_TOLOWER, CTYPE_TOUPPER.
	Define real function versions of include/ctype.h inlines here.
	* ctype/Versions (libc: GLIBC_2.3): Add __ctype_b_loc,
	__ctype_tolower_loc, __ctype_toupper_loc.
	* locale/lc-ctype.c: Revert last reversion back the other way.
	(_nl_postload_ctype): If current thread uses the global locale,
	update its tsd vars.
	* locale/uselocale.c (__uselocale): Update tsd vars from new locale.
	* hurd/hurd/threadvar.h (enum __hurd_threadvar_index): Add CTYPE_B,
	CTYPE_TOLOWER, CTYPE_TOUPPER.

	* sysdeps/generic/bits/libc-tsd.h (__libc_tsd_address): New macro.
	* sysdeps/mach/hurd/bits/libc-tsd.h (__libc_tsd_address): Renamed
	from __libc_tsd_threadvar_location.
	(__libc_tsd_set, __libc_tsd_get): Update uses.
  • Loading branch information
Roland McGrath committed Sep 2, 2002
1 parent 4032add commit cf68434
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 115 deletions.
29 changes: 29 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
2002-09-01 Roland McGrath <[email protected]>

* ctype/ctype.h (__ctype_b, __ctype_toupper, __ctype_tolower):
Variable declarations removed.
(__ctype_b_loc, __ctype_toupper_loc, __ctype_tolower_loc): Declare
these functions to replace them.
(__isctype, tolower, toupper, _tolower, _toupper): Use those accessor
functions plus an indirection rather than the old global variables.
* include/ctype.h (__isctype, tolower, _tolower, toupper, _toupper):
Macros removed.
(__ctype_b_loc, __ctype_toupper_loc, __ctype_tolower_loc): New extern
inline functions.
* ctype/ctype-info.c: Revert last reversion back the other way.
Define tsd vars CTYPE_B, CTYPE_TOLOWER, CTYPE_TOUPPER.
Define real function versions of include/ctype.h inlines here.
* ctype/Versions (libc: GLIBC_2.3): Add __ctype_b_loc,
__ctype_tolower_loc, __ctype_toupper_loc.
* locale/lc-ctype.c: Revert last reversion back the other way.
(_nl_postload_ctype): If current thread uses the global locale,
update its tsd vars.
* locale/uselocale.c (__uselocale): Update tsd vars from new locale.
* hurd/hurd/threadvar.h (enum __hurd_threadvar_index): Add CTYPE_B,
CTYPE_TOLOWER, CTYPE_TOUPPER.

* sysdeps/generic/bits/libc-tsd.h (__libc_tsd_address): New macro.
* sysdeps/mach/hurd/bits/libc-tsd.h (__libc_tsd_address): Renamed
from __libc_tsd_threadvar_location.
(__libc_tsd_set, __libc_tsd_get): Update uses.

2002-09-01 Ulrich Drepper <[email protected]>

* ctype/ctype.h: Undo the patch before the last one. Put back the
Expand Down
4 changes: 4 additions & 0 deletions bits/libc-tsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
keys used in only one source file,
empty for global definitions, or
`extern' for global declarations.
__libc_tsd_address(KEY) -- Return the `void **' pointing to
the current thread's datum for KEY.
__libc_tsd_get(KEY) -- Return the `void *' datum for KEY.
__libc_tsd_set(KEY, VALUE) -- Set the datum for KEY to VALUE.
Expand All @@ -52,11 +54,13 @@
#if USE_TLS && HAVE___THREAD
# define __libc_tsd_define(CLASS, KEY) CLASS __thread void *__libc_tsd_##KEY;

# define __libc_tsd_address(KEY) (&__libc_tsd_##KEY)
# define __libc_tsd_get(KEY) (__libc_tsd_##KEY)
# define __libc_tsd_set(KEY, VALUE) (__libc_tsd_##KEY = (VALUE))
#else
# define __libc_tsd_define(CLASS, KEY) CLASS void *__libc_tsd_##KEY##_data;

# define __libc_tsd_address(KEY) (&__libc_tsd_##KEY)
# define __libc_tsd_get(KEY) (__libc_tsd_##KEY##_data)
# define __libc_tsd_set(KEY, VALUE) (__libc_tsd_##KEY##_data = (VALUE))
#endif
Expand Down
3 changes: 3 additions & 0 deletions ctype/Versions
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ libc {
}
GLIBC_2.3 {
isctype; __isctype;

# functions used by optimized macros in ctype.h
__ctype_b_loc; __ctype_tolower_loc; __ctype_toupper_loc;
}
}
56 changes: 25 additions & 31 deletions ctype/ctype-info.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1991,92,95,96,97,99,2000,2002 Free Software Foundation, Inc.
/* Copyright (C) 1991,92,95,96,97,99,2000,02 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand All @@ -16,9 +16,18 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#define CTYPE_EXTERN_INLINE /* Define real functions for accessors. */
#include <ctype.h>
#include <locale/localeinfo.h>

__libc_tsd_define (, CTYPE_B)
__libc_tsd_define (, CTYPE_TOLOWER)
__libc_tsd_define (, CTYPE_TOUPPER)


#include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)

/* Defined in locale/C-ctype.c. */
extern const char _nl_C_LC_CTYPE_class[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class32[] attribute_hidden;
Expand All @@ -36,36 +45,21 @@ extern const char _nl_C_LC_CTYPE_class_blank[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class_cntrl[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class_punct[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_class_alnum[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_map_toupper[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_map_tolower[] attribute_hidden;
extern const char _nl_C_LC_CTYPE_width[] attribute_hidden;

#define b(t,x,o) (((const t *) _nl_C_LC_CTYPE_##x) + o)

const unsigned short int *__ctype_b = b (unsigned short int, class, 128);
const __uint32_t *__ctype32_b = b (__uint32_t, class32, 0);
const __int32_t *__ctype_tolower = b (__int32_t, tolower, 128);
const __int32_t *__ctype_toupper = b (__int32_t, toupper, 128);
const __uint32_t *__ctype32_tolower = b (__uint32_t, tolower, 128);
const __uint32_t *__ctype32_toupper = b (__uint32_t, toupper, 128);
const char *__ctype32_wctype[12] attribute_hidden =
{
b(char, class_upper, 32),
b(char, class_lower, 32),
b(char, class_alpha, 32),
b(char, class_digit, 32),
b(char, class_xdigit, 32),
b(char, class_space, 32),
b(char, class_print, 32),
b(char, class_graph, 32),
b(char, class_blank, 32),
b(char, class_cntrl, 32),
b(char, class_punct, 32),
b(char, class_alnum, 32)
};
const char *__ctype32_wctrans[2] attribute_hidden =
{
b(char, map_toupper, 0),
b(char, map_tolower, 0)
};
const char *__ctype32_width attribute_hidden = b (char, width, 0);
const unsigned short int *__ctype_old_b = b (unsigned short int, class, 128);
const __uint32_t *__ctype32_old_b = b (__uint32_t, class32, 0);
const __int32_t *__ctype_old_tolower = b (__int32_t, tolower, 128);
const __int32_t *__ctype_old_toupper = b (__int32_t, toupper, 128);
const __uint32_t *__ctype32_old_tolower = b (__uint32_t, tolower, 128);
const __uint32_t *__ctype32_old_toupper = b (__uint32_t, toupper, 128);

compat_symbol (libc, __ctype_old_b, __ctype_b, GLIBC_2_0);
compat_symbol (libc, __ctype_old_tolower, __ctype_tolower, GLIBC_2_0);
compat_symbol (libc, __ctype_old_toupper, __ctype_toupper, GLIBC_2_0);
compat_symbol (libc, __ctype32_old_b, __ctype32_b, GLIBC_2_0);
compat_symbol (libc, __ctype32_old_tolower, __ctype32_tolower, GLIBC_2_2);
compat_symbol (libc, __ctype32_old_toupper, __ctype32_toupper, GLIBC_2_2);

#endif
28 changes: 18 additions & 10 deletions ctype/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ enum
/* These are defined in ctype-info.c.
The declarations here must match those in localeinfo.h.
In the thread-specific locale model (see `uselocale' in <locale.h>)
we cannot use global variables for these as was done in the past.
Instead, the following accessor functions return the address of
each variable, which is local to the current thread if multithreaded.
These point into arrays of 384, so they can be indexed by any `unsigned
char' value [0,255]; by EOF (-1); or by any `signed char' value
[-128,-1). ISO C requires that the ctype functions work for `unsigned
Expand All @@ -73,12 +78,15 @@ enum
rather than `unsigned char's because tolower (EOF) must be EOF, which
doesn't fit into an `unsigned char'. But today more important is that
the arrays are also used for multi-byte character sets. */
extern __const unsigned short int *__ctype_b; /* Characteristics. */
extern __const __int32_t *__ctype_tolower; /* Case conversions. */
extern __const __int32_t *__ctype_toupper; /* Case conversions. */
extern __const unsigned short int **__ctype_b_loc (void)
__attribute__ ((__const));
extern __const __int32_t **__ctype_tolower_loc (void)
__attribute__ ((__const));
extern __const __int32_t **__ctype_toupper_loc (void)
__attribute__ ((__const));

#define __isctype(c, type) \
(__ctype_b[(int) (c)] & (unsigned short int) type)
((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)

#define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
#define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
Expand Down Expand Up @@ -182,27 +190,27 @@ __exctype (_tolower);
extern __inline int
tolower (int __c) __THROW
{
return __c >= -128 && __c < 256 ? __ctype_tolower[__c] : __c;
return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc ())[__c] : __c;
}

extern __inline int
toupper (int __c) __THROW
{
return __c >= -128 && __c < 256 ? __ctype_toupper[__c] : __c;
return __c >= -128 && __c < 256 ? (*__ctype_toupper_loc ())[__c] : __c;
}
# endif

# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
# define tolower(c) __tobody (c, tolower, __ctype_tolower, (c))
# define toupper(c) __tobody (c, toupper, __ctype_toupper, (c))
# define tolower(c) __tobody (c, tolower, *__ctype_tolower_loc (), (c))
# define toupper(c) __tobody (c, toupper, *__ctype_toupper_loc (), (c))
# endif /* Optimizing gcc */

# if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
# define isascii(c) __isascii (c)
# define toascii(c) __toascii (c)

# define _tolower(c) ((int) __ctype_tolower[(int) (c)])
# define _toupper(c) ((int) __ctype_toupper[(int) (c)])
# define _tolower(c) ((int) (*__ctype_tolower_loc ())[(int) (c)])
# define _toupper(c) ((int) (*__ctype_toupper_loc ())[(int) (c)])
# endif

#endif /* Not __NO_CTYPE. */
Expand Down
5 changes: 4 additions & 1 deletion hurd/hurd/threadvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ enum __hurd_threadvar_index
_HURD_THREADVAR_MALLOC, /* For use of malloc. */
_HURD_THREADVAR_DL_ERROR, /* For use of -ldl and dynamic linker. */
_HURD_THREADVAR_RPC_VARS, /* For state of RPC functions. */
_HURD_THREADVAR_LOCALE, /* For thread-locale locale setting. */
_HURD_THREADVAR_LOCALE, /* For thread-local locale setting. */
_HURD_THREADVAR_CTYPE_B, /* Cache of thread-local locale data. */
_HURD_THREADVAR_CTYPE_TOLOWER, /* Cache of thread-local locale data. */
_HURD_THREADVAR_CTYPE_TOUPPER, /* Cache of thread-local locale data. */
_HURD_THREADVAR_MAX /* Default value for __hurd_threadvar_max. */
};

Expand Down
77 changes: 48 additions & 29 deletions include/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,58 @@

extern int __isctype (int __c, int __mask);

# include <ctype/ctype.h>

# ifndef NOT_IN_libc

/* The optimized macros are not defined for users because they can't see
the thread-local locale state. For inside libc, define them using the
_NL_CURRENT accessors. We don't use _NL_CURRENT_LOCALE->__ctype_b here
because we want to cause a link-time ref to _nl_current_LC_CTYPE under
/* These accessors are used by the optimized macros to find the
thread-local cache of ctype information from the current thread's
locale. For inside libc, define them as inlines using the _NL_CURRENT
accessors. We don't use _NL_CURRENT_LOCALE->__ctype_b here because we
want to cause a link-time ref to _nl_current_LC_CTYPE under
NL_CURRENT_INDIRECT. */

# include "../locale/localeinfo.h"
# ifndef __NO_CTYPE
# undef __isctype
# define __isctype(c, type) \
(((uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128) \
[(int) (c)] & (uint16_t) type)

# undef tolower
# define tolower(c) \
__tobody (c, tolower, \
(uint32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128, \
(c))
# undef _tolower
# define _tolower(c) tolower (c)
# undef toupper
# define toupper(c) \
__tobody (c, toupper, \
(uint32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128, \
(c))
# undef _toupper
# define _toupper(c) toupper (c)

# endif /* Not __NO_CTYPE. */
# endif /* _LIBC_REENTRANT. */
# include <bits/libc-tsd.h>

# ifndef CTYPE_EXTERN_INLINE /* Used by ctype/ctype-info.c, which see. */
# define CTYPE_EXTERN_INLINE extern inline
# endif

__libc_tsd_define (extern, CTYPE_B)
__libc_tsd_define (extern, CTYPE_TOUPPER)
__libc_tsd_define (extern, CTYPE_TOLOWER)

CTYPE_EXTERN_INLINE const uint16_t ** __attribute__ ((const))
__ctype_b_loc (void)
{
const uint16_t **tablep =
(const uint16_t **) __libc_tsd_address (CTYPE_B);
if (__builtin_expect (*tablep == NULL, 0))
*tablep = (const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128;
return tablep;
}

CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
__ctype_toupper_loc (void)
{
const int32_t **tablep =
(const int32_t **) __libc_tsd_address (CTYPE_TOUPPER);
if (__builtin_expect (*tablep == NULL, 0))
*tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128);
return tablep;
}

CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
__ctype_tolower_loc (void)
{
const int32_t **tablep =
(const int32_t **) __libc_tsd_address (CTYPE_TOLOWER);
if (__builtin_expect (*tablep == NULL, 0))
*tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128);
return tablep;
}

# endif /* Not NOT_IN_libc. */

# include <ctype/ctype.h>

#endif /* ctype.h */
13 changes: 13 additions & 0 deletions linuxthreads/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2002-09-01 Roland McGrath <[email protected]>

* sysdeps/pthread/bits/libc-tsd.h (enum __libc_tsd_key_t): Add new keys
CTYPE_B, CTYPE_TOLOWER, CTYPE_TOUPPER.

* sysdeps/pthread/bits/libc-tsd.h (__libc_tsd_address): New macro.
(__libc_internal_tsd_address): Declare it.
* Versions (libc, ld, libpthread: GLIBC_PRIVATE): Add
__libc_internal_tsd_address.
* specific.c (libc_internal_tsd_address): New function.
(__libc_internal_tsd_address): New variable.
* no-tsd.c (__libc_internal_tsd_address): New variable.

2002-08-31 Ulrich Drepper <[email protected]>

* Makefile: Don't use rule for crt%.o, spell it out as rules for
Expand Down
10 changes: 10 additions & 0 deletions linuxthreads/sysdeps/pthread/bits/libc-tsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0,
_LIBC_TSD_KEY_DL_ERROR,
_LIBC_TSD_KEY_RPC_VARS,
_LIBC_TSD_KEY_LOCALE,
_LIBC_TSD_KEY_CTYPE_B,
_LIBC_TSD_KEY_CTYPE_TOLOWER,
_LIBC_TSD_KEY_CTYPE_TOUPPER,
_LIBC_TSD_KEY_N };

#include <tls.h>
Expand All @@ -39,6 +42,13 @@ enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0,
extern void *(*__libc_internal_tsd_get) (enum __libc_tsd_key_t) __THROW;
extern int (*__libc_internal_tsd_set) (enum __libc_tsd_key_t,
__const void *) __THROW;
extern void **(*const __libc_internal_tsd_address) (enum __libc_tsd_key_t)
__THROW __attribute__ ((__const__));

#define __libc_tsd_address(KEY) \
(__libc_internal_tsd_address != NULL \
? __libc_internal_tsd_address (_LIBC_TSD_KEY_##KEY) \
: &__libc_tsd_##KEY##_data)

#define __libc_tsd_define(CLASS, KEY) CLASS void *__libc_tsd_##KEY##_data;
#define __libc_tsd_get(KEY) \
Expand Down
Loading

0 comments on commit cf68434

Please sign in to comment.