[XLA] Don't rely on ctype for classifying characters
Instead, use the ascii routines in ABSL. This makes the code do the same thing regardless of how the locale is configured. PiperOrigin-RevId: 229995801
This commit is contained in:
parent
916df403fb
commit
5c5102a3c9
@ -15,9 +15,9 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/compiler/xla/metric_table_report.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "tensorflow/core/platform/logging.h"
|
||||
@ -249,7 +249,7 @@ string MetricTableReport::MetricString(double metric) {
|
||||
string output;
|
||||
// Copy leading non-digit characters unconditionally.
|
||||
// This picks up the leading sign.
|
||||
while (!sp1.empty() && !isdigit(sp1[0])) {
|
||||
while (!sp1.empty() && !absl::ascii_isdigit(sp1[0])) {
|
||||
output.push_back(sp1[0]);
|
||||
sp1.remove_prefix(1);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ limitations under the License.
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "absl/types/span.h"
|
||||
@ -37,7 +38,7 @@ limitations under the License.
|
||||
|
||||
namespace xla {
|
||||
|
||||
static const char kWS[] = " \t\r\n"; // whitespace
|
||||
static const char kWS[] = " \t\r\n"; // whitespace
|
||||
|
||||
// The following struct represents an argv[]-style array, parsed
|
||||
// from data gleaned from the environment.
|
||||
@ -104,7 +105,8 @@ static void ParseArgvFromString(const string& flag_str, EnvArgv* a) {
|
||||
// Set e to the index just past the end of the flag.
|
||||
size_t e = b;
|
||||
while (e != flag_str.size() && isascii(flag_str[e]) &&
|
||||
(strchr("-_", flag_str[e]) != nullptr || isalnum(flag_str[e]))) {
|
||||
(strchr("-_", flag_str[e]) != nullptr ||
|
||||
absl::ascii_isalnum(flag_str[e]))) {
|
||||
e++;
|
||||
}
|
||||
if (e != flag_str.size() && flag_str[e] == '=' &&
|
||||
|
@ -3656,12 +3656,13 @@ tf_cc_test(
|
||||
extra_copts = ["-Wno-string-plus-int"],
|
||||
deps = [
|
||||
":hlo_matchers",
|
||||
":hlo_parser",
|
||||
":indexed_array_analysis",
|
||||
"//tensorflow/compiler/xla:test",
|
||||
"//tensorflow/compiler/xla/service:hlo_parser",
|
||||
"//tensorflow/compiler/xla/tests:hlo_test_base",
|
||||
"//tensorflow/compiler/xla/tests:test_utils",
|
||||
"//tensorflow/core:test",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -16,7 +16,6 @@ limitations under the License.
|
||||
// Tests that we call into Eigen for dot operations as needed.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
|
@ -14,9 +14,9 @@ limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "tensorflow/compiler/xla/service/cpu/cpu_compiler.h"
|
||||
#include "tensorflow/compiler/xla/service/cpu/tests/cpu_codegen_test.h"
|
||||
@ -59,8 +59,9 @@ class CpuUnaryIntrinsicTest
|
||||
|
||||
string features{spec.features.data(), spec.features.size()};
|
||||
if (!features.empty()) {
|
||||
std::replace_if(features.begin(), features.end(),
|
||||
[](char c) { return c != '_' && !isalnum(c); }, '_');
|
||||
std::replace_if(
|
||||
features.begin(), features.end(),
|
||||
[](char c) { return c != '_' && !absl::ascii_isalnum(c); }, '_');
|
||||
} else {
|
||||
features = "";
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/escaping.h"
|
||||
#include "absl/strings/numbers.h"
|
||||
#include "absl/strings/str_split.h"
|
||||
@ -37,8 +38,8 @@ constexpr int kError = -2;
|
||||
|
||||
// [a-zA-Z0-9_.-]
|
||||
bool IsIdentifierChar(char c) {
|
||||
return isalnum(static_cast<unsigned char>(c)) || c == '-' || c == '.' ||
|
||||
c == '_';
|
||||
return absl::ascii_isalnum(static_cast<unsigned char>(c)) || c == '-' ||
|
||||
c == '.' || c == '_';
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -105,7 +106,7 @@ TokKind HloLexer::LexToken() {
|
||||
switch (current_char) {
|
||||
default:
|
||||
// [a-zA-Z_]
|
||||
if (isalpha(static_cast<unsigned char>(current_char)) ||
|
||||
if (absl::ascii_isalpha(static_cast<unsigned char>(current_char)) ||
|
||||
current_char == '_') {
|
||||
return LexIdentifier();
|
||||
}
|
||||
@ -300,7 +301,7 @@ TokKind HloLexer::LexIdentifier() {
|
||||
// name ::= [a-zA-Z_][a-zA-Z0-9_.-]*
|
||||
TokKind HloLexer::LexPercent() {
|
||||
const char* name_start = current_ptr_;
|
||||
if (isalpha(static_cast<unsigned char>(PeekCurrentChar())) ||
|
||||
if (absl::ascii_isalpha(static_cast<unsigned char>(PeekCurrentChar())) ||
|
||||
PeekCurrentChar() == '_') {
|
||||
current_ptr_++;
|
||||
while (IsIdentifierChar(PeekCurrentChar())) {
|
||||
|
@ -13,9 +13,8 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "tensorflow/compiler/xla/service/indexed_array_analysis.h"
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "tensorflow/compiler/xla/tests/hlo_test_base.h"
|
||||
#include "tensorflow/compiler/xla/tests/test_utils.h"
|
||||
|
||||
@ -43,7 +42,7 @@ class IndexedArrayAnalysisTest : public HloTestBase {
|
||||
string result;
|
||||
|
||||
for (char c : text) {
|
||||
if (!isspace(c)) {
|
||||
if (!absl::ascii_isspace(c)) {
|
||||
result.push_back(c);
|
||||
} else if (!result.empty() && result.back() != ' ') {
|
||||
result.push_back(' ');
|
||||
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/compiler/xla/service/name_uniquer.h"
|
||||
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/numbers.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "tensorflow/compiler/xla/primitive_util.h"
|
||||
@ -28,7 +29,7 @@ namespace {
|
||||
|
||||
bool IsAllowed(char character) {
|
||||
auto c = static_cast<unsigned char>(character);
|
||||
return (isalnum(c) != 0) || c == '_' || c == '.' || c == '-';
|
||||
return (absl::ascii_isalnum(c) != 0) || c == '_' || c == '.' || c == '-';
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -46,7 +47,7 @@ NameUniquer::NameUniquer(const string& separator) {
|
||||
|
||||
string result = name;
|
||||
char c = static_cast<unsigned char>(result[0]);
|
||||
if (!isalpha(c) && c != '_') {
|
||||
if (!absl::ascii_isalpha(c) && c != '_') {
|
||||
result[0] = '_';
|
||||
}
|
||||
for (int i = 1; i < result.length(); i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user