grpc 1.34.0 → 1.35.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (458) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +808 -2787
  3. data/etc/roots.pem +257 -573
  4. data/include/grpc/compression.h +1 -1
  5. data/include/grpc/grpc.h +14 -0
  6. data/include/grpc/grpc_security.h +61 -3
  7. data/include/grpc/impl/codegen/atm_windows.h +4 -0
  8. data/include/grpc/impl/codegen/byte_buffer.h +1 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/log.h +0 -2
  11. data/include/grpc/impl/codegen/sync_windows.h +4 -0
  12. data/include/grpc/slice_buffer.h +3 -3
  13. data/include/grpc/support/sync.h +3 -3
  14. data/include/grpc/support/time.h +7 -7
  15. data/src/core/ext/filters/client_channel/backend_metric.cc +2 -4
  16. data/src/core/ext/filters/client_channel/client_channel.cc +2734 -1498
  17. data/src/core/ext/filters/client_channel/client_channel.h +0 -4
  18. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
  19. data/src/core/ext/filters/client_channel/config_selector.h +4 -0
  20. data/src/core/ext/filters/client_channel/dynamic_filters.cc +186 -0
  21. data/src/core/ext/filters/client_channel/dynamic_filters.h +99 -0
  22. data/src/core/ext/filters/client_channel/health/health_check_client.cc +6 -6
  23. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -2
  24. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +4 -5
  25. data/src/core/ext/filters/client_channel/http_proxy.cc +21 -20
  26. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy.h +2 -3
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +32 -30
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +3 -3
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +162 -20
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +0 -8
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +24 -0
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +5 -2
  35. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +1 -1
  36. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +1262 -0
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +7 -14
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -32
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +454 -16
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -0
  42. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +6 -9
  43. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -2
  44. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +18 -31
  45. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +3 -5
  46. data/src/core/ext/filters/client_channel/resolver_factory.h +6 -6
  47. data/src/core/ext/filters/client_channel/resolver_registry.cc +40 -39
  48. data/src/core/ext/filters/client_channel/resolver_registry.h +2 -2
  49. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +11 -13
  50. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +8 -8
  51. data/src/core/ext/filters/client_channel/retry_throttle.cc +5 -3
  52. data/src/core/ext/filters/client_channel/retry_throttle.h +3 -1
  53. data/src/core/ext/filters/client_channel/service_config_call_data.h +19 -1
  54. data/src/core/ext/filters/client_channel/subchannel.cc +34 -50
  55. data/src/core/ext/filters/client_channel/subchannel.h +12 -18
  56. data/src/core/ext/filters/deadline/deadline_filter.cc +4 -2
  57. data/src/core/ext/filters/http/client_authority_filter.cc +6 -6
  58. data/src/core/ext/filters/http/http_filters_plugin.cc +6 -3
  59. data/src/core/ext/filters/message_size/message_size_filter.cc +1 -1
  60. data/src/core/ext/filters/workarounds/workaround_utils.cc +1 -1
  61. data/src/core/ext/transport/chttp2/client/authority.cc +3 -3
  62. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +20 -8
  63. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +21 -10
  64. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +26 -14
  65. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +178 -86
  66. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +12 -5
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +7 -8
  68. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  69. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  70. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +6 -6
  71. data/src/core/ext/transport/chttp2/transport/writing.cc +1 -1
  72. data/src/core/ext/transport/inproc/inproc_transport.cc +42 -8
  73. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +1 -0
  74. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.c +1 -1
  75. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +7 -0
  76. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +27 -27
  77. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +139 -40
  78. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +13 -13
  79. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +44 -17
  80. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +111 -111
  81. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +424 -241
  82. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.c +3 -3
  83. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +13 -5
  84. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.c +22 -22
  85. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +47 -21
  86. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +21 -21
  87. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +88 -39
  88. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.c +4 -4
  89. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +15 -6
  90. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +44 -44
  91. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +200 -78
  92. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +17 -17
  93. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +72 -35
  94. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +1 -1
  95. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +7 -0
  96. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +7 -7
  97. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +27 -11
  98. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +30 -30
  99. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +136 -49
  100. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +39 -39
  101. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +157 -89
  102. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.c +4 -4
  103. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +17 -9
  104. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +47 -47
  105. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +163 -78
  106. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +1 -1
  107. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +7 -0
  108. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.c +2 -2
  109. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +9 -2
  110. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +1 -1
  111. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +7 -0
  112. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +13 -13
  113. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +59 -36
  114. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +16 -16
  115. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +61 -29
  116. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +26 -26
  117. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +101 -66
  118. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.c +2 -2
  119. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +11 -3
  120. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +28 -28
  121. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +122 -77
  122. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +23 -23
  123. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +106 -54
  124. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +2 -2
  125. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +13 -0
  126. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +16 -16
  127. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +81 -35
  128. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +7 -7
  129. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +38 -22
  130. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +203 -203
  131. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +845 -495
  132. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +5 -5
  133. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +26 -6
  134. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +3 -3
  135. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +17 -3
  136. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +87 -87
  137. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +343 -204
  138. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +1 -0
  139. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +20 -20
  140. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +85 -46
  141. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +7 -7
  142. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +33 -11
  143. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +32 -32
  144. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +118 -67
  145. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.c +1 -1
  146. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +7 -0
  147. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.c +1 -1
  148. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +7 -0
  149. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +29 -29
  150. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +120 -82
  151. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.c +1 -1
  152. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +7 -0
  153. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.c +1 -1
  154. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +7 -0
  155. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +7 -7
  156. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +31 -16
  157. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.c +1 -1
  158. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +7 -0
  159. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.c +1 -1
  160. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +7 -0
  161. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +5 -5
  162. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +25 -11
  163. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +1 -1
  164. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +7 -0
  165. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +1 -1
  166. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +7 -0
  167. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +6 -6
  168. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +29 -8
  169. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +2 -2
  170. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +16 -3
  171. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +3 -3
  172. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +19 -0
  173. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +7 -7
  174. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +46 -3
  175. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +8 -8
  176. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +41 -8
  177. data/src/core/ext/upb-generated/envoy/type/v3/http.upb.h +1 -0
  178. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.c +3 -3
  179. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +15 -2
  180. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.c +3 -3
  181. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +19 -0
  182. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.c +1 -1
  183. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +7 -0
  184. data/src/core/ext/upb-generated/google/api/annotations.upb.h +1 -0
  185. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +34 -34
  186. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +149 -72
  187. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +34 -34
  188. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +142 -59
  189. data/src/core/ext/upb-generated/google/api/http.upb.c +3 -3
  190. data/src/core/ext/upb-generated/google/api/http.upb.h +25 -6
  191. data/src/core/ext/upb-generated/google/protobuf/any.upb.c +1 -1
  192. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +7 -0
  193. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +90 -90
  194. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +455 -292
  195. data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +1 -1
  196. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +7 -0
  197. data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +1 -1
  198. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +7 -0
  199. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +4 -4
  200. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +22 -3
  201. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +1 -1
  202. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +7 -0
  203. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +9 -9
  204. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +55 -0
  205. data/src/core/ext/upb-generated/google/rpc/status.upb.c +1 -1
  206. data/src/core/ext/upb-generated/google/rpc/status.upb.h +10 -3
  207. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +4 -4
  208. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +11 -3
  209. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +41 -41
  210. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +149 -76
  211. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +5 -5
  212. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +21 -6
  213. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +2 -2
  214. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +13 -0
  215. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +17 -17
  216. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +82 -25
  217. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.c +3 -3
  218. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +19 -0
  219. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +1 -1
  220. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +7 -0
  221. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +1 -0
  222. data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +2 -2
  223. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +9 -2
  224. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +1 -1
  225. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +7 -0
  226. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +1 -1
  227. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +7 -0
  228. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +5 -5
  229. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +21 -7
  230. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +2 -2
  231. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +7 -0
  232. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +4 -4
  233. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +17 -8
  234. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +7 -7
  235. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +31 -18
  236. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +5 -5
  237. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +19 -11
  238. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +3 -3
  239. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +7 -0
  240. data/src/core/ext/upb-generated/validate/validate.upb.c +64 -64
  241. data/src/core/ext/upb-generated/validate/validate.upb.h +296 -157
  242. data/src/core/ext/xds/certificate_provider_store.cc +10 -7
  243. data/src/core/ext/xds/certificate_provider_store.h +12 -7
  244. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +25 -0
  245. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -4
  246. data/src/core/ext/xds/xds_api.cc +220 -31
  247. data/src/core/ext/xds/xds_api.h +41 -10
  248. data/src/core/ext/xds/xds_bootstrap.h +0 -1
  249. data/src/core/ext/xds/xds_certificate_provider.cc +61 -2
  250. data/src/core/ext/xds/xds_certificate_provider.h +40 -2
  251. data/src/core/ext/xds/xds_client.cc +31 -29
  252. data/src/core/ext/xds/xds_client.h +6 -1
  253. data/src/core/ext/xds/xds_client_stats.cc +2 -2
  254. data/src/core/ext/xds/xds_server_config_fetcher.cc +131 -0
  255. data/src/core/lib/channel/channel_args.cc +8 -8
  256. data/src/core/lib/channel/channel_trace.h +1 -1
  257. data/src/core/lib/channel/channelz.cc +13 -14
  258. data/src/core/lib/channel/channelz.h +0 -1
  259. data/src/core/lib/channel/channelz_registry.h +0 -1
  260. data/src/core/lib/channel/handshaker.cc +2 -2
  261. data/src/core/lib/compression/compression_args.cc +3 -2
  262. data/src/core/lib/debug/stats.h +2 -2
  263. data/src/core/lib/debug/stats_data.h +13 -13
  264. data/src/core/lib/gpr/alloc.cc +3 -2
  265. data/src/core/lib/gpr/log.cc +53 -16
  266. data/src/core/lib/gpr/log_linux.cc +3 -1
  267. data/src/core/lib/gpr/log_posix.cc +3 -1
  268. data/src/core/lib/gpr/log_windows.cc +3 -1
  269. data/src/core/lib/gpr/spinlock.h +10 -2
  270. data/src/core/lib/gpr/string.cc +22 -21
  271. data/src/core/lib/gpr/string.h +5 -6
  272. data/src/core/lib/gpr/sync.cc +4 -4
  273. data/src/core/lib/gpr/time.cc +12 -12
  274. data/src/core/lib/gprpp/arena.h +3 -2
  275. data/src/core/lib/gprpp/ref_counted.h +2 -2
  276. data/src/core/lib/gprpp/ref_counted_ptr.h +9 -1
  277. data/src/core/lib/gprpp/thd_posix.cc +6 -1
  278. data/src/core/lib/gprpp/thd_windows.cc +3 -1
  279. data/src/core/lib/http/httpcli.cc +1 -1
  280. data/src/core/lib/http/httpcli.h +2 -3
  281. data/src/core/lib/http/httpcli_security_connector.cc +1 -1
  282. data/src/core/lib/http/parser.cc +1 -2
  283. data/src/core/lib/iomgr/call_combiner.cc +8 -5
  284. data/src/core/lib/iomgr/combiner.cc +2 -1
  285. data/src/core/lib/iomgr/endpoint.h +1 -1
  286. data/src/core/lib/iomgr/error.cc +15 -11
  287. data/src/core/lib/iomgr/error_internal.h +1 -1
  288. data/src/core/lib/iomgr/ev_epoll1_linux.cc +20 -13
  289. data/src/core/lib/iomgr/ev_epollex_linux.cc +17 -13
  290. data/src/core/lib/iomgr/ev_poll_posix.cc +9 -7
  291. data/src/core/lib/iomgr/exec_ctx.h +6 -4
  292. data/src/core/lib/iomgr/executor.cc +2 -1
  293. data/src/core/lib/iomgr/executor.h +1 -1
  294. data/src/core/lib/iomgr/executor/threadpool.h +1 -1
  295. data/src/core/lib/iomgr/iomgr.cc +1 -1
  296. data/src/core/lib/iomgr/load_file.h +1 -1
  297. data/src/core/lib/iomgr/lockfree_event.cc +19 -14
  298. data/src/core/lib/iomgr/lockfree_event.h +2 -2
  299. data/src/core/lib/iomgr/parse_address.cc +52 -46
  300. data/src/core/lib/iomgr/parse_address.h +13 -9
  301. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +1 -1
  302. data/src/core/lib/iomgr/pollset_set_custom.cc +1 -1
  303. data/src/core/lib/iomgr/python_util.h +1 -1
  304. data/src/core/lib/iomgr/resolve_address.cc +4 -4
  305. data/src/core/lib/iomgr/resource_quota.cc +4 -4
  306. data/src/core/lib/iomgr/sockaddr_utils.cc +10 -10
  307. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  308. data/src/core/lib/iomgr/socket_factory_posix.cc +3 -2
  309. data/src/core/lib/iomgr/socket_mutator.cc +3 -2
  310. data/src/core/lib/iomgr/tcp_client.cc +3 -3
  311. data/src/core/lib/iomgr/tcp_client_custom.cc +7 -6
  312. data/src/core/lib/iomgr/tcp_custom.cc +22 -17
  313. data/src/core/lib/iomgr/tcp_posix.cc +9 -6
  314. data/src/core/lib/iomgr/tcp_server_custom.cc +28 -22
  315. data/src/core/lib/iomgr/timer_custom.cc +3 -3
  316. data/src/core/lib/iomgr/timer_generic.cc +3 -3
  317. data/src/core/lib/iomgr/timer_manager.cc +2 -2
  318. data/src/core/lib/iomgr/udp_server.cc +1 -2
  319. data/src/core/lib/iomgr/udp_server.h +1 -2
  320. data/src/core/lib/iomgr/unix_sockets_posix.cc +17 -18
  321. data/src/core/lib/json/json.h +10 -0
  322. data/src/core/lib/security/authorization/evaluate_args.cc +5 -10
  323. data/src/core/lib/security/authorization/evaluate_args.h +1 -1
  324. data/src/core/lib/security/context/security_context.cc +4 -3
  325. data/src/core/lib/security/credentials/alts/check_gcp_environment.cc +1 -1
  326. data/src/core/lib/security/credentials/credentials.cc +6 -6
  327. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +413 -0
  328. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +80 -0
  329. data/src/core/lib/security/credentials/external/aws_request_signer.cc +15 -10
  330. data/src/core/lib/security/credentials/external/aws_request_signer.h +1 -2
  331. data/src/core/lib/security/credentials/external/external_account_credentials.cc +217 -31
  332. data/src/core/lib/security/credentials/external/external_account_credentials.h +7 -5
  333. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +5 -6
  334. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +3 -4
  335. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +20 -18
  336. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +5 -6
  337. data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -1
  338. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +18 -12
  339. data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +18 -5
  340. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  341. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -3
  342. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +37 -44
  343. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +5 -4
  344. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  345. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +5 -5
  346. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +1 -1
  347. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +1 -6
  348. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +1 -6
  349. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +326 -5
  350. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +64 -0
  351. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +1 -1
  352. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +0 -1
  353. data/src/core/lib/security/credentials/tls/tls_credentials.cc +1 -1
  354. data/src/core/lib/security/credentials/tls/tls_utils.cc +91 -0
  355. data/src/core/lib/security/credentials/tls/tls_utils.h +38 -0
  356. data/src/core/lib/security/credentials/xds/xds_credentials.cc +140 -10
  357. data/src/core/lib/security/credentials/xds/xds_credentials.h +27 -9
  358. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +1 -1
  359. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -1
  360. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +46 -13
  361. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +23 -6
  362. data/src/core/lib/security/security_connector/local/local_security_connector.cc +1 -1
  363. data/src/core/lib/security/security_connector/security_connector.cc +3 -2
  364. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -4
  365. data/src/core/lib/security/security_connector/ssl_utils.cc +2 -2
  366. data/src/core/lib/security/security_connector/ssl_utils.h +12 -19
  367. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +57 -12
  368. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +2 -3
  369. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  370. data/src/core/lib/security/transport/security_handshaker.cc +2 -2
  371. data/src/core/lib/slice/slice_intern.cc +4 -5
  372. data/src/core/lib/slice/slice_internal.h +2 -2
  373. data/src/core/lib/surface/call.cc +32 -24
  374. data/src/core/lib/surface/call_details.cc +8 -8
  375. data/src/core/lib/surface/channel.cc +16 -10
  376. data/src/core/lib/surface/channel.h +3 -2
  377. data/src/core/lib/surface/channel_init.cc +1 -1
  378. data/src/core/lib/surface/completion_queue.cc +23 -18
  379. data/src/core/lib/surface/completion_queue.h +16 -16
  380. data/src/core/lib/surface/init.cc +6 -5
  381. data/src/core/lib/surface/lame_client.cc +20 -46
  382. data/src/core/lib/surface/lame_client.h +4 -0
  383. data/src/core/lib/surface/server.cc +59 -15
  384. data/src/core/lib/surface/server.h +37 -5
  385. data/src/core/lib/surface/version.cc +1 -1
  386. data/src/core/lib/transport/authority_override.cc +6 -4
  387. data/src/core/lib/transport/authority_override.h +5 -2
  388. data/src/core/lib/transport/connectivity_state.h +6 -4
  389. data/src/core/lib/transport/error_utils.h +1 -1
  390. data/src/core/lib/transport/metadata_batch.h +4 -4
  391. data/src/core/lib/transport/static_metadata.cc +1 -1
  392. data/src/core/lib/transport/status_metadata.cc +4 -3
  393. data/src/core/lib/transport/transport.h +7 -7
  394. data/src/core/lib/uri/uri_parser.cc +131 -249
  395. data/src/core/lib/uri/uri_parser.h +57 -21
  396. data/src/core/plugin_registry/grpc_plugin_registry.cc +10 -4
  397. data/src/core/tsi/alts/crypt/gsec.cc +5 -4
  398. data/src/core/tsi/alts/frame_protector/frame_handler.cc +8 -6
  399. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
  400. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +23 -23
  401. data/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +8 -6
  402. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +4 -4
  403. data/src/core/tsi/fake_transport_security.cc +5 -3
  404. data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +1 -1
  405. data/src/core/tsi/ssl_transport_security.cc +62 -49
  406. data/src/core/tsi/ssl_transport_security.h +6 -6
  407. data/src/core/tsi/transport_security.cc +6 -6
  408. data/src/core/tsi/transport_security_interface.h +1 -1
  409. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  410. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -0
  411. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +31 -13
  412. data/src/ruby/lib/grpc/version.rb +1 -1
  413. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +28 -0
  414. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +18 -0
  415. data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -6
  416. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +606 -0
  417. data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +197 -0
  418. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +399 -0
  419. data/third_party/abseil-cpp/absl/status/statusor.cc +71 -0
  420. data/third_party/abseil-cpp/absl/status/statusor.h +760 -0
  421. data/third_party/upb/third_party/wyhash/wyhash.h +145 -0
  422. data/third_party/upb/upb/decode.c +248 -167
  423. data/third_party/upb/upb/decode.h +20 -1
  424. data/third_party/upb/upb/decode.int.h +163 -0
  425. data/third_party/upb/upb/decode_fast.c +1040 -0
  426. data/third_party/upb/upb/decode_fast.h +126 -0
  427. data/third_party/upb/upb/def.c +525 -516
  428. data/third_party/upb/upb/def.h +16 -31
  429. data/third_party/upb/upb/def.hpp +37 -123
  430. data/third_party/upb/upb/encode.c +227 -169
  431. data/third_party/upb/upb/encode.h +27 -2
  432. data/third_party/upb/upb/json_decode.c +1443 -0
  433. data/third_party/upb/upb/json_decode.h +23 -0
  434. data/third_party/upb/upb/json_encode.c +713 -0
  435. data/third_party/upb/upb/json_encode.h +36 -0
  436. data/third_party/upb/upb/msg.c +167 -88
  437. data/third_party/upb/upb/msg.h +174 -34
  438. data/third_party/upb/upb/port_def.inc +74 -61
  439. data/third_party/upb/upb/port_undef.inc +3 -7
  440. data/third_party/upb/upb/reflection.c +36 -19
  441. data/third_party/upb/upb/table.c +34 -197
  442. data/third_party/upb/upb/table.int.h +14 -5
  443. data/third_party/upb/upb/text_encode.c +45 -22
  444. data/third_party/upb/upb/text_encode.h +4 -1
  445. data/third_party/upb/upb/upb.c +18 -41
  446. data/third_party/upb/upb/upb.h +36 -7
  447. data/third_party/upb/upb/upb.hpp +4 -4
  448. data/third_party/upb/upb/upb.int.h +29 -0
  449. metadata +60 -46
  450. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +0 -909
  451. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +0 -485
  452. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +0 -68
  453. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +0 -355
  454. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +0 -138
  455. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +0 -265
  456. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +0 -104
  457. data/src/core/lib/gprpp/map.h +0 -53
  458. data/third_party/upb/upb/port.c +0 -26
