Commenting differences I find between your patch and the one I sent
On Tue, Oct 15, 2013 at 03:32:29PM +0200, Martin Pelikan wrote:

Index: Makefile
+CFLAGS+=-D__NO_TLS
I had removed parts that used TLS, but this is better.

Index: arch/amd64/gdtoa/strtold.c
I didn't have this  (neither for other architectures, however I
concentrate in amd64).

Index: citrus/citrus_none.c
...
+int
+_none_init(struct xlocale_ctype *l, _RuneLocale *rl)
+{
+       l->__mbrtowc = _citrus_none_ctype_mbrtowc;
+       l->__mbsinit = _citrus_none_ctype_mbsinit;
+       l->__mbsnrtowcs = _citrus_none_ctype_mbsnrtowcs;
+       l->__wcrtomb = _citrus_none_ctype_wcrtomb;
+       l->__wcsnrtombs = _citrus_none_ctype_wcsnrtombs;
+       l->runes = rl;
+       l->__mb_cur_max = 1;
+       l->__mb_sb_limit = 256;
+       return (0);
+}
...
+struct xlocale_ctype __xlocale_global_ctype = {
...
+struct xlocale_ctype __xlocale_C_ctype = {

I put that in locale/none.c

+struct xlocale_collate {

I put in collate.h

+struct xlocale_collate __xlocale_global_collate = {
+       {{0}, "C"}, 1, 0
+};
+struct xlocale_collate __xlocale_C_collate = {
+       {{0}, "C"}, 1, 0
+};

In collate.c  (I had forgotten {{0}, "C"}, thanks, fixed!)

Index: gdtoa/gdtoaimp.h
+typedef struct _xlocale *locale_t;

Wouldn't be better #include <xlocale.h> ?

Index: gdtoa/strtod.c
Index: gdtoa/strtodg.c
Index: gdtoa/strtof.c
Index: gdtoa/strtorQ.c
Index: gdtoa/strtord.c
Index: gdtoa/strtorx.c

I didn't have these

Index: locale/Makefile.inc
-       _wctrans.c wcsxfrm.c
+       _wctrans.c wcsxfrm.c xlocale.c ctype.c runetype.c tolower.c toupper.c
I added
collate.c nextwctype.c none.c xlocale.c

MLINKS+=setlocale.3 localeconv.3 \
        iswalnum.3 iswalpha.3 \
        iswalnum.3 iswblank.3 \

Here I added:

iswalnum.3 iswalpha.3 \
mblen.3 mblen_l.3\
mbrtowc.3 mbrtowc_l.3\
mbsinit.3 mbsinit_l.3\
mbstowcs.3 mbstowcs_l.3\
mbtowc.3 mbtowc_l.3\
setlocale.3 localeconv.3 \
towlower.3 towlower_l.3 \
towlower.3 towupper_l.3
wcstombs.3 wcstombs_l.3 \
wctob.3 wctob_l.3 \
wctomb.3 wctomb_l.3 \
mbsrtowcs.3 mbsnrtowcs_l.3 \
mbsrtowcs.3 mbsrtowcs_l.3 \
wcsrtombs.3 wcsnrtombs.3 \
wcsrtombs.3 wcsrtombs_l.3 \
wcsrtombs.3 wcsnrtombs_l.3

Index: locale/__mb_cur_max.c

 #include <sys/types.h>
 #include <limits.h>
+#include <wchar.h>
+#include "mblocal.h"

Not needed

Index: locale/btowc.c

...
 wint_t
-btowc(int c)
+btowc_l(int c, locale_t l)
 {
-       mbstate_t mbs;
+       static const mbstate_t initial;
+       mbstate_t mbs = initial;
        char cc;
        wchar_t wc;
+       FIX_LOCALE(l);
if (c == EOF)
                return (WEOF);
@@ -44,9 +51,13 @@ btowc(int c)
         * which detects error return values as well as "impossible" byte
         * counts.
         */
-       memset(&mbs, 0, sizeof(mbs));
        cc = (char)c;
-       if (mbrtowc(&wc, &cc, 1, &mbs) > 1)
+       if (XLOCALE_CTYPE(l)->__mbrtowc(&wc, &cc, 1, &mbs) > 1)
                return (WEOF);
        return (wc);
+}

I'm using
wint_t
btowc_l(int c, locale_t loc)
{
       mbstate_t mbs;
       char cc;
       wchar_t wc;

       if (c == EOF)
               return (WEOF);
       /*
        * We expect mbrtowc() to return 0 or 1, hence the check for n > 1
        * which detects error return values as well as "impossible" byte
        * counts.
        */
       memset(&mbs, 0, sizeof(mbs));
       cc = (char)c;
       if (mbrtowc_l(&wc, &cc, 1, &mbs, loc) > 1)
               return (WEOF);
       return (wc);
}

Other functions like mbrlen_l, mbtowc_l I implemented in similar way.

Index: locale/localeconv.c
I didn't have this

Index: locale/mblocal.h
...
+#include <runetype.h>

Here  (an wherever runetype.h is included) I have
#include "runetype.h"

Index: locale/multibyte_citrus.c
 size_t
-mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+mbrtowc_l(wchar_t *pwc, const char *s, size_t n,
+    mbstate_t *ps, locale_t locale)
 {
        static mbstate_t mbs;
        struct _citrus_ctype_rec *cc;
+ /* XXX xlocale not yet implemented */
+       (void) locale;
        if (ps == NULL)
                ps = &mbs;
        cc = _CurrentRuneLocale->rl_citrus_ctype;
        return (*cc->cc_ops->co_mbrtowc)(pwc, s, n, _ps_to_private(ps));
 }

This one I implemented:

size_t
mbrtowc_l(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps, locale_t l)
{
     static mbstate_t mbs;
     struct _citrus_ctype_rec *cc;

     if (ps == NULL)
            ps = &mbs;
     FIX_LOCALE(l);
     _RuneLocale *rl = XLOCALE_CTYPE(l)->runes;
     cc = rl->rl_citrus_ctype;
return (*cc->cc_ops->co_mbrtowc)(pwc, s, n, _ps_to_private(ps)); }


 size_t
-mbsrtowcs(wchar_t *dst, const char **src, size_t len, mbstate_t *ps)
+mbsrtowcs_l(wchar_t *dst, const char **src, size_t len,
+    mbstate_t *ps, locale_t locale)
 {
        static mbstate_t mbs;
+ /* XXX xlocale not yet implemented */
+       (void) locale;
        if (ps == NULL)
                ps = &mbs;
        return (mbsnrtowcs(dst, src, SIZE_MAX, len, ps));
 }

This one and next:

size_t
mbsrtowcs_l(wchar_t *dst, const char **src, size_t len, mbstate_t *ps,
   locale_t l)
{
       static mbstate_t mbs;

       if (ps == NULL)
               ps = &mbs;
       return (mbsnrtowcs_l(dst, src, SIZE_MAX, len, ps, l));
}


size_t
mbsnrtowcs_l(wchar_t *dst, const char **src, size_t nmc, size_t len,
   mbstate_t *ps, locale_t l)
{
       static mbstate_t mbs;
       struct _citrus_ctype_rec *cc;
if (ps == NULL)
               ps = &mbs;
       FIX_LOCALE(l);
       _RuneLocale *rl = XLOCALE_CTYPE(l)->runes;
       cc = rl->rl_citrus_ctype;
       return (*cc->cc_ops->co_mbsnrtowcs)(dst, src, nmc, len,
           _ps_to_private(ps));
}

 size_t
-wcrtomb(char *s, wchar_t wc, mbstate_t *ps)
+wcrtomb_l(char *s, wchar_t wc, mbstate_t *ps, locale_t locale)
 {
        static mbstate_t mbs;
        struct _citrus_ctype_rec *cc;
+ /* XXX xlocale not yet implemented */
+       (void) locale;
        if (ps == NULL)
                ps = &mbs;
        cc = _CurrentRuneLocale->rl_citrus_ctype;
        return (*cc->cc_ops->co_wcrtomb)(s, wc, _ps_to_private(ps));
 }

Here

size_t
wcrtomb_l(char *s, wchar_t wc, mbstate_t *ps, locale_t l)
{
       static mbstate_t mbs;
       struct _citrus_ctype_rec *cc;

       if (ps == NULL)
               ps = &mbs;
       FIX_LOCALE(l);
       _RuneLocale *rl = XLOCALE_CTYPE(l)->runes;
       cc = rl->rl_citrus_ctype;
       return (*cc->cc_ops->co_wcrtomb)(s, wc, _ps_to_private(ps));
}

In similar way implemented others.

Index: locale/rune.h

-extern _RuneLocale _DefaultRuneLocale;
-extern _RuneLocale *_CurrentRuneLocale;
+extern const _RuneLocale _DefaultRuneLocale;
+extern const _RuneLocale *_CurrentRuneLocale;

Ok. I added const

Index: locale/rune_local.h
+#include "runetype.h"

I don't need it

Index: locale/runetable.c
+#include "mblocal.h"

Don't need

-_RuneLocale _DefaultRuneLocale = {
+const _RuneLocale _DefaultRuneLocale = {

I added const

-_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale;
+const _RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale;

I added const

+_RuneLocale *
+__runes_for_locale(locale_t locale, int *mb_sb_limit)
I don't use this one

Index: locale/runetype.c

I don't need this file

Index: locale/runetype.h

You moved this one to /usr/include I didn't, but made this change:

@@ -40,7 +40,10 @@
#include <sys/types.h>
#include "ctype_private.h"

+#ifndef _RUNE_T_DEFINED
+#define _RUNE_T_DEFINED
typedef uint32_t       rune_t;
+#endif
typedef uint64_t       __runepad_t;


Index: locale/setlocale.h

I don't use this, but

+#define ENCODING_LEN 31
+#define CATEGORY_LEN 11

I added to xlocale_private.h

Index: locale/tolower.c

I don't use this

Index: locale/toupper.c

Neither this

Index: locale/wcscoll.c
Index: locale/wcsxfrm.c

The one you sent are fine without collation support.

Index: locale/wctob.c

+       static const mbstate_t initial;
+       mbstate_t mbs = initial;
        char buf[MB_LEN_MAX];
+       FIX_LOCALE(locale);
- memset(&mbs, 0, sizeof(mbs));
-       if (c == WEOF || wcrtomb(buf, c, &mbs) != 1)
+       if (c == WEOF /* || XLOCALE_CTYPE(locale)->__wcrtomb(buf, c, &mbs) != 1 
*/)

I do
       mbstate_t mbs;
       char buf[MB_LEN_MAX];

       memset(&mbs, 0, sizeof(mbs));
              if (c == WEOF || wcrtomb_l(buf, c, &mbs, loc) != 1)
                            return (EOF);
       return ((unsigned char)*buf);

Index: locale/xlocale.c
+#if 0
+               &__xlocale_global_collate,
+               &__xlocale_global_ctype,
+               &__xlocale_global_monetary,
+               &__xlocale_global_numeric,
+               &__xlocale_global_time,
+               &__xlocale_global_messages
+#endif

I have

                &__xlocale_global_collate,
                &__xlocale_global_ctype, 0, 0, 0, 0

...

+void *__collate_load(const char *a, locale_t b) { return NULL; }

This one I have in collate.c (not NULL)

+void *__ctype_load(const char *a, locale_t b) { return NULL; }

Instead of this I have in setrunelocale.c:

void
destruct_ctype(void *t)
{
        /* We don't free runes, because they are in the cache starting at
         * localerunes_head */
        if (t != NULL) {
                free(t);
        }
}


/** Based on __collate_load */
void *
__ctype_load(const char *locname, locale_t unused)
{
        struct xlocale_ctype *l = calloc(sizeof(struct xlocale_ctype), 1);

        l->header.header.destructor = destruct_ctype;
        if (xlocale_setrunelocale(l, locname))
        {
                xlocale_release(l);
                return NULL;
        }
        return l;
}

+void *__monetary_load(const char *a, locale_t b) { return NULL; }
+void *__numeric_load(const char *a, locale_t b) { return NULL; }
+void *__time_load(const char *a, locale_t b) { return NULL; }
+void *__messages_load(const char *a, locale_t b) { return NULL; }

These I had in setlocale.c, but better I moved to xlocale.c

+static pthread_key_t locale_info_key;

This one I commented

+#else
+       __has_thread_locale = 1;

Here I added:

        fake_tls = 1;
+
+static pthread_once_t once_control = PTHREAD_ONCE_INIT;
+/* Single threaded pthread_once(3).  libc won't have to -lpthread. */
+static int
+_once(pthread_once_t *o, void (*init_routine)(void))
+{
+       if (o->state == PTHREAD_DONE_INIT)
+               return (0);
+       init_routine();
+       o->state = PTHREAD_DONE_INIT;
+       return (0);
+}

I added this. Thank you (what license does your patch have?).
+       // XXX FreeBSD uses &__xlocale_global_locale
+       return (l ? l : &__xlocale_C_locale);

I also used &__xlocale_global_localeo

Index: locale/xlocale_private.h
+/**
+ * Decrements the reference count of a reference-counted structure, freeing it
+ * if this is the last reference, calling its destructor if it has one.
+ */
+__attribute__((unused)) static void
+xlocale_release(void *val)
+{
+       struct xlocale_refcounted *obj = val;
+       long count = obj->retain_count--;
+       // XXX long count = atomic_fetchadd_long(&(obj->retain_count), -1) - 1;

Here I have
       obj->retain_count--;
       long count = obj->retain_count;

That I think is consistent with the implementation of atomic_fetchadd_long:
http://fxr.watson.org/fxr/source/ia64/include/atomic.h?im=excerpts#L379

Index: stdio/asprintf.c
Index: stdio/fscanf.c
Index: stdio/local.h
Index: stdio/scanf.c
Index: stdio/snprintf.c
Index: stdio/sprintf.c
Index: stdio/sscanf.c
Index: stdio/vasprintf.c
Index: stdio/vdprintf.c
Index: stdio/vfprintf.c
Index: stdio/vfscanf.c
Index: stdio/vsnprintf.c
Index: stdio/vsprintf.c
Index: stdio/vsscanf.c
Index: stdlib/strtoimax.c
Index: stdlib/strtol.c
Index: stdlib/strtoll.c
Index: stdlib/strtoul.c
Index: stdlib/strtoull.c
Index: stdlib/strtoumax.c

I didn't have these.

Index: string/wcscasecmp.c
I have wcsncasecmp_l

Index: string/wcscmp.c
Index: string/wcsncmp.c
Index: string/wmemcmp.c

I didn't touch these

Index: time/strftime.c

I didn't have this one

Thank you, I updated my patches, and thanked you in commit message.
https://github.com/pasosdeJesus/adJ/commit/a5d66cd5bf2b814287cfc1bdc68e707cddf5ef17

I will be checking in detail new files you sent that I didn't have and
will try to add to my patches.


--
Dios, gracias por tu amor infinito.
-- Vladimir Támara Patiño. http://vtamara.pasosdeJesus.org/
 http://www.pasosdejesus.org/dominio_publico_colombia.html

Reply via email to