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,572 @@
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/util/def_to_proto.h"
29
+
30
+ #include <inttypes.h>
31
+ #include <math.h>
32
+ #include <setjmp.h>
33
+ #include <stdio.h>
34
+
35
+ #include "upb/reflection.h"
36
+
37
+ /* Must be last. */
38
+ #include "upb/port_def.inc"
39
+
40
+ typedef struct {
41
+ upb_Arena* arena;
42
+ jmp_buf err;
43
+ } upb_ToProto_Context;
44
+
45
+ #define CHK_OOM(val) \
46
+ if (!(val)) UPB_LONGJMP(ctx->err, 1);
47
+
48
+ // We want to copy the options verbatim into the destination options proto.
49
+ // We use serialize+parse as our deep copy.
50
+ #define SET_OPTIONS(proto, desc_type, options_type, src) \
51
+ { \
52
+ size_t size; \
53
+ /* MEM: could use a temporary arena here instead. */ \
54
+ char* pb = \
55
+ google_protobuf_##options_type##_serialize(src, ctx->arena, &size); \
56
+ CHK_OOM(pb); \
57
+ google_protobuf_##options_type* dst = \
58
+ google_protobuf_##options_type##_parse(pb, size, ctx->arena); \
59
+ CHK_OOM(dst); \
60
+ google_protobuf_##desc_type##_set_options(proto, dst); \
61
+ }
62
+
63
+ static upb_StringView strviewdup2(upb_ToProto_Context* ctx,
64
+ upb_StringView str) {
65
+ char* p = upb_Arena_Malloc(ctx->arena, str.size);
66
+ CHK_OOM(p);
67
+ memcpy(p, str.data, str.size);
68
+ return (upb_StringView){.data = p, .size = str.size};
69
+ }
70
+
71
+ static upb_StringView strviewdup(upb_ToProto_Context* ctx, const char* s) {
72
+ return strviewdup2(ctx, (upb_StringView){.data = s, .size = strlen(s)});
73
+ }
74
+
75
+ static upb_StringView qual_dup(upb_ToProto_Context* ctx, const char* s) {
76
+ size_t n = strlen(s);
77
+ char* p = upb_Arena_Malloc(ctx->arena, n + 1);
78
+ CHK_OOM(p);
79
+ p[0] = '.';
80
+ memcpy(p + 1, s, n);
81
+ return (upb_StringView){.data = p, .size = n + 1};
82
+ }
83
+
84
+ UPB_PRINTF(2, 3)
85
+ static upb_StringView printf_dup(upb_ToProto_Context* ctx, const char* fmt,
86
+ ...) {
87
+ const size_t max = 32;
88
+ char* p = upb_Arena_Malloc(ctx->arena, max);
89
+ CHK_OOM(p);
90
+ va_list args;
91
+ va_start(args, fmt);
92
+ size_t n = vsnprintf(p, max, fmt, args);
93
+ va_end(args);
94
+ UPB_ASSERT(n < max);
95
+ return (upb_StringView){.data = p, .size = n};
96
+ }
97
+
98
+ static bool upb_isprint(char ch) { return ch >= 0x20 && ch <= 0x7f; }
99
+
100
+ static upb_StringView default_bytes(upb_ToProto_Context* ctx,
101
+ upb_StringView val) {
102
+ size_t n = 0;
103
+ for (size_t i = 0; i < val.size; i++) {
104
+ n += upb_isprint(val.data[i]) ? 1 : 4; // '\123'
105
+ }
106
+ char* p = upb_Arena_Malloc(ctx->arena, n);
107
+ CHK_OOM(p);
108
+ char* dst = p;
109
+ const char* src = val.data;
110
+ const char* end = src + val.size;
111
+ while (src < end) {
112
+ unsigned char ch = *src++;
113
+ if (upb_isprint(ch)) {
114
+ *dst++ = ch;
115
+ } else {
116
+ *dst++ = '\\';
117
+ *dst++ = '0' + (ch >> 6);
118
+ *dst++ = '0' + ((ch >> 3) & 0x7);
119
+ *dst++ = '0' + (ch & 0x7);
120
+ }
121
+ }
122
+ return (upb_StringView){.data = p, .size = n};
123
+ }
124
+
125
+ static upb_StringView default_string(upb_ToProto_Context* ctx,
126
+ const upb_FieldDef* f) {
127
+ upb_MessageValue d = upb_FieldDef_Default(f);
128
+ upb_CType type = upb_FieldDef_CType(f);
129
+
130
+ if (type == kUpb_CType_Float || type == kUpb_CType_Double) {
131
+ double val = type == kUpb_CType_Float ? d.float_val : d.double_val;
132
+ if (val == INFINITY) {
133
+ return strviewdup(ctx, "inf");
134
+ } else if (val == -INFINITY) {
135
+ return strviewdup(ctx, "-inf");
136
+ } else if (val != val) {
137
+ return strviewdup(ctx, "nan");
138
+ }
139
+ }
140
+
141
+ switch (upb_FieldDef_CType(f)) {
142
+ case kUpb_CType_Bool:
143
+ return strviewdup(ctx, d.bool_val ? "true" : "false");
144
+ case kUpb_CType_Enum: {
145
+ const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f);
146
+ const upb_EnumValueDef* ev =
147
+ upb_EnumDef_FindValueByNumber(e, d.int32_val);
148
+ return strviewdup(ctx, upb_EnumValueDef_Name(ev));
149
+ }
150
+ case kUpb_CType_Int64:
151
+ return printf_dup(ctx, "%" PRId64, d.int64_val);
152
+ case kUpb_CType_UInt64:
153
+ return printf_dup(ctx, "%" PRIu64, d.uint64_val);
154
+ case kUpb_CType_Int32:
155
+ return printf_dup(ctx, "%" PRId32, d.int32_val);
156
+ case kUpb_CType_UInt32:
157
+ return printf_dup(ctx, "%" PRIu32, d.uint32_val);
158
+ case kUpb_CType_Float:
159
+ return printf_dup(ctx, "%.9g", d.float_val);
160
+ case kUpb_CType_Double:
161
+ return printf_dup(ctx, "%.17g", d.double_val);
162
+ case kUpb_CType_String:
163
+ return strviewdup2(ctx, d.str_val);
164
+ case kUpb_CType_Bytes:
165
+ return default_bytes(ctx, d.str_val);
166
+ default:
167
+ UPB_UNREACHABLE();
168
+ }
169
+ }
170
+
171
+ static google_protobuf_FieldDescriptorProto* fielddef_toproto(
172
+ upb_ToProto_Context* ctx, const upb_FieldDef* f) {
173
+ google_protobuf_FieldDescriptorProto* proto =
174
+ google_protobuf_FieldDescriptorProto_new(ctx->arena);
175
+ CHK_OOM(proto);
176
+
177
+ google_protobuf_FieldDescriptorProto_set_name(
178
+ proto, strviewdup(ctx, upb_FieldDef_Name(f)));
179
+ google_protobuf_FieldDescriptorProto_set_number(proto,
180
+ upb_FieldDef_Number(f));
181
+ google_protobuf_FieldDescriptorProto_set_label(proto, upb_FieldDef_Label(f));
182
+ google_protobuf_FieldDescriptorProto_set_type(proto, upb_FieldDef_Type(f));
183
+
184
+ if (upb_FieldDef_HasJsonName(f)) {
185
+ google_protobuf_FieldDescriptorProto_set_json_name(
186
+ proto, strviewdup(ctx, upb_FieldDef_JsonName(f)));
187
+ }
188
+
189
+ if (upb_FieldDef_IsSubMessage(f)) {
190
+ google_protobuf_FieldDescriptorProto_set_type_name(
191
+ proto,
192
+ qual_dup(ctx, upb_MessageDef_FullName(upb_FieldDef_MessageSubDef(f))));
193
+ } else if (upb_FieldDef_CType(f) == kUpb_CType_Enum) {
194
+ google_protobuf_FieldDescriptorProto_set_type_name(
195
+ proto, qual_dup(ctx, upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f))));
196
+ }
197
+
198
+ if (upb_FieldDef_IsExtension(f)) {
199
+ google_protobuf_FieldDescriptorProto_set_extendee(
200
+ proto,
201
+ qual_dup(ctx, upb_MessageDef_FullName(upb_FieldDef_ContainingType(f))));
202
+ }
203
+
204
+ if (upb_FieldDef_HasDefault(f)) {
205
+ google_protobuf_FieldDescriptorProto_set_default_value(
206
+ proto, default_string(ctx, f));
207
+ }
208
+
209
+ const upb_OneofDef* o = upb_FieldDef_ContainingOneof(f);
210
+ if (o) {
211
+ google_protobuf_FieldDescriptorProto_set_oneof_index(proto,
212
+ upb_OneofDef_Index(o));
213
+ }
214
+
215
+ if (_upb_FieldDef_IsProto3Optional(f)) {
216
+ google_protobuf_FieldDescriptorProto_set_proto3_optional(proto, true);
217
+ }
218
+
219
+ if (upb_FieldDef_HasOptions(f)) {
220
+ SET_OPTIONS(proto, FieldDescriptorProto, FieldOptions,
221
+ upb_FieldDef_Options(f));
222
+ }
223
+
224
+ return proto;
225
+ }
226
+
227
+ static google_protobuf_OneofDescriptorProto* oneofdef_toproto(
228
+ upb_ToProto_Context* ctx, const upb_OneofDef* o) {
229
+ google_protobuf_OneofDescriptorProto* proto =
230
+ google_protobuf_OneofDescriptorProto_new(ctx->arena);
231
+ CHK_OOM(proto);
232
+
233
+ google_protobuf_OneofDescriptorProto_set_name(
234
+ proto, strviewdup(ctx, upb_OneofDef_Name(o)));
235
+
236
+ if (upb_OneofDef_HasOptions(o)) {
237
+ SET_OPTIONS(proto, OneofDescriptorProto, OneofOptions,
238
+ upb_OneofDef_Options(o));
239
+ }
240
+
241
+ return proto;
242
+ }
243
+
244
+ static google_protobuf_EnumValueDescriptorProto* enumvaldef_toproto(
245
+ upb_ToProto_Context* ctx, const upb_EnumValueDef* e) {
246
+ google_protobuf_EnumValueDescriptorProto* proto =
247
+ google_protobuf_EnumValueDescriptorProto_new(ctx->arena);
248
+ CHK_OOM(proto);
249
+
250
+ google_protobuf_EnumValueDescriptorProto_set_name(
251
+ proto, strviewdup(ctx, upb_EnumValueDef_Name(e)));
252
+ google_protobuf_EnumValueDescriptorProto_set_number(
253
+ proto, upb_EnumValueDef_Number(e));
254
+
255
+ if (upb_EnumValueDef_HasOptions(e)) {
256
+ SET_OPTIONS(proto, EnumValueDescriptorProto, EnumValueOptions,
257
+ upb_EnumValueDef_Options(e));
258
+ }
259
+
260
+ return proto;
261
+ }
262
+
263
+ static google_protobuf_EnumDescriptorProto* enumdef_toproto(
264
+ upb_ToProto_Context* ctx, const upb_EnumDef* e) {
265
+ google_protobuf_EnumDescriptorProto* proto =
266
+ google_protobuf_EnumDescriptorProto_new(ctx->arena);
267
+ CHK_OOM(proto);
268
+
269
+ google_protobuf_EnumDescriptorProto_set_name(
270
+ proto, strviewdup(ctx, upb_EnumDef_Name(e)));
271
+
272
+ int n;
273
+
274
+ n = upb_EnumDef_ValueCount(e);
275
+ google_protobuf_EnumValueDescriptorProto** vals =
276
+ google_protobuf_EnumDescriptorProto_resize_value(proto, n, ctx->arena);
277
+ CHK_OOM(vals);
278
+ for (int i = 0; i < n; i++) {
279
+ vals[i] = enumvaldef_toproto(ctx, upb_EnumDef_Value(e, i));
280
+ }
281
+
282
+ // TODO: reserved range, reserved name
283
+
284
+ if (upb_EnumDef_HasOptions(e)) {
285
+ SET_OPTIONS(proto, EnumDescriptorProto, EnumOptions,
286
+ upb_EnumDef_Options(e));
287
+ }
288
+
289
+ return proto;
290
+ }
291
+
292
+ static google_protobuf_DescriptorProto_ExtensionRange* extrange_toproto(
293
+ upb_ToProto_Context* ctx, const upb_ExtensionRange* e) {
294
+ google_protobuf_DescriptorProto_ExtensionRange* proto =
295
+ google_protobuf_DescriptorProto_ExtensionRange_new(ctx->arena);
296
+ CHK_OOM(proto);
297
+
298
+ google_protobuf_DescriptorProto_ExtensionRange_set_start(
299
+ proto, upb_ExtensionRange_Start(e));
300
+ google_protobuf_DescriptorProto_ExtensionRange_set_end(
301
+ proto, upb_ExtensionRange_End(e));
302
+
303
+ if (upb_ExtensionRange_HasOptions(e)) {
304
+ SET_OPTIONS(proto, DescriptorProto_ExtensionRange, ExtensionRangeOptions,
305
+ upb_ExtensionRange_Options(e));
306
+ }
307
+
308
+ return proto;
309
+ }
310
+
311
+ static google_protobuf_DescriptorProto* msgdef_toproto(
312
+ upb_ToProto_Context* ctx, const upb_MessageDef* m) {
313
+ google_protobuf_DescriptorProto* proto =
314
+ google_protobuf_DescriptorProto_new(ctx->arena);
315
+ CHK_OOM(proto);
316
+
317
+ google_protobuf_DescriptorProto_set_name(
318
+ proto, strviewdup(ctx, upb_MessageDef_Name(m)));
319
+
320
+ int n;
321
+
322
+ n = upb_MessageDef_FieldCount(m);
323
+ google_protobuf_FieldDescriptorProto** fields =
324
+ google_protobuf_DescriptorProto_resize_field(proto, n, ctx->arena);
325
+ CHK_OOM(fields);
326
+ for (int i = 0; i < n; i++) {
327
+ fields[i] = fielddef_toproto(ctx, upb_MessageDef_Field(m, i));
328
+ }
329
+
330
+ n = upb_MessageDef_OneofCount(m);
331
+ google_protobuf_OneofDescriptorProto** oneofs =
332
+ google_protobuf_DescriptorProto_resize_oneof_decl(proto, n, ctx->arena);
333
+ for (int i = 0; i < n; i++) {
334
+ oneofs[i] = oneofdef_toproto(ctx, upb_MessageDef_Oneof(m, i));
335
+ }
336
+
337
+ n = upb_MessageDef_NestedMessageCount(m);
338
+ google_protobuf_DescriptorProto** nested_msgs =
339
+ google_protobuf_DescriptorProto_resize_nested_type(proto, n, ctx->arena);
340
+ for (int i = 0; i < n; i++) {
341
+ nested_msgs[i] = msgdef_toproto(ctx, upb_MessageDef_NestedMessage(m, i));
342
+ }
343
+
344
+ n = upb_MessageDef_NestedEnumCount(m);
345
+ google_protobuf_EnumDescriptorProto** nested_enums =
346
+ google_protobuf_DescriptorProto_resize_enum_type(proto, n, ctx->arena);
347
+ for (int i = 0; i < n; i++) {
348
+ nested_enums[i] = enumdef_toproto(ctx, upb_MessageDef_NestedEnum(m, i));
349
+ }
350
+
351
+ n = upb_MessageDef_NestedExtensionCount(m);
352
+ google_protobuf_FieldDescriptorProto** nested_exts =
353
+ google_protobuf_DescriptorProto_resize_extension(proto, n, ctx->arena);
354
+ for (int i = 0; i < n; i++) {
355
+ nested_exts[i] =
356
+ fielddef_toproto(ctx, upb_MessageDef_NestedExtension(m, i));
357
+ }
358
+
359
+ n = upb_MessageDef_ExtensionRangeCount(m);
360
+ google_protobuf_DescriptorProto_ExtensionRange** ext_ranges =
361
+ google_protobuf_DescriptorProto_resize_extension_range(proto, n,
362
+ ctx->arena);
363
+ for (int i = 0; i < n; i++) {
364
+ ext_ranges[i] = extrange_toproto(ctx, upb_MessageDef_ExtensionRange(m, i));
365
+ }
366
+
367
+ // TODO: reserved ranges and reserved names
368
+
369
+ if (upb_MessageDef_HasOptions(m)) {
370
+ SET_OPTIONS(proto, DescriptorProto, MessageOptions,
371
+ upb_MessageDef_Options(m));
372
+ }
373
+
374
+ return proto;
375
+ }
376
+
377
+ static google_protobuf_MethodDescriptorProto* methoddef_toproto(
378
+ upb_ToProto_Context* ctx, const upb_MethodDef* m) {
379
+ google_protobuf_MethodDescriptorProto* proto =
380
+ google_protobuf_MethodDescriptorProto_new(ctx->arena);
381
+ CHK_OOM(proto);
382
+
383
+ google_protobuf_MethodDescriptorProto_set_name(
384
+ proto, strviewdup(ctx, upb_MethodDef_Name(m)));
385
+
386
+ google_protobuf_MethodDescriptorProto_set_input_type(
387
+ proto,
388
+ qual_dup(ctx, upb_MessageDef_FullName(upb_MethodDef_InputType(m))));
389
+ google_protobuf_MethodDescriptorProto_set_output_type(
390
+ proto,
391
+ qual_dup(ctx, upb_MessageDef_FullName(upb_MethodDef_OutputType(m))));
392
+
393
+ if (upb_MethodDef_ClientStreaming(m)) {
394
+ google_protobuf_MethodDescriptorProto_set_client_streaming(proto, true);
395
+ }
396
+
397
+ if (upb_MethodDef_ServerStreaming(m)) {
398
+ google_protobuf_MethodDescriptorProto_set_server_streaming(proto, true);
399
+ }
400
+
401
+ if (upb_MethodDef_HasOptions(m)) {
402
+ SET_OPTIONS(proto, MethodDescriptorProto, MethodOptions,
403
+ upb_MethodDef_Options(m));
404
+ }
405
+
406
+ return proto;
407
+ }
408
+
409
+ static google_protobuf_ServiceDescriptorProto* servicedef_toproto(
410
+ upb_ToProto_Context* ctx, const upb_ServiceDef* s) {
411
+ google_protobuf_ServiceDescriptorProto* proto =
412
+ google_protobuf_ServiceDescriptorProto_new(ctx->arena);
413
+ CHK_OOM(proto);
414
+
415
+ google_protobuf_ServiceDescriptorProto_set_name(
416
+ proto, strviewdup(ctx, upb_ServiceDef_Name(s)));
417
+
418
+ size_t n = upb_ServiceDef_MethodCount(s);
419
+ google_protobuf_MethodDescriptorProto** methods =
420
+ google_protobuf_ServiceDescriptorProto_resize_method(proto, n,
421
+ ctx->arena);
422
+ for (int i = 0; i < n; i++) {
423
+ methods[i] = methoddef_toproto(ctx, upb_ServiceDef_Method(s, i));
424
+ }
425
+
426
+ if (upb_ServiceDef_HasOptions(s)) {
427
+ SET_OPTIONS(proto, ServiceDescriptorProto, ServiceOptions,
428
+ upb_ServiceDef_Options(s));
429
+ }
430
+
431
+ return proto;
432
+ }
433
+
434
+ static google_protobuf_FileDescriptorProto* filedef_toproto(
435
+ upb_ToProto_Context* ctx, const upb_FileDef* f) {
436
+ google_protobuf_FileDescriptorProto* proto =
437
+ google_protobuf_FileDescriptorProto_new(ctx->arena);
438
+ CHK_OOM(proto);
439
+
440
+ google_protobuf_FileDescriptorProto_set_name(
441
+ proto, strviewdup(ctx, upb_FileDef_Name(f)));
442
+
443
+ const char* package = upb_FileDef_Package(f);
444
+ if (package) {
445
+ size_t n = strlen(package);
446
+ if (n) {
447
+ google_protobuf_FileDescriptorProto_set_package(
448
+ proto, strviewdup(ctx, upb_FileDef_Package(f)));
449
+ }
450
+ }
451
+
452
+ if (upb_FileDef_Syntax(f) == kUpb_Syntax_Proto3) {
453
+ google_protobuf_FileDescriptorProto_set_syntax(proto,
454
+ strviewdup(ctx, "proto3"));
455
+ }
456
+
457
+ size_t n;
458
+ n = upb_FileDef_DependencyCount(f);
459
+ upb_StringView* deps = google_protobuf_FileDescriptorProto_resize_dependency(
460
+ proto, n, ctx->arena);
461
+ for (int i = 0; i < n; i++) {
462
+ deps[i] = strviewdup(ctx, upb_FileDef_Name(upb_FileDef_Dependency(f, i)));
463
+ }
464
+
465
+ n = upb_FileDef_PublicDependencyCount(f);
466
+ int32_t* public_deps =
467
+ google_protobuf_FileDescriptorProto_resize_public_dependency(proto, n,
468
+ ctx->arena);
469
+ const int32_t* public_dep_nums = _upb_FileDef_PublicDependencyIndexes(f);
470
+ if (n) memcpy(public_deps, public_dep_nums, n * sizeof(int32_t));
471
+
472
+ n = upb_FileDef_WeakDependencyCount(f);
473
+ int32_t* weak_deps =
474
+ google_protobuf_FileDescriptorProto_resize_weak_dependency(proto, n,
475
+ ctx->arena);
476
+ const int32_t* weak_dep_nums = _upb_FileDef_WeakDependencyIndexes(f);
477
+ if (n) memcpy(weak_deps, weak_dep_nums, n * sizeof(int32_t));
478
+
479
+ n = upb_FileDef_TopLevelMessageCount(f);
480
+ google_protobuf_DescriptorProto** msgs =
481
+ google_protobuf_FileDescriptorProto_resize_message_type(proto, n,
482
+ ctx->arena);
483
+ for (int i = 0; i < n; i++) {
484
+ msgs[i] = msgdef_toproto(ctx, upb_FileDef_TopLevelMessage(f, i));
485
+ }
486
+
487
+ n = upb_FileDef_TopLevelEnumCount(f);
488
+ google_protobuf_EnumDescriptorProto** enums =
489
+ google_protobuf_FileDescriptorProto_resize_enum_type(proto, n,
490
+ ctx->arena);
491
+ for (int i = 0; i < n; i++) {
492
+ enums[i] = enumdef_toproto(ctx, upb_FileDef_TopLevelEnum(f, i));
493
+ }
494
+
495
+ n = upb_FileDef_ServiceCount(f);
496
+ google_protobuf_ServiceDescriptorProto** services =
497
+ google_protobuf_FileDescriptorProto_resize_service(proto, n, ctx->arena);
498
+ for (int i = 0; i < n; i++) {
499
+ services[i] = servicedef_toproto(ctx, upb_FileDef_Service(f, i));
500
+ }
501
+
502
+ n = upb_FileDef_TopLevelExtensionCount(f);
503
+ google_protobuf_FieldDescriptorProto** exts =
504
+ google_protobuf_FileDescriptorProto_resize_extension(proto, n,
505
+ ctx->arena);
506
+ for (int i = 0; i < n; i++) {
507
+ exts[i] = fielddef_toproto(ctx, upb_FileDef_TopLevelExtension(f, i));
508
+ }
509
+
510
+ if (upb_FileDef_HasOptions(f)) {
511
+ SET_OPTIONS(proto, FileDescriptorProto, FileOptions,
512
+ upb_FileDef_Options(f));
513
+ }
514
+
515
+ return proto;
516
+ }
517
+
518
+ google_protobuf_DescriptorProto* upb_MessageDef_ToProto(const upb_MessageDef* m,
519
+ upb_Arena* a) {
520
+ upb_ToProto_Context ctx = {a};
521
+ if (UPB_SETJMP(ctx.err)) return NULL;
522
+ return msgdef_toproto(&ctx, m);
523
+ }
524
+
525
+ google_protobuf_EnumDescriptorProto* upb_EnumDef_ToProto(const upb_EnumDef* e,
526
+ upb_Arena* a) {
527
+ upb_ToProto_Context ctx = {a};
528
+ if (UPB_SETJMP(ctx.err)) return NULL;
529
+ return enumdef_toproto(&ctx, e);
530
+ }
531
+
532
+ google_protobuf_EnumValueDescriptorProto* upb_EnumValueDef_ToProto(
533
+ const upb_EnumValueDef* e, upb_Arena* a) {
534
+ upb_ToProto_Context ctx = {a};
535
+ if (UPB_SETJMP(ctx.err)) return NULL;
536
+ return enumvaldef_toproto(&ctx, e);
537
+ }
538
+
539
+ google_protobuf_FieldDescriptorProto* upb_FieldDef_ToProto(
540
+ const upb_FieldDef* f, upb_Arena* a) {
541
+ upb_ToProto_Context ctx = {a};
542
+ if (UPB_SETJMP(ctx.err)) return NULL;
543
+ return fielddef_toproto(&ctx, f);
544
+ }
545
+
546
+ google_protobuf_OneofDescriptorProto* upb_OneofDef_ToProto(
547
+ const upb_OneofDef* o, upb_Arena* a) {
548
+ upb_ToProto_Context ctx = {a};
549
+ if (UPB_SETJMP(ctx.err)) return NULL;
550
+ return oneofdef_toproto(&ctx, o);
551
+ }
552
+
553
+ google_protobuf_FileDescriptorProto* upb_FileDef_ToProto(const upb_FileDef* f,
554
+ upb_Arena* a) {
555
+ upb_ToProto_Context ctx = {a};
556
+ if (UPB_SETJMP(ctx.err)) return NULL;
557
+ return filedef_toproto(&ctx, f);
558
+ }
559
+
560
+ google_protobuf_MethodDescriptorProto* upb_MethodDef_ToProto(
561
+ const upb_MethodDef* m, upb_Arena* a) {
562
+ upb_ToProto_Context ctx = {a};
563
+ if (UPB_SETJMP(ctx.err)) return NULL;
564
+ return methoddef_toproto(&ctx, m);
565
+ }
566
+
567
+ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
568
+ const upb_ServiceDef* s, upb_Arena* a) {
569
+ upb_ToProto_Context ctx = {a};
570
+ if (UPB_SETJMP(ctx.err)) return NULL;
571
+ return servicedef_toproto(&ctx, s);
572
+ }
@@ -0,0 +1,62 @@
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_UTIL_DEF_TO_PROTO_H_
29
+ #define UPB_UTIL_DEF_TO_PROTO_H_
30
+
31
+ #include "upb/def.h"
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ // Functions for converting defs back to the equivalent descriptor proto.
38
+ // Ultimately the goal is that a round-trip proto->def->proto is lossless. Each
39
+ // function returns a new proto created in arena `a`, or NULL if memory
40
+ // allocation failed.
41
+ google_protobuf_DescriptorProto* upb_MessageDef_ToProto(const upb_MessageDef* m,
42
+ upb_Arena* a);
43
+ google_protobuf_EnumDescriptorProto* upb_EnumDef_ToProto(const upb_EnumDef* e,
44
+ upb_Arena* a);
45
+ google_protobuf_EnumValueDescriptorProto* upb_EnumValueDef_ToProto(
46
+ const upb_EnumValueDef* e, upb_Arena* a);
47
+ google_protobuf_FieldDescriptorProto* upb_FieldDef_ToProto(
48
+ const upb_FieldDef* f, upb_Arena* a);
49
+ google_protobuf_OneofDescriptorProto* upb_OneofDef_ToProto(
50
+ const upb_OneofDef* o, upb_Arena* a);
51
+ google_protobuf_FileDescriptorProto* upb_FileDef_ToProto(const upb_FileDef* f,
52
+ upb_Arena* a);
53
+ google_protobuf_MethodDescriptorProto* upb_MethodDef_ToProto(
54
+ const upb_MethodDef* m, upb_Arena* a);
55
+ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
56
+ const upb_ServiceDef* s, upb_Arena* a);
57
+
58
+ #ifdef __cplusplus
59
+ } /* extern "C" */
60
+ #endif
61
+
62
+ #endif /* UPB_UTIL_DEF_TO_PROTO_H_ */
@@ -0,0 +1,32 @@
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
+ syntax = "proto3";
29
+
30
+ package pkg;
31
+
32
+ message PublicImportMessage {}
@@ -0,0 +1,36 @@
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
+ syntax = "proto3";
29
+
30
+ package pkg;
31
+
32
+ message RegularImportMessage {}
33
+
34
+ enum Proto3Enum {
35
+ PROTO3_ENUM_ZERO = 0;
36
+ }