ruby_memprofiler_pprof 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +7 -0
  2. data/ext/ruby_memprofiler_pprof/backtrace.c +429 -0
  3. data/ext/ruby_memprofiler_pprof/collector.c +1055 -0
  4. data/ext/ruby_memprofiler_pprof/compat.c +182 -0
  5. data/ext/ruby_memprofiler_pprof/extconf.rb +72 -0
  6. data/ext/ruby_memprofiler_pprof/pprof.upb.c +170 -0
  7. data/ext/ruby_memprofiler_pprof/pprof.upb.h +848 -0
  8. data/ext/ruby_memprofiler_pprof/pprof_out.c +285 -0
  9. data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.c +11 -0
  10. data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.h +301 -0
  11. data/ext/ruby_memprofiler_pprof/strtab.c +391 -0
  12. data/ext/ruby_memprofiler_pprof/vendor/upb/BUILD +719 -0
  13. data/ext/ruby_memprofiler_pprof/vendor/upb/CONTRIBUTING.md +37 -0
  14. data/ext/ruby_memprofiler_pprof/vendor/upb/DESIGN.md +201 -0
  15. data/ext/ruby_memprofiler_pprof/vendor/upb/LICENSE +26 -0
  16. data/ext/ruby_memprofiler_pprof/vendor/upb/README.md +78 -0
  17. data/ext/ruby_memprofiler_pprof/vendor/upb/WORKSPACE +58 -0
  18. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/BUILD +53 -0
  19. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/amalgamate.py +129 -0
  20. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/build_defs.bzl +160 -0
  21. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/lua.BUILD +127 -0
  22. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/protobuf.patch +54 -0
  23. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/py_proto_library.bzl +137 -0
  24. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/python_downloads.bzl +84 -0
  25. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/system_python.bzl +101 -0
  26. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/upb_proto_library.bzl +388 -0
  27. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/workspace_deps.bzl +89 -0
  28. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD +252 -0
  29. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD.googleapis +54 -0
  30. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/benchmark.cc +333 -0
  31. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/build_defs.bzl +88 -0
  32. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/compare.py +118 -0
  33. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor.proto +888 -0
  34. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor_sv.proto +890 -0
  35. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/empty.proto +6 -0
  36. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_protobuf_binary_cc.py +64 -0
  37. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_synthetic_protos.py +118 -0
  38. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_upb_binary_c.py +65 -0
  39. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/BUILD.bazel +102 -0
  40. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/README.md +23 -0
  41. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/build_defs.bzl +73 -0
  42. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/make_cmakelists.py +340 -0
  43. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test.py +57 -0
  44. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test_lib.py +186 -0
  45. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/render.py +43 -0
  46. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/style-guide.md +65 -0
  47. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/vs-cpp-protos.md +255 -0
  48. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/wrapping-upb.md +444 -0
  49. data/ext/ruby_memprofiler_pprof/vendor/upb/python/BUILD +216 -0
  50. data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.c +394 -0
  51. data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.h +63 -0
  52. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.c +1694 -0
  53. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.h +80 -0
  54. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.c +704 -0
  55. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.h +114 -0
  56. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.c +650 -0
  57. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.h +48 -0
  58. data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/BUILD.bazel +193 -0
  59. data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/dist.bzl +190 -0
  60. data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.c +247 -0
  61. data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.h +39 -0
  62. data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.c +522 -0
  63. data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.h +66 -0
  64. data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.c +1909 -0
  65. data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.h +101 -0
  66. data/ext/ruby_memprofiler_pprof/vendor/upb/python/minimal_test.py +183 -0
  67. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/BUILD +70 -0
  68. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/README.md +11 -0
  69. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_database_test_wrapper.py +30 -0
  70. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_pool_test_wrapper.py +45 -0
  71. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_test_wrapper.py +46 -0
  72. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/generator_test_wrapper.py +30 -0
  73. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/json_format_test_wrapper.py +30 -0
  74. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/keywords_test_wrapper.py +30 -0
  75. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_factory_test_wrapper.py +37 -0
  76. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_test_wrapper.py +52 -0
  77. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/proto_builder_test_wrapper.py +32 -0
  78. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/pyproto_test_wrapper.bzl +36 -0
  79. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/reflection_test_wrapper.py +45 -0
  80. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/service_reflection_test_wrapper.py +30 -0
  81. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/symbol_database_test_wrapper.py +30 -0
  82. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_encoding_test_wrapper.py +30 -0
  83. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_format_test_wrapper.py +30 -0
  84. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/unknown_fields_test_wrapper.py +30 -0
  85. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/well_known_types_test_wrapper.py +36 -0
  86. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/wire_format_test_wrapper.py +30 -0
  87. data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.c +350 -0
  88. data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.h +230 -0
  89. data/ext/ruby_memprofiler_pprof/vendor/upb/python/py_extension.bzl +55 -0
  90. data/ext/ruby_memprofiler_pprof/vendor/upb/python/python_api.h +61 -0
  91. data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.c +828 -0
  92. data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.h +69 -0
  93. data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.c +404 -0
  94. data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.h +39 -0
  95. data/ext/ruby_memprofiler_pprof/vendor/upb/python/version_script.lds +6 -0
  96. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/LICENSE +32 -0
  97. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/README.google +9 -0
  98. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/console.lua +156 -0
  99. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/lunit.lua +725 -0
  100. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/BUILD +19 -0
  101. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/LICENSE +21 -0
  102. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/naive.c +92 -0
  103. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-neon.c +157 -0
  104. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-sse.c +170 -0
  105. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/utf8_range.h +9 -0
  106. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/BUILD.bazel +129 -0
  107. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/README.md +8 -0
  108. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/def.c +939 -0
  109. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/lua_proto_library.bzl +138 -0
  110. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/main.c +83 -0
  111. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/msg.c +1118 -0
  112. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test.proto +69 -0
  113. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test_upb.lua +846 -0
  114. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.c +258 -0
  115. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.h +132 -0
  116. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.lua +58 -0
  117. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upbc.cc +134 -0
  118. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.c +192 -0
  119. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.h +174 -0
  120. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb.c +346 -0
  121. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb_failures.txt +1 -0
  122. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.c +1221 -0
  123. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.h +94 -0
  124. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.c +1055 -0
  125. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.h +153 -0
  126. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_internal.h +211 -0
  127. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.c +3262 -0
  128. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.h +414 -0
  129. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.hpp +438 -0
  130. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/empty.proto +1 -0
  131. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.c +604 -0
  132. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.h +71 -0
  133. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/BUILD +13 -0
  134. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/file_descriptor_parsenew_fuzzer.cc +43 -0
  135. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.c +1509 -0
  136. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.h +47 -0
  137. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.c +776 -0
  138. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.h +62 -0
  139. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.c +1147 -0
  140. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.h +189 -0
  141. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.hpp +112 -0
  142. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.c +363 -0
  143. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.h +263 -0
  144. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_internal.h +59 -0
  145. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_test.cc +425 -0
  146. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_test.cc +230 -0
  147. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.c +428 -0
  148. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.h +114 -0
  149. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_internal.h +836 -0
  150. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.cc +491 -0
  151. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.proto +195 -0
  152. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_def.inc +261 -0
  153. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_undef.inc +62 -0
  154. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.c +323 -0
  155. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.h +109 -0
  156. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.hpp +37 -0
  157. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table.c +926 -0
  158. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table_internal.h +385 -0
  159. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test.proto +74 -0
  160. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.cc +186 -0
  161. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.proto +12 -0
  162. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_generated_code.cc +977 -0
  163. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_table.cc +580 -0
  164. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.c +472 -0
  165. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.h +64 -0
  166. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.c +362 -0
  167. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.h +378 -0
  168. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.hpp +115 -0
  169. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb_internal.h +68 -0
  170. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/BUILD +121 -0
  171. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/README.md +7 -0
  172. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.c +300 -0
  173. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.h +66 -0
  174. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare_test.cc +236 -0
  175. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.c +572 -0
  176. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.h +62 -0
  177. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_public_import_test.proto +32 -0
  178. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_regular_import_test.proto +36 -0
  179. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.cc +143 -0
  180. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.proto +119 -0
  181. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_weak_import_test.proto +28 -0
  182. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_wweak_import_test.proto +28 -0
  183. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.c +311 -0
  184. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.h +94 -0
  185. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.cc +202 -0
  186. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.proto +48 -0
  187. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/BUILD +78 -0
  188. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.cc +77 -0
  189. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.h +112 -0
  190. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upb.cc +1997 -0
  191. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upbdefs.cc +193 -0
  192. data/lib/ruby_memprofiler_pprof/atfork.rb +77 -0
  193. data/lib/ruby_memprofiler_pprof/block_flusher.rb +61 -0
  194. data/lib/ruby_memprofiler_pprof/file_flusher.rb +45 -0
  195. data/lib/ruby_memprofiler_pprof/profile_app.rb +30 -0
  196. data/lib/ruby_memprofiler_pprof/profile_data.rb +18 -0
  197. data/lib/ruby_memprofiler_pprof/version.rb +5 -0
  198. data/lib/ruby_memprofiler_pprof.rb +8 -0
  199. data/libexec/ruby_memprofiler_pprof_profile +16 -0
  200. metadata +257 -0
