| 1 | /* Table that maps a locale object to the names of the locale categories. |
| 2 | Copyright (C) 2018-2020 Free Software Foundation, Inc. |
| 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 16 | |
| 17 | /* Written by Bruno Haible <[email protected]>, 2018. */ |
| 18 | |
| 19 | #if HAVE_WORKING_USELOCALE && HAVE_NAMELESS_LOCALES |
| 20 | |
| 21 | # include <stddef.h> |
| 22 | # include <locale.h> |
| 23 | |
| 24 | # ifdef IN_LIBINTL |
| 25 | # include "lock.h" |
| 26 | # else |
| 27 | # include "glthread/lock.h" |
| 28 | # endif |
| 29 | |
| 30 | struct locale_categories_names |
| 31 | { |
| 32 | /* Locale category -> name (allocated with indefinite extent). */ |
| 33 | const char *category_name[6]; |
| 34 | }; |
| 35 | |
| 36 | /* A hash table of fixed size. Multiple threads can access it read-only |
| 37 | simultaneously, but only one thread can insert into it or remove from it |
| 38 | at the same time. |
| 39 | This hash table has global scope, so that when an application uses both |
| 40 | GNU libintl and gnulib, the application sees only one hash table. (When |
| 41 | linking statically with libintl, the fact that localename-table.c is a |
| 42 | separate compilation unit resolves the duplicate symbol conflict. When |
| 43 | linking with libintl as a shared library, we rely on ELF and the symbol |
| 44 | conflict resolution implemented in the ELF dynamic loader here.) |
| 45 | Both the libintl overrides and the gnulib overrides of the functions |
| 46 | newlocale, duplocale, freelocale see the same hash table (and the same lock). |
| 47 | For this reason, the internal layout of the hash table and the hash function |
| 48 | MUST NEVER CHANGE. If you need to change the internal layout or the hash |
| 49 | function, introduce versioning by appending a version suffix to the symbols |
| 50 | at the linker level. */ |
| 51 | # define locale_hash_function libintl_locale_hash_function |
| 52 | # define locale_hash_table libintl_locale_hash_table |
| 53 | # define locale_lock libintl_locale_lock |
| 54 | |
| 55 | extern size_t _GL_ATTRIBUTE_CONST locale_hash_function (locale_t x); |
| 56 | |
| 57 | /* A node in a hash bucket collision list. */ |
| 58 | struct locale_hash_node |
| 59 | { |
| 60 | struct locale_hash_node *next; |
| 61 | locale_t locale; |
| 62 | struct locale_categories_names names; |
| 63 | }; |
| 64 | |
| 65 | # define LOCALE_HASH_TABLE_SIZE 101 |
| 66 | extern struct locale_hash_node * locale_hash_table[LOCALE_HASH_TABLE_SIZE]; |
| 67 | |
| 68 | /* This lock protects the locale_hash_table against multiple simultaneous |
| 69 | accesses (except that multiple simultaneous read accesses are allowed). */ |
| 70 | |
| 71 | gl_rwlock_define(extern, locale_lock) |
| 72 | |
| 73 | #endif |