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,192 @@
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/collections.h"
29
+
30
+ #include <string.h>
31
+
32
+ #include "upb/msg.h"
33
+ #include "upb/port_def.inc"
34
+ #include "upb/table_internal.h"
35
+
36
+ /* Strings/bytes are special-cased in maps. */
37
+ static char _upb_CTypeo_mapsize[12] = {
38
+ 0,
39
+ 1, /* kUpb_CType_Bool */
40
+ 4, /* kUpb_CType_Float */
41
+ 4, /* kUpb_CType_Int32 */
42
+ 4, /* kUpb_CType_UInt32 */
43
+ 4, /* kUpb_CType_Enum */
44
+ sizeof(void*), /* kUpb_CType_Message */
45
+ 8, /* kUpb_CType_Double */
46
+ 8, /* kUpb_CType_Int64 */
47
+ 8, /* kUpb_CType_UInt64 */
48
+ 0, /* kUpb_CType_String */
49
+ 0, /* kUpb_CType_Bytes */
50
+ };
51
+
52
+ static const char _upb_CTypeo_sizelg2[12] = {
53
+ 0,
54
+ 0, /* kUpb_CType_Bool */
55
+ 2, /* kUpb_CType_Float */
56
+ 2, /* kUpb_CType_Int32 */
57
+ 2, /* kUpb_CType_UInt32 */
58
+ 2, /* kUpb_CType_Enum */
59
+ UPB_SIZE(2, 3), /* kUpb_CType_Message */
60
+ 3, /* kUpb_CType_Double */
61
+ 3, /* kUpb_CType_Int64 */
62
+ 3, /* kUpb_CType_UInt64 */
63
+ UPB_SIZE(3, 4), /* kUpb_CType_String */
64
+ UPB_SIZE(3, 4), /* kUpb_CType_Bytes */
65
+ };
66
+
67
+ /** upb_Array *****************************************************************/
68
+
69
+ upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) {
70
+ return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]);
71
+ }
72
+
73
+ size_t upb_Array_Size(const upb_Array* arr) { return arr->len; }
74
+
75
+ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) {
76
+ upb_MessageValue ret;
77
+ const char* data = _upb_array_constptr(arr);
78
+ int lg2 = arr->data & 7;
79
+ UPB_ASSERT(i < arr->len);
80
+ memcpy(&ret, data + (i << lg2), 1 << lg2);
81
+ return ret;
82
+ }
83
+
84
+ void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) {
85
+ char* data = _upb_array_ptr(arr);
86
+ int lg2 = arr->data & 7;
87
+ UPB_ASSERT(i < arr->len);
88
+ memcpy(data + (i << lg2), &val, 1 << lg2);
89
+ }
90
+
91
+ bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) {
92
+ if (!upb_Array_Resize(arr, arr->len + 1, arena)) {
93
+ return false;
94
+ }
95
+ upb_Array_Set(arr, arr->len - 1, val);
96
+ return true;
97
+ }
98
+
99
+ void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx,
100
+ size_t count) {
101
+ char* data = _upb_array_ptr(arr);
102
+ int lg2 = arr->data & 7;
103
+ memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2);
104
+ }
105
+
106
+ bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count,
107
+ upb_Arena* arena) {
108
+ UPB_ASSERT(i <= arr->len);
109
+ UPB_ASSERT(count + arr->len >= count);
110
+ size_t oldsize = arr->len;
111
+ if (!upb_Array_Resize(arr, arr->len + count, arena)) {
112
+ return false;
113
+ }
114
+ upb_Array_Move(arr, i + count, i, oldsize - i);
115
+ return true;
116
+ }
117
+
118
+ /*
119
+ * i end arr->len
120
+ * |------------|XXXXXXXX|--------|
121
+ */
122
+ void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) {
123
+ size_t end = i + count;
124
+ UPB_ASSERT(i <= end);
125
+ UPB_ASSERT(end <= arr->len);
126
+ upb_Array_Move(arr, i, end, arr->len - end);
127
+ arr->len -= count;
128
+ }
129
+
130
+ bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) {
131
+ return _upb_Array_Resize(arr, size, arena);
132
+ }
133
+
134
+ /** upb_Map *******************************************************************/
135
+
136
+ upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) {
137
+ return _upb_Map_New(a, _upb_CTypeo_mapsize[key_type],
138
+ _upb_CTypeo_mapsize[value_type]);
139
+ }
140
+
141
+ size_t upb_Map_Size(const upb_Map* map) { return _upb_Map_Size(map); }
142
+
143
+ bool upb_Map_Get(const upb_Map* map, upb_MessageValue key,
144
+ upb_MessageValue* val) {
145
+ return _upb_Map_Get(map, &key, map->key_size, val, map->val_size);
146
+ }
147
+
148
+ void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); }
149
+
150
+ upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key,
151
+ upb_MessageValue val, upb_Arena* arena) {
152
+ return (upb_MapInsertStatus)_upb_Map_Insert(map, &key, map->key_size, &val,
153
+ map->val_size, arena);
154
+ }
155
+
156
+ bool upb_Map_Delete(upb_Map* map, upb_MessageValue key) {
157
+ return _upb_Map_Delete(map, &key, map->key_size);
158
+ }
159
+
160
+ bool upb_MapIterator_Next(const upb_Map* map, size_t* iter) {
161
+ return _upb_map_next(map, iter);
162
+ }
163
+
164
+ bool upb_MapIterator_Done(const upb_Map* map, size_t iter) {
165
+ upb_strtable_iter i;
166
+ UPB_ASSERT(iter != kUpb_Map_Begin);
167
+ i.t = &map->table;
168
+ i.index = iter;
169
+ return upb_strtable_done(&i);
170
+ }
171
+
172
+ /* Returns the key and value for this entry of the map. */
173
+ upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter) {
174
+ upb_strtable_iter i;
175
+ upb_MessageValue ret;
176
+ i.t = &map->table;
177
+ i.index = iter;
178
+ _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size);
179
+ return ret;
180
+ }
181
+
182
+ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) {
183
+ upb_strtable_iter i;
184
+ upb_MessageValue ret;
185
+ i.t = &map->table;
186
+ i.index = iter;
187
+ _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size);
188
+ return ret;
189
+ }
190
+
191
+ /* void upb_MapIterator_SetValue(upb_Map *map, size_t iter, upb_MessageValue
192
+ * value); */
@@ -0,0 +1,174 @@
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 UPB_COLLECTIONS_H_
29
+ #define UPB_COLLECTIONS_H_
30
+
31
+ #include "google/protobuf/descriptor.upb.h"
32
+ #include "upb/port_def.inc"
33
+
34
+ #ifdef __cplusplus
35
+ extern "C" {
36
+ #endif
37
+
38
+ typedef union {
39
+ bool bool_val;
40
+ float float_val;
41
+ double double_val;
42
+ int32_t int32_val;
43
+ int64_t int64_val;
44
+ uint32_t uint32_val;
45
+ uint64_t uint64_val;
46
+ const upb_Map* map_val;
47
+ const upb_Message* msg_val;
48
+ const upb_Array* array_val;
49
+ upb_StringView str_val;
50
+ } upb_MessageValue;
51
+
52
+ typedef union {
53
+ upb_Map* map;
54
+ upb_Message* msg;
55
+ upb_Array* array;
56
+ } upb_MutableMessageValue;
57
+
58
+ /** upb_Array *****************************************************************/
59
+
60
+ /* Creates a new array on the given arena that holds elements of this type. */
61
+ upb_Array* upb_Array_New(upb_Arena* a, upb_CType type);
62
+
63
+ /* Returns the size of the array. */
64
+ size_t upb_Array_Size(const upb_Array* arr);
65
+
66
+ /* Returns the given element, which must be within the array's current size. */
67
+ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i);
68
+
69
+ /* Sets the given element, which must be within the array's current size. */
70
+ void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val);
71
+
72
+ /* Appends an element to the array. Returns false on allocation failure. */
73
+ bool upb_Array_Append(upb_Array* array, upb_MessageValue val, upb_Arena* arena);
74
+
75
+ /* Moves elements within the array using memmove(). Like memmove(), the source
76
+ * and destination elements may be overlapping. */
77
+ void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx,
78
+ size_t count);
79
+
80
+ /* Inserts one or more empty elements into the array. Existing elements are
81
+ * shifted right. The new elements have undefined state and must be set with
82
+ * `upb_Array_Set()`.
83
+ * REQUIRES: `i <= upb_Array_Size(arr)` */
84
+ bool upb_Array_Insert(upb_Array* array, size_t i, size_t count,
85
+ upb_Arena* arena);
86
+
87
+ /* Deletes one or more elements from the array. Existing elements are shifted
88
+ * left.
89
+ * REQUIRES: `i + count <= upb_Array_Size(arr)` */
90
+ void upb_Array_Delete(upb_Array* array, size_t i, size_t count);
91
+
92
+ /* Changes the size of a vector. New elements are initialized to empty/0.
93
+ * Returns false on allocation failure. */
94
+ bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena);
95
+
96
+ /** upb_Map *******************************************************************/
97
+
98
+ /* Creates a new map on the given arena with the given key/value size. */
99
+ upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type);
100
+
101
+ /* Returns the number of entries in the map. */
102
+ size_t upb_Map_Size(const upb_Map* map);
103
+
104
+ /* Stores a value for the given key into |*val| (or the zero value if the key is
105
+ * not present). Returns whether the key was present. The |val| pointer may be
106
+ * NULL, in which case the function tests whether the given key is present. */
107
+ bool upb_Map_Get(const upb_Map* map, upb_MessageValue key,
108
+ upb_MessageValue* val);
109
+
110
+ /* Removes all entries in the map. */
111
+ void upb_Map_Clear(upb_Map* map);
112
+
113
+ typedef enum {
114
+ // LINT.IfChange
115
+ kUpb_MapInsertStatus_Inserted = 0,
116
+ kUpb_MapInsertStatus_Replaced = 1,
117
+ kUpb_MapInsertStatus_OutOfMemory = 2,
118
+ // LINT.ThenChange(//depot/google3/third_party/upb/upb/msg_internal.h)
119
+ } upb_MapInsertStatus;
120
+
121
+ /* Sets the given key to the given value, returning whether the key was inserted
122
+ * or replaced. If the key was inserted, then any existing iterators will be
123
+ * invalidated. */
124
+ upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key,
125
+ upb_MessageValue val, upb_Arena* arena);
126
+
127
+ /* Sets the given key to the given value. Returns false if memory allocation
128
+ * failed. If the key is newly inserted, then any existing iterators will be
129
+ * invalidated. */
130
+ UPB_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key,
131
+ upb_MessageValue val, upb_Arena* arena) {
132
+ return upb_Map_Insert(map, key, val, arena) !=
133
+ kUpb_MapInsertStatus_OutOfMemory;
134
+ }
135
+
136
+ /* Deletes this key from the table. Returns true if the key was present. */
137
+ bool upb_Map_Delete(upb_Map* map, upb_MessageValue key);
138
+
139
+ /* Map iteration:
140
+ *
141
+ * size_t iter = kUpb_Map_Begin;
142
+ * while (upb_MapIterator_Next(map, &iter)) {
143
+ * upb_MessageValue key = upb_MapIterator_Key(map, iter);
144
+ * upb_MessageValue val = upb_MapIterator_Value(map, iter);
145
+ *
146
+ * // If mutating is desired.
147
+ * upb_MapIterator_SetValue(map, iter, value2);
148
+ * }
149
+ */
150
+
151
+ /* Advances to the next entry. Returns false if no more entries are present. */
152
+ bool upb_MapIterator_Next(const upb_Map* map, size_t* iter);
153
+
154
+ /* Returns true if the iterator still points to a valid entry, or false if the
155
+ * iterator is past the last element. It is an error to call this function with
156
+ * kUpb_Map_Begin (you must call next() at least once first). */
157
+ bool upb_MapIterator_Done(const upb_Map* map, size_t iter);
158
+
159
+ /* Returns the key and value for this entry of the map. */
160
+ upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter);
161
+ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter);
162
+
163
+ /* Sets the value for this entry. The iterator must not be done, and the
164
+ * iterator must not have been initialized const. */
165
+ void upb_MapIterator_SetValue(upb_Map* map, size_t iter,
166
+ upb_MessageValue value);
167
+
168
+ #ifdef __cplusplus
169
+ } /* extern "C" */
170
+ #endif
171
+
172
+ #include "upb/port_undef.inc"
173
+
174
+ #endif /* UPB_COLLECTIONS_H_ */