Skip to content

Commit 12abe8a

Browse files
authored
[libc] Stub out message catalog functions from <nl_types.h> (#164360)
Create a POSIX `<nl_types.h>` header with `catopen`, `catclose`, and `catgets` function declarations. Provide the stub/placeholder implementations which always return error. This is consistent with the way locales are currently (un-)implemented in llvm-libc. Notably, providing `<nl_types.h>` fixes the last remaining issue with building libc++ against llvm-libc (on certain configuration of x86_64 Linux) after disabling threads and wide-characters in libc++.
1 parent 321a419 commit 12abe8a

File tree

17 files changed

+277
-0
lines changed

17 files changed

+277
-0
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,11 @@ if(LLVM_LIBC_FULL_BUILD)
13741374
libc.src.wchar.wcstombs
13751375
libc.src.wchar.wcsrtombs
13761376
libc.src.wchar.wcsnrtombs
1377+
1378+
# nl_types.h entrypoints
1379+
libc.src.nl_types.catopen
1380+
libc.src.nl_types.catclose
1381+
libc.src.nl_types.catgets
13771382
)
13781383
endif()
13791384

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set(TARGET_PUBLIC_HEADERS
1919
libc.include.malloc
2020
libc.include.math
2121
libc.include.netinet_in
22+
libc.include.nl_types
2223
libc.include.poll
2324
libc.include.pthread
2425
libc.include.sched

libc/include/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,14 @@ add_header_macro(
771771
.llvm-libc-macros.poll-macros
772772
)
773773

774+
add_header_macro(
775+
nl_types
776+
../libc/include/nl_types.yaml
777+
nl_types.h
778+
DEPENDS
779+
.llvm-libc-types.nl_catd
780+
)
781+
774782
# UEFI spec references "Uefi.h" so we use that name for compatibility
775783
add_header_macro(
776784
uefi

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ add_header(mbstate_t HDR mbstate_t.h)
4646
add_header(mode_t HDR mode_t.h)
4747
add_header(mtx_t HDR mtx_t.h DEPENDS .__futex_word .__mutex_type)
4848
add_header(nfds_t HDR nfds_t.h)
49+
add_header(nl_catd HDR nl_catd.h)
4950
add_header(nlink_t HDR nlink_t.h)
5051
add_header(off_t HDR off_t.h)
5152
add_header(once_flag HDR once_flag.h DEPENDS .__futex_word)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- Definition of nl_catd type ----------------------------------------===//
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_NL_CATD_H
10+
#define LLVM_LIBC_TYPES_NL_CATD_H
11+
12+
typedef void *nl_catd;
13+
14+
#endif // LLVM_LIBC_TYPES_NL_CATD_H

libc/include/nl_types.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
header: nl_types.h
2+
standards:
3+
- posix
4+
macros: []
5+
types:
6+
- type_name: nl_catd
7+
enums: []
8+
objects: []
9+
functions:
10+
- name: catopen
11+
standards:
12+
- posix
13+
return_type: nl_catd
14+
arguments:
15+
- type: const char *
16+
- type: int
17+
- name: catclose
18+
standards:
19+
- posix
20+
return_type: int
21+
arguments:
22+
- type: nl_catd
23+
- name: catgets
24+
standards:
25+
- posix
26+
return_type: char *
27+
arguments:
28+
- type: nl_catd
29+
- type: int
30+
- type: int
31+
- type: const char*

libc/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_subdirectory(arpa)
3737
add_subdirectory(assert)
3838
add_subdirectory(compiler)
3939
add_subdirectory(locale)
40+
add_subdirectory(nl_types)
4041
add_subdirectory(search)
4142
add_subdirectory(setjmp)
4243
add_subdirectory(signal)

libc/src/nl_types/CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
add_entrypoint_object(
2+
catopen
3+
SRCS
4+
catopen.cpp
5+
HDRS
6+
catopen.h
7+
DEPENDS
8+
libc.include.llvm-libc-types.nl_catd
9+
libc.src.errno.errno
10+
)
11+
12+
add_entrypoint_object(
13+
catclose
14+
SRCS
15+
catclose.cpp
16+
HDRS
17+
catclose.h
18+
DEPENDS
19+
libc.include.llvm-libc-types.nl_catd
20+
)
21+
22+
add_entrypoint_object(
23+
catgets
24+
SRCS
25+
catgets.cpp
26+
HDRS
27+
catgets.h
28+
DEPENDS
29+
libc.include.llvm-libc-types.nl_catd
30+
)
31+

libc/src/nl_types/catclose.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation of catclose ----------------------------------------===//
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+
#include "src/nl_types/catclose.h"
10+
#include "include/llvm-libc-types/nl_catd.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(int, catclose, ([[maybe_unused]] nl_catd catalog)) {
17+
// TODO: Add implementation for message catalogs. For now, return error
18+
// regardless of input.
19+
return -1;
20+
}
21+
22+
} // namespace LIBC_NAMESPACE_DECL

libc/src/nl_types/catclose.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for catclose ----------------------*- C++ -*-===//
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_SRC_NL_TYPES_CATCLOSE_H
10+
#define LLVM_LIBC_SRC_NL_TYPES_CATCLOSE_H
11+
12+
#include "include/llvm-libc-types/nl_catd.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int catclose(nl_catd catalog);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_NL_TYPES_CATCLOSE_H

0 commit comments

Comments
 (0)