-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc] Implemented wmemset and added tests #141691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
7494a42
da350d3
2860250
7592ccb
472589a
c1670df
02dd7c8
93305b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===-- Implementation of wmemset -----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/wchar/wmemset.h" | ||
|
|
||
| #include "hdr/types/size_t.h" | ||
| #include "hdr/types/wchar_t.h" | ||
| #include "src/__support/common.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(wchar_t *, wmemset, (wchar_t * s, wchar_t c, size_t n)) { | ||
| for (size_t i = 0; i < n; i++) { | ||
|
||
| s[i] = c; | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===-- Implementation header for wmemset | ||
| //----------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SRC_WCHAR_WMEMSET_H | ||
| #define LLVM_LIBC_SRC_WCHAR_WMEMSET_H | ||
|
|
||
| #include "hdr/types/size_t.h" | ||
| #include "hdr/types/wchar_t.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_WCHAR_WMEMSET_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,3 +32,15 @@ add_libc_test( | |
| DEPENDS | ||
| libc.src.wchar.wctob | ||
| ) | ||
|
|
||
| add_libc_test( | ||
| wmemset_test | ||
| SUITE | ||
| libc_wchar_unittests | ||
| SRCS | ||
| wmemset_test.cpp | ||
| DEPENDS | ||
| libc.hdr.types.size_t | ||
| libc.hdr.types.wchar_t | ||
| libc.src.wchar.wmemset | ||
| ) | ||
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,87 @@ | ||||||
| //===-- Unittests for wmemset ---------------------------------------------===// | ||||||
| // | ||||||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||||
| // See https://llvm.org/LICENSE.txt for license information. | ||||||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||
| // | ||||||
| //===----------------------------------------------------------------------===// | ||||||
|
|
||||||
| #include "hdr/types/size_t.h" | ||||||
| #include "hdr/types/wchar_t.h" | ||||||
| #include "src/wchar/wmemset.h" | ||||||
| #include "test/UnitTest/Test.h" | ||||||
|
|
||||||
| TEST(LlvmLibcWMemsetTest, SmallStringBoundCheck) { | ||||||
| wchar_t *str = new wchar_t[5]; | ||||||
|
||||||
| wchar_t *str = new wchar_t[5]; | |
| wchar_t str[5]; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: make this constexpr
| const int str_size = 1000; | |
| constexpr int STR_SIZE = 1000; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not necessarily safe to assume wchar_t is 32 bits. Instead it's better to use the provided WCHAR_MAX macro.
It would also be good to give magic a more descriptive name.
| const wchar_t magic = INT32_MAX; | |
| const wchar_t magic = WCHAR_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fix missing newline