Skip to content

Commit 861c120

Browse files
committed
[libc][stdlib][annex_k] Add set_constraint_handler_s.
1 parent 8c1ce5e commit 861c120

File tree

9 files changed

+105
-0
lines changed

9 files changed

+105
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ if(LLVM_LIBC_FULL_BUILD)
10821082
libc.src.stdlib.getenv
10831083
libc.src.stdlib.ignore_handler_s
10841084
libc.src.stdlib.quick_exit
1085+
libc.src.stdlib.set_constraint_handler_s
10851086

10861087
# signal.h entrypoints
10871088
libc.src.signal.kill

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ if(LLVM_LIBC_FULL_BUILD)
12091209
libc.src.stdlib.getenv
12101210
libc.src.stdlib.ignore_handler_s
12111211
libc.src.stdlib.quick_exit
1212+
libc.src.stdlib.set_constraint_handler_s
12121213

12131214
# signal.h entrypoints
12141215
libc.src.signal.kill

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ if(LLVM_LIBC_FULL_BUILD)
12481248
libc.src.stdlib.getenv
12491249
libc.src.stdlib.ignore_handler_s
12501250
libc.src.stdlib.quick_exit
1251+
libc.src.stdlib.set_constraint_handler_s
12511252

12521253
# signal.h entrypoints
12531254
libc.src.signal.kill

libc/include/stdlib.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ functions:
202202
- type: void *__restrict
203203
- type: errno_t
204204
guard: 'LIBC_HAS_ANNEX_K'
205+
- name: set_constraint_handler_s
206+
standards:
207+
- stdc
208+
return_type: constraint_handler_t
209+
arguments:
210+
- type: constraint_handler_t
211+
guard: 'LIBC_HAS_ANNEX_K'
205212
- name: srand
206213
standards:
207214
- stdc

libc/src/__support/annex_k/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ add_header_library(
2828
.abort_handler_s
2929
libc.hdr.types.constraint_handler_t
3030
)
31+
32+
add_header_library(
33+
set_constraint_handler_s
34+
HDRS
35+
set_constraint_handler_s.h
36+
DEPENDS
37+
.abort_handler_s
38+
.libc_constraint_handler
39+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- Implementation for set_constraint_handler_s -------------*- 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___SUPPORT_ANNEX_K_SET_CONSTRAINT_HANDLER_S_H
10+
#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_SET_CONSTRAINT_HANDLER_S_H
11+
12+
#include "abort_handler_s.h"
13+
#include "libc_constraint_handler.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
namespace annex_k {
18+
19+
LIBC_INLINE static constraint_handler_t
20+
set_constraint_handler_s(constraint_handler_t handler) {
21+
constraint_handler_t previous_handler = libc_constraint_handler;
22+
23+
if (!handler) {
24+
libc_constraint_handler = &abort_handler_s;
25+
} else {
26+
libc_constraint_handler = handler;
27+
}
28+
29+
return previous_handler;
30+
}
31+
32+
} // namespace annex_k
33+
34+
} // namespace LIBC_NAMESPACE_DECL
35+
36+
#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_SET_CONSTRAINT_HANDLER_S_H

libc/src/stdlib/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,16 @@ add_entrypoint_object(
664664
.${LIBC_TARGET_OS}.system
665665
)
666666

667+
add_entrypoint_object(
668+
set_constraint_handler_s
669+
SRCS
670+
set_constraint_handler_s.cpp
671+
HDRS
672+
set_constraint_handler_s.h
673+
DEPENDS
674+
libc.src.__support.annex_k.set_constraint_handler_s
675+
)
676+
667677
add_entrypoint_object(
668678
ignore_handler_s
669679
HDRS
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of set_constraint_handler_s ------------------------===//
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 "set_constraint_handler_s.h"
10+
#include "src/__support/annex_k/set_constraint_handler_s.h"
11+
12+
namespace LIBC_NAMESPACE_DECL {
13+
14+
LLVM_LIBC_FUNCTION(constraint_handler_t, set_constraint_handler_s,
15+
(constraint_handler_t handler)) {
16+
return annex_k::set_constraint_handler_s(handler);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for set_constraint_handler_s ------*- 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_STDLIB_SET_CONSTRAINT_HANDLER_S_H
10+
#define LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H
11+
12+
#include "hdr/types/constraint_handler_t.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
constraint_handler_t set_constraint_handler_s(constraint_handler_t handler);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H

0 commit comments

Comments
 (0)