| 1 |
/* Table that maps a locale object to the names of the locale categories. |
| 2 |
Copyright (C) 2018-2025 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 Lesser General Public License as published by |
| 6 |
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser 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 |
# include "glthread/lock.h" |
| 25 |
|
| 26 |
/* Smallest among the six LC_* category values. */ |
| 27 |
# define LCMIN (LC_ALL == 0 ? 1 : 0) |
| 28 |
|
| 29 |
struct locale_categories_names |
| 30 |
{ |
| 31 |
/* (Locale category - LCMIN) -> name (allocated with indefinite extent). */ |
| 32 |
const char *category_name[6]; |
| 33 |
}; |
| 34 |
|
| 35 |
/* A hash table of fixed size. Multiple threads can access it read-only |
| 36 |
simultaneously, but only one thread can insert into it or remove from it |
| 37 |
at the same time. |
| 38 |
This hash table has global scope, so that when an application uses both |
| 39 |
GNU libintl and gnulib, the application sees only one hash table. (When |
| 40 |
linking statically with libintl, the fact that localename-table.c is a |
| 41 |
separate compilation unit resolves the duplicate symbol conflict. When |
| 42 |
linking with libintl as a shared library, we rely on ELF and the symbol |
| 43 |
conflict resolution implemented in the ELF dynamic loader here.) |
| 44 |
Both the libintl overrides and the gnulib overrides of the functions |
| 45 |
newlocale, duplocale, freelocale see the same hash table (and the same lock). |
| 46 |
For this reason, the internal layout of the hash table and the hash function |
| 47 |
MUST NEVER CHANGE. If you need to change the internal layout or the hash |
| 48 |
function, introduce versioning by appending a version suffix to the symbols |
| 49 |
at the linker level. */ |
| 50 |
# define locale_hash_function libintl_locale_hash_function |
| 51 |
# define locale_hash_table libintl_locale_hash_table |
| 52 |
# define locale_lock libintl_locale_lock |
| 53 |
|
| 54 |
extern size_t _GL_ATTRIBUTE_CONST locale_hash_function (locale_t x); |
| 55 |
|
| 56 |
/* A node in a hash bucket collision list. */ |
| 57 |
struct locale_hash_node |
| 58 |
{ |
| 59 |
struct locale_hash_node *next; |
| 60 |
locale_t locale; |
| 61 |
struct locale_categories_names names; |
| 62 |
}; |
| 63 |
|
| 64 |
# define LOCALE_HASH_TABLE_SIZE 101 |
| 65 |
extern struct locale_hash_node * locale_hash_table[LOCALE_HASH_TABLE_SIZE]; |
| 66 |
|
| 67 |
/* This lock protects the locale_hash_table against multiple simultaneous |
| 68 |
accesses (except that multiple simultaneous read accesses are allowed). */ |
| 69 |
|
| 70 |
gl_rwlock_define(extern, locale_lock) |
| 71 |
|
| 72 |
#endif |