@@ -0,0 +1,126 @@
1
+ // These are the specialized field parser functions for the fast parser.
2
+ // Generated tables will refer to these by name.
3
+ //
4
+ // The function names are encoded with names like:
5
+ //
6
+ // // 123 4
7
+ // upb_pss_1bt(); // Parse singular string, 1 byte tag.
8
+ //
9
+ // In position 1:
10
+ // - 'p' for parse, most function use this
11
+ // - 'c' for copy, for when we are copying strings instead of aliasing
12
+ //
13
+ // In position 2 (cardinality):
14
+ // - 's' for singular, with or without hasbit
15
+ // - 'o' for oneof
16
+ // - 'r' for non-packed repeated
17
+ // - 'p' for packed repeated
18
+ //
19
+ // In position 3 (type):
20
+ // - 'b1' for bool
21
+ // - 'v4' for 4-byte varint
22
+ // - 'v8' for 8-byte varint
23
+ // - 'z4' for zig-zag-encoded 4-byte varint
24
+ // - 'z8' for zig-zag-encoded 8-byte varint
25
+ // - 'f4' for 4-byte fixed
26
+ // - 'f8' for 8-byte fixed
27
+ // - 'm' for sub-message
28
+ // - 's' for string (validate UTF-8)
29
+ // - 'b' for bytes
30
+ //
31
+ // In position 4 (tag length):
32
+ // - '1' for one-byte tags (field numbers 1-15)
33
+ // - '2' for two-byte tags (field numbers 16-2048)
34
+
35
+ #ifndef UPB_DECODE_FAST_H_
36
+ #define UPB_DECODE_FAST_H_
37
+
38
+ #include "upb/msg.h"
39
+
40
+ struct upb_decstate;
41
+
42
+ // The fallback, generic parsing function that can handle any field type.
43
+ // This just uses the regular (non-fast) parser to parse a single field.
44
+ const char *fastdecode_generic(struct upb_decstate *d, const char *ptr,
45
+ upb_msg *msg, intptr_t table, uint64_t hasbits,
46
+ uint64_t data);
47
+
48
+ #define UPB_PARSE_PARAMS \
49
+ struct upb_decstate *d, const char *ptr, upb_msg *msg, intptr_t table, \
50
+ uint64_t hasbits, uint64_t data
51
+
52
+ /* primitive fields ***********************************************************/
53
+
54
+ #define F(card, type, valbytes, tagbytes) \
55
+ const char *upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS);
56
+
57
+ #define TYPES(card, tagbytes) \
58
+ F(card, b, 1, tagbytes) \
59
+ F(card, v, 4, tagbytes) \
60
+ F(card, v, 8, tagbytes) \
61
+ F(card, z, 4, tagbytes) \
62
+ F(card, z, 8, tagbytes) \
63
+ F(card, f, 4, tagbytes) \
64
+ F(card, f, 8, tagbytes)
65
+
66
+ #define TAGBYTES(card) \
67
+ TYPES(card, 1) \
68
+ TYPES(card, 2)
69
+
70
+ TAGBYTES(s)
71
+ TAGBYTES(o)
72
+ TAGBYTES(r)
73
+ TAGBYTES(p)
74
+
75
+ #undef F
76
+ #undef TYPES
77
+ #undef TAGBYTES
78
+
79
+ /* string fields **************************************************************/
80
+
81
+ #define F(card, tagbytes, type) \
82
+ const char *upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \
83
+ const char *upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS);
84
+
85
+ #define UTF8(card, tagbytes) \
86
+ F(card, tagbytes, s) \
87
+ F(card, tagbytes, b)
88
+
89
+ #define TAGBYTES(card) \
90
+ UTF8(card, 1) \
91
+ UTF8(card, 2)
92
+
93
+ TAGBYTES(s)
94
+ TAGBYTES(o)
95
+ TAGBYTES(r)
96
+
97
+ #undef F
98
+ #undef TAGBYTES
99
+
100
+ /* sub-message fields *********************************************************/
101
+
102
+ #define F(card, tagbytes, size_ceil, ceil_arg) \
103
+ const char *upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS);
104
+
105
+ #define SIZES(card, tagbytes) \
106
+ F(card, tagbytes, 64, 64) \
107
+ F(card, tagbytes, 128, 128) \
108
+ F(card, tagbytes, 192, 192) \
109
+ F(card, tagbytes, 256, 256) \
110
+ F(card, tagbytes, max, -1)
111
+
112
+ #define TAGBYTES(card) \
113
+ SIZES(card, 1) \
114
+ SIZES(card, 2)
115
+
116
+ TAGBYTES(s)
117
+ TAGBYTES(o)
118
+ TAGBYTES(r)
119
+
120
+ #undef TAGBYTES
121
+ #undef SIZES
122
+ #undef F
123
+
124
+ #undef UPB_PARSE_PARAMS
125
+
126
+ #endif /* UPB_DECODE_FAST_H_ */
@@ -3,10 +3,11 @@
3
3
 
