Start adding upb test runs to CI for protobuf repo

This change moves the upb Fastbuild, Optimized, and FastTable test runs over to
the protobuf repo CI in preparation for moving the upb codebase itself. There
are a bunch more test runs to move, but this initial change handles the easy
ones first.

I also updated our pinned upb version to the current head to pick up some
recent fixes.

PiperOrigin-RevId: 557486174
pull/13561/head
Adam Cozzette 2 years ago committed by Copybara-Service
parent 1f9583069f
commit 8059da24d2
  1. 8
      .github/workflows/test_runner.yml
  2. 41
      .github/workflows/test_upb.yml
  3. 11
      build_defs/upb.patch
  4. 13794
      php/ext/google/protobuf/php-upb.c
  5. 890
      php/ext/google/protobuf/php-upb.h
  6. 5
      protobuf_deps.bzl
  7. 13794
      ruby/ext/google/protobuf_c/ruby-upb.c
  8. 826
      ruby/ext/google/protobuf_c/ruby-upb.h

@ -176,6 +176,14 @@ jobs:
safe-checkout: ${{ needs.check-tag.outputs.checkout-sha }}
secrets: inherit
upb:
name: μpb
needs: [check-tag]
uses: ./.github/workflows/test_upb.yml
with:
safe-checkout: ${{ needs.check-tag.outputs.checkout-sha }}
secrets: inherit
staleness:
name: Staleness
needs: [check-tag]

@ -0,0 +1,41 @@
name: μpb Tests
on:
workflow_call:
inputs:
safe-checkout:
required: true
description: "The SHA key for the commit we want to run over"
type: string
permissions:
contents: read
jobs:
linux:
strategy:
fail-fast: false # Don't cancel all jobs if one fails.
matrix:
config:
- { name: "Fastbuild" }
- { name: "Optimized", flags: "-c opt" }
- { name: "FastTable", flags: "--@upb//:fasttable_enabled=true" }
include:
# Set defaults
- image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:04cd765285bc52cbbf51d66c8c66d8603579cf0f19cc42df26b09d2c270541fb
- targets: "@upb//..."
name: ${{ matrix.config.name }}
runs-on: ubuntu-latest
steps:
- name: Checkout pending changes
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
ref: ${{ inputs.safe-checkout }}
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v2
with:
image: ${{ matrix.image }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: upb-bazel
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.targets }} ${{ matrix.config.flags }}

@ -1,11 +0,0 @@
--- upbc/bootstrap_compiler.bzl
+++ upbc/bootstrap_compiler.bzl
@@ -20,7 +20,7 @@ _upbc_base = "//upbc:protoc-gen-upb"
# begin:github_only
_is_google3 = False
-_extra_proto_path = "-Iexternal/com_google_protobuf/src "
+_extra_proto_path = "-Isrc "
# end:github_only
def _upbc(stage):

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -150,7 +150,6 @@ def protobuf_deps():
_github_archive(
name = "upb",
repo = "https://github.com/protocolbuffers/upb",
commit = "58877b55e0796bcca743e9bd4d2be42092562f30",
sha256 = "b3a3279cffb91e22fd38fb316a39ded87211bf89ff39337c7f151d88ed3b71fd",
patches = ["@com_google_protobuf//build_defs:upb.patch"],
commit = "cd176a0cd1913ea8c643680d206c8ca278815c2c",
sha256 = "661b2d63dff82c6868cd1dea5e7be2ca1a6467746a146c293834f18aaa709077",
)

File diff suppressed because it is too large Load Diff

