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