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]

Re: Link failure with locale routines (when _MB_CAPABLE undefined)


Corinna Vinschen wrote:
> On Aug 18 15:29, Corinna Vinschen wrote:
> > On Aug 18 14:02, Ulrich Weigand wrote:
> > > The reason for the failure appears to be that __C_locale and
> > > __loadlocale are defined only if _MB_CAPABLE is defined, but
> > > they are used unconditionally from newlocale.c / freelocale.c.
> > Any chance for a patch?  You're set up for testing !_MB_CAPABLE
> > after all...
> 
> The problem with !_MB_CAPABLE is that these targets don't support any
> kind of locale settings at all and, so far, setlocale just returns the
> fixed string "C".
> 
> Thus it seems it doesn't make any sense to expose the POSIX-1.2008
> locale functions to !_MB_CAPABLE targets at all, so I propose to disable
> these functions and their prototypes unless #ifdef _MB_CAPABLE.
> 
> Thoughts?

I had a quick look, but I'm not exactly sure what !_MB_CAPABLE
is supposed to mean, exactly.  Is this supposed to affect the
list of routines in the public API, or just what the routines do?

With the current code, the main problem is that if !MB_CAPABLE,
in particular the __global_locale global variable is nowhere defined,
although setlocale.h still provides a declaration.  Trying to disable
this prototype generates a long list of errors, since __global_locale
is used from __get_current_locale, which is used by many locale routines
(I think even pre-POSIX-1.2008 ones).

As a quick hack, I simply made the definition of __global_locale
available even on !_MB_CAPABLE systems, and now the only errors are
in the POSIX-1.2008 routines.  Disabling those are you suggest in
addition gets me a clean build.

The patch below implements this.  Does this make sense to you?

Bye,
Ulrich

diff --git a/newlib/libc/include/locale.h b/newlib/libc/include/locale.h
index 6b3b788..49655ec 100644
--- a/newlib/libc/include/locale.h
+++ b/newlib/libc/include/locale.h
@@ -71,24 +71,24 @@ struct _reent;
 char *_EXFUN(_setlocale_r,(struct _reent *, int, const char *));
 struct lconv *_EXFUN(_localeconv_r,(struct _reent *));
 
-#if __POSIX_VISIBLE >= 200809
+#if defined (_MB_CAPABLE) && __POSIX_VISIBLE >= 200809
 locale_t _newlocale_r (struct _reent *, int, const char *, locale_t);
 void _freelocale_r (struct _reent *, locale_t);
 locale_t _duplocale_r (struct _reent *, locale_t);
 locale_t _uselocale_r (struct _reent *, locale_t);
-#endif /* __POSIX_VISIBLE >= 200809 */
+#endif /* defined (_MB_CAPABLE) && __POSIX_VISIBLE >= 200809 */
 
 #ifndef _REENT_ONLY
 
 char *_EXFUN(setlocale,(int, const char *));
 struct lconv *_EXFUN(localeconv,(void));
 
-#if __POSIX_VISIBLE >= 200809
+#if defined (_MB_CAPABLE) && __POSIX_VISIBLE >= 200809
 locale_t newlocale (int, const char *, locale_t);
 void freelocale (locale_t);
 locale_t duplocale (locale_t);
 locale_t uselocale (locale_t);
-#endif /* __POSIX_VISIBLE >= 200809 */
+#endif /* defined (_MB_CAPABLE) && __POSIX_VISIBLE >= 200809 */
 
 #endif /* _REENT_ONLY */
 
diff --git a/newlib/libc/locale/duplocale.c b/newlib/libc/locale/duplocale.c
index 7bd89ea..b804c90 100644
--- a/newlib/libc/locale/duplocale.c
+++ b/newlib/libc/locale/duplocale.c
@@ -39,6 +39,8 @@ PORTABILITY
 #include <stdlib.h>
 #include "setlocale.h"
 
+#ifdef _MB_CAPABLE
+
 struct __locale_t *
 _duplocale_r (struct _reent *p, struct __locale_t *locobj)
 {
@@ -95,3 +97,5 @@ duplocale (struct __locale_t *locobj)
   return _duplocale_r (_REENT, locobj);
 }
 #endif