@@ -0,0 +1,428 @@
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 "upb/msg.h"
29
+
30
+ #include "upb/msg_internal.h"
31
+ #include "upb/port_def.inc"
32
+ #include "upb/table_internal.h"
33
+
34
+ /** upb_Message ***************************************************************/
35
+
36
+ static const size_t overhead = sizeof(upb_Message_InternalData);
37
+
38
+ static const upb_Message_Internal* upb_Message_Getinternal_const(
39
+ const upb_Message* msg) {
40
+ ptrdiff_t size = sizeof(upb_Message_Internal);
41
+ return (upb_Message_Internal*)((char*)msg - size);
42
+ }
43
+
44
+ upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a) {
45
+ return _upb_Message_New_inl(l, a);
46
+ }
47
+
48
+ void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) {
49
+ void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char);
50
+ memset(mem, 0, upb_msg_sizeof(l));
51
+ }
52
+
53
+ static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) {
54
+ upb_Message_Internal* in = upb_Message_Getinternal(msg);
55
+ if (!in->internal) {
56
+ /* No internal data, allocate from scratch. */
57
+ size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead));
58
+ upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size);
59
+ if (!internal) return false;
60
+ internal->size = size;
61
+ internal->unknown_end = overhead;
62
+ internal->ext_begin = size;
63
+ in->internal = internal;
64
+ } else if (in->internal->ext_begin - in->internal->unknown_end < need) {
65
+ /* Internal data is too small, reallocate. */
66
+ size_t new_size = _upb_Log2CeilingSize(in->internal->size + need);
67
+ size_t ext_bytes = in->internal->size - in->internal->ext_begin;
68
+ size_t new_ext_begin = new_size - ext_bytes;
69
+ upb_Message_InternalData* internal =
70
+ upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size);
71
+ if (!internal) return false;
72
+ if (ext_bytes) {
73
+ /* Need to move extension data to the end. */
74
+ char* ptr = (char*)internal;
75
+ memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes);
76
+ }
77
+ internal->ext_begin = new_ext_begin;
78
+ internal->size = new_size;
79
+ in->internal = internal;
80
+ }
81
+ UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need);
82
+ return true;
83
+ }
84
+
85
+ bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
86
+ upb_Arena* arena) {
87
+ if (!realloc_internal(msg, len, arena)) return false;
88
+ upb_Message_Internal* in = upb_Message_Getinternal(msg);
89
+ memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len);
90
+ in->internal->unknown_end += len;
91
+ return true;
92
+ }
93
+
94
+ void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) {
95
+ upb_Message_Internal* in = upb_Message_Getinternal(msg);
96
+ if (in->internal) {
97
+ in->internal->unknown_end = overhead;
98
+ }
99
+ }
100
+
101
+ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) {
102
+ const upb_Message_Internal* in = upb_Message_Getinternal_const(msg);
103
+ if (in->internal) {
104
+ *len = in->internal->unknown_end - overhead;
105
+ return (char*)(in->internal + 1);
106
+ } else {
107
+ *len = 0;
108
+ return NULL;
109
+ }
110
+ }
111
+
112
+ const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg,
113
+ size_t* count) {
114
+ const upb_Message_Internal* in = upb_Message_Getinternal_const(msg);
115
+ if (in->internal) {
116
+ *count = (in->internal->size - in->internal->ext_begin) /
117
+ sizeof(upb_Message_Extension);
118
+ return UPB_PTR_AT(in->internal, in->internal->ext_begin, void);
119
+ } else {
120
+ *count = 0;
121
+ return NULL;
122
+ }
123
+ }
124
+
125
+ const upb_Message_Extension* _upb_Message_Getext(
126
+ const upb_Message* msg, const upb_MiniTable_Extension* e) {
127
+ size_t n;
128
+ const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n);
129
+
130
+ /* For now we use linear search exclusively to find extensions. If this
131
+ * becomes an issue due to messages with lots of extensions, we can introduce
132
+ * a table of some sort. */
133
+ for (size_t i = 0; i < n; i++) {
134
+ if (ext[i].ext == e) {
135
+ return &ext[i];
136
+ }
137
+ }
138
+
139
+ return NULL;
140
+ }
141
+
142
+ void _upb_Message_Clearext(upb_Message* msg,
143
+ const upb_MiniTable_Extension* ext_l) {
144
+ upb_Message_Internal* in = upb_Message_Getinternal(msg);
145
+ if (!in->internal) return;
146
+ const upb_Message_Extension* base =
147
+ UPB_PTR_AT(in->internal, in->internal->ext_begin, void);
148
+ upb_Message_Extension* ext =
149
+ (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l);
150
+ if (ext) {
151
+ *ext = *base;
152
+ in->internal->ext_begin += sizeof(upb_Message_Extension);
153
+ }
154
+ }
155
+
156
+ upb_Message_Extension* _upb_Message_GetOrCreateExtension(
157
+ upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) {
158
+ upb_Message_Extension* ext =
159
+ (upb_Message_Extension*)_upb_Message_Getext(msg, e);
160
+ if (ext) return ext;
161
+ if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL;
162
+ upb_Message_Internal* in = upb_Message_Getinternal(msg);
163
+ in->internal->ext_begin -= sizeof(upb_Message_Extension);
164
+ ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void);
165
+ memset(ext, 0, sizeof(upb_Message_Extension));
166
+ ext->ext = e;
167
+ return ext;
168
+ }
169
+
170
+ size_t upb_Message_ExtensionCount(const upb_Message* msg) {
171
+ size_t count;
172
+ _upb_Message_Getexts(msg, &count);
173
+ return count;
174
+ }
175
+
176
+ /** upb_Array *****************************************************************/
177
+
178
+ bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena) {
179
+ size_t new_size = UPB_MAX(arr->size, 4);
180
+ int elem_size_lg2 = arr->data & 7;
181
+ size_t old_bytes = arr->size << elem_size_lg2;
182
+ size_t new_bytes;
183
+ void* ptr = _upb_array_ptr(arr);
184
+
185
+ /* Log2 ceiling of size. */
186
+ while (new_size < min_size) new_size *= 2;
187
+
188
+ new_bytes = new_size << elem_size_lg2;
189
+ ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes);
190
+
191
+ if (!ptr) {
192
+ return false;
193
+ }
194
+
195
+ arr->data = _upb_tag_arrptr(ptr, elem_size_lg2);
196
+ arr->size = new_size;
197
+ return true;
198
+ }
199
+
200
+ static upb_Array* getorcreate_array(upb_Array** arr_ptr, int elem_size_lg2,
201
+ upb_Arena* arena) {
202
+ upb_Array* arr = *arr_ptr;
203
+ if (!arr) {
204
+ arr = _upb_Array_New(arena, 4, elem_size_lg2);
205
+ if (!arr) return NULL;
206
+ *arr_ptr = arr;
207
+ }
208
+ return arr;
209
+ }
210
+
211
+ void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size,
212
+ int elem_size_lg2, upb_Arena* arena) {
213
+ upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena);
214
+ return arr && _upb_Array_Resize(arr, size, arena) ? _upb_array_ptr(arr)
215
+ : NULL;
216
+ }
217
+
218
+ bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value,
219
+ int elem_size_lg2, upb_Arena* arena) {
220
+ upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena);
221
+ if (!arr) return false;
222
+
223
+ size_t elems = arr->len;
224
+
225
+ if (!_upb_Array_Resize(arr, elems + 1, arena)) {
226
+ return false;
227
+ }
228
+
229
+ char* data = _upb_array_ptr(arr);
230
+ memcpy(data + (elems << elem_size_lg2), value, 1 << elem_size_lg2);
231
+ return true;
232
+ }
233
+
234
+ /** upb_Map *******************************************************************/
235
+
236
+ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) {
237
+ upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map));
238
+
239
+ if (!map) {
240
+ return NULL;
241
+ }
242
+
243
+ upb_strtable_init(&map->table, 4, a);
244
+ map->key_size = key_size;
245
+ map->val_size = value_size;
246
+
247
+ return map;
248
+ }
249
+
250
+ static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key,
251
+ void* b_key, size_t size) {
252
+ const upb_tabent* const* a = _a;
253
+ const upb_tabent* const* b = _b;
254
+ upb_StringView a_tabkey = upb_tabstrview((*a)->key);
255
+ upb_StringView b_tabkey = upb_tabstrview((*b)->key);
256
+ _upb_map_fromkey(a_tabkey, a_key, size);
257
+ _upb_map_fromkey(b_tabkey, b_key, size);
258
+ }
259
+
260
+ #define UPB_COMPARE_INTEGERS(a, b) ((a) < (b) ? -1 : ((a) == (b) ? 0 : 1))
261
+
262
+ static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) {
263
+ int64_t a, b;
264
+ _upb_mapsorter_getkeys(_a, _b, &a, &b, 8);
265
+ return UPB_COMPARE_INTEGERS(a, b);
266
+ }
267
+
268
+ static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) {
269
+ uint64_t a, b;
270
+ _upb_mapsorter_getkeys(_a, _b, &a, &b, 8);
271
+ return UPB_COMPARE_INTEGERS(a, b);
272
+ }
273
+
274
+ static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) {
275
+ int32_t a, b;
276
+ _upb_mapsorter_getkeys(_a, _b, &a, &b, 4);
277
+ return UPB_COMPARE_INTEGERS(a, b);
278
+ }
279
+
280
+ static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) {
281
+ uint32_t a, b;
282
+ _upb_mapsorter_getkeys(_a, _b, &a, &b, 4);
283
+ return UPB_COMPARE_INTEGERS(a, b);
284
+ }
285
+
286
+ static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) {
287
+ bool a, b;
288
+ _upb_mapsorter_getkeys(_a, _b, &a, &b, 1);
289
+ return UPB_COMPARE_INTEGERS(a, b);
290
+ }
291
+
292
+ static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) {
293
+ upb_StringView a, b;
294
+ _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING);
295
+ size_t common_size = UPB_MIN(a.size, b.size);
296
+ int cmp = memcmp(a.data, b.data, common_size);
297
+ if (cmp) return -cmp;
298
+ return UPB_COMPARE_INTEGERS(a.size, b.size);
299
+ }
300
+
301
+ #undef UPB_COMPARE_INTEGERS
302
+
303
+ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type,
304
+ const upb_Map* map, _upb_sortedmap* sorted) {
305
+ int map_size = _upb_Map_Size(map);
306
+ sorted->start = s->size;
307
+ sorted->pos = sorted->start;
308
+ sorted->end = sorted->start + map_size;
309
+
310
+ /* Grow s->entries if necessary. */
311
+ if (sorted->end > s->cap) {
312
+ s->cap = _upb_Log2CeilingSize(sorted->end);
313
+ s->entries = realloc(s->entries, s->cap * sizeof(*s->entries));
314
+ if (!s->entries) return false;
315
+ }
316
+
317
+ s->size = sorted->end;
318
+
319
+ /* Copy non-empty entries from the table to s->entries. */
320
+ upb_tabent const** dst = &s->entries[sorted->start];
321
+ const upb_tabent* src = map->table.t.entries;
322
+ const upb_tabent* end = src + upb_table_size(&map->table.t);
323
+ for (; src < end; src++) {
324
+ if (!upb_tabent_isempty(src)) {
325
+ *dst = src;
326
+ dst++;
327
+ }
328
+ }
329
+ UPB_ASSERT(dst == &s->entries[sorted->end]);
330
+
331
+ /* Sort entries according to the key type. */
332
+
333
+ int (*compar)(const void*, const void*);
334
+
335
+ switch (key_type) {
336
+ case kUpb_FieldType_Int64:
337
+ case kUpb_FieldType_SFixed64:
338
+ case kUpb_FieldType_SInt64:
339
+ compar = _upb_mapsorter_cmpi64;
340
+ break;
341
+ case kUpb_FieldType_UInt64:
342
+ case kUpb_FieldType_Fixed64:
343
+ compar = _upb_mapsorter_cmpu64;
344
+ break;
345
+ case kUpb_FieldType_Int32:
346
+ case kUpb_FieldType_SInt32:
347
+ case kUpb_FieldType_SFixed32:
348
+ case kUpb_FieldType_Enum:
349
+ compar = _upb_mapsorter_cmpi32;
350
+ break;
351
+ case kUpb_FieldType_UInt32:
352
+ case kUpb_FieldType_Fixed32:
353
+ compar = _upb_mapsorter_cmpu32;
354
+ break;
355
+ case kUpb_FieldType_Bool:
356
+ compar = _upb_mapsorter_cmpbool;
357
+ break;
358
+ case kUpb_FieldType_String:
359
+ case kUpb_FieldType_Bytes:
360
+ compar = _upb_mapsorter_cmpstr;
361
+ break;
362
+ default:
363
+ UPB_UNREACHABLE();
364
+ }
365
+
366
+ qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), compar);
367
+ return true;
368
+ }
369
+
370
+ /** upb_ExtensionRegistry *****************************************************/
371
+
372
+ struct upb_ExtensionRegistry {
373
+ upb_Arena* arena;
374
+ upb_strtable exts; /* Key is upb_MiniTable* concatenated with fieldnum. */
375
+ };
376
+
377
+ #define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t))
378
+
379
+ static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) {
380
+ memcpy(buf, &l, sizeof(l));
381
+ memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum));
382
+ }
383
+
384
+ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) {
385
+ upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r));
386
+ if (!r) return NULL;
387
+ r->arena = arena;
388
+ if (!upb_strtable_init(&r->exts, 8, arena)) return NULL;
389
+ return r;
390
+ }
391
+
392
+ bool _upb_extreg_add(upb_ExtensionRegistry* r,
393
+ const upb_MiniTable_Extension** e, size_t count) {
394
+ char buf[EXTREG_KEY_SIZE];
395
+ const upb_MiniTable_Extension** start = e;
396
+ const upb_MiniTable_Extension** end = UPB_PTRADD(e, count);
397
+ for (; e < end; e++) {
398
+ const upb_MiniTable_Extension* ext = *e;
399
+ extreg_key(buf, ext->extendee, ext->field.number);
400
+ if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE,
401
+ upb_value_constptr(ext), r->arena)) {
402
+ goto failure;
403
+ }
404
+ }
405
+ return true;
406
+
407
+ failure:
408
+ /* Back out the entries previously added. */
409
+ for (end = e, e = start; e < end; e++) {
410
+ const upb_MiniTable_Extension* ext = *e;
411
+ extreg_key(buf, ext->extendee, ext->field.number);
412
+ upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL);
413
+ }
414
+ return false;
415
+ }
416
+
417
+ const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r,
418
+ const upb_MiniTable* l,
419
+ uint32_t num) {
420
+ char buf[EXTREG_KEY_SIZE];
421
+ upb_value v;
422
+ extreg_key(buf, l, num);
423
+ if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) {
424
+ return upb_value_getconstptr(v);
425
+ } else {
426
+ return NULL;
427
+ }
428
+ }
@@ -0,0 +1,114 @@
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
+ /*
29
+ * Public APIs for message operations that do not require descriptors.
30
+ * These functions can be used even in build that does not want to depend on
31
+ * reflection or descriptors.
32
+ *
33
+ * Descriptor-based reflection functionality lives in reflection.h.
34
+ */
35
+
36
+ #ifndef UPB_MSG_H_
37
+ #define UPB_MSG_H_
38
+
39
+ #include <stddef.h>
40
+
41
+ #include "upb/upb.h"
42
+
43
+ #ifdef __cplusplus
44
+ extern "C" {
45
+ #endif
46
+
47
+ /** upb_Message ***************************************************************/
48
+
49
+ typedef void upb_Message;
50
+
51
+ /* For users these are opaque. They can be obtained from
52
+ * upb_MessageDef_MiniTable() but users cannot access any of the members. */
53
+ struct upb_MiniTable;
54
+ typedef struct upb_MiniTable upb_MiniTable;
55
+
56
+ /* Adds unknown data (serialized protobuf data) to the given message. The data
57
+ * is copied into the message instance. */
58
+ void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
59
+ upb_Arena* arena);
60
+
61
+ /* Returns a reference to the message's unknown data. */
62
+ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len);
63
+
64
+ /* Returns the number of extensions present in this message. */
65
+ size_t upb_Message_ExtensionCount(const upb_Message* msg);
66
+
67
+ /** upb_ExtensionRegistry *****************************************************/
68
+
69
+ /* Extension registry: a dynamic data structure that stores a map of:
70
+ * (upb_MiniTable, number) -> extension info
71
+ *
72
+ * upb_decode() uses upb_ExtensionRegistry to look up extensions while parsing
73
+ * binary format.
74
+ *
75
+ * upb_ExtensionRegistry is part of the mini-table (msglayout) family of
76
+ * objects. Like all mini-table objects, it is suitable for reflection-less
77
+ * builds that do not want to expose names into the binary.
78
+ *
79
+ * Unlike most mini-table types, upb_ExtensionRegistry requires dynamic memory
80
+ * allocation and dynamic initialization:
81
+ * * If reflection is being used, then upb_DefPool will construct an appropriate
82
+ * upb_ExtensionRegistry automatically.
83
+ * * For a mini-table only build, the user must manually construct the
84
+ * upb_ExtensionRegistry and populate it with all of the extensions the user
85
+ * cares about.
86
+ * * A third alternative is to manually unpack relevant extensions after the
87
+ * main parse is complete, similar to how Any works. This is perhaps the
88
+ * nicest solution from the perspective of reducing dependencies, avoiding
89
+ * dynamic memory allocation, and avoiding the need to parse uninteresting
90
+ * extensions. The downsides are:
91
+ * (1) parse errors are not caught during the main parse
92
+ * (2) the CPU hit of parsing comes during access, which could cause an
93
+ * undesirable stutter in application performance.
94
+ *
95
+ * Users cannot directly get or put into this map. Users can only add the
96
+ * extensions from a generated module and pass the extension registry to the
97
+ * binary decoder.
98
+ *
99
+ * A upb_DefPool provides a upb_ExtensionRegistry, so any users who use
100
+ * reflection do not need to populate a upb_ExtensionRegistry directly.
101
+ */
102
+
103
+ struct upb_ExtensionRegistry;
104
+ typedef struct upb_ExtensionRegistry upb_ExtensionRegistry;
105
+
106
+ /* Creates a upb_ExtensionRegistry in the given arena. The arena must outlive
107
+ * any use of the extreg. */
108
+ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena);
109
+
110
+ #ifdef __cplusplus
111
+ } /* extern "C" */
112
+ #endif
113
+
114
+ #endif /* UPB_MSG_INT_H_ */