Changeset 3915 for trunk


Ignore:
Timestamp:
Oct 24, 2014, 8:27:59 PM (11 years ago)
Author:
bird
Message:

0.6/locale.c: Rewrote the locale commiting code to not temporarily leave members with invalid NULL pointers and to prefer old string allocations if the value didn't change. Also, postpone the freeing of old locale resources till we're done comitting all. This effort is to reduce potential trouble with setlocale() being called on one thread while another is using it, however, this is not claiming to fix these kind of issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/tests/libc/smoketests/setlocale-1.c

    r3897 r3915  
    6161{
    6262    char   *psz1;
     63    char   *psz1Copy;
    6364    char   *psz2;
    6465    int     rc = 0;
     
    6667    setlocale(LC_ALL, "en_US");
    6768    psz1 = setlocale(LC_CTYPE, "de_DE");
     69    psz1Copy = psz1 ? strdup(psz1) : NULL;
     70
    6871    psz2 = setlocale(LC_CTYPE, "de_DE");
    69     if (psz1 && psz2 && !strcmp(psz1, psz2))
    70         printf("2nd setlocale returns the same. %s errno=%d\n", psz1, errno);
     72    if (psz1 == psz2 && psz2 && !strcmp(psz1Copy, psz2))
     73        printf("2nd setlocale returns the same pointer, great (%s). errno=%d\n", psz1, errno);
     74    else if (psz1 && psz2 && !strcmp(psz1Copy, psz2))
     75    {
     76#if 1 /* kLibC behaviour */
     77        printf("error: 2nd setlocale returns different points, but same value (%s): %p != %p errno=%d\n",
     78               psz2, psz1, psz2, errno);
     79        rc++;
     80#else
     81        printf("2nd setlocale returns the same value. %s errno=%d\n", psz2, errno);
     82#endif
     83    }
    7184    else
    7285    {
    73         printf("error: 2nd setlocale returns differntly. %s != %s errno=%d\n", psz1, psz2, errno);
     86        printf("error: 2nd setlocale returns differntly. %s != %s (%p, %p) errno=%d\n", psz1, psz2, psz1, psz2, errno);
    7487        rc++;
    7588    }
     89    free(psz1Copy);
    7690
    7791    return rc;
Note: See TracChangeset for help on using the changeset viewer.