Skip to content

Commit 9c7d2b9

Browse files
Make the utf8_range implementation just in C
PiperOrigin-RevId: 590961088
1 parent 1db8ed4 commit 9c7d2b9

13 files changed

Lines changed: 499 additions & 477 deletions

File tree

php/ext/google/protobuf/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if test "$PHP_PROTOBUF" != "no"; then
44

55
PHP_NEW_EXTENSION(
66
protobuf,
7-
arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/naive.c third_party/utf8_range/range2-neon.c third_party/utf8_range/range2-sse.c,
7+
arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/utf8_range.c,
88
$ext_shared, , -std=gnu99 -I@ext_srcdir@/third_party/utf8_range)
99
PHP_ADD_BUILD_DIR($ext_builddir/third_party/utf8_range)
1010

python/convert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
241241
// Use the object's bytes if they are valid UTF-8.
242242
char* ptr;
243243
if (PyBytes_AsStringAndSize(obj, &ptr, &size) < 0) return false;
244-
if (utf8_range2((const unsigned char*)ptr, size) != 0) {
244+
if (!utf8_range_IsValid(ptr, size)) {
245245
// Invalid UTF-8. Try to convert the message to a Python Unicode
246246
// object, even though we know this will fail, just to get the
247247
// idiomatic Python error message.

ruby/.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ pkg/
88
tmp/
99
tests/google/
1010
ext/google/protobuf_c/third_party/utf8_range/utf8_range.h
11-
ext/google/protobuf_c/third_party/utf8_range/range2-sse.c
12-
ext/google/protobuf_c/third_party/utf8_range/range2-neon.c
13-
ext/google/protobuf_c/third_party/utf8_range/naive.c
11+
ext/google/protobuf_c/third_party/utf8_range/utf8_range.c
1412
ext/google/protobuf_c/third_party/utf8_range/LICENSE
1513
lib/google/protobuf/*_pb.rb

ruby/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ task :copy_third_party do
7575
# We need utf8_range in-tree.
7676
utf8_root = '../third_party/utf8_range'
7777
%w[
78-
utf8_range.h naive.c range2-neon.c range2-neon.c range2-sse.c LICENSE
78+
utf8_range.h utf8_range.c LICENSE
7979
].each do |file|
8080
FileUtils.cp File.join(utf8_root, file),
8181
"ext/google/protobuf_c/third_party/utf8_range"

ruby/ext/google/protobuf_c/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
$srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
2424
"repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
25-
"naive.c", "range2-neon.c", "range2-sse.c", "shared_convert.c",
25+
"utf8_range.c", "shared_convert.c",
2626
"shared_message.c"]
2727

2828
create_makefile(ext_name)

ruby/lib/google/tasks/ffi.rake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ begin
7474
FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c|
7575
configure_common_compile_task c
7676
# Ruby UPB was already compiled with different flags.
77-
c.exclude << "/range2-neon.c"
78-
c.exclude << "/range2-sse.c"
79-
c.exclude << "/naive.c"
77+
c.exclude << "/utf8_range.c"
8078
c.exclude << "/ruby-upb.c"
8179
end
8280

third_party/utf8_range/BUILD.bazel

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ exports_files([
2323
filegroup(
2424
name = "utf8_range_srcs",
2525
srcs = [
26-
"naive.c",
27-
"range2-neon.c",
28-
"range2-sse.c",
26+
"utf8_range.c",
2927
"utf8_range.h",
3028
],
3129
visibility = ["//:__subpackages__"],
@@ -34,9 +32,7 @@ filegroup(
3432
cc_library(
3533
name = "utf8_range",
3634
srcs = [
37-
"naive.c",
38-
"range2-neon.c",
39-
"range2-sse.c",
35+
"utf8_range.c",
4036
],
4137
hdrs = ["utf8_range.h"],
4238
strip_include_prefix = "/third_party/utf8_range",
@@ -48,14 +44,19 @@ cc_library(
4844
hdrs = ["utf8_validity.h"],
4945
strip_include_prefix = "/third_party/utf8_range",
5046
deps = [
47+
":utf8_range",
5148
"@com_google_absl//absl/strings",
5249
],
5350
)
5451

5552
cc_test(
5653
name = "utf8_validity_test",
57-
srcs = ["utf8_validity_test.cc"],
54+
srcs = [
55+
"utf8_range.c",
56+
"utf8_validity_test.cc",
57+
],
5858
deps = [
59+
":utf8_range",
5960
":utf8_validity",
6061
"@com_google_absl//absl/strings",
6162
"@com_google_googletest//:gtest_main",

third_party/utf8_range/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ option (utf8_range_ENABLE_INSTALL "Configure installation" ON)
1212
##
1313
# Create the lightweight C library
1414
add_library (utf8_range STATIC
15-
naive.c
16-
range2-neon.c
17-
range2-sse.c
15+
utf8_range.c
1816
)
1917

2018
##
2119
# A heavier-weight C++ wrapper that supports Abseil.
22-
add_library (utf8_validity STATIC utf8_validity.cc)
20+
add_library (utf8_validity STATIC utf8_validity.cc utf8_range.c)
2321

2422
# Load Abseil dependency.
2523
if (NOT TARGET absl::strings)

0 commit comments

Comments
 (0)