This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][STEP1]Remove direct access to locale structures


Hi all,

 

With this patch I move the usage of the locale structures from all files in
folders outside ctype and locale to macros in setlocale.h 

This is the first step to prepare for removing all locale structures 

 

Jaap de Wolff

 

 

==================================PATCH===========================

diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h

index 85a38d586..f74aedd45 100644

--- a/newlib/libc/locale/setlocale.h

+++ b/newlib/libc/locale/setlocale.h

@@ -439,6 +439,11 @@ extern void __set_charset_from_locale (const char
*locale, char *charset);

extern char *__set_locale_from_locale_alias (const char *, char *);

#endif

+#define loc_get_decimalpoint(loc) (__localeconv_l(loc))->decimal_point

+#define loc_wctomb(loc,r,buff,wc,ps) (loc)->wctomb(r,buff,wc,ps)

+#define cur_loc_wctomb __get_current_locale ()->wctomb

+#define cur_loc_mbtowc __get_current_locale ()->mbtowc

+

__END_DECLS

 #endif /* !_SETLOCALE_H_ */

diff --git a/newlib/libc/stdlib/gdtoa-gethex.c
b/newlib/libc/stdlib/gdtoa-gethex.c

index 939e0dd8d..b7b89a6dc 100644

--- a/newlib/libc/stdlib/gdtoa-gethex.c

+++ b/newlib/libc/stdlib/gdtoa-gethex.c

@@ -150,8 +150,7 @@ gethex (struct _reent *ptr, const char **sp, const FPI
*fpi,

             int esign, havedig, irv, k, n, nbits, up, zret;

             __ULong L, lostbits, *x;

             Long e, e1;

-             unsigned char *decimalpoint = (unsigned char *)

-
__localeconv_l (loc)->decimal_point;

+            unsigned char *decimalpoint = (unsigned char
*)loc_get_decimalpoint(loc);

             size_t decp_len = strlen ((const char *) decimalpoint);

             unsigned char decp_end = decimalpoint[decp_len - 1];

diff --git a/newlib/libc/stdlib/local.h b/newlib/libc/stdlib/local.h

index a96ed2cc4..b73bf12b6 100644

--- a/newlib/libc/stdlib/local.h

+++ b/newlib/libc/stdlib/local.h

@@ -29,7 +29,7 @@ wctomb_f __big5_wctomb;

#endif

#endif

-#define __WCTOMB (__get_current_locale ()->wctomb)

+#define __WCTOMB ( cur_loc_wctomb )

 typedef int mbtowc_f (struct _reent *, wchar_t *, const char *, size_t,

                                  mbstate_t *);

@@ -50,7 +50,7 @@ mbtowc_f __big5_mbtowc;

#endif

#endif

-#define __MBTOWC (__get_current_locale ()->mbtowc)

+#define __MBTOWC ( cur_loc_mbtowc )

 extern wchar_t __iso_8859_conv[14][0x60];

int __iso_8859_val_index (int);

diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c

index 402510cdf..62bfe343b 100644

--- a/newlib/libc/stdlib/strtod.c

+++ b/newlib/libc/stdlib/strtod.c

@@ -256,8 +256,7 @@ _strtod_l (struct _reent *ptr, const char *__restrict
s00, char **__restrict se,

#ifdef Honor_FLT_ROUNDS

             int rounding;

#endif

-             struct lconv *lconv = __localeconv_l (loc);

-             int dec_len = strlen (lconv->decimal_point);

+            int dec_len = strlen (loc_get_decimalpoint(loc));

              delta = bs = bd = NULL;

             sign = nz0 = nz = decpt = 0;

@@ -337,7 +336,7 @@ _strtod_l (struct _reent *ptr, const char *__restrict
s00, char **__restrict se,

                            else

                                          z = 10*z + c - '0';

             nd0 = nd;

-             if (strncmp (s, lconv->decimal_point, dec_len) == 0)

+            if (strncmp (s, loc_get_decimalpoint(loc), dec_len) == 0)

                            {

                            decpt = 1;

                            c = *(s += dec_len);

diff --git a/newlib/libc/stdlib/wcsnrtombs.c
b/newlib/libc/stdlib/wcsnrtombs.c

index 43dd2f3e6..6419de87e 100644

--- a/newlib/libc/stdlib/wcsnrtombs.c

+++ b/newlib/libc/stdlib/wcsnrtombs.c

@@ -101,7 +101,7 @@ _wcsnrtombs_l (struct _reent *r, char *dst, const
wchar_t **src, size_t nwc,

     {

       int count = ps->__count;

       wint_t wch = ps->__value.__wch;

-      int bytes = loc->wctomb (r, buff, *pwcs, ps);

+      int bytes = loc_wctomb(loc, r, buff, *pwcs, ps);

       if (bytes == -1)

             {

               r->_errno = EILSEQ;

diff --git a/newlib/libc/stdlib/wcstod.c b/newlib/libc/stdlib/wcstod.c

index 9e0d563ef..ecf16ec0b 100644

--- a/newlib/libc/stdlib/wcstod.c

+++ b/newlib/libc/stdlib/wcstod.c

@@ -198,10 +198,10 @@ _wcstod_l (struct _reent *ptr, const wchar_t *nptr,
wchar_t **endptr,

                               just one byte long.  The resulting difference
(end - buf)

                               is then equivalent to the number of valid
wide characters

                               in the input string. */

-                           len = strlen (__localeconv_l
(loc)->decimal_point);

+                           len = strlen (loc_get_decimalpoint(loc));

                            if (len > 1) {

                                          char *d = strstr (buf,

-
__localeconv_l (loc)->decimal_point);

+
loc_get_decimalpoint(loc));

                                          if (d && d < end)

                                                         end -= len - 1;

                            }

diff --git a/newlib/libc/stdlib/wcstold.c b/newlib/libc/stdlib/wcstold.c

index 4876e119b..d33b6138a 100644

--- a/newlib/libc/stdlib/wcstold.c

+++ b/newlib/libc/stdlib/wcstold.c

@@ -93,10 +93,10 @@ wcstold_l (const wchar_t *__restrict nptr, wchar_t
**__restrict endptr,

              just one byte long.  The resulting difference (end - buf)

              is then equivalent to the number of valid wide characters

              in the input string.  */

-      len = strlen (__localeconv_l (loc)->decimal_point);

+      len = strlen (loc_get_decimalpoint (loc));

       if (len > 1)

             {

-               char *d = strstr (buf, __localeconv_l (loc)->decimal_point);

+              char *d = strstr (buf, loc_get_decimalpoint (loc));

                if (d && d < end)

                 end -= len - 1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]