Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ add_header_library(
wctype_utils.h
DEPENDS
libc.hdr.types.wchar_t
libc.hdr.types.wint_t
)

add_header_library(
Expand Down
26 changes: 0 additions & 26 deletions libc/src/__support/wctype_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#define LLVM_LIBC_SRC___SUPPORT_WCTYPE_UTILS_H

#include "hdr/types/wchar_t.h"
#include "hdr/types/wint_t.h"
#include "src/__support/CPP/optional.h"
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h"

Expand Down Expand Up @@ -584,30 +582,6 @@ is_char_or_wchar(wchar_t ch, [[maybe_unused]] char, wchar_t wc_value) {
return (ch == wc_value);
}

// ------------------------------------------------------
// Rationale: Since these classification functions are
// called in other functions, we will avoid the overhead
// of a function call by inlining them.
// ------------------------------------------------------

LIBC_INLINE cpp::optional<int> wctob(wint_t c) {
// This needs to be translated to EOF at the callsite. This is to avoid
// including stdio.h in this file.
// The standard states that wint_t may either be an alias of wchar_t or
// an alias of an integer type, different platforms define this type with
// different signedness. This is equivalent to `(c > 127) || (c < 0)` but also
// works without -Wtype-limits warnings when `wint_t` is unsigned.
if ((c & ~127) != 0)
return cpp::nullopt;
return static_cast<int>(c);
}

LIBC_INLINE cpp::optional<wint_t> btowc(int c) {
if (c > 127 || c < 0)
return cpp::nullopt;
return static_cast<wint_t>(c);
}

} // namespace internal
} // namespace LIBC_NAMESPACE_DECL

Expand Down
2 changes: 0 additions & 2 deletions libc/src/wchar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ add_entrypoint_object(
DEPENDS
libc.hdr.types.wint_t
libc.hdr.stdio_macros
libc.src.__support.wctype_utils
)

add_entrypoint_object(
Expand All @@ -52,7 +51,6 @@ add_entrypoint_object(
DEPENDS
libc.hdr.types.wint_t
libc.hdr.wchar_macros
libc.src.__support.wctype_utils
)

add_entrypoint_object(
Expand Down
8 changes: 2 additions & 6 deletions libc/src/wchar/btowc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@
#include "src/wchar/btowc.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/wctype_utils.h"

#include "hdr/types/wint_t.h"
#include "hdr/wchar_macros.h" // for WEOF.

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(wint_t, btowc, (int c)) {
auto result = internal::btowc(c);
if (result.has_value()) {
return result.value();
} else {
if (c > 127 || c < 0)
return WEOF;
}
return static_cast<wint_t>(c);
}

} // namespace LIBC_NAMESPACE_DECL
12 changes: 6 additions & 6 deletions libc/src/wchar/wctob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
#include "src/wchar/wctob.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/wctype_utils.h"

#include "hdr/stdio_macros.h" // for EOF.
#include "hdr/types/wint_t.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, wctob, (wint_t c)) {
auto result = internal::wctob(c);
if (result.has_value()) {
return result.value();
} else {
// The standard states that wint_t may either be an alias of wchar_t or
// an alias of an integer type, different platforms define this type with
// different signedness. This is equivalent to `(c > 127) || (c < 0)` but also
// works without -Wtype-limits warnings when `wint_t` is unsigned.
if ((c & ~127) != 0)
return EOF;
}
return static_cast<int>(c);
}

} // namespace LIBC_NAMESPACE_DECL
4 changes: 0 additions & 4 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1799,11 +1799,9 @@ libc_support_library(
name = "__support_wctype_utils",
hdrs = ["src/__support/wctype_utils.h"],
deps = [
":__support_cpp_optional",
":__support_macros_attributes",
":__support_macros_config",
":types_wchar_t",
":types_wint_t",
],
)

Expand Down Expand Up @@ -7472,7 +7470,6 @@ libc_function(
deps = [
":__support_common",
":__support_macros_config",
":__support_wctype_utils",
":hdr_wchar_macros",
":types_wint_t",
],
Expand Down Expand Up @@ -7704,7 +7701,6 @@ libc_function(
":__support_common",
":__support_macros_config",
":__support_macros_null_check",
":__support_wctype_utils",
":hdr_stdio_macros",
":types_wint_t",
],
Expand Down
Loading