Skip to content

Commit a629bad

Browse files
jhuber6cjdb
authored andcommitted
[libc] Add ctype.h locale variants (llvm#102711)
Summary: This patch adds all the libc ctype variants. These ignore the locale ingormation completely, so they're pretty much just stubs. Because these use locale information, which is system scope, we do not enable building them outisde of full build mode.
1 parent 1dd214c commit a629bad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1738
-31
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,35 @@ set(TARGET_LIBC_ENTRYPOINTS
44

55
# ctype.h entrypoints
66
libc.src.ctype.isalnum
7+
libc.src.ctype.isalnum_l
78
libc.src.ctype.isalpha
9+
libc.src.ctype.isalpha_l
810
libc.src.ctype.isascii
911
libc.src.ctype.isblank
12+
libc.src.ctype.isblank_l
1013
libc.src.ctype.iscntrl
14+
libc.src.ctype.iscntrl_l
1115
libc.src.ctype.isdigit
16+
libc.src.ctype.isdigit_l
1217
libc.src.ctype.isgraph
18+
libc.src.ctype.isgraph_l
1319
libc.src.ctype.islower
20+
libc.src.ctype.islower_l
1421
libc.src.ctype.isprint
22+
libc.src.ctype.isprint_l
1523
libc.src.ctype.ispunct
24+
libc.src.ctype.ispunct_l
1625
libc.src.ctype.isspace
26+
libc.src.ctype.isspace_l
1727
libc.src.ctype.isupper
28+
libc.src.ctype.isupper_l
1829
libc.src.ctype.isxdigit
30+
libc.src.ctype.isxdigit_l
1931
libc.src.ctype.toascii
2032
libc.src.ctype.tolower
33+
libc.src.ctype.tolower_l
2134
libc.src.ctype.toupper
35+
libc.src.ctype.toupper_l
2236

2337
# string.h entrypoints
2438
libc.src.string.bcmp
@@ -233,6 +247,15 @@ set(TARGET_LIBC_ENTRYPOINTS
233247
# wchar.h entrypoints
234248
libc.src.wchar.wctob
235249

250+
# locale.h entrypoints
251+
libc.src.locale.localeconv
252+
libc.src.locale.duplocale
253+
libc.src.locale.freelocale
254+
libc.src.locale.localeconv
255+
libc.src.locale.newlocale
256+
libc.src.locale.setlocale
257+
libc.src.locale.uselocale
258+
236259
# gpu/rpc.h entrypoints
237260
libc.src.gpu.rpc_host_call
238261
)

libc/config/gpu/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(TARGET_PUBLIC_HEADERS
1616
libc.include.wchar
1717
libc.include.uchar
1818
libc.include.features
19+
libc.include.locale
1920

2021
# Header for RPC extensions
2122
libc.include.gpu_rpc

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,22 @@ endif()
782782

783783
if(LLVM_LIBC_FULL_BUILD)
784784
list(APPEND TARGET_LIBC_ENTRYPOINTS
785+
# ctype.h entrypoints
786+
libc.src.ctype.isalnum_l
787+
libc.src.ctype.isalpha_l
788+
libc.src.ctype.isblank_l
789+
libc.src.ctype.iscntrl_l
790+
libc.src.ctype.isdigit_l
791+
libc.src.ctype.isgraph_l
792+
libc.src.ctype.islower_l
793+
libc.src.ctype.isprint_l
794+
libc.src.ctype.ispunct_l
795+
libc.src.ctype.isspace_l
796+
libc.src.ctype.isupper_l
797+
libc.src.ctype.isxdigit_l
798+
libc.src.ctype.tolower_l
799+
libc.src.ctype.toupper_l
800+
785801
# assert.h entrypoints
786802
libc.src.assert.__assert_fail
787803

@@ -982,6 +998,15 @@ if(LLVM_LIBC_FULL_BUILD)
982998
libc.src.time.nanosleep
983999
libc.src.time.time
9841000

1001+
# locale.h entrypoints
1002+
libc.src.locale.localeconv
1003+
libc.src.locale.duplocale
1004+
libc.src.locale.freelocale
1005+
libc.src.locale.localeconv
1006+
libc.src.locale.newlocale
1007+
libc.src.locale.setlocale
1008+
libc.src.locale.uselocale
1009+
9851010
# unistd.h entrypoints
9861011
libc.src.unistd.__llvm_libc_syscall
9871012
libc.src.unistd._exit

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(TARGET_PUBLIC_HEADERS
3333
libc.include.unistd
3434
libc.include.wchar
3535
libc.include.uchar
36+
libc.include.locale
3637

3738
libc.include.arpa_inet
3839

libc/hdr/types/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,12 @@ add_proxy_header_library(
162162
libc.include.llvm-libc-types.cookie_io_functions_t
163163
libc.include.stdio
164164
)
165+
166+
add_proxy_header_library(
167+
locale_t
168+
HDRS
169+
locale_t.h
170+
FULL_BUILD_DEPENDS
171+
libc.include.llvm-libc-types.locale_t
172+
libc.include.locale
173+
)

libc/hdr/types/locale_t.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from locale_t.h ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_HDR_LOCALE_T_H
10+
#define LLVM_LIBC_HDR_LOCALE_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/locale_t.h"
15+
16+
#else // overlay mode
17+
18+
#error "type not available in overlay mode"
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_LOCALE_T_H

libc/include/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ add_header_macro(
4545
ctype.h
4646
DEPENDS
4747
.llvm_libc_common_h
48+
.llvm-libc-types.locale_t
4849
)
4950

5051
add_header_macro(
@@ -719,6 +720,18 @@ add_header_macro(
719720
.llvm-libc-types.wchar_t
720721
)
721722

723+
add_header_macro(
724+
locale
725+
../libc/newhdrgen/yaml/locale.yaml
726+
locale.h.def
727+
locale.h
728+
DEPENDS
729+
.llvm_libc_common_h
730+
.llvm-libc-macros.locale_macros
731+
.llvm-libc-types.locale_t
732+
.llvm-libc-types.struct_lconv
733+
)
734+
722735
if(LIBC_TARGET_OS_IS_GPU)
723736
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/gpu)
724737

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,9 @@ add_macro_header(
295295
HDR
296296
elf-macros.h
297297
)
298+
299+
add_macro_header(
300+
locale_macros
301+
HDR
302+
locale-macros.h
303+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===-- Definition of macros from locale.h --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_MACROS_LOCALE_MACROS_H
10+
#define LLVM_LIBC_MACROS_LOCALE_MACROS_H
11+
12+
#include "../llvm-libc-types/locale_t.h"
13+
14+
#define LC_CTYPE 0
15+
#define LC_NUMERIC 1
16+
#define LC_TIME 2
17+
#define LC_COLLATE 3
18+
#define LC_MONETARY 4
19+
#define LC_MESSAGES 5
20+
#define LC_ALL 6
21+
22+
#define LC_GLOBAL_LOCALE ((locale_t)(-1))
23+
24+
#define LC_CTYPE_MASK (1 << LC_CTYPE)
25+
#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
26+
#define LC_TIME_MASK (1 << LC_TIME)
27+
#define LC_COLLATE_MASK (1 << LC_COLLATE)
28+
#define LC_MONETARY_MASK (1 << LC_MONETARY)
29+
#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
30+
#define LC_ALL_MASK 0x7fffffff
31+
32+
#endif // LLVM_LIBC_MACROS_LOCALE_MACROS_H

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,5 @@ DEPENDS
142142
.fsblkcnt_t
143143
.fsfilcnt_t
144144
)
145+
add_header(locale_t HDR locale_t.h)
146+
add_header(struct_lconv HDR struct_lconv.h)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of type locale_t ---------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_LOCALE_T_H
10+
#define LLVM_LIBC_TYPES_LOCALE_T_H
11+
12+
#define NUM_LOCALE_CATEGORIES 6
13+
14+
struct __locale_data;
15+
16+
struct __locale_t {
17+
struct __locale_data *data[NUM_LOCALE_CATEGORIES];
18+
};
19+
20+
typedef struct __locale_t *locale_t;
21+
22+
#endif // LLVM_LIBC_TYPES_LOCALE_T_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===-- Definition of type lconv ------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_LCONV_H
10+
#define LLVM_LIBC_TYPES_LCONV_H
11+
12+
struct lconv {
13+
char *decimal_point;
14+
char *thousands_sep;
15+
char *grouping;
16+
char *mon_decimal_point;
17+
char *mon_thousands_sep;
18+
char *mon_grouping;
19+
char *positive_sign;
20+
char *negative_sign;
21+
char *currency_symbol;
22+
char frac_digits;
23+
char p_cs_precedes;
24+
char n_cs_precedes;
25+
char p_sep_by_space;
26+
char n_sep_by_space;
27+
char p_sign_posn;
28+
char n_sign_posn;
29+
char *int_curr_symbol;
30+
char int_frac_digits;
31+
char int_p_cs_precedes;
32+
char int_n_cs_precedes;
33+
char int_p_sep_by_space;
34+
char int_n_sep_by_space;
35+
char int_p_sign_posn;
36+
char int_n_sign_posn;
37+
};
38+
39+
#endif // LLVM_LIBC_TYPES_LCONV_H

libc/include/locale.h.def

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- C standard library header locale.h --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_LOCALE_H
10+
#define LLVM_LIBC_LOCALE_H
11+
12+
#include "__llvm-libc-common.h"
13+
14+
#include "llvm-libc-macros/locale-macros.h"
15+
#include "llvm-libc-types/locale_t.h"
16+
#include "llvm-libc-types/struct_lconv.h"
17+
18+
%%public_api()
19+
20+
#endif // LLVM_LIBC_LOCALE_H

0 commit comments

Comments
 (0)