@ -359,8 +359,8 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
#endif /* UPB_BASE_STATUS_H_ */
#ifndef UPB_INTERNAL_ARRAY_INTERNAL_H_
#define UPB_INTERNAL_ARRAY_INTERNAL_H_
#ifndef UPB_COLLECTIONS_INTERNAL_ARRAY_H_
#define UPB_COLLECTIONS_INTERNAL_ARRAY_H_
#include <string.h>
@ -1366,7 +1366,7 @@ UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) {
#endif
#endif /* UPB_INTERNAL_ARRAY_INTERNAL_H_ */
#endif /* UPB_COLLECTIONS_INTERNAL_ARRAY_H_ */
#ifndef UPB_COLLECTIONS_MAP_H_
#define UPB_COLLECTIONS_MAP_H_
@ -1479,8 +1479,8 @@ UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter);
// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
#ifndef UPB_COLLECTIONS_MAP_INTERNAL_H_
#define UPB_COLLECTIONS_MAP_INTERNAL_H_
#ifndef UPB_COLLECTIONS_INTERNAL_MAP_H_
#define UPB_COLLECTIONS_INTERNAL_MAP_H_
#ifndef UPB_HASH_STR_TABLE_H_
@ -1916,47 +1916,18 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size);
#endif
#endif /* UPB_COLLECTIONS_MAP_INTERNAL_H_ */
#ifndef UPB_BASE_LOG2_H_
#define UPB_BASE_LOG2_H_
// Must be last.
#ifdef __cplusplus
extern "C" {
#endif
UPB_INLINE int upb_Log2Ceiling(int x) {
if (x <= 1) return 0;
#ifdef __GNUC__
return 32 - __builtin_clz(x - 1);
#else
int lg2 = 0;
while ((1 << lg2) < x) lg2++;
return lg2;
#endif
}
UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); }
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_BASE_LOG2_H_ */
#endif /* UPB_COLLECTIONS_INTERNAL_MAP_H_ */
// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
#ifndef UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_
#define UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_
#ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_
#define UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_
#include <stdlib.h>
#ifndef UPB_MESSAGE_EXTENSION_INTERNAL_H_
#define UPB_MESSAGE_EXTENSION_INTERNAL_H_
#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_
#define UPB_MESSAGE_INTERNAL_EXTENSION_H_
// Public APIs for message operations that do not depend on the schema.
@ -2070,7 +2041,7 @@ const upb_Message_Extension* _upb_Message_Getext(
#endif
#endif /* UPB_MESSAGE_EXTENSION_INTERNAL_H_ */
#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */
#ifndef UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
#define UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
@ -2110,7 +2081,7 @@ typedef struct {
// require 8-byte alignment.
double d;
};
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal.h:internal_layout)
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal/message.h:internal_layout)
upb_MapEntryData data;
} upb_MapEntry;
@ -2184,7 +2155,36 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s,
#endif
#endif /* UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ */
#endif /* UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ */
#ifndef UPB_BASE_LOG2_H_
#define UPB_BASE_LOG2_H_
// Must be last.
#ifdef __cplusplus
extern "C" {
#endif
UPB_INLINE int upb_Log2Ceiling(int x) {
if (x <= 1) return 0;
#ifdef __GNUC__
return 32 - __builtin_clz(x - 1);
#else
int lg2 = 0;
while ((1 << lg2) < x) lg2++;
return lg2;
#endif
}
UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); }
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_BASE_LOG2_H_ */
#ifndef UPB_GENERATED_CODE_SUPPORT_H_
#define UPB_GENERATED_CODE_SUPPORT_H_
@ -2244,6 +2244,10 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val,
#define UPB_MESSAGE_ACCESSORS_H_
#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
/*
** Our memory representation for parsing tables and messages themselves.
** Functions in this file are used by generated code and possibly reflection.
@ -2423,10 +2427,6 @@ bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
#endif /* UPB_MESSAGE_INTERNAL_H_ */
#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
// Must be last.
#if defined(__GNUC__) && !defined(__clang__)
@ -11732,12 +11732,12 @@ UPB_INLINE const char* upb_WireReader_SkipValue(
#endif // UPB_WIRE_READER_H_
#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_
#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_
#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
// Must be last.
@ -11746,117 +11746,377 @@ UPB_INLINE const char* upb_WireReader_SkipValue(
extern "C" {
#endif
upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s);
size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s);
upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s);
bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext,
const upb_FieldDef* f);
bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v,
upb_Status* status);
bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size,
upb_value* v);
void** _upb_DefPool_ScratchData(const upb_DefPool* s);
size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s);
void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform);
// For generated code only: loads a generated descriptor.
typedef struct _upb_DefPool_Init {
struct _upb_DefPool_Init** deps; // Dependencies of this file.
const upb_MiniTableFile* layout;
const char* filename;
upb_StringView descriptor; // Serialized descriptor.
} _upb_DefPool_Init;
UPB_INLINE char _upb_ToBase92(int8_t ch) {
extern const char _kUpb_ToBase92[];
UPB_ASSERT(0 <= ch && ch < 92);
return _kUpb_ToBase92[ch];
}
bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init);
UPB_INLINE char _upb_FromBase92(uint8_t ch) {
extern const int8_t _kUpb_FromBase92[];
if (' ' > ch || ch > '~') return -1;
return _kUpb_FromBase92[ch - ' '];
}
// Should only be directly called by tests. This variant lets us suppress
// the use of compiled-in tables, forcing a rebuild of the tables at runtime.
bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init,
bool rebuild_minitable);
UPB_INLINE const char* _upb_Base92_DecodeVarint(const char* ptr,
const char* end, char first_ch,
uint8_t min, uint8_t max,
uint32_t* out_val) {
uint32_t val = 0;
uint32_t shift = 0;
const int bits_per_char =
upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min));
char ch = first_ch;
while (1) {
uint32_t bits = _upb_FromBase92(ch) - _upb_FromBase92(min);
val |= bits << shift;
if (ptr == end || *ptr < min || max < *ptr) {
*out_val = val;
UPB_ASSUME(ptr != NULL);
return ptr;
}
ch = *ptr++;
shift += bits_per_char;
if (shift >= 32) return NULL;
}
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
// Must be last.
// We want to copy the options verbatim into the destination options proto.
// We use serialize+parse as our deep copy.
#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \
if (UPB_DESC(desc_type##_has_options)(proto)) { \
size_t size; \
char* pb = UPB_DESC(options_type##_serialize)( \
UPB_DESC(desc_type##_options)(proto), ctx->tmp_arena, &size); \
if (!pb) _upb_DefBuilder_OomErr(ctx); \
target = \
UPB_DESC(options_type##_parse)(pb, size, _upb_DefBuilder_Arena(ctx)); \
if (!target) _upb_DefBuilder_OomErr(ctx); \
} else { \
target = (const UPB_DESC(options_type)*)kUpbDefOptDefault; \
}
// upb_MdDecoder: used internally for decoding MiniDescriptors for messages,
// extensions, and enums.
typedef struct {
const char* end;
upb_Status* status;
jmp_buf err;
} upb_MdDecoder;
#ifdef __cplusplus
extern "C" {
#endif
UPB_PRINTF(2, 3)
UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp(upb_MdDecoder* d,
const char* fmt, ...) {
if (d->status) {
va_list argp;
upb_Status_SetErrorMessage(d->status, "Error building mini table: ");
va_start(argp, fmt);
upb_Status_VAppendErrorFormat(d->status, fmt, argp);
va_end(argp);
}
UPB_LONGJMP(d->err, 1);
}
struct upb_DefBuilder {
upb_DefPool* symtab;
upb_FileDef* file; // File we are building.
upb_Arena* arena; // Allocate defs here.
upb_Arena* tmp_arena; // For temporary allocations.
upb_Status* status; // Record errors here.
const upb_MiniTableFile* layout; // NULL if we should build layouts.
upb_MiniTablePlatform platform; // Platform we are targeting.
int enum_count; // Count of enums built so far.
int msg_count; // Count of messages built so far.
int ext_count; // Count of extensions built so far.
jmp_buf err; // longjmp() on error.
};
UPB_INLINE void upb_MdDecoder_CheckOutOfMemory(upb_MdDecoder* d,
const void* ptr) {
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Out of memory");
}
extern const char* kUpbDefOptDefault;
UPB_INLINE const char* upb_MdDecoder_DecodeBase92Varint(
upb_MdDecoder* d, const char* ptr, char first_ch, uint8_t min, uint8_t max,
uint32_t* out_val) {
ptr = _upb_Base92_DecodeVarint(ptr, d->end, first_ch, min, max, out_val);
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Overlong varint");
return ptr;
}
// ctx->status has already been set elsewhere so just fail/longjmp()
UPB_NORETURN void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx);
UPB_NORETURN void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt,
...) UPB_PRINTF(2, 3);
UPB_NORETURN void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx);
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx,
const char* prefix,
upb_StringView name);
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
// Given a symbol and the base symbol inside which it is defined,
// find the symbol's definition.
const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx,
const char* from_name_dbg,
const char* base, upb_StringView sym,
upb_deftype_t* type);
const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx,
const char* from_name_dbg, const char* base,
upb_StringView sym, upb_deftype_t type);
// Must be last.
char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f,
const char** src, const char* end);
typedef enum {
kUpb_EncodedType_Double = 0,
kUpb_EncodedType_Float = 1,
kUpb_EncodedType_Fixed32 = 2,
kUpb_EncodedType_Fixed64 = 3,
kUpb_EncodedType_SFixed32 = 4,
kUpb_EncodedType_SFixed64 = 5,
kUpb_EncodedType_Int32 = 6,
kUpb_EncodedType_UInt32 = 7,
kUpb_EncodedType_SInt32 = 8,
kUpb_EncodedType_Int64 = 9,
kUpb_EncodedType_UInt64 = 10,
kUpb_EncodedType_SInt64 = 11,
kUpb_EncodedType_OpenEnum = 12,
kUpb_EncodedType_Bool = 13,
kUpb_EncodedType_Bytes = 14,
kUpb_EncodedType_String = 15,
kUpb_EncodedType_Group = 16,
kUpb_EncodedType_Message = 17,
kUpb_EncodedType_ClosedEnum = 18,
const char* _upb_DefBuilder_FullToShort(const char* fullname);
kUpb_EncodedType_RepeatedBase = 20,
} upb_EncodedType;
UPB_INLINE void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) {
if (bytes == 0) return NULL;
void* ret = upb_Arena_Malloc(ctx->arena, bytes);
if (!ret) _upb_DefBuilder_OomErr(ctx);
return ret;
}
typedef enum {
kUpb_EncodedFieldModifier_FlipPacked = 1 << 0,
kUpb_EncodedFieldModifier_IsRequired = 1 << 1,
kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2,
} upb_EncodedFieldModifier;
// Adds a symbol |v| to the symtab, which must be a def pointer previously
// packed with pack_def(). The def's pointer to upb_FileDef* must be set before
// adding, so we know which entries to remove if building this file fails.
enum {
kUpb_EncodedValue_MinField = ' ',
kUpb_EncodedValue_MaxField = 'I',
kUpb_EncodedValue_MinModifier = 'L',
kUpb_EncodedValue_MaxModifier = '[',
kUpb_EncodedValue_End = '^',
kUpb_EncodedValue_MinSkip = '_',
kUpb_EncodedValue_MaxSkip = '~',
kUpb_EncodedValue_OneofSeparator = '~',
kUpb_EncodedValue_FieldSeparator = '|',
kUpb_EncodedValue_MinOneofField = ' ',
kUpb_EncodedValue_MaxOneofField = 'b',
kUpb_EncodedValue_MaxEnumMask = 'A',
};
enum {
kUpb_EncodedVersion_EnumV1 = '!',
kUpb_EncodedVersion_ExtensionV1 = '#',
kUpb_EncodedVersion_MapV1 = '%',
kUpb_EncodedVersion_MessageV1 = '$',
kUpb_EncodedVersion_MessageSetV1 = '&',
};
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
// Must be last.
typedef enum {
kUpb_FieldModifier_IsRepeated = 1 << 0,
kUpb_FieldModifier_IsPacked = 1 << 1,
kUpb_FieldModifier_IsClosedEnum = 1 << 2,
kUpb_FieldModifier_IsProto3Singular = 1 << 3,
kUpb_FieldModifier_IsRequired = 1 << 4,
} kUpb_FieldModifier;
typedef enum {
kUpb_MessageModifier_ValidateUtf8 = 1 << 0,
kUpb_MessageModifier_DefaultIsPacked = 1 << 1,
kUpb_MessageModifier_IsExtendable = 1 << 2,
} kUpb_MessageModifier;
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
// Must be last.
// If the input buffer has at least this many bytes available, the encoder call
// is guaranteed to succeed (as long as field number order is maintained).
#define kUpb_MtDataEncoder_MinSize 16
typedef struct {
char* end; // Limit of the buffer passed as a parameter.
// Aliased to internal-only members in .cc.
char internal[32];
} upb_MtDataEncoder;
#ifdef __cplusplus
extern "C" {
#endif
// Encodes field/oneof information for a given message. The sequence of calls
// should look like:
//
// upb_MtDataEncoder e;
// char buf[256];
// char* ptr = buf;
// e.end = ptr + sizeof(buf);
// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero
// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod);
// // Fields *must* be in field number order.
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
//
// // If oneofs are present. Oneofs must be encoded after regular fields.
// ptr = upb_MiniTable_StartOneof(&e, ptr)
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// ptr = upb_MiniTable_StartOneof(&e, ptr);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// Oneofs must be encoded after all regular fields.
char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr,
uint64_t msg_mod);
char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr,
upb_FieldType type, uint32_t field_num,
uint64_t field_mod);
char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr);
char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr,
uint32_t field_num);
// Encodes the set of values for a given enum. The values must be given in
// order (after casting to uint32_t), and repeats are not allowed.
char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr);
char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr,
uint32_t val);
char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr);
// Encodes an entire mini descriptor for an extension.
char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr,
upb_FieldType type, uint32_t field_num,
uint64_t field_mod);
// Encodes an entire mini descriptor for a map.
char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr,
upb_FieldType key_type,
upb_FieldType value_type, uint64_t key_mod,
uint64_t value_mod);
// Encodes an entire mini descriptor for a message set.
char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */
#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_
#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_
#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_
#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_
// Must be last.
#ifdef __cplusplus
extern "C" {
#endif
upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s);
size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s);
upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s);
bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext,
const upb_FieldDef* f);
bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v,
upb_Status* status);
bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size,
upb_value* v);
void** _upb_DefPool_ScratchData(const upb_DefPool* s);
size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s);
void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform);
// For generated code only: loads a generated descriptor.
typedef struct _upb_DefPool_Init {
struct _upb_DefPool_Init** deps; // Dependencies of this file.
const upb_MiniTableFile* layout;
const char* filename;
upb_StringView descriptor; // Serialized descriptor.
} _upb_DefPool_Init;
bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init);
// Should only be directly called by tests. This variant lets us suppress
// the use of compiled-in tables, forcing a rebuild of the tables at runtime.
bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init,
bool rebuild_minitable);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */
// Must be last.
// We want to copy the options verbatim into the destination options proto.
// We use serialize+parse as our deep copy.
#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \
if (UPB_DESC(desc_type##_has_options)(proto)) { \
size_t size; \
char* pb = UPB_DESC(options_type##_serialize)( \
UPB_DESC(desc_type##_options)(proto), ctx->tmp_arena, &size); \
if (!pb) _upb_DefBuilder_OomErr(ctx); \
target = \
UPB_DESC(options_type##_parse)(pb, size, _upb_DefBuilder_Arena(ctx)); \
if (!target) _upb_DefBuilder_OomErr(ctx); \
} else { \
target = (const UPB_DESC(options_type)*)kUpbDefOptDefault; \
}
#ifdef __cplusplus
extern "C" {
#endif
struct upb_DefBuilder {
upb_DefPool* symtab;
upb_FileDef* file; // File we are building.
upb_Arena* arena; // Allocate defs here.
upb_Arena* tmp_arena; // For temporary allocations.
upb_Status* status; // Record errors here.
const upb_MiniTableFile* layout; // NULL if we should build layouts.
upb_MiniTablePlatform platform; // Platform we are targeting.
int enum_count; // Count of enums built so far.
int msg_count; // Count of messages built so far.
int ext_count; // Count of extensions built so far.
jmp_buf err; // longjmp() on error.
};
extern const char* kUpbDefOptDefault;
// ctx->status has already been set elsewhere so just fail/longjmp()
UPB_NORETURN void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx);
UPB_NORETURN void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt,
...) UPB_PRINTF(2, 3);
UPB_NORETURN void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx);
const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx,
const char* prefix,
upb_StringView name);
// Given a symbol and the base symbol inside which it is defined,
// find the symbol's definition.
const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx,
const char* from_name_dbg,
const char* base, upb_StringView sym,
upb_deftype_t* type);
const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx,
const char* from_name_dbg, const char* base,
upb_StringView sym, upb_deftype_t type);
char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f,
const char** src, const char* end);
const char* _upb_DefBuilder_FullToShort(const char* fullname);
UPB_INLINE void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) {
if (bytes == 0) return NULL;
void* ret = upb_Arena_Malloc(ctx->arena, bytes);
if (!ret) _upb_DefBuilder_OomErr(ctx);
return ret;
}
// Adds a symbol |v| to the symtab, which must be a def pointer previously
// packed with pack_def(). The def's pointer to upb_FileDef* must be set before
// adding, so we know which entries to remove if building this file fails.
UPB_INLINE void _upb_DefBuilder_Add(upb_DefBuilder* ctx, const char* name,
upb_value v) {
upb_StringView sym = {.data = name, .size = strlen(name)};
@ -12067,116 +12327,35 @@ upb_MessageDef* _upb_MessageDefs_New(
#endif
#endif /* UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ */
#ifndef UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
#define UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
// Must be last.
#ifdef __cplusplus
extern "C" {
#endif
upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i);
// Allocate and initialize an array of |n| service defs.
upb_ServiceDef* _upb_ServiceDefs_New(
upb_DefBuilder* ctx, int n,
const UPB_DESC(ServiceDescriptorProto) * const* protos);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */
#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_
#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
// Must be last.
#endif /* UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ */
// If the input buffer has at least this many bytes available, the encoder call
// is guaranteed to succeed (as long as field number order is maintained).
#define kUpb_MtDataEncoder_MinSize 16
#ifndef UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
#define UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
typedef struct {
char* end; // Limit of the buffer passed as a parameter.
// Aliased to internal-only members in .cc.
char internal[32];
} upb_MtDataEncoder;
// Must be last.
#ifdef __cplusplus
extern "C" {
#endif
// Encodes field/oneof information for a given message. The sequence of calls
// should look like:
//
// upb_MtDataEncoder e;
// char buf[256];
// char* ptr = buf;
// e.end = ptr + sizeof(buf);
// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero
// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod);
// // Fields *must* be in field number order.
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
//
// // If oneofs are present. Oneofs must be encoded after regular fields.
// ptr = upb_MiniTable_StartOneof(&e, ptr)
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// ptr = upb_MiniTable_StartOneof(&e, ptr);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// Oneofs must be encoded after all regular fields.
char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr,
uint64_t msg_mod);
char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr,
upb_FieldType type, uint32_t field_num,
uint64_t field_mod);
char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr);
char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr,
uint32_t field_num);
// Encodes the set of values for a given enum. The values must be given in
// order (after casting to uint32_t), and repeats are not allowed.
char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr);
char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr,
uint32_t val);
char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr);
// Encodes an entire mini descriptor for an extension.
char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr,
upb_FieldType type, uint32_t field_num,
uint64_t field_mod);
// Encodes an entire mini descriptor for a map.
char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr,
upb_FieldType key_type,
upb_FieldType value_type, uint64_t key_mod,
uint64_t value_mod);
upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i);
// Encodes an entire mini descriptor for a message set.
char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr);
// Allocate and initialize an array of |n| service defs.
upb_ServiceDef* _upb_ServiceDefs_New(
upb_DefBuilder* ctx, int n,
const UPB_DESC(ServiceDescriptorProto) * const* protos);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */
#endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */
#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_
#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_
// Must be last.
@ -12281,28 +12460,6 @@ upb_ExtensionRange* _upb_ExtensionRanges_New(
#endif /* UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ */
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
// Must be last.
typedef enum {
kUpb_FieldModifier_IsRepeated = 1 << 0,
kUpb_FieldModifier_IsPacked = 1 << 1,
kUpb_FieldModifier_IsClosedEnum = 1 << 2,
kUpb_FieldModifier_IsProto3Singular = 1 << 3,
kUpb_FieldModifier_IsRequired = 1 << 4,
} kUpb_FieldModifier;
typedef enum {
kUpb_MessageModifier_ValidateUtf8 = 1 << 0,
kUpb_MessageModifier_DefaultIsPacked = 1 << 1,
kUpb_MessageModifier_IsExtendable = 1 << 2,
} kUpb_MessageModifier;
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
#ifndef UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_
#define UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_
@ -12556,163 +12713,6 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) {
#endif /* UPB_WIRE_INTERNAL_DECODE_H_ */
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
// Must be last.
#ifdef __cplusplus
extern "C" {
#endif
UPB_INLINE char _upb_ToBase92(int8_t ch) {
extern const char _kUpb_ToBase92[];
UPB_ASSERT(0 <= ch && ch < 92);
return _kUpb_ToBase92[ch];
}
UPB_INLINE char _upb_FromBase92(uint8_t ch) {
extern const int8_t _kUpb_FromBase92[];
if (' ' > ch || ch > '~') return -1;
return _kUpb_FromBase92[ch - ' '];
}
UPB_INLINE const char* _upb_Base92_DecodeVarint(const char* ptr,
const char* end, char first_ch,
uint8_t min, uint8_t max,
uint32_t* out_val) {
uint32_t val = 0;
uint32_t shift = 0;
const int bits_per_char =
upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min));
char ch = first_ch;
while (1) {
uint32_t bits = _upb_FromBase92(ch) - _upb_FromBase92(min);
val |= bits << shift;
if (ptr == end || *ptr < min || max < *ptr) {
*out_val = val;
UPB_ASSUME(ptr != NULL);
return ptr;
}
ch = *ptr++;
shift += bits_per_char;
if (shift >= 32) return NULL;
}
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
// Must be last.
typedef enum {
kUpb_EncodedType_Double = 0,
kUpb_EncodedType_Float = 1,
kUpb_EncodedType_Fixed32 = 2,
kUpb_EncodedType_Fixed64 = 3,
kUpb_EncodedType_SFixed32 = 4,
kUpb_EncodedType_SFixed64 = 5,
kUpb_EncodedType_Int32 = 6,
kUpb_EncodedType_UInt32 = 7,
kUpb_EncodedType_SInt32 = 8,
kUpb_EncodedType_Int64 = 9,
kUpb_EncodedType_UInt64 = 10,
kUpb_EncodedType_SInt64 = 11,
kUpb_EncodedType_OpenEnum = 12,
kUpb_EncodedType_Bool = 13,
kUpb_EncodedType_Bytes = 14,
kUpb_EncodedType_String = 15,
kUpb_EncodedType_Group = 16,
kUpb_EncodedType_Message = 17,
kUpb_EncodedType_ClosedEnum = 18,
kUpb_EncodedType_RepeatedBase = 20,
} upb_EncodedType;
typedef enum {
kUpb_EncodedFieldModifier_FlipPacked = 1 << 0,
kUpb_EncodedFieldModifier_IsRequired = 1 << 1,
kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2,
} upb_EncodedFieldModifier;
enum {
kUpb_EncodedValue_MinField = ' ',
kUpb_EncodedValue_MaxField = 'I',
kUpb_EncodedValue_MinModifier = 'L',
kUpb_EncodedValue_MaxModifier = '[',
kUpb_EncodedValue_End = '^',
kUpb_EncodedValue_MinSkip = '_',
kUpb_EncodedValue_MaxSkip = '~',
kUpb_EncodedValue_OneofSeparator = '~',
kUpb_EncodedValue_FieldSeparator = '|',
kUpb_EncodedValue_MinOneofField = ' ',
kUpb_EncodedValue_MaxOneofField = 'b',
kUpb_EncodedValue_MaxEnumMask = 'A',
};
enum {
kUpb_EncodedVersion_EnumV1 = '!',
kUpb_EncodedVersion_ExtensionV1 = '#',
kUpb_EncodedVersion_MapV1 = '%',
kUpb_EncodedVersion_MessageV1 = '$',
kUpb_EncodedVersion_MessageSetV1 = '&',
};
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
// Must be last.
// upb_MdDecoder: used internally for decoding MiniDescriptors for messages,
// extensions, and enums.
typedef struct {
const char* end;
upb_Status* status;
jmp_buf err;
} upb_MdDecoder;
UPB_PRINTF(2, 3)
UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp(upb_MdDecoder* d,
const char* fmt, ...) {
if (d->status) {
va_list argp;
upb_Status_SetErrorMessage(d->status, "Error building mini table: ");
va_start(argp, fmt);
upb_Status_VAppendErrorFormat(d->status, fmt, argp);
va_end(argp);
}
UPB_LONGJMP(d->err, 1);
}
UPB_INLINE void upb_MdDecoder_CheckOutOfMemory(upb_MdDecoder* d,
const void* ptr) {
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Out of memory");
}
UPB_INLINE const char* upb_MdDecoder_DecodeBase92Varint(
upb_MdDecoder* d, const char* ptr, char first_ch, uint8_t min, uint8_t max,
uint32_t* out_val) {
ptr = _upb_Base92_DecodeVarint(ptr, d->end, first_ch, min, max, out_val);
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Overlong varint");
return ptr;
}
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
// This should #undef all macros #defined in def.inc
#undef UPB_SIZE

Loading…
Cancel
Save