4
4
  #include <ctype.h>
5
5
  #include <errno.h>
6
+ #include <setjmp.h>
6
7
  #include <stdlib.h>
7
8
  #include <string.h>
8
- #include "google/protobuf/descriptor.upb.h"
9
9
 
10
+ #include "google/protobuf/descriptor.upb.h"
10
11
  #include "upb/port_def.inc"
11
12
 
12
13
  typedef struct {
@@ -14,15 +15,6 @@ typedef struct {
14
15
  char str[1]; /* Null-terminated string data follows. */
15
16
  } str_t;
16
17
 
17
- static str_t *newstr(upb_alloc *alloc, const char *data, size_t len) {
18
- str_t *ret = upb_malloc(alloc, sizeof(*ret) + len);
19
- if (!ret) return NULL;
20
- ret->len = len;
21
- if (len) memcpy(ret->str, data, len);
22
- ret->str[len] = '\0';
23
- return ret;
24
- }
25
-
26
18
  struct upb_fielddef {
27
19
  const upb_filedef *file;
28
20
  const upb_msgdef *msgdef;
@@ -89,7 +81,9 @@ struct upb_enumdef {
89
81
  struct upb_oneofdef {
90
82
  const upb_msgdef *parent;
91
83
  const char *full_name;
92
- uint32_t index;
84
+ int field_count;
85
+ bool synthetic;
86
+ const upb_fielddef **fields;
93
87
  upb_strtable ntof;
94
88
  upb_inttable itof;
95
89
  };
@@ -99,23 +93,25 @@ struct upb_filedef {
99
93
  const char *package;
100
94
  const char *phpprefix;
101
95
  const char *phpnamespace;
102
- upb_syntax_t syntax;
103
96
 
104
97
  const upb_filedef **deps;
105
98
  const upb_msgdef *msgs;
106
99
  const upb_enumdef *enums;
107
100
  const upb_fielddef *exts;
101
+ const upb_symtab *symtab;
108
102
 
109
103
  int dep_count;
110
104
  int msg_count;
111
105
  int enum_count;
112
106
  int ext_count;
107
+ upb_syntax_t syntax;
113
108
  };
114
109
 
115
110
  struct upb_symtab {
116
111
  upb_arena *arena;
117
112
  upb_strtable syms; /* full_name -> packed def ptr */
118
113
  upb_strtable files; /* file_name -> upb_filedef* */
114
+ size_t bytes_loaded;
119
115
  };
120
116
 
121
117
  /* Inside a symtab we store tagged pointers to specific def types. */
@@ -154,38 +150,6 @@ static bool upb_isalphanum(char c) {
154
150
  return upb_isletter(c) || upb_isbetween(c, '0', '9');
155
151
  }
156
152
 
157
- static bool upb_isident(upb_strview name, bool full, upb_status *s) {
158
- const char *str = name.data;
159
- size_t len = name.size;
160
- bool start = true;
161
- size_t i;
162
- for (i = 0; i < len; i++) {
163
- char c = str[i];
164
- if (c == '.') {
165
- if (start || !full) {
166
- upb_status_seterrf(s, "invalid name: unexpected '.' (%s)", str);
167
- return false;
168
- }
169
- start = true;
170
- } else if (start) {
171
- if (!upb_isletter(c)) {
172
- upb_status_seterrf(
173
- s, "invalid name: path components must start with a letter (%s)",
174
- str);
175
- return false;
176
- }
177
- start = false;
178
- } else {
179
- if (!upb_isalphanum(c)) {
180
- upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)",
181
- str);
182
- return false;
183
- }
184
- }
185
- }
186
- return !start;
187
- }
188
-
189
153
  static const char *shortdefname(const char *fullname) {
190
154
  const char *p;
191
155
 
@@ -245,85 +209,6 @@ static void upb_status_setoom(upb_status *status) {
245
209
  upb_status_seterrmsg(status, "out of memory");
246
210
  }
247
211
 
248
- static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
249
- /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the
250
- * lowest indexes, but we do not publicly guarantee this. */
251
- upb_msg_field_iter j;
252
- int i;
253
- uint32_t selector;
254
- int n = upb_msgdef_numfields(m);
255
- upb_fielddef **fields;
256
-
257
- if (n == 0) {
258
- m->selector_count = UPB_STATIC_SELECTOR_COUNT;
259
- m->submsg_field_count = 0;
260
- return true;
261
- }
262
-
263
- fields = upb_gmalloc(n * sizeof(*fields));
264
- if (!fields) {
265
- upb_status_setoom(s);
266
- return false;
267
- }
268
-
269
- m->submsg_field_count = 0;
270
- for(i = 0, upb_msg_field_begin(&j, m);
271
- !upb_msg_field_done(&j);
272
- upb_msg_field_next(&j), i++) {
273
- upb_fielddef *f = upb_msg_iter_field(&j);
274
- UPB_ASSERT(f->msgdef == m);
275
- if (upb_fielddef_issubmsg(f)) {
276
- m->submsg_field_count++;
277
- }
278
- fields[i] = f;
279
- }
280
-
281
- qsort(fields, n, sizeof(*fields), cmp_fields);
282
-
283
- selector = UPB_STATIC_SELECTOR_COUNT + m->submsg_field_count;
284
- for (i = 0; i < n; i++) {
285
- upb_fielddef *f = fields[i];
286
- f->index_ = i;
287
- f->selector_base = selector + upb_handlers_selectorbaseoffset(f);
288
- selector += upb_handlers_selectorcount(f);
289
- }
290
- m->selector_count = selector;
291
-
292
- upb_gfree(fields);
293
- return true;
294
- }
295
-
296
- static bool check_oneofs(upb_msgdef *m, upb_status *s) {
297
- int i;
298
- int first_synthetic = -1;
299
- upb_oneofdef *mutable_oneofs = (upb_oneofdef*)m->oneofs;
300
-
301
- for (i = 0; i < m->oneof_count; i++) {
302
- mutable_oneofs[i].index = i;
303
-
304
- if (upb_oneofdef_issynthetic(&mutable_oneofs[i])) {
305
- if (first_synthetic == -1) {
306
- first_synthetic = i;
307
- }
308
- } else {
309
- if (first_synthetic != -1) {
310
- upb_status_seterrf(
311
- s, "Synthetic oneofs must be after all other oneofs: %s",
312
- upb_oneofdef_name(&mutable_oneofs[i]));
313
- return false;
314
- }
315
- }
316
- }
317
-
318
- if (first_synthetic == -1) {
319
- m->real_oneof_count = m->oneof_count;
320
- } else {
321
- m->real_oneof_count = first_synthetic;
322
- }
323
-
324
- return true;
325
- }
326
-
327
212
  static void assign_msg_wellknowntype(upb_msgdef *m) {
328
213
  const char *name = upb_msgdef_fullname(m);
329
214
  if (name == NULL) {
@@ -726,15 +611,32 @@ int upb_msgdef_numrealoneofs(const upb_msgdef *m) {
726
611
  return m->real_oneof_count;
727
612
  }
728
613
 
614
+ int upb_msgdef_fieldcount(const upb_msgdef *m) {
615
+ return m->field_count;
616
+ }
617
+
618
+ int upb_msgdef_oneofcount(const upb_msgdef *m) {
619
+ return m->oneof_count;
620
+ }
621
+
622
+ int upb_msgdef_realoneofcount(const upb_msgdef *m) {
623
+ return m->real_oneof_count;
624
+ }
625
+
729
626
  const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m) {
730
627
  return m->layout;
731
628
  }
732
629
 
733
- const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i) {
734
- if (i >= m->field_count) return NULL;
630
+ const upb_fielddef *upb_msgdef_field(const upb_msgdef *m, int i) {
631
+ UPB_ASSERT(i >= 0 && i < m->field_count);
735
632
  return &m->fields[i];
736
633
  }
737
634
 
635
+ const upb_oneofdef *upb_msgdef_oneof(const upb_msgdef *m, int i) {
636
+ UPB_ASSERT(i >= 0 && i < m->oneof_count);
637
+ return &m->oneofs[i];
638
+ }
639
+
738
640
  bool upb_msgdef_mapentry(const upb_msgdef *m) {
739
641
  return m->map_entry;
740
642
  }
@@ -822,22 +724,25 @@ const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) {
822
724
  return o->parent;
823
725
  }
824
726
 
727
+ int upb_oneofdef_fieldcount(const upb_oneofdef *o) {
728
+ return o->field_count;
729
+ }
730
+
731
+ const upb_fielddef *upb_oneofdef_field(const upb_oneofdef *o, int i) {
732
+ UPB_ASSERT(i < o->field_count);
733
+ return o->fields[i];
734
+ }
735
+
825
736
  int upb_oneofdef_numfields(const upb_oneofdef *o) {
826
- return (int)upb_strtable_count(&o->ntof);
737
+ return o->field_count;
827
738
  }
828
739
 
829
740
  uint32_t upb_oneofdef_index(const upb_oneofdef *o) {
830
- return o->index;
741
+ return o - o->parent->oneofs;
831
742
  }
832
743
 
833
744
  bool upb_oneofdef_issynthetic(const upb_oneofdef *o) {
834
- upb_inttable_iter iter;
835
- const upb_fielddef *f;
836
- upb_inttable_begin(&iter, &o->itof);
837
- if (upb_oneofdef_numfields(o) != 1) return false;
838
- f = upb_value_getptr(upb_inttable_iter_value(&iter));
839
- UPB_ASSERT(f);
840
- return f->proto3_optional_;
745
+ return o->synthetic;
841
746
  }
842
747
 
843
748
  const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
@@ -873,7 +778,189 @@ void upb_oneof_iter_setdone(upb_oneof_iter *iter) {
873
778
  upb_inttable_iter_setdone(iter);
874
779
  }
875
780
 
876
- /* Dynamic Layout Generation. *************************************************/
781
+ /* upb_filedef ****************************************************************/
782
+
783
+ const char *upb_filedef_name(const upb_filedef *f) {
784
+ return f->name;
785
+ }
786
+
787
+ const char *upb_filedef_package(const upb_filedef *f) {
788
+ return f->package;
789
+ }
790
+
791
+ const char *upb_filedef_phpprefix(const upb_filedef *f) {
792
+ return f->phpprefix;
793
+ }
794
+
795
+ const char *upb_filedef_phpnamespace(const upb_filedef *f) {
796
+ return f->phpnamespace;
797
+ }
798
+
799
+ upb_syntax_t upb_filedef_syntax(const upb_filedef *f) {
800
+ return f->syntax;
801
+ }
802
+
803
+ int upb_filedef_msgcount(const upb_filedef *f) {
804
+ return f->msg_count;
805
+ }
806
+
807
+ int upb_filedef_depcount(const upb_filedef *f) {
808
+ return f->dep_count;
809
+ }
810
+
811
+ int upb_filedef_enumcount(const upb_filedef *f) {
812
+ return f->enum_count;
813
+ }
814
+
815
+ const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i) {
816
+ return i < 0 || i >= f->dep_count ? NULL : f->deps[i];
817
+ }
818
+
819
+ const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i) {
820
+ return i < 0 || i >= f->msg_count ? NULL : &f->msgs[i];
821
+ }
822
+
823
+ const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i) {
824
+ return i < 0 || i >= f->enum_count ? NULL : &f->enums[i];
825
+ }
826
+
827
+ const upb_symtab *upb_filedef_symtab(const upb_filedef *f) {
828
+ return f->symtab;
829
+ }
830
+
831
+ void upb_symtab_free(upb_symtab *s) {
832
+ upb_arena_free(s->arena);
833
+ upb_gfree(s);
834
+ }
835
+
836
+ upb_symtab *upb_symtab_new(void) {
837
+ upb_symtab *s = upb_gmalloc(sizeof(*s));
838
+ upb_alloc *alloc;
839
+
840
+ if (!s) {
841
+ return NULL;
842
+ }
843
+
844
+ s->arena = upb_arena_new();
845
+ s->bytes_loaded = 0;
846
+ alloc = upb_arena_alloc(s->arena);
847
+
848
+ if (!upb_strtable_init2(&s->syms, UPB_CTYPE_CONSTPTR, 32, alloc) ||
849
+ !upb_strtable_init2(&s->files, UPB_CTYPE_CONSTPTR, 4, alloc)) {
850
+ upb_arena_free(s->arena);
851
+ upb_gfree(s);
852
+ s = NULL;
853
+ }
854
+ return s;
855
+ }
856
+
857
+ const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) {
858
+ upb_value v;
859
+ return upb_strtable_lookup(&s->syms, sym, &v) ?
860
+ unpack_def(v, UPB_DEFTYPE_MSG) : NULL;
861
+ }
862
+
863
+ const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym,
864
+ size_t len) {
865
+ upb_value v;
866
+ return upb_strtable_lookup2(&s->syms, sym, len, &v) ?
867
+ unpack_def(v, UPB_DEFTYPE_MSG) : NULL;
868
+ }
869
+
870
+ const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) {
871
+ upb_value v;
872
+ return upb_strtable_lookup(&s->syms, sym, &v) ?
873
+ unpack_def(v, UPB_DEFTYPE_ENUM) : NULL;
874
+ }
875
+
876
+ const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name) {
877
+ upb_value v;
878
+ return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v)
879
+ : NULL;
880
+ }
881
+
882
+ const upb_filedef *upb_symtab_lookupfile2(
883
+ const upb_symtab *s, const char *name, size_t len) {
884
+ upb_value v;
885
+ return upb_strtable_lookup2(&s->files, name, len, &v) ?
886
+ upb_value_getconstptr(v) : NULL;
887
+ }
888
+
889
+ int upb_symtab_filecount(const upb_symtab *s) {
890
+ return (int)upb_strtable_count(&s->files);
891
+ }
892
+
893
+ /* Code to build defs from descriptor protos. *********************************/
894
+
895
+ /* There is a question of how much validation to do here. It will be difficult
896
+ * to perfectly match the amount of validation performed by proto2. But since
897
+ * this code is used to directly build defs from Ruby (for example) we do need
898
+ * to validate important constraints like uniqueness of names and numbers. */
899
+
900
+ #define CHK_OOM(x) if (!(x)) { symtab_oomerr(ctx); }
901
+
902
+ typedef struct {
903
+ upb_symtab *symtab;
904
+ upb_filedef *file; /* File we are building. */
905
+ upb_arena *file_arena; /* Allocate defs here. */
906
+ upb_alloc *alloc; /* Alloc of file_arena, for tables. */
907
+ const upb_msglayout **layouts; /* NULL if we should build layouts. */
908
+ upb_status *status; /* Record errors here. */
909
+ jmp_buf err; /* longjmp() on error. */
910
+ } symtab_addctx;
911
+
912
+ UPB_NORETURN UPB_NOINLINE
913
+ static void symtab_errf(symtab_addctx *ctx, const char *fmt, ...) {
914
+ va_list argp;
915
+ va_start(argp, fmt);
916
+ upb_status_vseterrf(ctx->status, fmt, argp);
917
+ va_end(argp);
918
+ UPB_LONGJMP(ctx->err, 1);
919
+ }
920
+
921
+ UPB_NORETURN UPB_NOINLINE
922
+ static void symtab_oomerr(symtab_addctx *ctx) {
923
+ upb_status_setoom(ctx->status);
924
+ UPB_LONGJMP(ctx->err, 1);
925
+ }
926
+
927
+ void *symtab_alloc(symtab_addctx *ctx, size_t bytes) {
928
+ void *ret = upb_arena_malloc(ctx->file_arena, bytes);
929
+ if (!ret) symtab_oomerr(ctx);
930
+ return ret;
931
+ }
932
+
933
+ static void check_ident(symtab_addctx *ctx, upb_strview name, bool full) {
934
+ const char *str = name.data;
935
+ size_t len = name.size;
936
+ bool start = true;
937
+ size_t i;
938
+ for (i = 0; i < len; i++) {
939
+ char c = str[i];
940
+ if (c == '.') {
941
+ if (start || !full) {
942
+ symtab_errf(ctx, "invalid name: unexpected '.' (%.*s)", (int)len, str);
943
+ }
944
+ start = true;
945
+ } else if (start) {
946
+ if (!upb_isletter(c)) {
947
+ symtab_errf(
948
+ ctx,
949
+ "invalid name: path components must start with a letter (%.*s)",
950
+ (int)len, str);
951
+ }
952
+ start = false;
953
+ } else {
954
+ if (!upb_isalphanum(c)) {
955
+ symtab_errf(ctx, "invalid name: non-alphanumeric character (%.*s)",
956
+ (int)len, str);
957
+ }
958
+ }
959
+ }
960
+ if (start) {
961
+ symtab_errf(ctx, "invalid name: empty part (%.*s)", (int)len, str);
962
+ }
963
+ }
877
964
 
