Fix char2wchar/wchar2char to support collations properly.
These functions should take a pg_locale_t, not a collation OID, and should call mbstowcs_l/wcstombs_l where available. Where those functions are not available, temporarily select the correct locale with uselocale(). This change removes the bogus assumption that all locales selectable in a given database have the same wide-character conversion method; in particular, the collate.linux.utf8 regression test now passes with LC_CTYPE=C, so long as the database encoding is UTF8. I decided to move the char2wchar/wchar2char functions out of mbutils.c and into pg_locale.c, because they work on wchar_t not pg_wchar_t and thus don't really belong with the mbutils.c functions. Keeping them where they were would have required importing pg_locale_t into pg_wchar.h somehow, which did not seem like a good plan.
Showing
- configure 2 additions, 1 deletionconfigure
- configure.in 1 addition, 1 deletionconfigure.in
- src/backend/tsearch/ts_locale.c 11 additions, 6 deletionssrc/backend/tsearch/ts_locale.c
- src/backend/tsearch/wparser_def.c 4 additions, 2 deletionssrc/backend/tsearch/wparser_def.c
- src/backend/utils/adt/formatting.c 10 additions, 6 deletionssrc/backend/utils/adt/formatting.c
- src/backend/utils/adt/pg_locale.c 173 additions, 0 deletionssrc/backend/utils/adt/pg_locale.c
- src/backend/utils/mb/mbutils.c 0 additions, 121 deletionssrc/backend/utils/mb/mbutils.c
- src/include/mb/pg_wchar.h 0 additions, 7 deletionssrc/include/mb/pg_wchar.h
- src/include/pg_config.h.in 3 additions, 0 deletionssrc/include/pg_config.h.in
- src/include/pg_config.h.win32 3 additions, 0 deletionssrc/include/pg_config.h.win32
- src/include/port/win32.h 2 additions, 0 deletionssrc/include/port/win32.h
- src/include/utils/pg_locale.h 8 additions, 0 deletionssrc/include/utils/pg_locale.h
Loading
Please register or sign in to comment