Merge "New multi-byte character benchmarks."
diff --git a/libc/bionic/system.cpp b/libc/bionic/system.cpp
index 950f05c..93d7497 100644
--- a/libc/bionic/system.cpp
+++ b/libc/bionic/system.cpp
@@ -56,7 +56,7 @@
if ((errno = posix_spawnattr_setsigmask64(&attributes, &sigchld_blocker.old_set_))) return -1;
if ((errno = posix_spawnattr_setflags(&attributes, flags))) return -1;
- const char* argv[] = { "sh", "-c", command, nullptr };
+ const char* argv[] = {"sh", "-c", "--", command, nullptr};
pid_t child;
if ((errno = posix_spawn(&child, __bionic_get_shell_path(), nullptr, &attributes,
const_cast<char**>(argv), environ)) != 0) {
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 583287f..252e73a 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -161,11 +161,11 @@
void setprogname(const char* __name) __INTRODUCED_IN(21);
int mblen(const char* __s, size_t __n) __INTRODUCED_IN_NO_GUARD_FOR_NDK(26);
-size_t mbstowcs(wchar_t* __dst, const char* __src, size_t __n);
+size_t mbstowcs(wchar_t* __dst, const char* __src, size_t __n) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
int mbtowc(wchar_t* __wc_ptr, const char* __s, size_t __n) __INTRODUCED_IN_NO_GUARD_FOR_NDK(21);
int wctomb(char* __dst, wchar_t __wc) __INTRODUCED_IN_NO_GUARD_FOR_NDK(21);
-size_t wcstombs(char* __dst, const wchar_t* __src, size_t __n);
+size_t wcstombs(char* __dst, const wchar_t* __src, size_t __n) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
#if __ANDROID_API__ >= 21
size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21);
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 00b25d3..7397b68 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -631,7 +631,7 @@
mbsinit;
mbsnrtowcs; # introduced=21
mbsrtowcs;
- mbstowcs;
+ mbstowcs; # introduced=21
mbtowc; # introduced=21
memalign;
memccpy;
@@ -1194,7 +1194,7 @@
wcstold_l; # introduced=21
wcstoll; # introduced=21
wcstoll_l; # introduced=21
- wcstombs;
+ wcstombs; # introduced=21
wcstoul;
wcstoull; # introduced=21
wcstoull_l; # introduced=21
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index c429ff2..08df2eb 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -1219,7 +1219,7 @@
if (dup2(fds[child], desired_child_fd) == -1) _exit(127);
close(fds[child]);
if (bidirectional) dup2(STDOUT_FILENO, STDIN_FILENO);
- execl(__bionic_get_shell_path(), "sh", "-c", cmd, nullptr);
+ execl(__bionic_get_shell_path(), "sh", "-c", "--", cmd, nullptr);
_exit(127);
}
diff --git a/libc/system_properties/contexts_split.cpp b/libc/system_properties/contexts_split.cpp
index f71d70a..7ba835a 100644
--- a/libc/system_properties/contexts_split.cpp
+++ b/libc/system_properties/contexts_split.cpp
@@ -274,9 +274,6 @@
// still need the system / platform properties to function.
if (access("/vendor/etc/selinux/vendor_property_contexts", R_OK) != -1) {
InitializePropertiesFromFile("/vendor/etc/selinux/vendor_property_contexts");
- } else {
- // Fallback to nonplat_* if vendor_* doesn't exist.
- InitializePropertiesFromFile("/vendor/etc/selinux/nonplat_property_contexts");
}
} else {
if (!InitializePropertiesFromFile("/plat_property_contexts")) {
@@ -284,9 +281,6 @@
}
if (access("/vendor_property_contexts", R_OK) != -1) {
InitializePropertiesFromFile("/vendor_property_contexts");
- } else {
- // Fallback to nonplat_* if vendor_* doesn't exist.
- InitializePropertiesFromFile("/nonplat_property_contexts");
}
}
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index cef95cd..0046ef6 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -1181,14 +1181,6 @@
defaults: ["bionic_testlib_defaults"],
srcs: ["dl_df_1_global.cpp"],
ldflags: ["-Wl,-z,global"],
-
- target: {
- host: {
- // TODO (dimitry): host ld.gold does not yet support -z global
- // remove this line once it is updated.
- ldflags: ["-fuse-ld=bfd"],
- },
- },
}
// -----------------------------------------------------------------------------
@@ -1209,14 +1201,6 @@
defaults: ["bionic_testlib_defaults"],
srcs: ["dl_df_1_global_dummy.cpp"],
ldflags: ["-Wl,-z,global"],
-
- target: {
- host: {
- // TODO (dimitry): host ld.gold does not yet support -z global
- // remove this line once it is updated.
- ldflags: ["-fuse-ld=bfd"],
- },
- },
}
// -----------------------------------------------------------------------------
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 6679480..6dbd741 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -496,6 +496,30 @@
ASSERT_NE(0, system(nullptr));
}
+// https://austingroupbugs.net/view.php?id=1440
+TEST(stdlib, system_minus) {
+ // Create a script with a name that starts with a '-'.
+ TemporaryDir td;
+ std::string script = std::string(td.path) + "/-minus";
+ ASSERT_TRUE(android::base::WriteStringToFile("#!" BIN_DIR "sh\nexit 66\n", script));
+
+ // Set $PATH so we can find it.
+ setenv("PATH", td.path, 1);
+ // Make it executable so we can run it.
+ ASSERT_EQ(0, chmod(script.c_str(), 0555));
+
+ int status = system("-minus");
+ EXPECT_TRUE(WIFEXITED(status));
+ EXPECT_EQ(66, WEXITSTATUS(status));
+
+ // While we're here and have all the setup, let's test popen(3) too...
+ FILE* fp = popen("-minus", "r");
+ ASSERT_TRUE(fp != nullptr);
+ status = pclose(fp);
+ EXPECT_TRUE(WIFEXITED(status));
+ EXPECT_EQ(66, WEXITSTATUS(status));
+}
+
TEST(stdlib, atof) {
ASSERT_DOUBLE_EQ(1.23, atof("1.23"));
}
diff --git a/tests/uchar_test.cpp b/tests/uchar_test.cpp
index 48c500d..4dc6314 100644
--- a/tests/uchar_test.cpp
+++ b/tests/uchar_test.cpp
@@ -36,6 +36,7 @@
// Any non-initial state is invalid when calling c32rtomb.
memset(&ps, 0, sizeof(ps));
EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps));
+ errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(out, 0x00a2, &ps));
EXPECT_EQ(EILSEQ, errno);
@@ -87,11 +88,7 @@
EXPECT_EQ('\xe2', bytes[0]);
EXPECT_EQ('\x82', bytes[1]);
EXPECT_EQ('\xac', bytes[2]);
-}
-
-TEST(uchar, c16rtomb_surrogate) {
- char bytes[MB_LEN_MAX];
-
+ // 4-byte UTF-8 from a surrogate pair...
memset(bytes, 0, sizeof(bytes));
EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, nullptr));
EXPECT_EQ(4U, c16rtomb(bytes, 0xdfcd, nullptr));
@@ -143,16 +140,16 @@
// 3-byte UTF-8.
ASSERT_EQ(3U, mbrtoc16(&out, "\xe2\x82\xac" "def", 6, nullptr));
ASSERT_EQ(static_cast<char16_t>(0x20ac), out);
-}
-
-TEST(uchar, mbrtoc16_surrogate) {
- char16_t out;
-
+ // 4-byte UTF-8 will be returned as a surrogate pair...
ASSERT_EQ(static_cast<size_t>(-3),
mbrtoc16(&out, "\xf4\x8a\xaf\x8d", 6, nullptr));
ASSERT_EQ(static_cast<char16_t>(0xdbea), out);
ASSERT_EQ(4U, mbrtoc16(&out, "\xf4\x8a\xaf\x8d" "ef", 6, nullptr));
ASSERT_EQ(static_cast<char16_t>(0xdfcd), out);
+ // Illegal 5-byte UTF-8.
+ errno = 0;
+ ASSERT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\xf8\xa1\xa2\xa3\xa4", 5, nullptr));
+ ASSERT_EQ(EILSEQ, errno);
}
TEST(uchar, mbrtoc16_reserved_range) {
@@ -194,6 +191,7 @@
// Invalid 2-byte
ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xc2", 1, ps));
+ errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\x20" "cdef", 5, ps));
ASSERT_EQ(EILSEQ, errno);
}
@@ -247,6 +245,7 @@
EXPECT_EQ('\xad', bytes[2]);
EXPECT_EQ('\xa2', bytes[3]);
// Invalid code point.
+ errno = 0;
EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(bytes, 0xffffffff, nullptr));
EXPECT_EQ(EILSEQ, errno);
}
@@ -307,10 +306,12 @@
ASSERT_EQ(static_cast<char32_t>(0x24b62), out[0]);
#if defined(__BIONIC__) // glibc allows this.
// Illegal 5-byte UTF-8.
+ errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf8\xa1\xa2\xa3\xa4" "f", 6, nullptr));
ASSERT_EQ(EILSEQ, errno);
#endif
// Illegal over-long sequence.
+ errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(out, "\xf0\x82\x82\xac" "ef", 6, nullptr));
ASSERT_EQ(EILSEQ, errno);
}
@@ -340,6 +341,7 @@
// Invalid 2-byte
ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xc2", 1, ps));
+ errno = 0;
ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(&out, "\x20" "cdef", 5, ps));
ASSERT_EQ(EILSEQ, errno);
}