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,37 @@
|
|
1
|
+
|
2
|
+
# How to Contribute
|
3
|
+
|
4
|
+
We'd love to accept your patches and contributions to this project. There are
|
5
|
+
just a few small guidelines you need to follow.
|
6
|
+
|
7
|
+
## Get in touch
|
8
|
+
|
9
|
+
If your idea will take you more than, say, 30 minutes to
|
10
|
+
implement, please get in touch first via the issue tracker
|
11
|
+
to touch base about your plan. That will give an
|
12
|
+
opportunity for early feedback and help avoid wasting your
|
13
|
+
time.
|
14
|
+
|
15
|
+
## Contributor License Agreement
|
16
|
+
|
17
|
+
Contributions to this project must be accompanied by a Contributor License
|
18
|
+
Agreement. You (or your employer) retain the copyright to your contribution;
|
19
|
+
this simply gives us permission to use and redistribute your contributions as
|
20
|
+
part of the project. Head over to <https://cla.developers.google.com/> to see
|
21
|
+
your current agreements on file or to sign a new one.
|
22
|
+
|
23
|
+
You generally only need to submit a CLA once, so if you've already submitted one
|
24
|
+
(even if it was for a different project), you probably don't need to do it
|
25
|
+
again.
|
26
|
+
|
27
|
+
## Code Reviews
|
28
|
+
|
29
|
+
All submissions, including submissions by project members, require review. We
|
30
|
+
use GitHub pull requests for this purpose. Consult
|
31
|
+
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
|
32
|
+
information on using pull requests.
|
33
|
+
|
34
|
+
## Community Guidelines
|
35
|
+
|
36
|
+
This project follows [Google's Open Source Community
|
37
|
+
Guidelines](https://opensource.google/conduct/).
|
@@ -0,0 +1,201 @@
|
|
1
|
+
|
2
|
+
# upb Design
|
3
|
+
|
4
|
+
upb aims to be a minimal C protobuf kernel. It has a C API, but its primary
|
5
|
+
goal is to be the core runtime for a higher-level API.
|
6
|
+
|
7
|
+
## Design goals
|
8
|
+
|
9
|
+
- Full protobuf conformance
|
10
|
+
- Small code size
|
11
|
+
- Fast performance (without compromising code size)
|
12
|
+
- Easy to wrap in language runtimes
|
13
|
+
- Easy to adapt to different memory management schemes (refcounting, GC, etc)
|
14
|
+
|
15
|
+
## Design parameters
|
16
|
+
|
17
|
+
- C99
|
18
|
+
- 32 or 64-bit CPU (assumes 4 or 8 byte pointers)
|
19
|
+
- Uses pointer tagging, but avoids other implementation-defined behavior
|
20
|
+
- Aims to never invoke undefined behavior (tests with ASAN, UBSAN, etc)
|
21
|
+
- No global state, fully re-entrant
|
22
|
+
|
23
|
+
|
24
|
+
## Overall Structure
|
25
|
+
|
26
|
+
The upb library is divided into two main parts:
|
27
|
+
|
28
|
+
- A core message representation, which supports binary format parsing
|
29
|
+
and serialization.
|
30
|
+
- `upb/upb.h`: arena allocator (`upb_arena`)
|
31
|
+
- `upb/msg_internal.h`: core message representation and parse tables
|
32
|
+
- `upb/msg.h`: accessing metadata common to all messages, like unknown fields
|
33
|
+
- `upb/decode.h`: binary format parsing
|
34
|
+
- `upb/encode.h`: binary format serialization
|
35
|
+
- `upb/table_internal.h`: hash table (used for maps)
|
36
|
+
- `upbc/protoc-gen-upbc.cc`: compiler that generates `.upb.h`/`.upb.c` APIs for
|
37
|
+
accessing messages without reflection.
|
38
|
+
- A reflection add-on library that supports JSON and text format.
|
39
|
+
- `upb/def.h`: schema representation and loading from descriptors
|
40
|
+
- `upb/reflection.h`: reflective access to message data.
|
41
|
+
- `upb/json_encode.h`: JSON encoding
|
42
|
+
- `upb/json_decode.h`: JSON decoding
|
43
|
+
- `upb/text_encode.h`: text format encoding
|
44
|
+
- `upbc/protoc-gen-upbdefs.cc`: compiler that generates `.upbdefs.h`/`.upbdefs.c`
|
45
|
+
APIs for loading reflection.
|
46
|
+
|
47
|
+
## Core Message Representation
|
48
|
+
|
49
|
+
The representation for each message consists of:
|
50
|
+
- One pointer (`upb_msg_internaldata*`) for unknown fields and extensions. This
|
51
|
+
pointer is `NULL` when no unknown fields or extensions are present.
|
52
|
+
- Hasbits for any optional/required fields.
|
53
|
+
- Case integers for each oneof.
|
54
|
+
- Data for each field.
|
55
|
+
|
56
|
+
For example, a layout for a message with two `optional int32` fields would end
|
57
|
+
up looking something like this:
|
58
|
+
|
59
|
+
```c
|
60
|
+
// For illustration only, upb does not actually generate structs.
|
61
|
+
typedef struct {
|
62
|
+
upb_msg_internaldata* internal; // Unknown fields and extensions.
|
63
|
+
uint32_t hasbits; // We are only using two hasbits.
|
64
|
+
int32_t field1;
|
65
|
+
int32_t field2;
|
66
|
+
} package_name_MessageName;
|
67
|
+
```
|
68
|
+
|
69
|
+
Note in particular that messages do *not* have:
|
70
|
+
- A pointer to reflection or a parse table (upb messages are not self-describing).
|
71
|
+
- A pointer to an arena (the arena must be explicitly passed into any function that
|
72
|
+
allocates).
|
73
|
+
|
74
|
+
The upb compiler computes a layout for each message, and determines the offset for
|
75
|
+
each field using normal alignment rules (each data member must be aligned to a
|
76
|
+
multiple of its size). This layout is then embedded into the generated `.upb.h`
|
77
|
+
and `.upb.c` headers in two different forms. First as inline accessors that expect
|
78
|
+
the data at a given offset:
|
79
|
+
|
80
|
+
```c
|
81
|
+
// Example of a generated accessor, from foo.upb.h
|
82
|
+
UPB_INLINE int32_t package_name_MessageName_field1(
|
83
|
+
const upb_test_MessageName *msg) {
|
84
|
+
return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t);
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
Secondly, the layout is emitted as a table which is used by the parser and serializer.
|
89
|
+
We call these tables "mini-tables" to distinguish them from the larger and more
|
90
|
+
optimized "fast tables" used in `upb/decode_fast.c` (an experimental parser that is
|
91
|
+
2-3x the speed of the main parser, though the main parser is already quite fast).
|
92
|
+
|
93
|
+
```c
|
94
|
+
// Definition of mini-table structure, from upb/msg_internal.h
|
95
|
+
typedef struct {
|
96
|
+
uint32_t number;
|
97
|
+
uint16_t offset;
|
98
|
+
int16_t presence; /* If >0, hasbit_index. If <0, ~oneof_index. */
|
99
|
+
uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */
|
100
|
+
uint8_t descriptortype;
|
101
|
+
int8_t mode; /* upb_fieldmode, with flags from upb_labelflags */
|
102
|
+
} upb_msglayout_field;
|
103
|
+
|
104
|
+
typedef enum {
|
105
|
+
_UPB_MODE_MAP = 0,
|
106
|
+
_UPB_MODE_ARRAY = 1,
|
107
|
+
_UPB_MODE_SCALAR = 2,
|
108
|
+
} upb_fieldmode;
|
109
|
+
|
110
|
+
typedef struct {
|
111
|
+
const struct upb_msglayout *const* submsgs;
|
112
|
+
const upb_msglayout_field *fields;
|
113
|
+
uint16_t size;
|
114
|
+
uint16_t field_count;
|
115
|
+
bool extendable;
|
116
|
+
uint8_t dense_below;
|
117
|
+
uint8_t table_mask;
|
118
|
+
} upb_msglayout;
|
119
|
+
|
120
|
+
// Example of a generated mini-table, from foo.upb.c
|
121
|
+
static const upb_msglayout_field upb_test_MessageName__fields[2] = {
|
122
|
+
{1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR},
|
123
|
+
{2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR},
|
124
|
+
};
|
125
|
+
|
126
|
+
const upb_msglayout upb_test_MessageName_msginit = {
|
127
|
+
NULL,
|
128
|
+
&upb_test_MessageName__fields[0],
|
129
|
+
UPB_SIZE(16, 16), 2, false, 2, 255,
|
130
|
+
};
|
131
|
+
```
|
132
|
+
|
133
|
+
The upb compiler computes separate layouts for 32 and 64 bit modes, since the
|
134
|
+
pointer size will be 4 or 8 bytes respectively. The upb compiler embeds both
|
135
|
+
sizes into the source code, using a `UPB_SIZE(size32, size64)` macro that can
|
136
|
+
choose the appropriate size at build time based on the size of `UINTPTR_MAX`.
|
137
|
+
|
138
|
+
Note that `.upb.c` files contain data tables only. There is no "generated code"
|
139
|
+
except for the inline accessors in the `.upb.h` files: the entire footprint
|
140
|
+
of `.upb.c` files is in `.rodata`, none in `.text` or `.data`.
|
141
|
+
|
142
|
+
## Memory Management Model
|
143
|
+
|
144
|
+
All memory management in upb is built around arenas. A message is never
|
145
|
+
considered to "own" the strings or sub-messages contained within it. Instead a
|
146
|
+
message and all of its sub-messages/strings/etc. are all owned by an arena and
|
147
|
+
are freed when the arena is freed. An entire message tree will probably be
|
148
|
+
owned by a single arena, but this is not required or enforced. As far as upb is
|
149
|
+
concerned, it is up to the client how to partition its arenas. upb only requires
|
150
|
+
that when you ask it to serialize a message, that all reachable messages are
|
151
|
+
still alive.
|
152
|
+
|
153
|
+
The arena supports both a user-supplied initial block and a custom allocation
|
154
|
+
callback, so there is a lot of flexibility in memory allocation strategy. The
|
155
|
+
allocation callback can even be `NULL` for heap-free operation. The main
|
156
|
+
constraint of the arena is that all of the memory in each arena must be freed
|
157
|
+
together.
|
158
|
+
|
159
|
+
`upb_arena` supports a novel operation called "fuse". When two arenas are fused
|
160
|
+
together, their lifetimes are irreversibly joined, such that none of the arena
|
161
|
+
blocks in either arena will be freed until *both* arenas are freed with
|
162
|
+
`upb_arena_free()`. This is useful when joining two messages from separate
|
163
|
+
arenas (making one a sub-message of the other). Fuse is a very cheap
|
164
|
+
operation, and an unlimited number of arenas can be fused together efficiently.
|
165
|
+
|
166
|
+
## Reflection and Descriptors
|
167
|
+
|
168
|
+
upb offers a fully-featured reflection library. There are two main ways of
|
169
|
+
using reflection:
|
170
|
+
|
171
|
+
1. You can load descriptors from strings using `upb_symtab_addfile()`.
|
172
|
+
The upb runtime will dynamically create mini-tables like what the upb compiler
|
173
|
+
would have created if you had compiled this type into a `.upb.c` file.
|
174
|
+
2. You can load descriptors using generated `.upbdefs.h` interfaces.
|
175
|
+
This will load reflection that references the corresponding `.upb.c`
|
176
|
+
mini-tables instead of building a new mini-table on the fly. This lets
|
177
|
+
you reflect on generated types that are linked into your program.
|
178
|
+
|
179
|
+
upb's design for descriptors is similar to protobuf C++ in many ways, with
|
180
|
+
the following correspondences:
|
181
|
+
|
182
|
+
| C++ Type | upb type |
|
183
|
+
| ---------| ---------|
|
184
|
+
| `google::protobuf::DescriptorPool` | `upb_symtab`
|
185
|
+
| `google::protobuf::Descriptor` | `upb_msgdef`
|
186
|
+
| `google::protobuf::FieldDescriptor` | `upb_fielddef`
|
187
|
+
| `google::protobuf::OneofDescriptor` | `upb_oneofdef`
|
188
|
+
| `google::protobuf::EnumDescriptor` | `upb_enumdef`
|
189
|
+
| `google::protobuf::FileDescriptor` | `upb_filedef`
|
190
|
+
| `google::protobuf::ServiceDescriptor` | `upb_servicedef`
|
191
|
+
| `google::protobuf::MethodDescriptor` | `upb_methoddef`
|
192
|
+
|
193
|
+
Like in C++ descriptors (defs) are created by loading a
|
194
|
+
`google_protobuf_FileDescriptorProto` into a `upb_symtab`. This creates and
|
195
|
+
links all of the def objects corresponding to that `.proto` file, and inserts
|
196
|
+
the names into a symbol table so they can be looked up by name.
|
197
|
+
|
198
|
+
Once you have loaded some descriptors into a `upb_symtab`, you can create and
|
199
|
+
manipulate messages using the interfaces defined in `upb/reflection.h`. If your
|
200
|
+
descriptors are linked to your generated layouts using option (2) above, you can
|
201
|
+
safely access the same messages using both reflection and generated interfaces.
|
@@ -0,0 +1,26 @@
|
|
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
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of Google LLC nor the names of any other
|
14
|
+
contributors may be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
18
|
+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
19
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
20
|
+
EVENT SHALL GOOGLE LLC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
23
|
+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
24
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
+
POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
# μpb: small, fast C protos
|
3
|
+
|
4
|
+
μpb (often written 'upb') is a small
|
5
|
+
[protobuf](https://github.com/protocolbuffers/protobuf) implementation written
|
6
|
+
in C.
|
7
|
+
|
8
|
+
upb is the core runtime for protobuf languages extensions in
|
9
|
+
[Ruby](https://github.com/protocolbuffers/protobuf/tree/master/ruby),
|
10
|
+
[PHP](https://github.com/protocolbuffers/protobuf/tree/master/php), and (soon)
|
11
|
+
Python.
|
12
|
+
|
13
|
+
While upb offers a C API, the C API & ABI **are not stable**. For this reason,
|
14
|
+
upb is not generally offered as a C library for direct consumption, and there
|
15
|
+
are no releases.
|
16
|
+
|
17
|
+
## Features
|
18
|
+
|
19
|
+
upb has comparable speed to protobuf C++, but is an order of magnitude smaller
|
20
|
+
in code size.
|
21
|
+
|
22
|
+
Like the main protobuf implementation in C++, it supports:
|
23
|
+
|
24
|
+
- a generated API (in C)
|
25
|
+
- reflection
|
26
|
+
- binary & JSON wire formats
|
27
|
+
- text format serialization
|
28
|
+
- all standard features of protobufs (oneofs, maps, unknown fields, extensions,
|
29
|
+
etc.)
|
30
|
+
- full conformance with the protobuf conformance tests
|
31
|
+
|
32
|
+
upb also supports some features that C++ does not:
|
33
|
+
|
34
|
+
- **optional reflection:** generated messages are agnostic to whether
|
35
|
+
reflection will be linked in or not.
|
36
|
+
- **no global state:** no pre-main registration or other global state.
|
37
|
+
- **fast reflection-based parsing:** messages loaded at runtime parse
|
38
|
+
just as fast as compiled-in messages.
|
39
|
+
|
40
|
+
However there are a few features it does not support:
|
41
|
+
|
42
|
+
- text format parsing
|
43
|
+
- deep descriptor verification: upb's descriptor validation is not as exhaustive
|
44
|
+
as `protoc`.
|
45
|
+
|
46
|
+
## Install
|
47
|
+
|
48
|
+
For Ruby, use [RubyGems](https://rubygems.org/gems/google-protobuf):
|
49
|
+
|
50
|
+
```
|
51
|
+
$ gem install google-protobuf
|
52
|
+
```
|
53
|
+
|
54
|
+
For PHP, use [PECL](https://pecl.php.net/package/protobuf):
|
55
|
+
|
56
|
+
```
|
57
|
+
$ sudo pecl install protobuf
|
58
|
+
```
|
59
|
+
|
60
|
+
Alternatively, you can build and install upb using
|
61
|
+
[vcpkg](https://github.com/microsoft/vcpkg/) dependency manager:
|
62
|
+
|
63
|
+
git clone https://github.com/Microsoft/vcpkg.git
|
64
|
+
cd vcpkg
|
65
|
+
./bootstrap-vcpkg.sh
|
66
|
+
./vcpkg integrate install
|
67
|
+
./vcpkg install upb
|
68
|
+
|
69
|
+
The upb port in vcpkg is kept up to date by microsoft team members and community
|
70
|
+
contributors.
|
71
|
+
|
72
|
+
If the version is out of date, please
|
73
|
+
[create an issue or pull request](https://github.com/Microsoft/vcpkg) on the
|
74
|
+
vcpkg repository.
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Please see [CONTRIBUTING.md](CONTRIBUTING.md).
|
@@ -0,0 +1,58 @@
|
|
1
|
+
workspace(name = "upb")
|
2
|
+
|
3
|
+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
4
|
+
load("//bazel:workspace_deps.bzl", "upb_deps")
|
5
|
+
|
6
|
+
upb_deps()
|
7
|
+
register_toolchains("@system_python//:python_toolchain")
|
8
|
+
|
9
|
+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
|
10
|
+
protobuf_deps()
|
11
|
+
|
12
|
+
http_archive(
|
13
|
+
name = "lua",
|
14
|
+
build_file = "//bazel:lua.BUILD",
|
15
|
+
sha256 = "b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b",
|
16
|
+
strip_prefix = "lua-5.2.4",
|
17
|
+
urls = [
|
18
|
+
"https://mirror.bazel.build/www.lua.org/ftp/lua-5.2.4.tar.gz",
|
19
|
+
"https://www.lua.org/ftp/lua-5.2.4.tar.gz",
|
20
|
+
],
|
21
|
+
)
|
22
|
+
|
23
|
+
http_archive(
|
24
|
+
name = "com_google_googletest",
|
25
|
+
urls = ["https://github.com/google/googletest/archive/b6cd405286ed8635ece71c72f118e659f4ade3fb.zip"], # 2019-01-07
|
26
|
+
strip_prefix = "googletest-b6cd405286ed8635ece71c72f118e659f4ade3fb",
|
27
|
+
sha256 = "ff7a82736e158c077e76188232eac77913a15dac0b22508c390ab3f88e6d6d86",
|
28
|
+
)
|
29
|
+
|
30
|
+
http_archive(
|
31
|
+
name = "com_github_google_benchmark",
|
32
|
+
urls = ["https://github.com/google/benchmark/archive/0baacde3618ca617da95375e0af13ce1baadea47.zip"],
|
33
|
+
strip_prefix = "benchmark-0baacde3618ca617da95375e0af13ce1baadea47",
|
34
|
+
sha256 = "62e2f2e6d8a744d67e4bbc212fcfd06647080de4253c97ad5c6749e09faf2cb0",
|
35
|
+
)
|
36
|
+
|
37
|
+
http_archive(
|
38
|
+
name = "com_google_googleapis",
|
39
|
+
urls = ["https://github.com/googleapis/googleapis/archive/refs/heads/master.zip"],
|
40
|
+
build_file = "//benchmarks:BUILD.googleapis",
|
41
|
+
strip_prefix = "googleapis-master",
|
42
|
+
patch_cmds = ["find google -type f -name BUILD.bazel -delete"],
|
43
|
+
)
|
44
|
+
|
45
|
+
http_archive(
|
46
|
+
name = "rules_fuzzing",
|
47
|
+
sha256 = "23bb074064c6f488d12044934ab1b0631e8e6898d5cf2f6bde087adb01111573",
|
48
|
+
strip_prefix = "rules_fuzzing-0.3.1",
|
49
|
+
urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.3.1.zip"],
|
50
|
+
)
|
51
|
+
|
52
|
+
load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
|
53
|
+
|
54
|
+
rules_fuzzing_dependencies()
|
55
|
+
|
56
|
+
load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init")
|
57
|
+
|
58
|
+
rules_fuzzing_init()
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright (c) 2009-2021, 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_skylib//:bzl_library.bzl", "bzl_library")
|
27
|
+
|
28
|
+
licenses(["notice"])
|
29
|
+
|
30
|
+
py_binary(
|
31
|
+
name = "amalgamate",
|
32
|
+
srcs = ["amalgamate.py"],
|
33
|
+
visibility = ["//:__pkg__"],
|
34
|
+
)
|
35
|
+
|
36
|
+
# py_proto_library() is private rule, only intended for internal use by upb.
|
37
|
+
# Hopefully py_proto_library() will eventually be availble in rules_proto or
|
38
|
+
# another upstream package.
|
39
|
+
bzl_library(
|
40
|
+
name = "py_proto_library_bzl",
|
41
|
+
srcs = ["py_proto_library.bzl"],
|
42
|
+
)
|
43
|
+
|
44
|
+
bzl_library(
|
45
|
+
name = "upb_proto_library_bzl",
|
46
|
+
srcs = ["upb_proto_library.bzl"],
|
47
|
+
visibility = ["//visibility:public"],
|
48
|
+
deps = [
|
49
|
+
"@bazel_skylib//lib:paths",
|
50
|
+
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
|
51
|
+
"@rules_proto//proto:defs",
|
52
|
+
],
|
53
|
+
)
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009-2021, Google LLC
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer in the
|
12
|
+
# documentation and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of Google LLC nor the
|
14
|
+
# names of its contributors may be used to endorse or promote products
|
15
|
+
# derived from this software without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
|
21
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
import sys
|
29
|
+
import re
|
30
|
+
import os
|
31
|
+
|
32
|
+
INCLUDE_RE = re.compile('^#include "([^"]*)"$')
|
33
|
+
|
34
|
+
def parse_include(line):
|
35
|
+
match = INCLUDE_RE.match(line)
|
36
|
+
return match.groups()[0] if match else None
|
37
|
+
|
38
|
+
class Amalgamator:
|
39
|
+
def __init__(self, output_path, prefix):
|
40
|
+
self.include_paths = ["."]
|
41
|
+
self.included = set(["upb/port_def.inc", "upb/port_undef.inc"])
|
42
|
+
self.output_h = open(output_path + prefix + "upb.h", "w")
|
43
|
+
self.output_c = open(output_path + prefix + "upb.c", "w")
|
44
|
+
|
45
|
+
self.output_c.write("/* Amalgamated source file */\n")
|
46
|
+
self.output_c.write('#include "%supb.h"\n' % (prefix))
|
47
|
+
if prefix == "ruby-":
|
48
|
+
self.output_h.write("// Ruby is still using proto3 enum semantics for proto2\n")
|
49
|
+
self.output_h.write("#define UPB_DISABLE_PROTO2_ENUM_CHECKING\n")
|
50
|
+
self.output_c.write(open("upb/port_def.inc").read())
|
51
|
+
|
52
|
+
self.output_h.write("/* Amalgamated source file */\n")
|
53
|
+
self.output_h.write(open("upb/port_def.inc").read())
|
54
|
+
|
55
|
+
def add_include_path(self, path):
|
56
|
+
self.include_paths.append(path)
|
57
|
+
|
58
|
+
def finish(self):
|
59
|
+
self._add_header("upb/port_undef.inc")
|
60
|
+
self.add_src("upb/port_undef.inc")
|
61
|
+
|
62
|
+
def _process_file(self, infile_name, outfile):
|
63
|
+
file = None
|
64
|
+
for path in self.include_paths:
|
65
|
+
try:
|
66
|
+
full_path = os.path.join(path, infile_name)
|
67
|
+
file = open(full_path)
|
68
|
+
break
|
69
|
+
except IOError:
|
70
|
+
pass
|
71
|
+
if not file:
|
72
|
+
raise RuntimeError("Couldn't open file " + infile_name)
|
73
|
+
|
74
|
+
lines = file.readlines()
|
75
|
+
|
76
|
+
has_copyright = lines[1].startswith(" * Copyright")
|
77
|
+
if has_copyright:
|
78
|
+
while not lines[0].startswith(" */"):
|
79
|
+
lines.pop(0)
|
80
|
+
lines.pop(0)
|
81
|
+
|
82
|
+
lines.insert(0, "\n/** " + infile_name + " " + ("*" * 60) +"/");
|
83
|
+
|
84
|
+
for line in lines:
|
85
|
+
if not self._process_include(line, outfile):
|
86
|
+
outfile.write(line)
|
87
|
+
|
88
|
+
def _process_include(self, line, outfile):
|
89
|
+
include = parse_include(line)
|
90
|
+
if not include:
|
91
|
+
return False
|
92
|
+
if not (include.startswith("upb") or include.startswith("google")):
|
93
|
+
return False
|
94
|
+
if include.endswith("hpp"):
|
95
|
+
# Skip, we don't support the amalgamation from C++.
|
96
|
+
return True
|
97
|
+
else:
|
98
|
+
# Include this upb header inline.
|
99
|
+
if include not in self.included:
|
100
|
+
self.included.add(include)
|
101
|
+
self._add_header(include)
|
102
|
+
return True
|
103
|
+
|
104
|
+
def _add_header(self, filename):
|
105
|
+
self._process_file(filename, self.output_h)
|
106
|
+
|
107
|
+
def add_src(self, filename):
|
108
|
+
self._process_file(filename, self.output_c)
|
109
|
+
|
110
|
+
# ---- main ----
|
111
|
+
|
112
|
+
output_path = sys.argv[1]
|
113
|
+
prefix = sys.argv[2]
|
114
|
+
amalgamator = Amalgamator(output_path, prefix)
|
115
|
+
files = []
|
116
|
+
|
117
|
+
for arg in sys.argv[3:]:
|
118
|
+
arg = arg.strip()
|
119
|
+
if arg.startswith("-I"):
|
120
|
+
amalgamator.add_include_path(arg[2:])
|
121
|
+
elif arg.endswith(".h") or arg.endswith(".inc"):
|
122
|
+
pass
|
123
|
+
else:
|
124
|
+
files.append(arg)
|
125
|
+
|
126
|
+
for filename in files:
|
127
|
+
amalgamator.add_src(filename)
|
128
|
+
|
129
|
+
amalgamator.finish()
|