878
965
  static size_t div_round_up(size_t n, size_t d) {
879
966
  return (n + d - 1) / d;
@@ -940,7 +1027,7 @@ static void assign_layout_indices(const upb_msgdef *m, upb_msglayout_field *fiel
940
1027
 
941
1028
  /* This function is the dynamic equivalent of message_layout.{cc,h} in upbc.
942
1029
  * It computes a dynamic layout for all of the fields in |m|. */
943
- static bool make_layout(const upb_symtab *symtab, const upb_msgdef *m) {
1030
+ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) {
944
1031
  upb_msglayout *l = (upb_msglayout*)m->layout;
945
1032
  upb_msg_field_iter it;
946
1033
  upb_msg_oneof_iter oit;
@@ -948,22 +1035,21 @@ static bool make_layout(const upb_symtab *symtab, const upb_msgdef *m) {
948
1035
  size_t submsg_count = m->submsg_field_count;
949
1036
  const upb_msglayout **submsgs;
950
1037
  upb_msglayout_field *fields;
951
- upb_alloc *alloc = upb_arena_alloc(symtab->arena);
952
1038
 
953
- memset(l, 0, sizeof(*l));
1039
+ memset(l, 0, sizeof(*l) + sizeof(_upb_fasttable_entry));
954
1040
 
955
- fields = upb_malloc(alloc, upb_msgdef_numfields(m) * sizeof(*fields));
956
- submsgs = upb_malloc(alloc, submsg_count * sizeof(*submsgs));
957
-
958
- if ((!fields && upb_msgdef_numfields(m)) ||
959
- (!submsgs && submsg_count)) {
960
- /* OOM. */
961
- return false;
962
- }
1041
+ fields = symtab_alloc(ctx, upb_msgdef_numfields(m) * sizeof(*fields));
1042
+ submsgs = symtab_alloc(ctx, submsg_count * sizeof(*submsgs));
963
1043
 
964
1044
  l->field_count = upb_msgdef_numfields(m);
965
1045
  l->fields = fields;
966
1046
  l->submsgs = submsgs;
1047
+ l->table_mask = 0;
1048
+
1049
+ /* TODO(haberman): initialize fast tables so that reflection-based parsing
1050
+ * can get the same speeds as linked-in types. */
1051
+ l->fasttable[0].field_parser = &fastdecode_generic;
1052
+ l->fasttable[0].field_data = 0;
967
1053
 
968
1054
  if (upb_msgdef_mapentry(m)) {
969
1055
  /* TODO(haberman): refactor this method so this special case is more
@@ -989,7 +1075,7 @@ static bool make_layout(const upb_symtab *symtab, const upb_msgdef *m) {
989
1075
  l->field_count = 2;
990
1076
  l->size = 2 * sizeof(upb_strview);
991
1077
  l->size = UPB_ALIGN_UP(l->size, 8);
992
- return true;
1078
+ return;
993
1079
  }
994
1080
 
995
1081
  /* Allocate data offsets in three stages:
@@ -1101,31 +1187,52 @@ static bool make_layout(const upb_symtab *symtab, const upb_msgdef *m) {
1101
1187
  /* Sort fields by number. */
1102
1188
  qsort(fields, upb_msgdef_numfields(m), sizeof(*fields), field_number_cmp);
1103
1189
  assign_layout_indices(m, fields);
1104
-
1105
- return true;
1106
1190
  }
1107
1191
 
1108
- /* Code to build defs from descriptor protos. *********************************/
1192
+ static void assign_msg_indices(symtab_addctx *ctx, upb_msgdef *m) {
1193
+ /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the
1194
+ * lowest indexes, but we do not publicly guarantee this. */
1195
+ upb_msg_field_iter j;
1196
+ int i;
1197
+ uint32_t selector;
1198
+ int n = upb_msgdef_numfields(m);
1199
+ upb_fielddef **fields;
1109
1200
 
1110
- /* There is a question of how much validation to do here. It will be difficult
1111
- * to perfectly match the amount of validation performed by proto2. But since
1112
- * this code is used to directly build defs from Ruby (for example) we do need
1113
- * to validate important constraints like uniqueness of names and numbers. */
1201
+ if (n == 0) {
1202
+ m->selector_count = UPB_STATIC_SELECTOR_COUNT;
1203
+ m->submsg_field_count = 0;
1204
+ return;
1205
+ }
1114
1206
 
1115
- #define CHK(x) if (!(x)) { return false; }
1116
- #define CHK_OOM(x) if (!(x)) { upb_status_setoom(ctx->status); return false; }
1207
+ fields = upb_gmalloc(n * sizeof(*fields));
1117
1208
 
1118
- typedef struct {
1119
- const upb_symtab *symtab;
1120
- upb_filedef *file; /* File we are building. */
1121
- upb_alloc *alloc; /* Allocate defs here. */
1122
- upb_alloc *tmp; /* Alloc for addtab and any other tmp data. */
1123
- upb_strtable *addtab; /* full_name -> packed def ptr for new defs */
1124
- const upb_msglayout **layouts; /* NULL if we should build layouts. */
1125
- upb_status *status; /* Record errors here. */
1126
- } symtab_addctx;
1209
+ m->submsg_field_count = 0;
1210
+ for(i = 0, upb_msg_field_begin(&j, m);
1211
+ !upb_msg_field_done(&j);
1212
+ upb_msg_field_next(&j), i++) {
1213
+ upb_fielddef *f = upb_msg_iter_field(&j);
1214
+ UPB_ASSERT(f->msgdef == m);
1215
+ if (upb_fielddef_issubmsg(f)) {
1216
+ m->submsg_field_count++;
1217
+ }
1218
+ fields[i] = f;
1219
+ }
1220
+
1221
+ qsort(fields, n, sizeof(*fields), cmp_fields);
1222
+
1223
+ selector = UPB_STATIC_SELECTOR_COUNT + m->submsg_field_count;
1224
+ for (i = 0; i < n; i++) {
1225
+ upb_fielddef *f = fields[i];
1226
+ f->index_ = i;
1227
+ f->selector_base = selector + upb_handlers_selectorbaseoffset(f);
1228
+ selector += upb_handlers_selectorcount(f);
1229
+ }
1230
+ m->selector_count = selector;
1231
+
1232
+ upb_gfree(fields);
1233
+ }
1127
1234
 
1128
- static char* strviewdup(const symtab_addctx *ctx, upb_strview view) {
1235
+ static char *strviewdup(symtab_addctx *ctx, upb_strview view) {
1129
1236
  return upb_strdup2(view.data, view.size, ctx->alloc);
1130
1237
  }
1131
1238
 
@@ -1137,13 +1244,12 @@ static bool streql_view(upb_strview view, const char *b) {
1137
1244
  return streql2(view.data, view.size, b);
1138
1245
  }
1139
1246
 
1140
- static const char *makefullname(const symtab_addctx *ctx, const char *prefix,
1247
+ static const char *makefullname(symtab_addctx *ctx, const char *prefix,
1141
1248
  upb_strview name) {
1142
1249
  if (prefix) {
1143
1250
  /* ret = prefix + '.' + name; */
1144
1251
  size_t n = strlen(prefix);
1145
- char *ret = upb_malloc(ctx->alloc, n + name.size + 2);
1146
- CHK_OOM(ret);
1252
+ char *ret = symtab_alloc(ctx, n + name.size + 2);
1147
1253
  strcpy(ret, prefix);
1148
1254
  ret[n] = '.';
1149
1255
  memcpy(&ret[n + 1], name.data, name.size);
@@ -1154,6 +1260,41 @@ static const char *makefullname(const symtab_addctx *ctx, const char *prefix,
1154
1260
  }
1155
1261
  }
1156
1262
 
1263
+ static void finalize_oneofs(symtab_addctx *ctx, upb_msgdef *m) {
1264
+ int i;
1265
+ int synthetic_count = 0;
1266
+ upb_oneofdef *mutable_oneofs = (upb_oneofdef*)m->oneofs;
1267
+
1268
+ for (i = 0; i < m->oneof_count; i++) {
1269
+ upb_oneofdef *o = &mutable_oneofs[i];
1270
+
1271
+ if (o->synthetic && o->field_count != 1) {
1272
+ symtab_errf(ctx, "Synthetic oneofs must have one field, not %d: %s",
1273
+ o->field_count, upb_oneofdef_name(o));
1274
+ }
1275
+
1276
+ if (o->synthetic) {
1277
+ synthetic_count++;
1278
+ } else if (synthetic_count != 0) {
1279
+ symtab_errf(ctx, "Synthetic oneofs must be after all other oneofs: %s",
1280
+ upb_oneofdef_name(o));
1281
+ }
1282
+
1283
+ o->fields = symtab_alloc(ctx, sizeof(upb_fielddef *) * o->field_count);
1284
+ o->field_count = 0;
1285
+ }
1286
+
1287
+ for (i = 0; i < m->field_count; i++) {
1288
+ const upb_fielddef *f = &m->fields[i];
1289
+ upb_oneofdef *o = (upb_oneofdef*)f->oneof;
1290
+ if (o) {
1291
+ o->fields[o->field_count++] = f;
1292
+ }
1293
+ }
1294
+
1295
+ m->real_oneof_count = m->oneof_count - synthetic_count;
1296
+ }
1297
+
1157
1298
  size_t getjsonname(const char *name, char *buf, size_t len) {
1158
1299
  size_t src, dst = 0;
1159
1300
  bool ucase_next = false;
@@ -1192,76 +1333,57 @@ size_t getjsonname(const char *name, char *buf, size_t len) {
1192
1333
  #undef WRITE
1193
1334
  }
1194
1335
 
1195
- static char* makejsonname(const char* name, upb_alloc *alloc) {
1336
+ static char* makejsonname(symtab_addctx *ctx, const char* name) {
1196
1337
  size_t size = getjsonname(name, NULL, 0);
1197
- char* json_name = upb_malloc(alloc, size);
1338
+ char* json_name = symtab_alloc(ctx, size);
1198
1339
  getjsonname(name, json_name, size);
1199
1340
  return json_name;
1200
1341
  }
1201
1342
 
1202
- static bool symtab_add(const symtab_addctx *ctx, const char *name,
1203
- upb_value v) {
1204
- upb_value tmp;
1205
- if (upb_strtable_lookup(ctx->addtab, name, &tmp) ||
1206
- upb_strtable_lookup(&ctx->symtab->syms, name, &tmp)) {
1207
- upb_status_seterrf(ctx->status, "duplicate symbol '%s'", name);
1208
- return false;
1343
+ static void symtab_add(symtab_addctx *ctx, const char *name, upb_value v) {
1344
+ if (upb_strtable_lookup(&ctx->symtab->syms, name, NULL)) {
1345
+ symtab_errf(ctx, "duplicate symbol '%s'", name);
1209
1346
  }
1210
-
1211
- CHK_OOM(upb_strtable_insert3(ctx->addtab, name, strlen(name), v, ctx->tmp));
1212
- return true;
1347
+ upb_alloc *alloc = upb_arena_alloc(ctx->symtab->arena);
1348
+ size_t len = strlen(name);
1349
+ CHK_OOM(upb_strtable_insert3(&ctx->symtab->syms, name, len, v, alloc));
1213
1350
  }
1214
1351
 
1215
1352
  /* Given a symbol and the base symbol inside which it is defined, find the
1216
1353
  * symbol's definition in t. */
1217
- static bool resolvename(const upb_strtable *t, const upb_fielddef *f,
1218
- const char *base, upb_strview sym,
1219
- upb_deftype_t type, upb_status *status,
1220
- const void **def) {
1221
- if(sym.size == 0) return false;
1354
+ static const void *symtab_resolve(symtab_addctx *ctx, const upb_fielddef *f,
1355
+ const char *base, upb_strview sym,
1356
+ upb_deftype_t type) {
1357
+ const upb_strtable *t = &ctx->symtab->syms;
1358
+ if(sym.size == 0) goto notfound;
1222
1359
  if(sym.data[0] == '.') {
1223
1360
  /* Symbols starting with '.' are absolute, so we do a single lookup.
1224
1361
  * Slice to omit the leading '.' */
1225
1362
  upb_value v;
1226
1363
  if (!upb_strtable_lookup2(t, sym.data + 1, sym.size - 1, &v)) {
1227
- return false;
1364
+ goto notfound;
1228
1365
  }
1229
1366
 
1230
- *def = unpack_def(v, type);
1231
-
1232
- if (!*def) {
1233
- upb_status_seterrf(status,
1234
- "type mismatch when resolving field %s, name %s",
1235
- f->full_name, sym.data);
1236
- return false;
1367
+ const void *ret = unpack_def(v, type);
1368
+ if (!ret) {
1369
+ symtab_errf(ctx, "type mismatch when resolving field %s, name %s",
1370
+ f->full_name, sym.data);
1237
1371
  }
1238
-
1239
- return true;
1372
+ return ret;
1240
1373
  } else {
1241
1374
  /* Remove components from base until we find an entry or run out.
1242
1375
  * TODO: This branch is totally broken, but currently not used. */
1243
1376
  (void)base;
1244
1377
  UPB_ASSERT(false);
1245
- return false;
1378
+ goto notfound;
1246
1379
  }
1247
- }
1248
1380
 
1249
- const void *symtab_resolve(const symtab_addctx *ctx, const upb_fielddef *f,
1250
- const char *base, upb_strview sym,
1251
- upb_deftype_t type) {
1252
- const void *ret;
1253
- if (!resolvename(ctx->addtab, f, base, sym, type, ctx->status, &ret) &&
1254
- !resolvename(&ctx->symtab->syms, f, base, sym, type, ctx->status, &ret)) {
1255
- if (upb_ok(ctx->status)) {
1256
- upb_status_seterrf(ctx->status, "couldn't resolve name '%s'", sym.data);
1257
- }
1258
- return false;
1259
- }
1260
- return ret;
1381
+ notfound:
1382
+ symtab_errf(ctx, "couldn't resolve name '%s'", sym.data);
1261
1383
  }
1262
1384
 
1263
- static bool create_oneofdef(
1264
- const symtab_addctx *ctx, upb_msgdef *m,
1385
+ static void create_oneofdef(
1386
+ symtab_addctx *ctx, upb_msgdef *m,
1265
1387
  const google_protobuf_OneofDescriptorProto *oneof_proto) {
1266
1388
  upb_oneofdef *o;
1267
1389
  upb_strview name = google_protobuf_OneofDescriptorProto_name(oneof_proto);
@@ -1270,18 +1392,27 @@ static bool create_oneofdef(
1270
1392
  o = (upb_oneofdef*)&m->oneofs[m->oneof_count++];
1271
1393
  o->parent = m;
1272
1394
  o->full_name = makefullname(ctx, m->full_name, name);
1395
+ o->field_count = 0;
1396
+ o->synthetic = false;
1273
1397
 
1274
1398
  v = pack_def(o, UPB_DEFTYPE_ONEOF);
1275
- CHK_OOM(symtab_add(ctx, o->full_name, v));
1399
+ symtab_add(ctx, o->full_name, v);
1276
1400
  CHK_OOM(upb_strtable_insert3(&m->ntof, name.data, name.size, v, ctx->alloc));
1277
1401
 
1278
1402
  CHK_OOM(upb_inttable_init2(&o->itof, UPB_CTYPE_CONSTPTR, ctx->alloc));
1279
- CHK_OOM(upb_strtable_init2(&o->ntof, UPB_CTYPE_CONSTPTR, ctx->alloc));
1403
+ CHK_OOM(upb_strtable_init2(&o->ntof, UPB_CTYPE_CONSTPTR, 4, ctx->alloc));
1404
+ }
1280
1405
 
1281
- return true;
1406
+ static str_t *newstr(symtab_addctx *ctx, const char *data, size_t len) {
1407
+ str_t *ret = symtab_alloc(ctx, sizeof(*ret) + len);
1408
+ if (!ret) return NULL;
1409
+ ret->len = len;
1410
+ if (len) memcpy(ret->str, data, len);
1411
+ ret->str[len] = '\0';
1412
+ return ret;
1282
1413
  }
1283
1414
 
1284
- static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len,
1415
+ static void parse_default(symtab_addctx *ctx, const char *str, size_t len,
1285
1416
  upb_fielddef *f) {
1286
1417
  char *end;
1287
1418
  char nullz[64];
@@ -1296,7 +1427,7 @@ static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len,
1296
1427
  case UPB_TYPE_FLOAT:
1297
1428
  /* Standard C number parsing functions expect null-terminated strings. */
1298
1429
  if (len >= sizeof(nullz) - 1) {
1299
- return false;
1430
+ symtab_errf(ctx, "Default too long: %.*s", (int)len, str);
1300
1431
  }
1301
1432
  memcpy(nullz, str, len);
1302
1433
  nullz[len] = '\0';
@@ -1309,47 +1440,61 @@ static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len,
1309
1440
  switch (upb_fielddef_type(f)) {
1310
1441
  case UPB_TYPE_INT32: {
1311
1442
  long val = strtol(str, &end, 0);
1312
- CHK(val <= INT32_MAX && val >= INT32_MIN && errno != ERANGE && !*end);
1443
+ if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) {
1444
+ goto invalid;
1445
+ }
1313
1446
  f->defaultval.sint = val;
1314
1447
  break;
1315
1448
  }
1316
1449
  case UPB_TYPE_ENUM: {
1317
1450
  const upb_enumdef *e = f->sub.enumdef;
1318
1451
  int32_t val;
1319
- CHK(upb_enumdef_ntoi(e, str, len, &val));
1452
+ if (!upb_enumdef_ntoi(e, str, len, &val)) {
1453
+ goto invalid;
1454
+ }
1320
1455
  f->defaultval.sint = val;
1321
1456
  break;
1322
1457
  }
1323
1458
  case UPB_TYPE_INT64: {
1324
1459
  /* XXX: Need to write our own strtoll, since it's not available in c89. */
1325
1460
  int64_t val = strtol(str, &end, 0);
1326
- CHK(val <= INT64_MAX && val >= INT64_MIN && errno != ERANGE && !*end);
1461
+ if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) {
1462
+ goto invalid;
1463
+ }
1327
1464
  f->defaultval.sint = val;
1328
1465
  break;
1329
1466
  }
1330
1467
  case UPB_TYPE_UINT32: {
1331
1468
  unsigned long val = strtoul(str, &end, 0);
1332
- CHK(val <= UINT32_MAX && errno != ERANGE && !*end);
1469
+ if (val > UINT32_MAX || errno == ERANGE || *end) {
1470
+ goto invalid;
1471
+ }
1333
1472
  f->defaultval.uint = val;
1334
1473
  break;
1335
1474
  }
1336
1475
  case UPB_TYPE_UINT64: {
1337
1476
  /* XXX: Need to write our own strtoull, since it's not available in c89. */
1338
1477
  uint64_t val = strtoul(str, &end, 0);
1339
- CHK(val <= UINT64_MAX && errno != ERANGE && !*end);
1478
+ if (val > UINT64_MAX || errno == ERANGE || *end) {
1479
+ goto invalid;
1480
+ }
1340
1481
  f->defaultval.uint = val;
1341
1482
  break;
1342
1483
  }
1343
1484
  case UPB_TYPE_DOUBLE: {
1344
1485
  double val = strtod(str, &end);
1345
- CHK(errno != ERANGE && !*end);
1486
+ if (errno == ERANGE || *end) {
1487
+ goto invalid;
1488
+ }
1346
1489
  f->defaultval.dbl = val;
1347
1490
  break;
1348
1491
  }
1349
1492
  case UPB_TYPE_FLOAT: {
1350
1493
  /* XXX: Need to write our own strtof, since it's not available in c89. */
1351
1494
  float val = strtod(str, &end);
1352
- CHK(errno != ERANGE && !*end);
1495
+ if (errno == ERANGE || *end) {
1496
+ goto invalid;
1497
+ }
1353
1498
  f->defaultval.flt = val;
1354
1499
  break;
1355
1500
  }
@@ -1359,25 +1504,30 @@ static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len,
1359
1504
  } else if (streql2(str, len, "true")) {
1360
1505
  f->defaultval.boolean = true;
1361
1506
  } else {
1362
- return false;
1363
1507
  }
1364
1508
  break;
1365
1509
  }
1366
1510
  case UPB_TYPE_STRING:
1367
- f->defaultval.str = newstr(ctx->alloc, str, len);
1511
+ f->defaultval.str = newstr(ctx, str, len);
1368
1512
  break;
1369
1513
  case UPB_TYPE_BYTES:
1370
1514
  /* XXX: need to interpret the C-escaped value. */
1371
- f->defaultval.str = newstr(ctx->alloc, str, len);
1515
+ f->defaultval.str = newstr(ctx, str, len);
1372
1516
  break;
1373
1517
  case UPB_TYPE_MESSAGE:
1374
1518
  /* Should not have a default value. */
1375
- return false;
1519
+ symtab_errf(ctx, "Message should not have a default (%s)",
1520
+ upb_fielddef_fullname(f));
1376
1521
  }
1377
- return true;
1522
+
1523
+ return;
1524
+
1525
+ invalid:
1526
+ symtab_errf(ctx, "Invalid default '%.*s' for field %f", (int)len, str,
1527
+ upb_fielddef_fullname(f));
1378
1528
  }
1379
1529
 
1380
- static void set_default_default(const symtab_addctx *ctx, upb_fielddef *f) {
1530
+ static void set_default_default(symtab_addctx *ctx, upb_fielddef *f) {
1381
1531
  switch (upb_fielddef_type(f)) {
1382
1532
  case UPB_TYPE_INT32:
1383
1533
  case UPB_TYPE_INT64:
@@ -1394,7 +1544,7 @@ static void set_default_default(const symtab_addctx *ctx, upb_fielddef *f) {
1394
1544
  break;
1395
1545
  case UPB_TYPE_STRING:
1396
1546
  case UPB_TYPE_BYTES:
1397
- f->defaultval.str = newstr(ctx->alloc, NULL, 0);
1547
+ f->defaultval.str = newstr(ctx, NULL, 0);
1398
1548
  break;
1399
1549
  case UPB_TYPE_BOOL:
1400
1550
  f->defaultval.boolean = false;
@@ -1404,8 +1554,8 @@ static void set_default_default(const symtab_addctx *ctx, upb_fielddef *f) {
1404
1554
  }
1405
1555
  }
1406
1556
 
1407
- static bool create_fielddef(
1408
- const symtab_addctx *ctx, const char *prefix, upb_msgdef *m,
1557
+ static void create_fielddef(
1558
+ symtab_addctx *ctx, const char *prefix, upb_msgdef *m,
1409
1559
  const google_protobuf_FieldDescriptorProto *field_proto) {
1410
1560
  upb_alloc *alloc = ctx->alloc;
1411
1561
  upb_fielddef *f;
@@ -1417,12 +1567,11 @@ static bool create_fielddef(
1417
1567
  uint32_t field_number;
1418
1568
 
1419
1569
  if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) {
1420
- upb_status_seterrmsg(ctx->status, "field has no name");
1421
- return false;
1570
+ symtab_errf(ctx, "field has no name (%s)", upb_msgdef_fullname(m));
1422
1571
  }
1423
1572
 
1424
1573
  name = google_protobuf_FieldDescriptorProto_name(field_proto);
1425
- CHK(upb_isident(name, false, ctx->status));
1574
+ check_ident(ctx, name, false);
1426
1575
  full_name = makefullname(ctx, prefix, name);
1427
1576
  shortname = shortdefname(full_name);
1428
1577
 
@@ -1430,14 +1579,13 @@ static bool create_fielddef(
1430
1579
  json_name = strviewdup(
1431
1580
  ctx, google_protobuf_FieldDescriptorProto_json_name(field_proto));
1432
1581
  } else {
1433
- json_name = makejsonname(shortname, ctx->alloc);
1582
+ json_name = makejsonname(ctx, shortname);
1434
1583
  }
1435
1584
 
1436
1585
  field_number = google_protobuf_FieldDescriptorProto_number(field_proto);
1437
1586
 
1438
1587
  if (field_number == 0 || field_number > UPB_MAX_FIELDNUMBER) {
1439
- upb_status_seterrf(ctx->status, "invalid field number (%u)", field_number);
1440
- return false;
1588
+ symtab_errf(ctx, "invalid field number (%u)", field_number);
1441
1589
  }
1442
1590
 
1443
1591
  if (m) {
@@ -1450,19 +1598,15 @@ static bool create_fielddef(
1450
1598
  f->is_extension_ = false;
1451
1599
 
1452
1600
  if (upb_strtable_lookup(&m->ntof, shortname, NULL)) {
1453
- upb_status_seterrf(ctx->status, "duplicate field name (%s)", shortname);
1454
- return false;
1601
+ symtab_errf(ctx, "duplicate field name (%s)", shortname);
1455
1602
  }
1456
1603
 
1457
1604
  if (upb_strtable_lookup(&m->ntof, json_name, NULL)) {
1458
- upb_status_seterrf(ctx->status, "duplicate json_name (%s)", json_name);
1459
- return false;
1605
+ symtab_errf(ctx, "duplicate json_name (%s)", json_name);
1460
1606
  }
1461
1607
 
1462
1608
  if (upb_inttable_lookup(&m->itof, field_number, NULL)) {
1463
- upb_status_seterrf(ctx->status, "duplicate field number (%u)",
1464
- field_number);
1465
- return false;
1609
+ symtab_errf(ctx, "duplicate field number (%u)", field_number);
1466
1610
  }
1467
1611
 
1468
1612
  field_v = pack_def(f, UPB_DEFTYPE_FIELD);
@@ -1496,7 +1640,7 @@ static bool create_fielddef(
1496
1640
  /* extension field. */
1497
1641
  f = (upb_fielddef*)&ctx->file->exts[ctx->file->ext_count++];
1498
1642
  f->is_extension_ = true;
1499
- CHK_OOM(symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_FIELD)));
1643
+ symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_FIELD));
1500
1644
  }
1501
1645
 
1502
1646
  f->full_name = full_name;
@@ -1515,9 +1659,7 @@ static bool create_fielddef(
1515
1659
  f->sub.unresolved = field_proto;
1516
1660
 
1517
1661
  if (f->label_ == UPB_LABEL_REQUIRED && f->file->syntax == UPB_SYNTAX_PROTO3) {
1518
- upb_status_seterrf(ctx->status, "proto3 fields cannot be required (%s)",
1519
- f->full_name);
1520
- return false;
1662
+ symtab_errf(ctx, "proto3 fields cannot be required (%s)", f->full_name);
1521
1663
  }
1522
1664
 
1523
1665
  if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) {
@@ -1527,32 +1669,34 @@ static bool create_fielddef(
1527
1669
  upb_value v = upb_value_constptr(f);
1528
1670
 
1529
1671
  if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) {
1530
- upb_status_seterrf(ctx->status,
1531
- "fields in oneof must have OPTIONAL label (%s)",
1532
- f->full_name);
1533
- return false;
1672
+ symtab_errf(ctx, "fields in oneof must have OPTIONAL label (%s)",
1673
+ f->full_name);
1534
1674
  }
1535
1675
 
1536
1676
  if (!m) {
1537
- upb_status_seterrf(ctx->status,
1538
- "oneof_index provided for extension field (%s)",
1539
- f->full_name);
1540
- return false;
1677
+ symtab_errf(ctx, "oneof_index provided for extension field (%s)",
1678
+ f->full_name);
1541
1679
  }
1542
1680
 
1543
1681
  if (oneof_index >= m->oneof_count) {
1544
- upb_status_seterrf(ctx->status, "oneof_index out of range (%s)",
1545
- f->full_name);
1546
- return false;
1682
+ symtab_errf(ctx, "oneof_index out of range (%s)", f->full_name);
1547
1683
  }
1548
1684
 
1549
1685
  oneof = (upb_oneofdef*)&m->oneofs[oneof_index];
1550
1686
  f->oneof = oneof;
1551
1687
 
1552
- CHK(upb_inttable_insert2(&oneof->itof, f->number_, v, alloc));
1553
- CHK(upb_strtable_insert3(&oneof->ntof, name.data, name.size, v, alloc));
1688
+ oneof->field_count++;
1689
+ if (f->proto3_optional_) {
1690
+ oneof->synthetic = true;
1691
+ }
1692
+ CHK_OOM(upb_inttable_insert2(&oneof->itof, f->number_, v, alloc));
1693
+ CHK_OOM(upb_strtable_insert3(&oneof->ntof, name.data, name.size, v, alloc));
1554
1694
  } else {
1555
1695
  f->oneof = NULL;
1696
+ if (f->proto3_optional_) {
1697
+ symtab_errf(ctx, "field with proto3_optional was not in a oneof (%s)",
1698
+ f->full_name);
1699
+ }
1556
1700
  }
1557
1701
 
1558
1702
  options = google_protobuf_FieldDescriptorProto_has_options(field_proto) ?
@@ -1571,12 +1715,10 @@ static bool create_fielddef(
1571
1715
  } else {
1572
1716
  f->lazy_ = false;
1573
1717
  }
1574
-
1575
- return true;
1576
1718
  }
1577
1719
 
1578
- static bool create_enumdef(
1579
- const symtab_addctx *ctx, const char *prefix,
1720
+ static void create_enumdef(
1721
+ symtab_addctx *ctx, const char *prefix,
1580
1722
  const google_protobuf_EnumDescriptorProto *enum_proto) {
1581
1723
  upb_enumdef *e;
1582
1724
  const google_protobuf_EnumValueDescriptorProto *const *values;
@@ -1584,25 +1726,22 @@ static bool create_enumdef(
1584
1726
  size_t i, n;
1585
1727
 
1586
1728
  name = google_protobuf_EnumDescriptorProto_name(enum_proto);
1587
- CHK(upb_isident(name, false, ctx->status));
1729
+ check_ident(ctx, name, false);
1588
1730
 
1589
1731
  e = (upb_enumdef*)&ctx->file->enums[ctx->file->enum_count++];
1590
1732
  e->full_name = makefullname(ctx, prefix, name);
1591
- CHK_OOM(symtab_add(ctx, e->full_name, pack_def(e, UPB_DEFTYPE_ENUM)));
1733
+ symtab_add(ctx, e->full_name, pack_def(e, UPB_DEFTYPE_ENUM));
1592
1734
 
1593
- CHK_OOM(upb_strtable_init2(&e->ntoi, UPB_CTYPE_INT32, ctx->alloc));
1735
+ values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n);
1736
+ CHK_OOM(upb_strtable_init2(&e->ntoi, UPB_CTYPE_INT32, n, ctx->alloc));
1594
1737
  CHK_OOM(upb_inttable_init2(&e->iton, UPB_CTYPE_CSTR, ctx->alloc));
1595
1738
 
1596
1739
  e->file = ctx->file;
1597
1740
  e->defaultval = 0;
1598
1741
 
1599
- values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n);
1600
-
1601
1742
  if (n == 0) {
1602
- upb_status_seterrf(ctx->status,
1603
- "enums must contain at least one value (%s)",
1604
- e->full_name);
1605
- return false;
1743
+ symtab_errf(ctx, "enums must contain at least one value (%s)",
1744
+ e->full_name);
1606
1745
  }
1607
1746
 
1608
1747
  for (i = 0; i < n; i++) {
@@ -1613,15 +1752,12 @@ static bool create_enumdef(
1613
1752
  upb_value v = upb_value_int32(num);
1614
1753
 
1615
1754
  if (i == 0 && e->file->syntax == UPB_SYNTAX_PROTO3 && num != 0) {
1616
- upb_status_seterrf(ctx->status,
1617
- "for proto3, the first enum value must be zero (%s)",
1618
- e->full_name);
1619
- return false;
1755
+ symtab_errf(ctx, "for proto3, the first enum value must be zero (%s)",
1756
+ e->full_name);
1620
1757
  }
1621
1758
 
1622
1759
  if (upb_strtable_lookup(&e->ntoi, name2, NULL)) {
1623
- upb_status_seterrf(ctx->status, "duplicate enum label '%s'", name2);
1624
- return false;
1760
+ symtab_errf(ctx, "duplicate enum label '%s'", name2);
1625
1761
  }
1626
1762
 
1627
1763
  CHK_OOM(name2)
@@ -1635,11 +1771,9 @@ static bool create_enumdef(
1635
1771
  }
1636
1772
 
1637
1773
  upb_inttable_compact2(&e->iton, ctx->alloc);
1638
-
1639
- return true;
1640
1774
  }
1641
1775
 
1642
- static bool create_msgdef(symtab_addctx *ctx, const char *prefix,
1776
+ static void create_msgdef(symtab_addctx *ctx, const char *prefix,
1643
1777
  const google_protobuf_DescriptorProto *msg_proto) {
1644
1778
  upb_msgdef *m;
1645
1779
  const google_protobuf_MessageOptions *options;
@@ -1647,18 +1781,22 @@ static bool create_msgdef(symtab_addctx *ctx, const char *prefix,
1647
1781
  const google_protobuf_FieldDescriptorProto *const *fields;
1648
1782
  const google_protobuf_EnumDescriptorProto *const *enums;
1649
1783
  const google_protobuf_DescriptorProto *const *msgs;
1650
- size_t i, n;
1784
+ size_t i, n_oneof, n_field, n;
1651
1785
  upb_strview name;
1652
1786
 
1653
1787
  name = google_protobuf_DescriptorProto_name(msg_proto);
1654
- CHK(upb_isident(name, false, ctx->status));
1788
+ check_ident(ctx, name, false);
1655
1789
 
1656
1790
  m = (upb_msgdef*)&ctx->file->msgs[ctx->file->msg_count++];
1657
1791
  m->full_name = makefullname(ctx, prefix, name);
1658
- CHK_OOM(symtab_add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG)));
1792
+ symtab_add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG));
1793
+
1794
+ oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof);
1795
+ fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field);
1659
1796
 
1660
1797
  CHK_OOM(upb_inttable_init2(&m->itof, UPB_CTYPE_CONSTPTR, ctx->alloc));
1661
- CHK_OOM(upb_strtable_init2(&m->ntof, UPB_CTYPE_CONSTPTR, ctx->alloc));
1798
+ CHK_OOM(upb_strtable_init2(&m->ntof, UPB_CTYPE_CONSTPTR, n_oneof + n_field,
1799
+ ctx->alloc));
1662
1800
 
1663
1801
  m->file = ctx->file;
1664
1802
  m->map_entry = false;
@@ -1674,25 +1812,24 @@ static bool create_msgdef(symtab_addctx *ctx, const char *prefix,
1674
1812
  ctx->layouts++;
1675
1813
  } else {
1676
1814
  /* Allocate now (to allow cross-linking), populate later. */
1677
- m->layout = upb_malloc(ctx->alloc, sizeof(*m->layout));
1815
+ m->layout = symtab_alloc(
1816
+ ctx, sizeof(*m->layout) + sizeof(_upb_fasttable_entry));
1678
1817
  }
1679
1818
 
1680
- oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n);
1681
1819
  m->oneof_count = 0;
1682
- m->oneofs = upb_malloc(ctx->alloc, sizeof(*m->oneofs) * n);
1683
- for (i = 0; i < n; i++) {
1684
- CHK(create_oneofdef(ctx, m, oneofs[i]));
1820
+ m->oneofs = symtab_alloc(ctx, sizeof(*m->oneofs) * n_oneof);
1821
+ for (i = 0; i < n_oneof; i++) {
1822
+ create_oneofdef(ctx, m, oneofs[i]);
1685
1823
  }
1686
1824
 
1687
- fields = google_protobuf_DescriptorProto_field(msg_proto, &n);
1688
1825
  m->field_count = 0;
1689
- m->fields = upb_malloc(ctx->alloc, sizeof(*m->fields) * n);
1690
- for (i = 0; i < n; i++) {
1691
- CHK(create_fielddef(ctx, m->full_name, m, fields[i]));
1826
+ m->fields = symtab_alloc(ctx, sizeof(*m->fields) * n_field);
1827
+ for (i = 0; i < n_field; i++) {
1828
+ create_fielddef(ctx, m->full_name, m, fields[i]);
1692
1829
  }
1693
1830
 
1694
- CHK(assign_msg_indices(m, ctx->status));
1695
- CHK(check_oneofs(m, ctx->status));
1831
+ assign_msg_indices(ctx, m);
1832
+ finalize_oneofs(ctx, m);
1696
1833
  assign_msg_wellknowntype(m);
1697
1834
  upb_inttable_compact2(&m->itof, ctx->alloc);
1698
1835
 
@@ -1700,93 +1837,78 @@ static bool create_msgdef(symtab_addctx *ctx, const char *prefix,
1700
1837
 
1701
1838
  enums = google_protobuf_DescriptorProto_enum_type(msg_proto, &n);
1702
1839
  for (i = 0; i < n; i++) {
1703
- CHK(create_enumdef(ctx, m->full_name, enums[i]));
1840
+ create_enumdef(ctx, m->full_name, enums[i]);
1704
1841
  }
1705
1842
 
1706
1843
  msgs = google_protobuf_DescriptorProto_nested_type(msg_proto, &n);
1707
1844
  for (i = 0; i < n; i++) {
1708
- CHK(create_msgdef(ctx, m->full_name, msgs[i]));
1845
+ create_msgdef(ctx, m->full_name, msgs[i]);
1709
1846
  }
1710
-
1711
- return true;
1712
1847
  }
1713
1848
 
1714
- typedef struct {
1715
- int msg_count;
1716
- int enum_count;
1717
- int ext_count;
1718
- } decl_counts;
1719
-
1720
1849
  static void count_types_in_msg(const google_protobuf_DescriptorProto *msg_proto,
1721
- decl_counts *counts) {
1850
+ upb_filedef *file) {
1722
1851
  const google_protobuf_DescriptorProto *const *msgs;
1723
1852
  size_t i, n;
1724
1853
 
1725
- counts->msg_count++;
1854
+ file->msg_count++;
1726
1855
 
1727
1856
  msgs = google_protobuf_DescriptorProto_nested_type(msg_proto, &n);
1728
1857
  for (i = 0; i < n; i++) {
1729
- count_types_in_msg(msgs[i], counts);
1858
+ count_types_in_msg(msgs[i], file);
1730
1859
  }
1731
1860
 
1732
1861
  google_protobuf_DescriptorProto_enum_type(msg_proto, &n);
1733
- counts->enum_count += n;
1862
+ file->enum_count += n;
1734
1863
 
1735
1864
  google_protobuf_DescriptorProto_extension(msg_proto, &n);
1736
- counts->ext_count += n;
1865
+ file->ext_count += n;
1737
1866
  }
1738
1867
 
1739
1868
  static void count_types_in_file(
1740
1869
  const google_protobuf_FileDescriptorProto *file_proto,
1741
- decl_counts *counts) {
1870
+ upb_filedef *file) {
1742
1871
  const google_protobuf_DescriptorProto *const *msgs;
1743
1872
  size_t i, n;
1744
1873
 
1745
1874
  msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n);
1746
1875
  for (i = 0; i < n; i++) {
1747
- count_types_in_msg(msgs[i], counts);
1876
+ count_types_in_msg(msgs[i], file);
1748
1877
  }
1749
1878
 
1750
1879
  google_protobuf_FileDescriptorProto_enum_type(file_proto, &n);
1751
- counts->enum_count += n;
1880
+ file->enum_count += n;
1752
1881
 
1753
1882
  google_protobuf_FileDescriptorProto_extension(file_proto, &n);
1754
- counts->ext_count += n;
1883
+ file->ext_count += n;
1755
1884
  }
1756
1885
 
1757
- static bool resolve_fielddef(const symtab_addctx *ctx, const char *prefix,
1886
+ static void resolve_fielddef(symtab_addctx *ctx, const char *prefix,
1758
1887
  upb_fielddef *f) {
1759
1888
  upb_strview name;
1760
1889
  const google_protobuf_FieldDescriptorProto *field_proto = f->sub.unresolved;
1761
1890
 
1762
1891
  if (f->is_extension_) {
1763
1892
  if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) {
1764
- upb_status_seterrf(ctx->status,
1765
- "extension for field '%s' had no extendee",
1766
- f->full_name);
1767
- return false;
1893
+ symtab_errf(ctx, "extension for field '%s' had no extendee",
1894
+ f->full_name);
1768
1895
  }
1769
1896
 
1770
1897
  name = google_protobuf_FieldDescriptorProto_extendee(field_proto);
1771
1898
  f->msgdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_MSG);
1772
- CHK(f->msgdef);
1773
1899
  }
1774
1900
 
1775
1901
  if ((upb_fielddef_issubmsg(f) || f->type_ == UPB_DESCRIPTOR_TYPE_ENUM) &&
1776
1902
  !google_protobuf_FieldDescriptorProto_has_type_name(field_proto)) {
1777
- upb_status_seterrf(ctx->status, "field '%s' is missing type name",
1778
- f->full_name);
1779
- return false;
1903
+ symtab_errf(ctx, "field '%s' is missing type name", f->full_name);
1780
1904
  }
1781
1905
 
1782
1906
  name = google_protobuf_FieldDescriptorProto_type_name(field_proto);
1783
1907
 
1784
1908
  if (upb_fielddef_issubmsg(f)) {
1785
1909
  f->sub.msgdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_MSG);
1786
- CHK(f->sub.msgdef);
1787
1910
  } else if (f->type_ == UPB_DESCRIPTOR_TYPE_ENUM) {
1788
1911
  f->sub.enumdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_ENUM);
1789
- CHK(f->sub.enumdef);
1790
1912
  }
1791
1913
 
1792
1914
  /* Have to delay resolving of the default value until now because of the enum
@@ -1796,54 +1918,36 @@ static bool resolve_fielddef(const symtab_addctx *ctx, const char *prefix,
1796
1918
  google_protobuf_FieldDescriptorProto_default_value(field_proto);
1797
1919
 
1798
1920
  if (f->file->syntax == UPB_SYNTAX_PROTO3) {
1799
- upb_status_seterrf(ctx->status,
1800
- "proto3 fields cannot have explicit defaults (%s)",
1801
- f->full_name);
1802
- return false;
1921
+ symtab_errf(ctx, "proto3 fields cannot have explicit defaults (%s)",
1922
+ f->full_name);
1803
1923
  }
1804
1924
 
1805
1925
  if (upb_fielddef_issubmsg(f)) {
1806
- upb_status_seterrf(ctx->status,
1807
- "message fields cannot have explicit defaults (%s)",
1808
- f->full_name);
1809
- return false;
1926
+ symtab_errf(ctx, "message fields cannot have explicit defaults (%s)",
1927
+ f->full_name);
1810
1928
  }
1811
1929
 
1812
- if (!parse_default(ctx, defaultval.data, defaultval.size, f)) {
1813
- upb_status_seterrf(ctx->status,
1814
- "couldn't parse default '" UPB_STRVIEW_FORMAT
1815
- "' for field (%s)",
1816
- UPB_STRVIEW_ARGS(defaultval), f->full_name);
1817
- return false;
1818
- }
1930
+ parse_default(ctx, defaultval.data, defaultval.size, f);
1819
1931
  } else {
1820
1932
  set_default_default(ctx, f);
1821
1933
  }
1822
-
1823
- return true;
1824
1934
  }
1825
1935
 
1826
- static bool build_filedef(
1936
+ static void build_filedef(
1827
1937
  symtab_addctx *ctx, upb_filedef *file,
1828
1938
  const google_protobuf_FileDescriptorProto *file_proto) {
1829
- upb_alloc *alloc = ctx->alloc;
1830
1939
  const google_protobuf_FileOptions *file_options_proto;
1831
1940
  const google_protobuf_DescriptorProto *const *msgs;
1832
1941
  const google_protobuf_EnumDescriptorProto *const *enums;
1833
1942
  const google_protobuf_FieldDescriptorProto *const *exts;
1834
1943
  const upb_strview* strs;
1835
1944
  size_t i, n;
1836
- decl_counts counts = {0, 0, 0};
1837
1945
 
1838
- count_types_in_file(file_proto, &counts);
1946
+ count_types_in_file(file_proto, file);
1839
1947
 
1840
- file->msgs = upb_malloc(alloc, sizeof(*file->msgs) * counts.msg_count);
1841
- file->enums = upb_malloc(alloc, sizeof(*file->enums) * counts.enum_count);
1842
- file->exts = upb_malloc(alloc, sizeof(*file->exts) * counts.ext_count);
1843
-
1844
- CHK_OOM(counts.msg_count == 0 || file->msgs);
1845
- CHK_OOM(counts.enum_count == 0 || file->enums);
1846
- CHK_OOM(counts.ext_count == 0 || file->exts);
1948
+ file->msgs = symtab_alloc(ctx, sizeof(*file->msgs) * file->msg_count);
1949
+ file->enums = symtab_alloc(ctx, sizeof(*file->enums) * file->enum_count);
1950
+ file->exts = symtab_alloc(ctx, sizeof(*file->exts) * file->ext_count);
1847
1951
 
1848
1952
  /* We increment these as defs are added. */
1849
1953
  file->msg_count = 0;
@@ -1851,8 +1955,7 @@ static bool build_filedef(
1851
1955
  file->ext_count = 0;
1852
1956
 
1853
1957
  if (!google_protobuf_FileDescriptorProto_has_name(file_proto)) {
1854
- upb_status_seterrmsg(ctx->status, "File has no name");
1855
- return false;
1958
+ symtab_errf(ctx, "File has no name");
1856
1959
  }
1857
1960
 
1858
1961
  file->name =
@@ -1863,7 +1966,7 @@ static bool build_filedef(
1863
1966
  if (google_protobuf_FileDescriptorProto_has_package(file_proto)) {
1864
1967
  upb_strview package =
1865
1968
  google_protobuf_FileDescriptorProto_package(file_proto);
1866
- CHK(upb_isident(package, true, ctx->status));
1969
+ check_ident(ctx, package, true);
1867
1970
  file->package = strviewdup(ctx, package);
1868
1971
  } else {
1869
1972
  file->package = NULL;
@@ -1878,9 +1981,8 @@ static bool build_filedef(
1878
1981
  } else if (streql_view(syntax, "proto3")) {
1879
1982
  file->syntax = UPB_SYNTAX_PROTO3;
1880
1983
  } else {
1881
- upb_status_seterrf(ctx->status, "Invalid syntax '" UPB_STRVIEW_FORMAT "'",
1882
- UPB_STRVIEW_ARGS(syntax));
1883
- return false;
1984
+ symtab_errf(ctx, "Invalid syntax '" UPB_STRVIEW_FORMAT "'",
1985
+ UPB_STRVIEW_ARGS(syntax));
1884
1986
  }
1885
1987
  } else {
1886
1988
  file->syntax = UPB_SYNTAX_PROTO2;
@@ -1902,19 +2004,17 @@ static bool build_filedef(
1902
2004
 
1903
2005
  /* Verify dependencies. */
1904
2006
  strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n);
1905
- file->deps = upb_malloc(alloc, sizeof(*file->deps) * n) ;
1906
- CHK_OOM(n == 0 || file->deps);
2007
+ file->deps = symtab_alloc(ctx, sizeof(*file->deps) * n);
1907
2008
 
1908
2009
  for (i = 0; i < n; i++) {
1909
2010
  upb_strview dep_name = strs[i];
1910
2011
  upb_value v;
1911
2012
  if (!upb_strtable_lookup2(&ctx->symtab->files, dep_name.data,
1912
2013
  dep_name.size, &v)) {
1913
- upb_status_seterrf(ctx->status,
1914
- "Depends on file '" UPB_STRVIEW_FORMAT
1915
- "', but it has not been loaded",
1916
- UPB_STRVIEW_ARGS(dep_name));
1917
- return false;
2014
+ symtab_errf(ctx,
2015
+ "Depends on file '" UPB_STRVIEW_FORMAT
2016
+ "', but it has not been loaded",
2017
+ UPB_STRVIEW_ARGS(dep_name));
1918
2018
  }
1919
2019
  file->deps[i] = upb_value_getconstptr(v);
1920
2020
  }
@@ -1922,194 +2022,99 @@ static bool build_filedef(
1922
2022
  /* Create messages. */
1923
2023
  msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n);
1924
2024
  for (i = 0; i < n; i++) {
1925
- CHK(create_msgdef(ctx, file->package, msgs[i]));
2025
+ create_msgdef(ctx, file->package, msgs[i]);
1926
2026
  }
1927
2027
 
1928
2028
  /* Create enums. */
1929
2029
  enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n);
1930
2030
  for (i = 0; i < n; i++) {
1931
- CHK(create_enumdef(ctx, file->package, enums[i]));
2031
+ create_enumdef(ctx, file->package, enums[i]);
1932
2032
  }
1933
2033
 
1934
2034
  /* Create extensions. */
1935
2035
  exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n);
1936
- file->exts = upb_malloc(alloc, sizeof(*file->exts) * n);
1937
- CHK_OOM(n == 0 || file->exts);
2036
+ file->exts = symtab_alloc(ctx, sizeof(*file->exts) * n);
1938
2037
  for (i = 0; i < n; i++) {
1939
- CHK(create_fielddef(ctx, file->package, NULL, exts[i]));
2038
+ create_fielddef(ctx, file->package, NULL, exts[i]);
1940
2039
  }
1941
2040
 
1942
2041
  /* Now that all names are in the table, build layouts and resolve refs. */
1943
2042
  for (i = 0; i < (size_t)file->ext_count; i++) {
1944
- CHK(resolve_fielddef(ctx, file->package, (upb_fielddef*)&file->exts[i]));
2043
+ resolve_fielddef(ctx, file->package, (upb_fielddef*)&file->exts[i]);
1945
2044
  }
1946
2045
 
1947
2046
  for (i = 0; i < (size_t)file->msg_count; i++) {
1948
2047
  const upb_msgdef *m = &file->msgs[i];
1949
2048
  int j;
1950
2049
  for (j = 0; j < m->field_count; j++) {
1951
- CHK(resolve_fielddef(ctx, m->full_name, (upb_fielddef*)&m->fields[j]));
2050
+ resolve_fielddef(ctx, m->full_name, (upb_fielddef*)&m->fields[j]);
1952
2051
  }
1953
2052
  }
1954
2053
 
1955
2054
  if (!ctx->layouts) {
1956
2055
  for (i = 0; i < (size_t)file->msg_count; i++) {
1957
2056
  const upb_msgdef *m = &file->msgs[i];
1958
- make_layout(ctx->symtab, m);
2057
+ make_layout(ctx, m);
1959
2058
  }
1960
2059
  }
2060
+ }
1961
2061
 
1962
- return true;
1963
- }
1964
-
1965
- static bool upb_symtab_addtotabs(upb_symtab *s, symtab_addctx *ctx) {
1966
- const upb_filedef *file = ctx->file;
2062
+ static void remove_filedef(upb_symtab *s, upb_filedef *file) {
1967
2063
  upb_alloc *alloc = upb_arena_alloc(s->arena);
1968
- upb_strtable_iter iter;
1969
-
1970
- CHK_OOM(upb_strtable_insert3(&s->files, file->name, strlen(file->name),
1971
- upb_value_constptr(file), alloc));
1972
-
1973
- upb_strtable_begin(&iter, ctx->addtab);
1974
- for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
1975
- upb_strview key = upb_strtable_iter_key(&iter);
1976
- upb_value value = upb_strtable_iter_value(&iter);
1977
- CHK_OOM(upb_strtable_insert3(&s->syms, key.data, key.size, value, alloc));
2064
+ int i;
2065
+ for (i = 0; i < file->msg_count; i++) {
2066
+ const char *name = file->msgs[i].full_name;
2067
+ upb_strtable_remove3(&s->syms, name, strlen(name), NULL, alloc);
1978
2068
  }
1979
-
1980
- return true;
1981
- }
1982
-
1983
- /* upb_filedef ****************************************************************/
1984
-
1985
- const char *upb_filedef_name(const upb_filedef *f) {
1986
- return f->name;
1987
- }
1988
-
1989
- const char *upb_filedef_package(const upb_filedef *f) {
1990
- return f->package;
1991
- }
1992
-
1993
- const char *upb_filedef_phpprefix(const upb_filedef *f) {
1994
- return f->phpprefix;
1995
- }
1996
-
1997
- const char *upb_filedef_phpnamespace(const upb_filedef *f) {
1998
- return f->phpnamespace;
1999
- }
2000
-
2001
- upb_syntax_t upb_filedef_syntax(const upb_filedef *f) {
2002
- return f->syntax;
2003
- }
2004
-
2005
- int upb_filedef_msgcount(const upb_filedef *f) {
2006
- return f->msg_count;
2007
- }
2008
-
2009
- int upb_filedef_depcount(const upb_filedef *f) {
2010
- return f->dep_count;
2011
- }
2012
-
2013
- int upb_filedef_enumcount(const upb_filedef *f) {
2014
- return f->enum_count;
2015
- }
2016
-
2017
- const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i) {
2018
- return i < 0 || i >= f->dep_count ? NULL : f->deps[i];
2019
- }
2020
-
2021
- const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i) {
2022
- return i < 0 || i >= f->msg_count ? NULL : &f->msgs[i];
2023
- }
2024
-
2025
- const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i) {
2026
- return i < 0 || i >= f->enum_count ? NULL : &f->enums[i];
2027
- }
2028
-
2029
- void upb_symtab_free(upb_symtab *s) {
2030
- upb_arena_free(s->arena);
2031
- upb_gfree(s);
2032
- }
2033
-
2034
- upb_symtab *upb_symtab_new(void) {
2035
- upb_symtab *s = upb_gmalloc(sizeof(*s));
2036
- upb_alloc *alloc;
2037
-
2038
- if (!s) {
2039
- return NULL;
2069
+ for (i = 0; i < file->enum_count; i++) {
2070
+ const char *name = file->enums[i].full_name;
2071
+ upb_strtable_remove3(&s->syms, name, strlen(name), NULL, alloc);
2040
2072
  }
2041
-
2042
- s->arena = upb_arena_new();
2043
- alloc = upb_arena_alloc(s->arena);
2044
-
2045
- if (!upb_strtable_init2(&s->syms, UPB_CTYPE_CONSTPTR, alloc) ||
2046
- !upb_strtable_init2(&s->files, UPB_CTYPE_CONSTPTR, alloc)) {
2047
- upb_arena_free(s->arena);
2048
- upb_gfree(s);
2049
- s = NULL;
2073
+ for (i = 0; i < file->ext_count; i++) {
2074
+ const char *name = file->exts[i].full_name;
2075
+ upb_strtable_remove3(&s->syms, name, strlen(name), NULL, alloc);
2050
2076
  }
2051
- return s;
2052
- }
2053
-
2054
- const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) {
2055
- upb_value v;
2056
- return upb_strtable_lookup(&s->syms, sym, &v) ?
2057
- unpack_def(v, UPB_DEFTYPE_MSG) : NULL;
2058
- }
2059
-
2060
- const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym,
2061
- size_t len) {
2062
- upb_value v;
2063
- return upb_strtable_lookup2(&s->syms, sym, len, &v) ?
2064
- unpack_def(v, UPB_DEFTYPE_MSG) : NULL;
2065
- }
2066
-
2067
- const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) {
2068
- upb_value v;
2069
- return upb_strtable_lookup(&s->syms, sym, &v) ?
2070
- unpack_def(v, UPB_DEFTYPE_ENUM) : NULL;
2071
- }
2072
-
2073
- const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name) {
2074
- upb_value v;
2075
- return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v)
2076
- : NULL;
2077
- }
2078
-
2079
- const upb_filedef *upb_symtab_lookupfile2(
2080
- const upb_symtab *s, const char *name, size_t len) {
2081
- upb_value v;
2082
- return upb_strtable_lookup2(&s->files, name, len, &v) ?
2083
- upb_value_getconstptr(v) : NULL;
2084
- }
2085
-
2086
- int upb_symtab_filecount(const upb_symtab *s) {
2087
- return (int)upb_strtable_count(&s->files);
2088
2077
  }
2089
2078
 
2090
2079
  static const upb_filedef *_upb_symtab_addfile(
2091
2080
  upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto,
2092
2081
  const upb_msglayout **layouts, upb_status *status) {
2093
- upb_arena *tmparena = upb_arena_new();
2094
- upb_strtable addtab;
2095
- upb_alloc *alloc = upb_arena_alloc(s->arena);
2096
- upb_filedef *file = upb_malloc(alloc, sizeof(*file));
2097
- bool ok;
2082
+ upb_arena *file_arena = upb_arena_new();
2083
+ upb_filedef *file;
2098
2084
  symtab_addctx ctx;
2099
2085
 
2086
+ if (!file_arena) return NULL;
2087
+
2088
+ file = upb_arena_malloc(file_arena, sizeof(*file));
2089
+ if (!file) goto done;
2090
+
2100
2091
  ctx.file = file;
2101
2092
  ctx.symtab = s;
2102
- ctx.alloc = alloc;
2103
- ctx.tmp = upb_arena_alloc(tmparena);
2104
- ctx.addtab = &addtab;
2093
+ ctx.file_arena = file_arena;
2094
+ ctx.alloc = upb_arena_alloc(file_arena);
2105
2095
  ctx.layouts = layouts;
2106
2096
  ctx.status = status;
2107
2097
 
2108
- ok = file && upb_strtable_init2(&addtab, UPB_CTYPE_CONSTPTR, ctx.tmp) &&
2109
- build_filedef(&ctx, file, file_proto) && upb_symtab_addtotabs(s, &ctx);
2098
+ file->msg_count = 0;
2099
+ file->enum_count = 0;
2100
+ file->ext_count = 0;
2101
+ file->symtab = s;
2102
+
2103
+ if (UPB_UNLIKELY(UPB_SETJMP(ctx.err))) {
2104
+ UPB_ASSERT(!upb_ok(status));
2105
+ remove_filedef(s, file);
2106
+ file = NULL;
2107
+ } else {
2108
+ build_filedef(&ctx, file, file_proto);
2109
+ upb_strtable_insert3(&s->files, file->name, strlen(file->name),
2110
+ upb_value_constptr(file), ctx.alloc);
2111
+ UPB_ASSERT(upb_ok(status));
2112
+ upb_arena_fuse(s->arena, file_arena);
2113
+ }
2110
2114
 
2111
- upb_arena_free(tmparena);
2112
- return ok ? file : NULL;
2115
+ done:
2116
+ upb_arena_free(file_arena);
2117
+ return file;
2113
2118
  }
2114
2119
 
2115
2120
  const upb_filedef *upb_symtab_addfile(
@@ -2141,8 +2146,9 @@ bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) {
2141
2146
  if (!_upb_symtab_loaddefinit(s, *deps)) goto err;
2142
2147
  }
2143
2148
 
2144
- file = google_protobuf_FileDescriptorProto_parse(
2145
- init->descriptor.data, init->descriptor.size, arena);
2149
+ file = google_protobuf_FileDescriptorProto_parse_ex(
2150
+ init->descriptor.data, init->descriptor.size, arena, UPB_DECODE_ALIAS);
2151
+ s->bytes_loaded += init->descriptor.size;
2146
2152
 
2147
2153
  if (!file) {
2148
2154
  upb_status_seterrf(
@@ -2165,5 +2171,8 @@ err:
2165
2171
  return false;
2166
2172
  }
2167
2173
 
2168
- #undef CHK
2174
+ size_t _upb_symtab_bytesloaded(const upb_symtab *s) {
2175
+ return s->bytes_loaded;
2176
+ }
2177
+
2169
2178
  #undef CHK_OOM