ruby_memprofiler_pprof 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/ruby_memprofiler_pprof/backtrace.c +429 -0
- data/ext/ruby_memprofiler_pprof/collector.c +1055 -0
- data/ext/ruby_memprofiler_pprof/compat.c +182 -0
- data/ext/ruby_memprofiler_pprof/extconf.rb +72 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.c +170 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.h +848 -0
- data/ext/ruby_memprofiler_pprof/pprof_out.c +285 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.c +11 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.h +301 -0
- data/ext/ruby_memprofiler_pprof/strtab.c +391 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/BUILD +719 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/CONTRIBUTING.md +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/DESIGN.md +201 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/LICENSE +26 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/README.md +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/WORKSPACE +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/BUILD +53 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/amalgamate.py +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/build_defs.bzl +160 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/lua.BUILD +127 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/protobuf.patch +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/py_proto_library.bzl +137 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/python_downloads.bzl +84 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/system_python.bzl +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/upb_proto_library.bzl +388 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/workspace_deps.bzl +89 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD +252 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD.googleapis +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/benchmark.cc +333 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/build_defs.bzl +88 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/compare.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor.proto +888 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor_sv.proto +890 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/empty.proto +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_protobuf_binary_cc.py +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_synthetic_protos.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_upb_binary_c.py +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/BUILD.bazel +102 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/README.md +23 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/build_defs.bzl +73 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/make_cmakelists.py +340 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test.py +57 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test_lib.py +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/render.py +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/style-guide.md +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/vs-cpp-protos.md +255 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/wrapping-upb.md +444 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/BUILD +216 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.c +394 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.h +63 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.c +1694 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.h +80 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.c +704 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.c +650 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.h +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/BUILD.bazel +193 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/dist.bzl +190 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.c +247 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.c +522 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.c +1909 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.h +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/minimal_test.py +183 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/BUILD +70 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/README.md +11 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_pool_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_test_wrapper.py +46 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/generator_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/json_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/keywords_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_factory_test_wrapper.py +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_test_wrapper.py +52 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/proto_builder_test_wrapper.py +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/pyproto_test_wrapper.bzl +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/reflection_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/service_reflection_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/symbol_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_encoding_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/unknown_fields_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/well_known_types_test_wrapper.py +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/wire_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.c +350 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.h +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/py_extension.bzl +55 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/python_api.h +61 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.c +828 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.h +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.c +404 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/version_script.lds +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/LICENSE +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/README.google +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/console.lua +156 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/lunit.lua +725 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/BUILD +19 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/LICENSE +21 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/naive.c +92 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/BUILD.bazel +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/README.md +8 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/def.c +939 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/lua_proto_library.bzl +138 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/main.c +83 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/msg.c +1118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test.proto +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test_upb.lua +846 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.c +258 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.h +132 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.lua +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upbc.cc +134 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.c +192 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.h +174 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb.c +346 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb_failures.txt +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.c +1221 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.c +1055 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.h +153 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_internal.h +211 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.c +3262 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.h +414 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.hpp +438 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/empty.proto +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.c +604 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.h +71 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/BUILD +13 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/file_descriptor_parsenew_fuzzer.cc +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.c +1509 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.h +47 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.c +776 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.c +1147 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.h +189 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.hpp +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.c +363 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.h +263 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_internal.h +59 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_test.cc +425 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_test.cc +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.c +428 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_internal.h +836 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.cc +491 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.proto +195 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_def.inc +261 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_undef.inc +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.c +323 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.h +109 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.hpp +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table.c +926 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table_internal.h +385 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test.proto +74 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.cc +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.proto +12 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_generated_code.cc +977 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_table.cc +580 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.c +472 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.h +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.c +362 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.h +378 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.hpp +115 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb_internal.h +68 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/BUILD +121 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/README.md +7 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.c +300 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare_test.cc +236 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.c +572 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_public_import_test.proto +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_regular_import_test.proto +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.cc +143 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.proto +119 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_weak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_wweak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.c +311 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.cc +202 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.proto +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/BUILD +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.cc +77 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.h +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upb.cc +1997 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upbdefs.cc +193 -0
- data/lib/ruby_memprofiler_pprof/atfork.rb +77 -0
- data/lib/ruby_memprofiler_pprof/block_flusher.rb +61 -0
- data/lib/ruby_memprofiler_pprof/file_flusher.rb +45 -0
- data/lib/ruby_memprofiler_pprof/profile_app.rb +30 -0
- data/lib/ruby_memprofiler_pprof/profile_data.rb +18 -0
- data/lib/ruby_memprofiler_pprof/version.rb +5 -0
- data/lib/ruby_memprofiler_pprof.rb +8 -0
- data/libexec/ruby_memprofiler_pprof_profile +16 -0
- metadata +257 -0
@@ -0,0 +1,193 @@
|
|
1
|
+
# Copyright (c) 2009-2022, Google LLC
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
# * Redistributions of source code must retain the above copyright
|
7
|
+
# notice, this list of conditions and the following disclaimer.
|
8
|
+
# * Redistributions in binary form must reproduce the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer in the
|
10
|
+
# documentation and/or other materials provided with the distribution.
|
11
|
+
# * Neither the name of Google LLC nor the
|
12
|
+
# names of its contributors may be used to endorse or promote products
|
13
|
+
# derived from this software without specific prior written permission.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
|
19
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
26
|
+
load("//bazel:py_proto_library.bzl", "py_proto_library")
|
27
|
+
load(":dist.bzl", "py_dist", "py_dist_module")
|
28
|
+
load("@bazel_skylib//lib:selects.bzl", "selects")
|
29
|
+
load("@com_google_protobuf//:protobuf_version.bzl", "PROTOBUF_PYTHON_VERSION")
|
30
|
+
load("@rules_python//python:packaging.bzl", "py_wheel")
|
31
|
+
load("@system_python//:version.bzl", "SYSTEM_PYTHON_VERSION")
|
32
|
+
|
33
|
+
licenses(["notice"])
|
34
|
+
|
35
|
+
py_dist_module(
|
36
|
+
name = "message_mod",
|
37
|
+
extension = "//python:_message_binary",
|
38
|
+
module_name = "google._upb._message",
|
39
|
+
)
|
40
|
+
|
41
|
+
py_proto_library(
|
42
|
+
name = "well_known_proto_py_pb2",
|
43
|
+
deps = [
|
44
|
+
"@com_google_protobuf//:any_proto",
|
45
|
+
"@com_google_protobuf//:api_proto",
|
46
|
+
"@com_google_protobuf//:compiler_plugin_proto",
|
47
|
+
"@com_google_protobuf//:descriptor_proto",
|
48
|
+
"@com_google_protobuf//:duration_proto",
|
49
|
+
"@com_google_protobuf//:empty_proto",
|
50
|
+
"@com_google_protobuf//:field_mask_proto",
|
51
|
+
"@com_google_protobuf//:source_context_proto",
|
52
|
+
"@com_google_protobuf//:struct_proto",
|
53
|
+
"@com_google_protobuf//:timestamp_proto",
|
54
|
+
"@com_google_protobuf//:type_proto",
|
55
|
+
"@com_google_protobuf//:wrappers_proto",
|
56
|
+
],
|
57
|
+
)
|
58
|
+
|
59
|
+
config_setting(
|
60
|
+
name = "aarch64_cpu",
|
61
|
+
values = {"cpu": "linux-aarch_64"},
|
62
|
+
)
|
63
|
+
|
64
|
+
config_setting(
|
65
|
+
name = "x86_64_cpu",
|
66
|
+
values = {"cpu": "linux-x86_64"},
|
67
|
+
)
|
68
|
+
|
69
|
+
config_setting(
|
70
|
+
name = "osx-x86_64_cpu",
|
71
|
+
values = {"cpu": "osx-x86_64"},
|
72
|
+
)
|
73
|
+
|
74
|
+
config_setting(
|
75
|
+
name = "osx-aarch64_cpu",
|
76
|
+
values = {"cpu": "osx-aarch_64"},
|
77
|
+
)
|
78
|
+
|
79
|
+
config_setting(
|
80
|
+
name = "osx-universal2_cpu",
|
81
|
+
values = {"cpu": "osx-universal2"},
|
82
|
+
)
|
83
|
+
|
84
|
+
config_setting(
|
85
|
+
name = "win32_cpu",
|
86
|
+
values = {"cpu": "win32"},
|
87
|
+
)
|
88
|
+
|
89
|
+
config_setting(
|
90
|
+
name = "win64_cpu",
|
91
|
+
values = {"cpu": "win64"},
|
92
|
+
)
|
93
|
+
|
94
|
+
py_wheel(
|
95
|
+
name = "binary_wheel",
|
96
|
+
abi = select({
|
97
|
+
"//python:full_api_3.7": "cp37m",
|
98
|
+
"//python:full_api_3.8": "cp38",
|
99
|
+
"//python:full_api_3.9": "cp39",
|
100
|
+
"//conditions:default": "abi3",
|
101
|
+
}),
|
102
|
+
distribution = "protobuf",
|
103
|
+
platform = select({
|
104
|
+
":x86_64_cpu": "manylinux2014_x86_64",
|
105
|
+
":aarch64_cpu": "manylinux2014_aarch64",
|
106
|
+
":osx-universal2_cpu": "macosx_10_9_universal2",
|
107
|
+
":win32_cpu": "win32",
|
108
|
+
":win64_cpu": "win_amd64",
|
109
|
+
"//conditions:default": "any",
|
110
|
+
}),
|
111
|
+
python_tag = selects.with_or({
|
112
|
+
("//python:limited_api_3.7", "//python:full_api_3.7"): "cp37",
|
113
|
+
"//python:full_api_3.8": "cp38",
|
114
|
+
"//python:full_api_3.9": "cp39",
|
115
|
+
"//python:limited_api_3.10": "cp310",
|
116
|
+
"//conditions:default": "cp" + SYSTEM_PYTHON_VERSION,
|
117
|
+
}),
|
118
|
+
strip_path_prefixes = [
|
119
|
+
"python/dist/",
|
120
|
+
"python/",
|
121
|
+
],
|
122
|
+
version = PROTOBUF_PYTHON_VERSION,
|
123
|
+
deps = [
|
124
|
+
":message_mod",
|
125
|
+
":well_known_proto_py_pb2",
|
126
|
+
"@com_google_protobuf//:python_srcs",
|
127
|
+
],
|
128
|
+
)
|
129
|
+
|
130
|
+
py_wheel(
|
131
|
+
name = "pure_python_wheel",
|
132
|
+
abi = "none",
|
133
|
+
distribution = "protobuf",
|
134
|
+
platform = "any",
|
135
|
+
python_tag = "py3",
|
136
|
+
strip_path_prefixes = [
|
137
|
+
"python/",
|
138
|
+
],
|
139
|
+
version = PROTOBUF_PYTHON_VERSION,
|
140
|
+
deps = [
|
141
|
+
":well_known_proto_py_pb2",
|
142
|
+
"@com_google_protobuf//:python_srcs",
|
143
|
+
],
|
144
|
+
)
|
145
|
+
|
146
|
+
py_wheel(
|
147
|
+
name = "test_wheel",
|
148
|
+
abi = "none",
|
149
|
+
distribution = "protobuftests",
|
150
|
+
platform = "any",
|
151
|
+
python_tag = "py3",
|
152
|
+
strip_path_prefixes = ["python/"],
|
153
|
+
version = PROTOBUF_PYTHON_VERSION,
|
154
|
+
deps = [
|
155
|
+
"//python/pb_unit_tests:test_files",
|
156
|
+
"@com_google_protobuf//:python_common_test_protos",
|
157
|
+
"@com_google_protobuf//:python_specific_test_protos",
|
158
|
+
"@com_google_protobuf//:python_test_srcs",
|
159
|
+
"@com_google_protobuf//:testdata",
|
160
|
+
],
|
161
|
+
)
|
162
|
+
|
163
|
+
py_dist(
|
164
|
+
name = "dist",
|
165
|
+
binary_wheel = ":binary_wheel",
|
166
|
+
full_api_cpus = [
|
167
|
+
# TODO(b/231485326): fix win32 build
|
168
|
+
# "win32",
|
169
|
+
"win64",
|
170
|
+
],
|
171
|
+
# Windows needs version-specific wheels until 3.10.
|
172
|
+
full_api_versions = [
|
173
|
+
"37",
|
174
|
+
"38",
|
175
|
+
"39",
|
176
|
+
],
|
177
|
+
# Limited API: these wheels will satisfy any Python version >= the
|
178
|
+
# given version.
|
179
|
+
#
|
180
|
+
# Technically the limited API doesn't have the functions we need until
|
181
|
+
# 3.10, but on Linux we can get away with using 3.7 (see ../python_api.h for
|
182
|
+
# details).
|
183
|
+
limited_api_wheels = {
|
184
|
+
# TODO(b/231485326): fix win32 build
|
185
|
+
# "win32": "310",
|
186
|
+
"win64": "310",
|
187
|
+
"linux-x86_64": "37",
|
188
|
+
"linux-aarch_64": "37",
|
189
|
+
"osx-universal2": "37",
|
190
|
+
},
|
191
|
+
pure_python_wheel = ":pure_python_wheel",
|
192
|
+
tags = ["manual"],
|
193
|
+
)
|
@@ -0,0 +1,190 @@
|
|
1
|
+
"""Rules to create python distribution files and properly name them"""
|
2
|
+
|
3
|
+
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
|
4
|
+
load("@system_python//:version.bzl", "SYSTEM_PYTHON_VERSION")
|
5
|
+
|
6
|
+
def _get_suffix(limited_api, python_version, cpu):
|
7
|
+
"""Computes an ABI version tag for an extension module per PEP 3149."""
|
8
|
+
suffix = "pyd" if ("win" in cpu) else "so"
|
9
|
+
|
10
|
+
if limited_api == True:
|
11
|
+
if "win" not in cpu:
|
12
|
+
suffix = "abi3." + suffix
|
13
|
+
return "." + suffix
|
14
|
+
|
15
|
+
if "win32" in cpu or "win64" in cpu:
|
16
|
+
if "win32" in cpu:
|
17
|
+
abi = "win32"
|
18
|
+
elif "win64" in cpu:
|
19
|
+
abi = "win_amd64"
|
20
|
+
else:
|
21
|
+
fail("Unsupported CPU: " + cpu)
|
22
|
+
return ".cp{}-{}.{}".format(python_version, abi, suffix)
|
23
|
+
|
24
|
+
if python_version == "system":
|
25
|
+
python_version = SYSTEM_PYTHON_VERSION
|
26
|
+
if int(python_version) < 38:
|
27
|
+
python_version += "m"
|
28
|
+
abis = {
|
29
|
+
"darwin": "darwin",
|
30
|
+
"osx-x86_64": "darwin",
|
31
|
+
"osx-aarch_64": "darwin",
|
32
|
+
"linux-aarch_64": "aarch64-linux-gnu",
|
33
|
+
"linux-x86_64": "x86_64-linux-gnu",
|
34
|
+
"k8": "x86_64-linux-gnu",
|
35
|
+
}
|
36
|
+
|
37
|
+
return ".cpython-{}-{}.{}".format(python_version, abis[cpu], suffix)
|
38
|
+
|
39
|
+
fail("Unsupported combination of flags")
|
40
|
+
|
41
|
+
def _declare_module_file(ctx, module_name, python_version, limited_api):
|
42
|
+
"""Declares an output file for a Python module with this name, version, and limited api."""
|
43
|
+
base_filename = module_name.replace(".", "/")
|
44
|
+
suffix = _get_suffix(
|
45
|
+
python_version = python_version,
|
46
|
+
limited_api = limited_api,
|
47
|
+
cpu = ctx.var["TARGET_CPU"],
|
48
|
+
)
|
49
|
+
filename = base_filename + suffix
|
50
|
+
return ctx.actions.declare_file(filename)
|
51
|
+
|
52
|
+
# --------------------------------------------------------------------------------------------------
|
53
|
+
# py_dist_module()
|
54
|
+
#
|
55
|
+
# Creates a Python binary extension module that is ready for distribution.
|
56
|
+
#
|
57
|
+
# py_dist_module(
|
58
|
+
# name = "message_mod",
|
59
|
+
# extension = "//python:_message_binary",
|
60
|
+
# module_name = "google._upb._message",
|
61
|
+
# )
|
62
|
+
#
|
63
|
+
# In the simple case, this simply involves copying the input file to the proper filename for
|
64
|
+
# our current configuration (module_name, cpu, python_version, limited_abi).
|
65
|
+
#
|
66
|
+
# For multiarch platforms (osx-universal2), we must combine binaries for multiple architectures
|
67
|
+
# into a single output binary using the "llvm-lipo" tool. A config transition depends on multiple
|
68
|
+
# architectures to get us the input files we need.
|
69
|
+
|
70
|
+
def _py_multiarch_transition_impl(settings, attr):
|
71
|
+
if settings["//command_line_option:cpu"] == "osx-universal2":
|
72
|
+
return [{"//command_line_option:cpu": cpu} for cpu in ["osx-aarch_64", "osx-x86_64"]]
|
73
|
+
else:
|
74
|
+
return settings
|
75
|
+
|
76
|
+
_py_multiarch_transition = transition(
|
77
|
+
implementation = _py_multiarch_transition_impl,
|
78
|
+
inputs = ["//command_line_option:cpu"],
|
79
|
+
outputs = ["//command_line_option:cpu"],
|
80
|
+
)
|
81
|
+
|
82
|
+
def _py_dist_module_impl(ctx):
|
83
|
+
output_file = _declare_module_file(
|
84
|
+
ctx = ctx,
|
85
|
+
module_name = ctx.attr.module_name,
|
86
|
+
python_version = ctx.attr._python_version[BuildSettingInfo].value,
|
87
|
+
limited_api = ctx.attr._limited_api[BuildSettingInfo].value,
|
88
|
+
)
|
89
|
+
if len(ctx.attr.extension) == 1:
|
90
|
+
src = ctx.attr.extension[0][DefaultInfo].files.to_list()[0]
|
91
|
+
ctx.actions.run(
|
92
|
+
executable = "cp",
|
93
|
+
arguments = [src.path, output_file.path],
|
94
|
+
inputs = [src],
|
95
|
+
outputs = [output_file],
|
96
|
+
)
|
97
|
+
return [
|
98
|
+
DefaultInfo(files = depset([output_file])),
|
99
|
+
]
|
100
|
+
else:
|
101
|
+
srcs = [mod[DefaultInfo].files.to_list()[0] for mod in ctx.attr.extension]
|
102
|
+
ctx.actions.run(
|
103
|
+
executable = "/usr/local/bin/llvm-lipo",
|
104
|
+
arguments = ["-create", "-output", output_file.path] + [src.path for src in srcs],
|
105
|
+
inputs = srcs,
|
106
|
+
outputs = [output_file],
|
107
|
+
)
|
108
|
+
return [
|
109
|
+
DefaultInfo(files = depset([output_file])),
|
110
|
+
]
|
111
|
+
|
112
|
+
py_dist_module = rule(
|
113
|
+
output_to_genfiles = True,
|
114
|
+
implementation = _py_dist_module_impl,
|
115
|
+
attrs = {
|
116
|
+
"module_name": attr.string(mandatory = True),
|
117
|
+
"extension": attr.label(
|
118
|
+
mandatory = True,
|
119
|
+
cfg = _py_multiarch_transition,
|
120
|
+
),
|
121
|
+
"_limited_api": attr.label(default = "//python:limited_api"),
|
122
|
+
"_python_version": attr.label(default = "//python:python_version"),
|
123
|
+
"_allowlist_function_transition": attr.label(
|
124
|
+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
|
125
|
+
),
|
126
|
+
},
|
127
|
+
)
|
128
|
+
|
129
|
+
# --------------------------------------------------------------------------------------------------
|
130
|
+
# py_dist()
|
131
|
+
#
|
132
|
+
# A rule that builds a collection of binary wheels, using transitions to depend on many different
|
133
|
+
# python versions and cpus.
|
134
|
+
|
135
|
+
def _py_dist_transition_impl(settings, attr):
|
136
|
+
_ignore = (settings) # @unused
|
137
|
+
transitions = []
|
138
|
+
|
139
|
+
for cpu, version in attr.limited_api_wheels.items():
|
140
|
+
transitions.append({
|
141
|
+
"//command_line_option:cpu": cpu,
|
142
|
+
"//python:python_version": version,
|
143
|
+
"//python:limited_api": True,
|
144
|
+
})
|
145
|
+
|
146
|
+
for version in attr.full_api_versions:
|
147
|
+
for cpu in attr.full_api_cpus:
|
148
|
+
transitions.append({
|
149
|
+
"//command_line_option:cpu": cpu,
|
150
|
+
"//python:python_version": version,
|
151
|
+
"//python:limited_api": False,
|
152
|
+
})
|
153
|
+
|
154
|
+
return transitions
|
155
|
+
|
156
|
+
_py_dist_transition = transition(
|
157
|
+
implementation = _py_dist_transition_impl,
|
158
|
+
inputs = [],
|
159
|
+
outputs = [
|
160
|
+
"//command_line_option:cpu",
|
161
|
+
"//python:python_version",
|
162
|
+
"//python:limited_api",
|
163
|
+
],
|
164
|
+
)
|
165
|
+
|
166
|
+
def _py_dist_impl(ctx):
|
167
|
+
binary_files = [dep[DefaultInfo].files for dep in ctx.attr.binary_wheel]
|
168
|
+
pure_python_files = [ctx.attr.pure_python_wheel[DefaultInfo].files]
|
169
|
+
return [
|
170
|
+
DefaultInfo(files = depset(
|
171
|
+
transitive = binary_files + pure_python_files,
|
172
|
+
)),
|
173
|
+
]
|
174
|
+
|
175
|
+
py_dist = rule(
|
176
|
+
implementation = _py_dist_impl,
|
177
|
+
attrs = {
|
178
|
+
"binary_wheel": attr.label(
|
179
|
+
mandatory = True,
|
180
|
+
cfg = _py_dist_transition,
|
181
|
+
),
|
182
|
+
"pure_python_wheel": attr.label(mandatory = True),
|
183
|
+
"limited_api_wheels": attr.string_dict(),
|
184
|
+
"full_api_versions": attr.string_list(),
|
185
|
+
"full_api_cpus": attr.string_list(),
|
186
|
+
"_allowlist_function_transition": attr.label(
|
187
|
+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
|
188
|
+
),
|
189
|
+
},
|
190
|
+
)
|
@@ -0,0 +1,247 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
12
|
+
* * Neither the name of Google LLC nor the
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
14
|
+
* derived from this software without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include "python/extension_dict.h"
|
29
|
+
|
30
|
+
#include "python/message.h"
|
31
|
+
#include "python/protobuf.h"
|
32
|
+
|
33
|
+
// -----------------------------------------------------------------------------
|
34
|
+
// ExtensionDict
|
35
|
+
// -----------------------------------------------------------------------------
|
36
|
+
|
37
|
+
typedef struct {
|
38
|
+
PyObject_HEAD;
|
39
|
+
PyObject* msg; // Owning ref to our parent pessage.
|
40
|
+
} PyUpb_ExtensionDict;
|
41
|
+
|
42
|
+
PyObject* PyUpb_ExtensionDict_New(PyObject* msg) {
|
43
|
+
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
|
44
|
+
PyUpb_ExtensionDict* ext_dict =
|
45
|
+
(void*)PyType_GenericAlloc(state->extension_dict_type, 0);
|
46
|
+
ext_dict->msg = msg;
|
47
|
+
Py_INCREF(ext_dict->msg);
|
48
|
+
return &ext_dict->ob_base;
|
49
|
+
}
|
50
|
+
|
51
|
+
static PyObject* PyUpb_ExtensionDict_FindExtensionByName(PyObject* _self,
|
52
|
+
PyObject* key) {
|
53
|
+
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
|
54
|
+
const char* name = PyUpb_GetStrData(key);
|
55
|
+
const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(self->msg);
|
56
|
+
const upb_FileDef* file = upb_MessageDef_File(m);
|
57
|
+
const upb_DefPool* symtab = upb_FileDef_Pool(file);
|
58
|
+
const upb_FieldDef* ext = upb_DefPool_FindExtensionByName(symtab, name);
|
59
|
+
if (ext) {
|
60
|
+
return PyUpb_FieldDescriptor_Get(ext);
|
61
|
+
} else {
|
62
|
+
Py_RETURN_NONE;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
static PyObject* PyUpb_ExtensionDict_FindExtensionByNumber(PyObject* _self,
|
67
|
+
PyObject* arg) {
|
68
|
+
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
|
69
|
+
const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(self->msg);
|
70
|
+
const upb_MiniTable* l = upb_MessageDef_MiniTable(m);
|
71
|
+
const upb_FileDef* file = upb_MessageDef_File(m);
|
72
|
+
const upb_DefPool* symtab = upb_FileDef_Pool(file);
|
73
|
+
const upb_ExtensionRegistry* reg = upb_DefPool_ExtensionRegistry(symtab);
|
74
|
+
int64_t number = PyLong_AsLong(arg);
|
75
|
+
const upb_MiniTable_Extension* ext =
|
76
|
+
(upb_MiniTable_Extension*)_upb_extreg_get(reg, l, number);
|
77
|
+
if (ext) {
|
78
|
+
const upb_FieldDef* f = _upb_DefPool_FindExtensionByMiniTable(symtab, ext);
|
79
|
+
return PyUpb_FieldDescriptor_Get(f);
|
80
|
+
} else {
|
81
|
+
Py_RETURN_NONE;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
static void PyUpb_ExtensionDict_Dealloc(PyUpb_ExtensionDict* self) {
|
86
|
+
PyUpb_CMessage_ClearExtensionDict(self->msg);
|
87
|
+
Py_DECREF(self->msg);
|
88
|
+
PyUpb_Dealloc(self);
|
89
|
+
}
|
90
|
+
|
91
|
+
static PyObject* PyUpb_ExtensionDict_RichCompare(PyObject* _self,
|
92
|
+
PyObject* _other, int opid) {
|
93
|
+
// Only equality comparisons are implemented.
|
94
|
+
if (opid != Py_EQ && opid != Py_NE) {
|
95
|
+
Py_INCREF(Py_NotImplemented);
|
96
|
+
return Py_NotImplemented;
|
97
|
+
}
|
98
|
+
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
|
99
|
+
bool equals = false;
|
100
|
+
if (PyObject_TypeCheck(_other, Py_TYPE(_self))) {
|
101
|
+
PyUpb_ExtensionDict* other = (PyUpb_ExtensionDict*)_other;
|
102
|
+
equals = self->msg == other->msg;
|
103
|
+
}
|
104
|
+
bool ret = opid == Py_EQ ? equals : !equals;
|
105
|
+
return PyBool_FromLong(ret);
|
106
|
+
}
|
107
|
+
|
108
|
+
static int PyUpb_ExtensionDict_Contains(PyObject* _self, PyObject* key) {
|
109
|
+
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
|
110
|
+
const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
|
111
|
+
if (!f) return -1;
|
112
|
+
upb_Message* msg = PyUpb_CMessage_GetIfReified(self->msg);
|
113
|
+
if (!msg) return 0;
|
114
|
+
if (upb_FieldDef_IsRepeated(f)) {
|
115
|
+
upb_MessageValue val = upb_Message_Get(msg, f);
|
116
|
+
return upb_Array_Size(val.array_val) > 0;
|
117
|
+
} else {
|
118
|
+
return upb_Message_Has(msg, f);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
static Py_ssize_t PyUpb_ExtensionDict_Length(PyObject* _self) {
|
123
|
+
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
|
124
|
+
upb_Message* msg = PyUpb_CMessage_GetIfReified(self->msg);
|
125
|
+
return msg ? upb_Message_ExtensionCount(msg) : 0;
|
126
|
+
}
|
127
|
+
|
128
|
+
static PyObject* PyUpb_ExtensionDict_Subscript(PyObject* _self, PyObject* key) {
|
129
|
+
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
|
130
|
+
const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
|
131
|
+
if (!f) return NULL;
|
132
|
+
return PyUpb_CMessage_GetFieldValue(self->msg, f);
|
133
|
+
}
|
134
|
+
|
135
|
+
static int PyUpb_ExtensionDict_AssignSubscript(PyObject* _self, PyObject* key,
|
136
|
+
PyObject* val) {
|
137
|
+
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
|
138
|
+
const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
|
139
|
+
if (!f) return -1;
|
140
|
+
if (val) {
|
141
|
+
return PyUpb_CMessage_SetFieldValue(self->msg, f, val, PyExc_TypeError);
|
142
|
+
} else {
|
143
|
+
PyUpb_CMessage_DoClearField(self->msg, f);
|
144
|
+
return 0;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
static PyObject* PyUpb_ExtensionIterator_New(PyObject* _ext_dict);
|
149
|
+
|
150
|
+
static PyMethodDef PyUpb_ExtensionDict_Methods[] = {
|
151
|
+
{"_FindExtensionByName", PyUpb_ExtensionDict_FindExtensionByName, METH_O,
|
152
|
+
"Finds an extension by name."},
|
153
|
+
{"_FindExtensionByNumber", PyUpb_ExtensionDict_FindExtensionByNumber,
|
154
|
+
METH_O, "Finds an extension by number."},
|
155
|
+
{NULL, NULL},
|
156
|
+
};
|
157
|
+
|
158
|
+
static PyType_Slot PyUpb_ExtensionDict_Slots[] = {
|
159
|
+
{Py_tp_dealloc, PyUpb_ExtensionDict_Dealloc},
|
160
|
+
{Py_tp_methods, PyUpb_ExtensionDict_Methods},
|
161
|
+
//{Py_tp_getset, PyUpb_ExtensionDict_Getters},
|
162
|
+
//{Py_tp_hash, PyObject_HashNotImplemented},
|
163
|
+
{Py_tp_richcompare, PyUpb_ExtensionDict_RichCompare},
|
164
|
+
{Py_tp_iter, PyUpb_ExtensionIterator_New},
|
165
|
+
{Py_sq_contains, PyUpb_ExtensionDict_Contains},
|
166
|
+
{Py_sq_length, PyUpb_ExtensionDict_Length},
|
167
|
+
{Py_mp_length, PyUpb_ExtensionDict_Length},
|
168
|
+
{Py_mp_subscript, PyUpb_ExtensionDict_Subscript},
|
169
|
+
{Py_mp_ass_subscript, PyUpb_ExtensionDict_AssignSubscript},
|
170
|
+
{0, NULL}};
|
171
|
+
|
172
|
+
static PyType_Spec PyUpb_ExtensionDict_Spec = {
|
173
|
+
PYUPB_MODULE_NAME ".ExtensionDict", // tp_name
|
174
|
+
sizeof(PyUpb_ExtensionDict), // tp_basicsize
|
175
|
+
0, // tp_itemsize
|
176
|
+
Py_TPFLAGS_DEFAULT, // tp_flags
|
177
|
+
PyUpb_ExtensionDict_Slots,
|
178
|
+
};
|
179
|
+
|
180
|
+
// -----------------------------------------------------------------------------
|
181
|
+
// ExtensionIterator
|
182
|
+
// -----------------------------------------------------------------------------
|
183
|
+
|
184
|
+
typedef struct {
|
185
|
+
PyObject_HEAD;
|
186
|
+
PyObject* msg;
|
187
|
+
size_t iter;
|
188
|
+
} PyUpb_ExtensionIterator;
|
189
|
+
|
190
|
+
static PyObject* PyUpb_ExtensionIterator_New(PyObject* _ext_dict) {
|
191
|
+
PyUpb_ExtensionDict* ext_dict = (PyUpb_ExtensionDict*)_ext_dict;
|
192
|
+
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
|
193
|
+
PyUpb_ExtensionIterator* iter =
|
194
|
+
(void*)PyType_GenericAlloc(state->extension_iterator_type, 0);
|
195
|
+
if (!iter) return NULL;
|
196
|
+
iter->msg = ext_dict->msg;
|
197
|
+
iter->iter = kUpb_Message_Begin;
|
198
|
+
Py_INCREF(iter->msg);
|
199
|
+
return &iter->ob_base;
|
200
|
+
}
|
201
|
+
|
202
|
+
static void PyUpb_ExtensionIterator_Dealloc(void* _self) {
|
203
|
+
PyUpb_ExtensionIterator* self = (PyUpb_ExtensionIterator*)_self;
|
204
|
+
Py_DECREF(self->msg);
|
205
|
+
PyUpb_Dealloc(_self);
|
206
|
+
}
|
207
|
+
|
208
|
+
PyObject* PyUpb_ExtensionIterator_IterNext(PyObject* _self) {
|
209
|
+
PyUpb_ExtensionIterator* self = (PyUpb_ExtensionIterator*)_self;
|
210
|
+
upb_Message* msg = PyUpb_CMessage_GetIfReified(self->msg);
|
211
|
+
if (!msg) return NULL;
|
212
|
+
const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(self->msg);
|
213
|
+
const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
|
214
|
+
while (true) {
|
215
|
+
const upb_FieldDef* f;
|
216
|
+
upb_MessageValue val;
|
217
|
+
if (!upb_Message_Next(msg, m, symtab, &f, &val, &self->iter)) return NULL;
|
218
|
+
if (upb_FieldDef_IsExtension(f)) return PyUpb_FieldDescriptor_Get(f);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
static PyType_Slot PyUpb_ExtensionIterator_Slots[] = {
|
223
|
+
{Py_tp_dealloc, PyUpb_ExtensionIterator_Dealloc},
|
224
|
+
{Py_tp_iter, PyObject_SelfIter},
|
225
|
+
{Py_tp_iternext, PyUpb_ExtensionIterator_IterNext},
|
226
|
+
{0, NULL}};
|
227
|
+
|
228
|
+
static PyType_Spec PyUpb_ExtensionIterator_Spec = {
|
229
|
+
PYUPB_MODULE_NAME ".ExtensionIterator", // tp_name
|
230
|
+
sizeof(PyUpb_ExtensionIterator), // tp_basicsize
|
231
|
+
0, // tp_itemsize
|
232
|
+
Py_TPFLAGS_DEFAULT, // tp_flags
|
233
|
+
PyUpb_ExtensionIterator_Slots,
|
234
|
+
};
|
235
|
+
|
236
|
+
// -----------------------------------------------------------------------------
|
237
|
+
// Top Level
|
238
|
+
// -----------------------------------------------------------------------------
|
239
|
+
|
240
|
+
bool PyUpb_InitExtensionDict(PyObject* m) {
|
241
|
+
PyUpb_ModuleState* s = PyUpb_ModuleState_GetFromModule(m);
|
242
|
+
|
243
|
+
s->extension_dict_type = PyUpb_AddClass(m, &PyUpb_ExtensionDict_Spec);
|
244
|
+
s->extension_iterator_type = PyUpb_AddClass(m, &PyUpb_ExtensionIterator_Spec);
|
245
|
+
|
246
|
+
return s->extension_dict_type && s->extension_iterator_type;
|
247
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
12
|
+
* * Neither the name of Google LLC nor the
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
14
|
+
* derived from this software without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#ifndef PYUPB_EXTENSION_DICT_H__
|
29
|
+
#define PYUPB_EXTENSION_DICT_H__
|
30
|
+
|
31
|
+
#include <stdbool.h>
|
32
|
+
|
33
|
+
#include "python/python_api.h"
|
34
|
+
|
35
|
+
PyObject* PyUpb_ExtensionDict_New(PyObject* msg);
|
36
|
+
|
37
|
+
bool PyUpb_InitExtensionDict(PyObject* m);
|
38
|
+
|
39
|
+
#endif // PYUPB_EXTENSION_DICT_H__
|