Consolidate wctomb/mbtowc calls for POSIX-1.2008

- Remove charset parameter from low level __foo_wctomb/__foo_mbtowc calls.
- Instead, create array of function for ISO and Windows codepages to point
  to function which does not require to evaluate the charset string on
  each call.  Create matching helper functions.  I.e., __iso_wctomb,
  __iso_mbtowc, __cp_wctomb and __cp_mbtowc are functions returning the
  right function pointer now.
- Create __WCTOMB/__MBTOWC macros utilizing per-reent locale and replace
  calls to __wctomb/__mbtowc with calls to __WCTOMB/__MBTOWC.
- Drop global __wctomb/__mbtowc vars.
- Utilize aforementioned changes in Cygwin to get rid of charset in other,
  calling functions and simplify the code.
- In Cygwin restrict global cygheap locale info to the job performed
  by internal_setlocale.  Use UTF-8 instead of ASCII on the fly in
  internal conversion functions.
- In Cygwin dll_entry, make sure to initialize a TLS area with a NULL
  _REENT->_locale pointer.  Add comment to explain why.

Signed-off by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2016-07-20 22:05:59 +02:00
parent 88208d3735
commit d16a56306d
31 changed files with 941 additions and 355 deletions

View File

@@ -11,6 +11,9 @@ details. */
#include_next <wchar.h>
/* Internal headers from newlib */
#include "../locale/setlocale.h"
#define ENCODING_LEN 31
#ifdef __cplusplus
@@ -18,29 +21,23 @@ extern "C" {
#endif
typedef int mbtowc_f (struct _reent *, wchar_t *, const char *, size_t,
const char *, mbstate_t *);
mbstate_t *);
typedef mbtowc_f *mbtowc_p;
extern mbtowc_p __mbtowc;
extern mbtowc_f __ascii_mbtowc;
extern mbtowc_f __utf8_mbtowc;
extern mbtowc_f __iso_mbtowc;
extern mbtowc_f __cp_mbtowc;
extern mbtowc_f __sjis_mbtowc;
extern mbtowc_f __eucjp_mbtowc;
extern mbtowc_f __gbk_mbtowc;
extern mbtowc_f __kr_mbtowc;
extern mbtowc_f __big5_mbtowc;
extern mbtowc_p __iso_mbtowc (int);
extern mbtowc_p __cp_mbtowc (int);
typedef int wctomb_f (struct _reent *, char *, wchar_t, const char *,
mbstate_t *);
#define __MBTOWC (__get_current_locale ()->mbtowc)
typedef int wctomb_f (struct _reent *, char *, wchar_t, mbstate_t *);
typedef wctomb_f *wctomb_p;
extern wctomb_p __wctomb;
extern wctomb_f __ascii_wctomb;
extern wctomb_f __utf8_wctomb;
extern char *__locale_charset ();
#define __WCTOMB (__get_current_locale ()->wctomb)
#ifdef __cplusplus
}
@@ -49,20 +46,21 @@ extern char *__locale_charset ();
#ifdef __INSIDE_CYGWIN__
#ifdef __cplusplus
size_t __reg3 sys_wcstombs (char *dst, size_t len, const wchar_t * src,
size_t nwc = (size_t) -1);
size_t nwc = (size_t) -1);
size_t __reg3 sys_wcstombs_no_path (char *dst, size_t len,
const wchar_t * src, size_t nwc = (size_t) -1);
const wchar_t * src,
size_t nwc = (size_t) -1);
size_t __reg3 sys_wcstombs_alloc (char **, int, const wchar_t *,
size_t = (size_t) -1);
size_t = (size_t) -1);
size_t __reg3 sys_wcstombs_alloc_no_path (char **, int, const wchar_t *,
size_t = (size_t) -1);
size_t = (size_t) -1);
size_t __reg3 sys_cp_mbstowcs (mbtowc_p, const char *, wchar_t *, size_t,
const char *, size_t = (size_t) -1);
size_t __reg3 sys_cp_mbstowcs (mbtowc_p, wchar_t *, size_t, const char *,
size_t = (size_t) -1);
size_t __reg3 sys_mbstowcs (wchar_t * dst, size_t dlen, const char *src,
size_t nms = (size_t) -1);
size_t nms = (size_t) -1);
size_t __reg3 sys_mbstowcs_alloc (wchar_t **, int, const char *,
size_t = (size_t) -1);
size_t = (size_t) -1);
#endif /* __cplusplus */
#endif /* __INSIDE_CYGWIN__ */