This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Collation functions (was: Re: Results for g++ 3.1 application...)


Hi,

Benjamin, I'm not sure to understand what you meant when you wrote:

> These work for the generic code. For the linux codepath, it looks like
> there are some problems with glibc2.2.x and the following:
>
> #define _GNU_SOURCE 1
>
> #include <locale.h>
> #include <string.h>
> #include <stddef.h>
>
> #define __c_locale __locale_t
>
> int
> _M_transform_helper(char* __o, const char* __t, size_t __n, __c_locale __loc)
> { return __strxfrm_l(__o, __t, __n, __loc); }
>
> int main()
> {
>   __c_locale    loc;
>   __c_locale    loc_dup;
>
>   const char*   __s = "de_DE";
>   const char* __one = "Äuglein Augmen";
>   const char* __two = "Äuglein";
>   int i;
>   int j;
>   size_t __n1;
>   size_t __n2;
>   char* __c1;
>   char* __c2;
>
>   loc = __newlocale(1 << LC_ALL, __s, 0);
>   loc_dup = __duplocale(loc);
>
>   __n1 = strlen(__one);
>   __n2 = strlen(__two);
>   __c1 = __builtin_alloca(__n1);
>   __c2 = __builtin_alloca(__n2);
>   i = _M_transform_helper(__c1, __one, __n1, loc);
>   j = _M_transform_helper(__c2, __two, __n2, loc_dup);
>
>   return 0;
>  }

What I get with glibc2.2.5 is the following: i == 44 and j == 24, that is most
evidently the transformed strings do *not* fit in the arrays __c1 and __c2. If I
try, tentatively:

  __c3 = __builtin_alloca(100);
  __c4 = __builtin_alloca(50);
  i = _M_transform_helper(__c3, __one, 100, loc);
  j = _M_transform_helper(__c4, __two, 50, loc_dup);

then __c3 and __c4 seem ok to me:

__c3 == "\f \022\027\020\024\031\f \022\030\020\031\001\013", '\002' <repeats 12
times>,
"\001\004\002\002\002\002\002\002\004\002\002\002\002\002\001\b\021"

and

__c4 == "\f
\022\027\020\024\031\001\013\002\002\002\002\002\002\001\004\002\002\002\002\002\002"

respectively, and i == 44, j == 23, consistent with the length of the allocated
arrays.

Am I missing something? I can't see anything seriously not conforming to
glibc2.2.5 docs. I'm only puzzled a little bit by the fact that the first time j
== 24, the second j == 23, but in any case this is not really troublesome, IMO.

Ciao,
Paolo.




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