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,394 @@
|
|
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/convert.h"
|
29
|
+
|
30
|
+
#include "python/message.h"
|
31
|
+
#include "python/protobuf.h"
|
32
|
+
#include "upb/reflection.h"
|
33
|
+
#include "upb/util/compare.h"
|
34
|
+
|
35
|
+
PyObject* PyUpb_UpbToPy(upb_MessageValue val, const upb_FieldDef* f,
|
36
|
+
PyObject* arena) {
|
37
|
+
switch (upb_FieldDef_CType(f)) {
|
38
|
+
case kUpb_CType_Enum:
|
39
|
+
case kUpb_CType_Int32:
|
40
|
+
return PyLong_FromLong(val.int32_val);
|
41
|
+
case kUpb_CType_Int64:
|
42
|
+
return PyLong_FromLongLong(val.int64_val);
|
43
|
+
case kUpb_CType_UInt32:
|
44
|
+
return PyLong_FromSize_t(val.uint32_val);
|
45
|
+
case kUpb_CType_UInt64:
|
46
|
+
return PyLong_FromUnsignedLongLong(val.uint64_val);
|
47
|
+
case kUpb_CType_Float:
|
48
|
+
return PyFloat_FromDouble(val.float_val);
|
49
|
+
case kUpb_CType_Double:
|
50
|
+
return PyFloat_FromDouble(val.double_val);
|
51
|
+
case kUpb_CType_Bool:
|
52
|
+
return PyBool_FromLong(val.bool_val);
|
53
|
+
case kUpb_CType_Bytes:
|
54
|
+
return PyBytes_FromStringAndSize(val.str_val.data, val.str_val.size);
|
55
|
+
case kUpb_CType_String: {
|
56
|
+
PyObject* ret =
|
57
|
+
PyUnicode_DecodeUTF8(val.str_val.data, val.str_val.size, NULL);
|
58
|
+
// If the string can't be decoded in UTF-8, just return a bytes object
|
59
|
+
// that contains the raw bytes. This can't happen if the value was
|
60
|
+
// assigned using the members of the Python message object, but can happen
|
61
|
+
// if the values were parsed from the wire (binary).
|
62
|
+
if (ret == NULL) {
|
63
|
+
PyErr_Clear();
|
64
|
+
ret = PyBytes_FromStringAndSize(val.str_val.data, val.str_val.size);
|
65
|
+
}
|
66
|
+
return ret;
|
67
|
+
}
|
68
|
+
case kUpb_CType_Message:
|
69
|
+
return PyUpb_CMessage_Get((upb_Message*)val.msg_val,
|
70
|
+
upb_FieldDef_MessageSubDef(f), arena);
|
71
|
+
default:
|
72
|
+
PyErr_Format(PyExc_SystemError,
|
73
|
+
"Getting a value from a field of unknown type %d",
|
74
|
+
upb_FieldDef_CType(f));
|
75
|
+
return NULL;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
static bool PyUpb_GetInt64(PyObject* obj, int64_t* val) {
|
80
|
+
// We require that the value is either an integer or has an __index__
|
81
|
+
// conversion.
|
82
|
+
obj = PyNumber_Index(obj);
|
83
|
+
if (!obj) return false;
|
84
|
+
// If the value is already a Python long, PyLong_AsLongLong() retrieves it.
|
85
|
+
// Otherwise is converts to integer using __int__.
|
86
|
+
*val = PyLong_AsLongLong(obj);
|
87
|
+
bool ok = true;
|
88
|
+
if (PyErr_Occurred()) {
|
89
|
+
assert(PyErr_ExceptionMatches(PyExc_OverflowError));
|
90
|
+
PyErr_Clear();
|
91
|
+
PyErr_Format(PyExc_ValueError, "Value out of range: %S", obj);
|
92
|
+
ok = false;
|
93
|
+
}
|
94
|
+
Py_DECREF(obj);
|
95
|
+
return ok;
|
96
|
+
}
|
97
|
+
|
98
|
+
static bool PyUpb_GetUint64(PyObject* obj, uint64_t* val) {
|
99
|
+
// We require that the value is either an integer or has an __index__
|
100
|
+
// conversion.
|
101
|
+
obj = PyNumber_Index(obj);
|
102
|
+
if (!obj) return false;
|
103
|
+
*val = PyLong_AsUnsignedLongLong(obj);
|
104
|
+
bool ok = true;
|
105
|
+
if (PyErr_Occurred()) {
|
106
|
+
assert(PyErr_ExceptionMatches(PyExc_OverflowError));
|
107
|
+
PyErr_Clear();
|
108
|
+
PyErr_Format(PyExc_ValueError, "Value out of range: %S", obj);
|
109
|
+
ok = false;
|
110
|
+
}
|
111
|
+
Py_DECREF(obj);
|
112
|
+
return ok;
|
113
|
+
}
|
114
|
+
|
115
|
+
static bool PyUpb_GetInt32(PyObject* obj, int32_t* val) {
|
116
|
+
int64_t i64;
|
117
|
+
if (!PyUpb_GetInt64(obj, &i64)) return false;
|
118
|
+
if (i64 < INT32_MIN || i64 > INT32_MAX) {
|
119
|
+
PyErr_Format(PyExc_ValueError, "Value out of range: %S", obj);
|
120
|
+
return false;
|
121
|
+
}
|
122
|
+
*val = i64;
|
123
|
+
return true;
|
124
|
+
}
|
125
|
+
|
126
|
+
static bool PyUpb_GetUint32(PyObject* obj, uint32_t* val) {
|
127
|
+
uint64_t u64;
|
128
|
+
if (!PyUpb_GetUint64(obj, &u64)) return false;
|
129
|
+
if (u64 > UINT32_MAX) {
|
130
|
+
PyErr_Format(PyExc_ValueError, "Value out of range: %S", obj);
|
131
|
+
return false;
|
132
|
+
}
|
133
|
+
*val = u64;
|
134
|
+
return true;
|
135
|
+
}
|
136
|
+
|
137
|
+
// If `arena` is specified, copies the string data into the given arena.
|
138
|
+
// Otherwise aliases the given data.
|
139
|
+
static upb_MessageValue PyUpb_MaybeCopyString(const char* ptr, size_t size,
|
140
|
+
upb_Arena* arena) {
|
141
|
+
upb_MessageValue ret;
|
142
|
+
ret.str_val.size = size;
|
143
|
+
if (arena) {
|
144
|
+
char* buf = upb_Arena_Malloc(arena, size);
|
145
|
+
memcpy(buf, ptr, size);
|
146
|
+
ret.str_val.data = buf;
|
147
|
+
} else {
|
148
|
+
ret.str_val.data = ptr;
|
149
|
+
}
|
150
|
+
return ret;
|
151
|
+
}
|
152
|
+
|
153
|
+
static bool PyUpb_PyToUpbEnum(PyObject* obj, const upb_EnumDef* e,
|
154
|
+
upb_MessageValue* val) {
|
155
|
+
if (PyUnicode_Check(obj)) {
|
156
|
+
Py_ssize_t size;
|
157
|
+
const char* name = PyUnicode_AsUTF8AndSize(obj, &size);
|
158
|
+
const upb_EnumValueDef* ev =
|
159
|
+
upb_EnumDef_FindValueByNameWithSize(e, name, size);
|
160
|
+
if (!ev) {
|
161
|
+
PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", name);
|
162
|
+
return false;
|
163
|
+
}
|
164
|
+
val->int32_val = upb_EnumValueDef_Number(ev);
|
165
|
+
return true;
|
166
|
+
} else {
|
167
|
+
int32_t i32;
|
168
|
+
if (!PyUpb_GetInt32(obj, &i32)) return false;
|
169
|
+
if (upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2 &&
|
170
|
+
!upb_EnumDef_CheckNumber(e, i32)) {
|
171
|
+
PyErr_Format(PyExc_ValueError, "invalid enumerator %d", (int)i32);
|
172
|
+
return false;
|
173
|
+
}
|
174
|
+
val->int32_val = i32;
|
175
|
+
return true;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
|
180
|
+
upb_Arena* arena) {
|
181
|
+
switch (upb_FieldDef_CType(f)) {
|
182
|
+
case kUpb_CType_Enum:
|
183
|
+
return PyUpb_PyToUpbEnum(obj, upb_FieldDef_EnumSubDef(f), val);
|
184
|
+
case kUpb_CType_Int32:
|
185
|
+
return PyUpb_GetInt32(obj, &val->int32_val);
|
186
|
+
case kUpb_CType_Int64:
|
187
|
+
return PyUpb_GetInt64(obj, &val->int64_val);
|
188
|
+
case kUpb_CType_UInt32:
|
189
|
+
return PyUpb_GetUint32(obj, &val->uint32_val);
|
190
|
+
case kUpb_CType_UInt64:
|
191
|
+
return PyUpb_GetUint64(obj, &val->uint64_val);
|
192
|
+
case kUpb_CType_Float:
|
193
|
+
val->float_val = PyFloat_AsDouble(obj);
|
194
|
+
return !PyErr_Occurred();
|
195
|
+
case kUpb_CType_Double:
|
196
|
+
val->double_val = PyFloat_AsDouble(obj);
|
197
|
+
return !PyErr_Occurred();
|
198
|
+
case kUpb_CType_Bool:
|
199
|
+
val->bool_val = PyLong_AsLong(obj);
|
200
|
+
return !PyErr_Occurred();
|
201
|
+
case kUpb_CType_Bytes: {
|
202
|
+
char* ptr;
|
203
|
+
Py_ssize_t size;
|
204
|
+
if (PyBytes_AsStringAndSize(obj, &ptr, &size) < 0) return false;
|
205
|
+
*val = PyUpb_MaybeCopyString(ptr, size, arena);
|
206
|
+
return true;
|
207
|
+
}
|
208
|
+
case kUpb_CType_String: {
|
209
|
+
Py_ssize_t size;
|
210
|
+
const char* ptr;
|
211
|
+
PyObject* unicode = NULL;
|
212
|
+
if (PyBytes_Check(obj)) {
|
213
|
+
unicode = obj = PyUnicode_FromEncodedObject(obj, "utf-8", NULL);
|
214
|
+
if (!obj) return false;
|
215
|
+
}
|
216
|
+
ptr = PyUnicode_AsUTF8AndSize(obj, &size);
|
217
|
+
if (PyErr_Occurred()) {
|
218
|
+
Py_XDECREF(unicode);
|
219
|
+
return false;
|
220
|
+
}
|
221
|
+
*val = PyUpb_MaybeCopyString(ptr, size, arena);
|
222
|
+
Py_XDECREF(unicode);
|
223
|
+
return true;
|
224
|
+
}
|
225
|
+
case kUpb_CType_Message:
|
226
|
+
PyErr_Format(PyExc_ValueError, "Message objects may not be assigned",
|
227
|
+
upb_FieldDef_CType(f));
|
228
|
+
return false;
|
229
|
+
default:
|
230
|
+
PyErr_Format(PyExc_SystemError,
|
231
|
+
"Getting a value from a field of unknown type %d",
|
232
|
+
upb_FieldDef_CType(f));
|
233
|
+
return false;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
bool PyUpb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
|
238
|
+
const upb_MessageDef* m);
|
239
|
+
|
240
|
+
// -----------------------------------------------------------------------------
|
241
|
+
// Equal
|
242
|
+
// -----------------------------------------------------------------------------
|
243
|
+
|
244
|
+
bool PyUpb_ValueEq(upb_MessageValue val1, upb_MessageValue val2,
|
245
|
+
const upb_FieldDef* f) {
|
246
|
+
switch (upb_FieldDef_CType(f)) {
|
247
|
+
case kUpb_CType_Bool:
|
248
|
+
return val1.bool_val == val2.bool_val;
|
249
|
+
case kUpb_CType_Int32:
|
250
|
+
case kUpb_CType_UInt32:
|
251
|
+
case kUpb_CType_Enum:
|
252
|
+
return val1.int32_val == val2.int32_val;
|
253
|
+
case kUpb_CType_Int64:
|
254
|
+
case kUpb_CType_UInt64:
|
255
|
+
return val1.int64_val == val2.int64_val;
|
256
|
+
case kUpb_CType_Float:
|
257
|
+
return val1.float_val == val2.float_val;
|
258
|
+
case kUpb_CType_Double:
|
259
|
+
return val1.double_val == val2.double_val;
|
260
|
+
case kUpb_CType_String:
|
261
|
+
case kUpb_CType_Bytes:
|
262
|
+
return val1.str_val.size == val2.str_val.size &&
|
263
|
+
memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) ==
|
264
|
+
0;
|
265
|
+
case kUpb_CType_Message:
|
266
|
+
return PyUpb_Message_IsEqual(val1.msg_val, val2.msg_val,
|
267
|
+
upb_FieldDef_MessageSubDef(f));
|
268
|
+
default:
|
269
|
+
return false;
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
bool PyUpb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
|
274
|
+
const upb_FieldDef* f) {
|
275
|
+
assert(upb_FieldDef_IsMap(f));
|
276
|
+
if (map1 == map2) return true;
|
277
|
+
|
278
|
+
size_t size1 = map1 ? upb_Map_Size(map1) : 0;
|
279
|
+
size_t size2 = map2 ? upb_Map_Size(map2) : 0;
|
280
|
+
if (size1 != size2) return false;
|
281
|
+
if (size1 == 0) return true;
|
282
|
+
|
283
|
+
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
|
284
|
+
const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
|
285
|
+
size_t iter = kUpb_Map_Begin;
|
286
|
+
|
287
|
+
while (upb_MapIterator_Next(map1, &iter)) {
|
288
|
+
upb_MessageValue key = upb_MapIterator_Key(map1, iter);
|
289
|
+
upb_MessageValue val1 = upb_MapIterator_Value(map1, iter);
|
290
|
+
upb_MessageValue val2;
|
291
|
+
if (!upb_Map_Get(map2, key, &val2)) return false;
|
292
|
+
if (!PyUpb_ValueEq(val1, val2, val_f)) return false;
|
293
|
+
}
|
294
|
+
|
295
|
+
return true;
|
296
|
+
}
|
297
|
+
|
298
|
+
static bool PyUpb_ArrayElem_IsEqual(const upb_Array* arr1,
|
299
|
+
const upb_Array* arr2, size_t i,
|
300
|
+
const upb_FieldDef* f) {
|
301
|
+
assert(i < upb_Array_Size(arr1));
|
302
|
+
assert(i < upb_Array_Size(arr2));
|
303
|
+
upb_MessageValue val1 = upb_Array_Get(arr1, i);
|
304
|
+
upb_MessageValue val2 = upb_Array_Get(arr2, i);
|
305
|
+
return PyUpb_ValueEq(val1, val2, f);
|
306
|
+
}
|
307
|
+
|
308
|
+
bool PyUpb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
|
309
|
+
const upb_FieldDef* f) {
|
310
|
+
assert(upb_FieldDef_IsRepeated(f) && !upb_FieldDef_IsMap(f));
|
311
|
+
if (arr1 == arr2) return true;
|
312
|
+
|
313
|
+
size_t n1 = arr1 ? upb_Array_Size(arr1) : 0;
|
314
|
+
size_t n2 = arr2 ? upb_Array_Size(arr2) : 0;
|
315
|
+
if (n1 != n2) return false;
|
316
|
+
|
317
|
+
// Half the length rounded down. Important: the empty list rounds to 0.
|
318
|
+
size_t half = n1 / 2;
|
319
|
+
|
320
|
+
// Search from the ends-in. We expect differences to more quickly manifest
|
321
|
+
// at the ends than in the middle. If the length is odd we will miss the
|
322
|
+
// middle element.
|
323
|
+
for (size_t i = 0; i < half; i++) {
|
324
|
+
if (!PyUpb_ArrayElem_IsEqual(arr1, arr2, i, f)) return false;
|
325
|
+
if (!PyUpb_ArrayElem_IsEqual(arr1, arr2, n1 - 1 - i, f)) return false;
|
326
|
+
}
|
327
|
+
|
328
|
+
// For an odd-lengthed list, pick up the middle element.
|
329
|
+
if (n1 & 1) {
|
330
|
+
if (!PyUpb_ArrayElem_IsEqual(arr1, arr2, half, f)) return false;
|
331
|
+
}
|
332
|
+
|
333
|
+
return true;
|
334
|
+
}
|
335
|
+
|
336
|
+
bool PyUpb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
|
337
|
+
const upb_MessageDef* m) {
|
338
|
+
if (msg1 == msg2) return true;
|
339
|
+
if (upb_Message_ExtensionCount(msg1) != upb_Message_ExtensionCount(msg2))
|
340
|
+
return false;
|
341
|
+
|
342
|
+
// Compare messages field-by-field. This is slightly tricky, because while
|
343
|
+
// we can iterate over normal fields in a predictable order, the extension
|
344
|
+
// order is unpredictable and may be different between msg1 and msg2.
|
345
|
+
// So we use the following strategy:
|
346
|
+
// 1. Iterate over all msg1 fields (including extensions).
|
347
|
+
// 2. For non-extension fields, we find the corresponding field by simply
|
348
|
+
// using upb_Message_Next(msg2). If the two messages have the same set
|
349
|
+
// of fields, this will yield the same field.
|
350
|
+
// 3. For extension fields, we have to actually search for the corresponding
|
351
|
+
// field, which we do with upb_Message_Get(msg2, ext_f1).
|
352
|
+
// 4. Once iteration over msg1 is complete, we call upb_Message_Next(msg2)
|
353
|
+
// one
|
354
|
+
// final time to verify that we have visited all of msg2's regular fields
|
355
|
+
// (we pass NULL for ext_dict so that iteration will *not* return
|
356
|
+
// extensions).
|
357
|
+
//
|
358
|
+
// We don't need to visit all of msg2's extensions, because we verified up
|
359
|
+
// front that both messages have the same number of extensions.
|
360
|
+
const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
|
361
|
+
const upb_FieldDef *f1, *f2;
|
362
|
+
upb_MessageValue val1, val2;
|
363
|
+
size_t iter1 = kUpb_Message_Begin;
|
364
|
+
size_t iter2 = kUpb_Message_Begin;
|
365
|
+
while (upb_Message_Next(msg1, m, symtab, &f1, &val1, &iter1)) {
|
366
|
+
if (upb_FieldDef_IsExtension(f1)) {
|
367
|
+
val2 = upb_Message_Get(msg2, f1);
|
368
|
+
} else {
|
369
|
+
if (!upb_Message_Next(msg2, m, NULL, &f2, &val2, &iter2) || f1 != f2) {
|
370
|
+
return false;
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
if (upb_FieldDef_IsMap(f1)) {
|
375
|
+
if (!PyUpb_Map_IsEqual(val1.map_val, val2.map_val, f1)) return false;
|
376
|
+
} else if (upb_FieldDef_IsRepeated(f1)) {
|
377
|
+
if (!PyUpb_Array_IsEqual(val1.array_val, val2.array_val, f1)) {
|
378
|
+
return false;
|
379
|
+
}
|
380
|
+
} else {
|
381
|
+
if (!PyUpb_ValueEq(val1, val2, f1)) return false;
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
if (upb_Message_Next(msg2, m, NULL, &f2, &val2, &iter2)) return false;
|
386
|
+
|
387
|
+
size_t usize1, usize2;
|
388
|
+
const char* uf1 = upb_Message_GetUnknown(msg1, &usize1);
|
389
|
+
const char* uf2 = upb_Message_GetUnknown(msg2, &usize2);
|
390
|
+
// 100 is arbitrary, we're trying to prevent stack overflow but it's not
|
391
|
+
// obvious how deep we should allow here.
|
392
|
+
return upb_Message_UnknownFieldsAreEqual(uf1, usize1, uf2, usize2, 100) ==
|
393
|
+
kUpb_UnknownCompareResult_Equal;
|
394
|
+
}
|
@@ -0,0 +1,63 @@
|
|
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_CONVERT_H__
|
29
|
+
#define PYUPB_CONVERT_H__
|
30
|
+
|
31
|
+
#include "protobuf.h"
|
32
|
+
#include "upb/def.h"
|
33
|
+
#include "upb/reflection.h"
|
34
|
+
|
35
|
+
// Converts `val` to a Python object according to the type information in `f`.
|
36
|
+
// Any newly-created Python objects that reference non-primitive data from `val`
|
37
|
+
// will take a reference on `arena`; the caller must ensure that `val` belongs
|
38
|
+
// to `arena`. If the conversion cannot be performed, returns NULL and sets a
|
39
|
+
// Python error.
|
40
|
+
PyObject* PyUpb_UpbToPy(upb_MessageValue val, const upb_FieldDef* f,
|
41
|
+
PyObject* arena);
|
42
|
+
|
43
|
+
// Converts `obj` to a upb_MessageValue `*val` according to the type information
|
44
|
+
// in `f`. If `arena` is provided, any string data will be copied into `arena`,
|
45
|
+
// otherwise the returned value will alias the Python-owned data (this can be
|
46
|
+
// useful for an ephemeral upb_MessageValue). If the conversion cannot be
|
47
|
+
// performed, returns false.
|
48
|
+
bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
|
49
|
+
upb_Arena* arena);
|
50
|
+
|
51
|
+
// Returns true if the given values (of type `f`) are equal.
|
52
|
+
bool PyUpb_ValueEq(upb_MessageValue val1, upb_MessageValue val2,
|
53
|
+
const upb_FieldDef* f);
|
54
|
+
|
55
|
+
// Returns true if the given messages (of type `m`) are equal.
|
56
|
+
bool PyUpb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
|
57
|
+
const upb_MessageDef* m);
|
58
|
+
|
59
|
+
// Returns true if the two arrays (with element type `f`) are equal.
|
60
|
+
bool PyUpb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
|
61
|
+
const upb_FieldDef* f);
|
62
|
+
|
63
|
+
#endif // PYUPB_CONVERT_H__
|