+
+#endif /* _MB_CAPABLE */
diff --git a/newlib/libc/locale/freelocale.c b/newlib/libc/locale/freelocale.c
index e18b453..4cc161e 100644
--- a/newlib/libc/locale/freelocale.c
+++ b/newlib/libc/locale/freelocale.c
@@ -37,6 +37,8 @@ PORTABILITY
 #include <stdlib.h>
 #include "setlocale.h"
 
+#ifdef _MB_CAPABLE
+
 void
 _freelocale_r (struct _reent *p, struct __locale_t *locobj)
 {
@@ -59,3 +61,5 @@ freelocale (struct __locale_t *locobj)
 {
   _freelocale_r (_REENT, locobj);
 }
+
+#endif /* _MB_CAPABLE */
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index 58c2849..33b794c 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -203,6 +203,7 @@ static char *categories[_LC_LAST] = {
   "LC_TIME",
   "LC_MESSAGES",
 };
+#endif
 
 /*
  * Default locale per POSIX.  Can be overridden on a per-target base.
@@ -210,6 +211,8 @@ static char *categories[_LC_LAST] = {
 #ifndef DEFAULT_LOCALE
 #define DEFAULT_LOCALE	"C"
 #endif
+
+#ifdef _MB_CAPABLE
 /*
  * This variable can be changed by any outside mechanism.  This allows,
  * for instance, to load the default locale from a file.
@@ -251,6 +254,8 @@ const struct __locale_t __C_locale =
 #endif
 };
 
+#endif  /* _MB_CAPABLE */
+
 struct __locale_t __global_locale =
 {
   { "C", "C", DEFAULT_LOCALE, "C", "C", "C", "C", },
@@ -291,6 +296,8 @@ struct __locale_t __global_locale =
 #endif
 };
 
+#ifdef _MB_CAPABLE
+
 /* Renamed from current_locale_string to make clear this is only the
    *global* string for setlocale (LC_ALL, NULL).  There's no equivalent
    functionality for uselocale. */
diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c
index 239173b..eb96c03 100644
--- a/newlib/libc/locale/newlocale.c
+++ b/newlib/libc/locale/newlocale.c
@@ -79,6 +79,8 @@ PORTABILITY
 #include <stdlib.h>
 #include "setlocale.h"
 
+#ifdef _MB_CAPABLE
+
 #define LC_VALID_MASK	(LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MONETARY_MASK \
 			 | LC_NUMERIC_MASK | LC_TIME_MASK | LC_MESSAGES_MASK)
 
@@ -213,3 +215,5 @@ newlocale (int category_mask, const char *locale, struct __locale_t *base)
 {
   return _newlocale_r (_REENT, category_mask, locale, base);
 }
+
+#endif /* _MB_CAPABLE */
diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h
index 99bd466..837a576 100644
--- a/newlib/libc/locale/setlocale.h
+++ b/newlib/libc/locale/setlocale.h
@@ -194,11 +194,15 @@ struct __locale_t
 #endif
 };
 
+#ifdef _MB_CAPABLE
 extern const struct __locale_t __C_locale;
+#endif
 extern struct __locale_t __global_locale;
 
+#ifdef _MB_CAPABLE
 extern char *__loadlocale (struct __locale_t *, int, const char *);
 extern const char *__get_locale_env(struct _reent *, int);
+#endif
 
 extern struct lconv *__localeconv_l (struct __locale_t *locale);
 
diff --git a/newlib/libc/locale/uselocale.c b/newlib/libc/locale/uselocale.c
index 810590f..d8e04ab 100644
--- a/newlib/libc/locale/uselocale.c
+++ b/newlib/libc/locale/uselocale.c
@@ -55,6 +55,8 @@ PORTABILITY
 #include <stdlib.h>
 #include "setlocale.h"
 
+#ifdef _MB_CAPABLE
+
 struct __locale_t *
 _uselocale_r (struct _reent *p, struct __locale_t *newloc)
 {
@@ -77,3 +79,5 @@ uselocale (struct __locale_t *newloc)
   return _uselocale_r (_REENT, newloc);
 }
 #endif
+
+#endif /* _MB_CAPABLE */
-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


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