update PHP and Ruby to use the new accessors, delete the old ones

PiperOrigin-RevId: 493109199
pull/11129/head
Eric Salo 2 years ago committed by Copybara-Service
parent 9e12e81bc2
commit 3f36a91442
  1. 2
      php/ext/google/protobuf/config.m4
  2. 52
      php/ext/google/protobuf/message.c
  3. 88
      php/ext/google/protobuf/php-upb.c
  4. 226
      php/ext/google/protobuf/php-upb.h
  5. 4
      protobuf_deps.bzl
  6. 10
      ruby/Rakefile
  7. 6
      ruby/ext/google/protobuf_c/defs.c
  8. 53
      ruby/ext/google/protobuf_c/message.c
  9. 88
      ruby/ext/google/protobuf_c/ruby-upb.c
  10. 226
      ruby/ext/google/protobuf_c/ruby-upb.h

@ -5,7 +5,7 @@ if test "$PHP_PROTOBUF" != "no"; then
PHP_NEW_EXTENSION(
protobuf,
arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/naive.c third_party/utf8_range/range2-neon.c third_party/utf8_range/range2-sse.c,
$ext_shared, , -std=gnu99)
$ext_shared, , -std=gnu99 -I@ext_srcdir@/third_party/utf8_range)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/utf8_range)
fi

@ -153,11 +153,12 @@ static void Message_get(Message *intern, const upb_FieldDef *f, zval *rv) {
RepeatedField_GetPhpWrapper(rv, msgval.array, TypeInfo_Get(f),
&intern->arena);
} else {
if (upb_FieldDef_IsSubMessage(f) && !upb_Message_Has(intern->msg, f)) {
if (upb_FieldDef_IsSubMessage(f) &&
!upb_Message_HasFieldByDef(intern->msg, f)) {
ZVAL_NULL(rv);
return;
}
upb_MessageValue msgval = upb_Message_Get(intern->msg, f);
upb_MessageValue msgval = upb_Message_GetFieldByDef(intern->msg, f);
Convert_UpbToPhp(msgval, rv, TypeInfo_Get(f), &intern->arena);
}
}
@ -173,13 +174,13 @@ static bool Message_set(Message *intern, const upb_FieldDef *f, zval *val) {
msgval.array_val = RepeatedField_GetUpbArray(val, TypeInfo_Get(f), arena);
if (!msgval.array_val) return false;
} else if (upb_FieldDef_IsSubMessage(f) && Z_TYPE_P(val) == IS_NULL) {
upb_Message_ClearField(intern->msg, f);
upb_Message_ClearFieldByDef(intern->msg, f);
return true;
} else {
if (!Convert_PhpToUpb(val, &msgval, TypeInfo_Get(f), arena)) return false;
}
upb_Message_Set(intern->msg, f, msgval, arena);
upb_Message_SetFieldByDef(intern->msg, f, msgval, arena);
return true;
}
@ -224,14 +225,15 @@ static bool MessageEq(const upb_Message *m1, const upb_Message *m2, const upb_Me
const upb_FieldDef *f = upb_MessageDef_Field(m, i);
if (upb_FieldDef_HasPresence(f)) {
if (upb_Message_Has(m1, f) != upb_Message_Has(m2, f)) {
if (upb_Message_HasFieldByDef(m1, f) !=
upb_Message_HasFieldByDef(m2, f)) {
return false;
}
if (!upb_Message_Has(m1, f)) continue;
if (!upb_Message_HasFieldByDef(m1, f)) continue;
}
upb_MessageValue val1 = upb_Message_Get(m1, f);
upb_MessageValue val2 = upb_Message_Get(m2, f);
upb_MessageValue val1 = upb_Message_GetFieldByDef(m1, f);
upb_MessageValue val2 = upb_Message_GetFieldByDef(m2, f);
if (upb_FieldDef_IsMap(f)) {
if (!MapEq(val1.map_val, val2.map_val, MapType_Get(f))) return false;
@ -297,7 +299,7 @@ static int Message_has_property(PROTO_VAL *obj, PROTO_STR *member,
return 0;
}
return upb_Message_Has(intern->msg, f);
return upb_Message_HasFieldByDef(intern->msg, f);
}
/**
@ -331,7 +333,7 @@ static void Message_unset_property(PROTO_VAL *obj, PROTO_STR *member,
return;
}
upb_Message_ClearField(intern->msg, f);
upb_Message_ClearFieldByDef(intern->msg, f);
}
@ -572,7 +574,7 @@ bool Message_InitFromPhp(upb_Message *msg, const upb_MessageDef *m, zval *init,
}
}
upb_Message_Set(msg, f, msgval, arena);
upb_Message_SetFieldByDef(msg, f, msgval, arena);
zend_hash_move_forward_ex(table, &pos);
zval_dtor(&key);
}
@ -645,7 +647,7 @@ PHP_METHOD(Message, discardUnknownFields) {
*/
PHP_METHOD(Message, clear) {
Message* intern = (Message*)Z_OBJ_P(getThis());
upb_Message_Clear(intern->msg, intern->desc->msgdef);
upb_Message_ClearByDef(intern->msg, intern->desc->msgdef);
}
static bool Message_checkEncodeStatus(upb_EncodeStatus status) {
@ -878,11 +880,12 @@ PHP_METHOD(Message, readWrapperValue) {
return;
}
if (upb_Message_Has(intern->msg, f)) {
const upb_Message *wrapper = upb_Message_Get(intern->msg, f).msg_val;
if (upb_Message_HasFieldByDef(intern->msg, f)) {
const upb_Message *wrapper =
upb_Message_GetFieldByDef(intern->msg, f).msg_val;
const upb_MessageDef *m = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef *val_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_MessageValue msgval = upb_Message_Get(wrapper, val_f);
upb_MessageValue msgval = upb_Message_GetFieldByDef(wrapper, val_f);
zval ret;
Convert_UpbToPhp(msgval, &ret, TypeInfo_Get(val_f), &intern->arena);
RETURN_COPY_VALUE(&ret);
@ -933,7 +936,7 @@ PHP_METHOD(Message, writeWrapperValue) {
}
if (Z_TYPE_P(val) == IS_NULL) {
upb_Message_ClearField(intern->msg, f);
upb_Message_ClearFieldByDef(intern->msg, f);
} else {
const upb_MessageDef *m = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef *val_f = upb_MessageDef_FindFieldByNumber(m, 1);
@ -944,7 +947,7 @@ PHP_METHOD(Message, writeWrapperValue) {
}
wrapper = upb_Message_Mutable(intern->msg, f, arena).msg;
upb_Message_Set(wrapper, val_f, msgval, arena);
upb_Message_SetFieldByDef(wrapper, val_f, msgval, arena);
}
}
@ -1009,7 +1012,7 @@ PHP_METHOD(Message, hasOneof) {
(int)field_num);
}
RETVAL_BOOL(upb_Message_Has(intern->msg, f));
RETVAL_BOOL(upb_Message_HasFieldByDef(intern->msg, f));
}
/**
@ -1043,12 +1046,13 @@ PHP_METHOD(Message, readOneof) {
(int)field_num);
}
if (upb_FieldDef_IsSubMessage(f) && !upb_Message_Has(intern->msg, f)) {
if (upb_FieldDef_IsSubMessage(f) &&
!upb_Message_HasFieldByDef(intern->msg, f)) {
RETURN_NULL();
}
{
upb_MessageValue msgval = upb_Message_Get(intern->msg, f);
upb_MessageValue msgval = upb_Message_GetFieldByDef(intern->msg, f);
Convert_UpbToPhp(msgval, &ret, TypeInfo_Get(f), &intern->arena);
}
@ -1091,13 +1095,13 @@ PHP_METHOD(Message, writeOneof) {
f = upb_MessageDef_FindFieldByNumber(intern->desc->msgdef, field_num);
if (upb_FieldDef_IsSubMessage(f) && Z_TYPE_P(val) == IS_NULL) {
upb_Message_ClearField(intern->msg, f);
upb_Message_ClearFieldByDef(intern->msg, f);
return;
} else if (!Convert_PhpToUpb(val, &msgval, TypeInfo_Get(f), arena)) {
return;
}
upb_Message_Set(intern->msg, f, msgval, arena);
upb_Message_SetFieldByDef(intern->msg, f, msgval, arena);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 0)
@ -1147,7 +1151,7 @@ static const char TYPE_URL_PREFIX[] = "type.googleapis.com/";
static upb_MessageValue Message_getval(Message *intern, const char *field_name) {
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(intern->desc->msgdef, field_name);
PBPHP_ASSERT(f);
return upb_Message_Get(intern->msg, f);
return upb_Message_GetFieldByDef(intern->msg, f);
}
static void Message_setval(Message *intern, const char *field_name,
@ -1155,7 +1159,7 @@ static void Message_setval(Message *intern, const char *field_name,
const upb_FieldDef *f =
upb_MessageDef_FindFieldByName(intern->desc->msgdef, field_name);
PBPHP_ASSERT(f);
upb_Message_Set(intern->msg, f, val, Arena_Get(&intern->arena));
upb_Message_SetFieldByDef(intern->msg, f, val, Arena_Get(&intern->arena));
}
static upb_MessageValue StringVal(upb_StringView view) {

@ -62,7 +62,14 @@
#define UPB_MAPTYPE_STRING 0
/* UPB_INLINE: inline if possible, emit standalone code if required. */
// UPB_EXPORT: always generate a public symbol.
#if defined(__GNUC__) || defined(__clang__)
#define UPB_EXPORT __attribute__((visibility("default"))) __attribute__((used))
#else
#define UPB_EXPORT
#endif
// UPB_INLINE: inline if possible, emit standalone code if required.
#ifdef __cplusplus
#define UPB_INLINE inline
#elif defined (__GNUC__) || defined(__clang__)
@ -71,6 +78,14 @@
#define UPB_INLINE static
#endif
#ifdef UPB_BUILD_API
#define UPB_API UPB_EXPORT
#define UPB_API_INLINE UPB_EXPORT
#else
#define UPB_API
#define UPB_API_INLINE UPB_INLINE
#endif
#define UPB_MALLOC_ALIGN 8
#define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align))
#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
@ -3354,7 +3369,7 @@ static void jsondec_field(jsondec* d, upb_Message* msg,
jsondec_tomsg(d, submsg, subm);
} else {
upb_MessageValue val = jsondec_value(d, f);
upb_Message_Set(msg, f, val, d->arena);
upb_Message_SetFieldByDef(msg, f, val, d->arena);
}
d->debug_field = preserved;
@ -3507,9 +3522,10 @@ static void jsondec_timestamp(jsondec* d, upb_Message* msg,
jsondec_err(d, "Timestamp out of range");
}
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 1), seconds,
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1),
seconds, d->arena);
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, d->arena);
return;
malformed:
@ -3542,9 +3558,10 @@ static void jsondec_duration(jsondec* d, upb_Message* msg,
nanos.int32_val = -nanos.int32_val;
}
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 1), seconds,
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1),
seconds, d->arena);
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, d->arena);
}
static void jsondec_listvalue(jsondec* d, upb_Message* msg,
@ -3639,7 +3656,7 @@ static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg,
UPB_UNREACHABLE();
}
upb_Message_Set(msg, f, val, d->arena);
upb_Message_SetFieldByDef(msg, f, val, d->arena);
}
static upb_StringView jsondec_mask(jsondec* d, const char* buf,
@ -3726,7 +3743,7 @@ static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg,
upb_MessageValue val;
val.str_val = type_url;
upb_Message_Set(msg, type_url_f, val, d->arena);
upb_Message_SetFieldByDef(msg, type_url_f, val, d->arena);
/* Find message name after the last '/' */
while (ptr > type_url.data && *--ptr != '/') {
@ -3810,14 +3827,14 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) {
(char**)&encoded.str_val.data, &encoded.str_val.size);
// TODO(b/235839510): We should fail gracefully here on a bad return status.
UPB_ASSERT(status == kUpb_EncodeStatus_Ok);
upb_Message_Set(msg, value_f, encoded, d->arena);
upb_Message_SetFieldByDef(msg, value_f, encoded, d->arena);
}
static void jsondec_wrapper(jsondec* d, upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_MessageValue val = jsondec_value(d, value_f);
upb_Message_Set(msg, value_f, val, d->arena);
upb_Message_SetFieldByDef(msg, value_f, val, d->arena);
}
static void jsondec_wellknown(jsondec* d, upb_Message* msg,
@ -3996,8 +4013,8 @@ static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val;
int L, N, I, J, K, hour, min, sec;
if (seconds < -62135596800) {
@ -4039,8 +4056,8 @@ static void jsonenc_duration(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val;
bool negative = false;
if (seconds > 315576000000 || seconds < -315576000000 ||
@ -4201,7 +4218,7 @@ static void upb_JsonEncode_Float(jsonenc* e, float val) {
static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_MessageValue val = upb_Message_Get(msg, val_f);
upb_MessageValue val = upb_Message_GetFieldByDef(msg, val_f);
jsonenc_scalar(e, val, val_f);
}
@ -4246,8 +4263,8 @@ static void jsonenc_any(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2);
upb_StringView type_url = upb_Message_Get(msg, type_url_f).str_val;
upb_StringView value = upb_Message_Get(msg, value_f).str_val;
upb_StringView type_url = upb_Message_GetFieldByDef(msg, type_url_f).str_val;
upb_StringView value = upb_Message_GetFieldByDef(msg, value_f).str_val;
const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url);
const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m);
upb_Arena* arena = jsonenc_arena(e);
@ -4305,7 +4322,7 @@ static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) {
static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_Array* paths = upb_Message_Get(msg, paths_f).array_val;
const upb_Array* paths = upb_Message_GetFieldByDef(msg, paths_f).array_val;
bool first = true;
size_t i, n = 0;
@ -4326,7 +4343,7 @@ static void jsonenc_struct(jsonenc* e, const upb_Message* msg,
jsonenc_putstr(e, "{");
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_Map* fields = upb_Message_Get(msg, fields_f).map_val;
const upb_Map* fields = upb_Message_GetFieldByDef(msg, fields_f).map_val;
if (fields) {
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f);
@ -4351,7 +4368,7 @@ static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f);
const upb_Array* values = upb_Message_Get(msg, values_f).array_val;
const upb_Array* values = upb_Message_GetFieldByDef(msg, values_f).array_val;
size_t i;
bool first = true;
@ -4591,8 +4608,8 @@ static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg,
int n = upb_MessageDef_FieldCount(m);
for (i = 0; i < n; i++) {
f = upb_MessageDef_Field(m, i);
if (!upb_FieldDef_HasPresence(f) || upb_Message_Has(msg, f)) {
jsonenc_fieldval(e, f, upb_Message_Get(msg, f), &first);
if (!upb_FieldDef_HasPresence(f) || upb_Message_HasFieldByDef(msg, f)) {
jsonenc_fieldval(e, f, upb_Message_GetFieldByDef(msg, f), &first);
}
}
} else {
@ -9463,7 +9480,7 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx,
// Must be last.
bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f) {
bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) {
UPB_ASSERT(upb_FieldDef_HasPresence(f));
return _upb_MiniTable_HasField(msg, upb_FieldDef_MiniTable(f));
}
@ -9473,7 +9490,7 @@ const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg,
const upb_FieldDef* f = upb_OneofDef_Field(o, 0);
if (upb_OneofDef_IsSynthetic(o)) {
UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1);
return upb_Message_Has(msg, f) ? f : NULL;
return upb_Message_HasFieldByDef(msg, f) ? f : NULL;
} else {
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
uint32_t oneof_case = _upb_getoneofcase_field(msg, field);
@ -9483,7 +9500,7 @@ const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg,
}
}
upb_MessageValue upb_Message_Get(const upb_Message* msg,
upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg,
const upb_FieldDef* f) {
upb_MessageValue default_val = upb_FieldDef_Default(f);
upb_MessageValue ret;
@ -9495,12 +9512,12 @@ upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg,
const upb_FieldDef* f,
upb_Arena* a) {
UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f));
if (upb_FieldDef_HasPresence(f) && !upb_Message_Has(msg, f)) {
// We need to skip the upb_Message_Get() call in this case.
if (upb_FieldDef_HasPresence(f) && !upb_Message_HasFieldByDef(msg, f)) {
// We need to skip the upb_Message_GetFieldByDef() call in this case.
goto make;
}
upb_MessageValue val = upb_Message_Get(msg, f);
upb_MessageValue val = upb_Message_GetFieldByDef(msg, f);
if (val.array_val) {
return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val};
}
@ -9525,21 +9542,21 @@ make:
}
val.array_val = ret.array;
upb_Message_Set(msg, f, val, a);
upb_Message_SetFieldByDef(msg, f, val, a);
return ret;
}
bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f,
bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a) {
return _upb_MiniTable_SetField(msg, upb_FieldDef_MiniTable(f), &val, a);
}
void upb_Message_ClearField(upb_Message* msg, const upb_FieldDef* f) {
void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) {
_upb_MiniTable_ClearField(msg, upb_FieldDef_MiniTable(f));
}
void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m) {
void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) {
_upb_Message_Clear(msg, upb_MessageDef_MiniTable(m));
}
@ -9554,11 +9571,11 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
while (++i < n) {
const upb_FieldDef* f = upb_MessageDef_Field(m, i);
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
upb_MessageValue val = upb_Message_Get(msg, f);
upb_MessageValue val = upb_Message_GetFieldByDef(msg, f);
// Skip field if unset or empty.
if (upb_MiniTableField_HasPresence(field)) {
if (!upb_Message_Has(msg, f)) continue;
if (!upb_Message_HasFieldByDef(msg, f)) continue;
} else {
switch (upb_FieldMode_Get(field)) {
case kUpb_FieldMode_Map:
@ -13581,7 +13598,10 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l,
#undef UPB_READ_ONEOF
#undef UPB_WRITE_ONEOF
#undef UPB_MAPTYPE_STRING
#undef UPB_EXPORT
#undef UPB_INLINE
#undef UPB_API
#undef UPB_API_INLINE
#undef UPB_ALIGN_UP
#undef UPB_ALIGN_DOWN
#undef UPB_ALIGN_MALLOC

@ -61,7 +61,14 @@
#define UPB_MAPTYPE_STRING 0
/* UPB_INLINE: inline if possible, emit standalone code if required. */
// UPB_EXPORT: always generate a public symbol.
#if defined(__GNUC__) || defined(__clang__)
#define UPB_EXPORT __attribute__((visibility("default"))) __attribute__((used))
#else
#define UPB_EXPORT
#endif
// UPB_INLINE: inline if possible, emit standalone code if required.
#ifdef __cplusplus
#define UPB_INLINE inline
#elif defined (__GNUC__) || defined(__clang__)
@ -70,6 +77,14 @@
#define UPB_INLINE static
#endif
#ifdef UPB_BUILD_API
#define UPB_API UPB_EXPORT
#define UPB_API_INLINE UPB_EXPORT
#else
#define UPB_API
#define UPB_API_INLINE UPB_INLINE
#endif
#define UPB_MALLOC_ALIGN 8
#define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align))
#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
@ -279,11 +294,11 @@ typedef struct {
extern "C" {
#endif
const char* upb_Status_ErrorMessage(const upb_Status* status);
bool upb_Status_IsOk(const upb_Status* status);
UPB_API const char* upb_Status_ErrorMessage(const upb_Status* status);
UPB_API bool upb_Status_IsOk(const upb_Status* status);
// These are no-op if |status| is NULL.
void upb_Status_Clear(upb_Status* status);
UPB_API void upb_Status_Clear(upb_Status* status);
void upb_Status_SetErrorMessage(upb_Status* status, const char* msg);
void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...)
UPB_PRINTF(2, 3);
@ -394,7 +409,7 @@ typedef struct {
extern "C" {
#endif
UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
UPB_API_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
size_t size) {
upb_StringView ret;
ret.data = data;
@ -564,11 +579,13 @@ extern "C" {
// Creates an arena from the given initial block (if any -- n may be 0).
// Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this
// is a fixed-size arena and cannot grow.
upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc);
UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc);
UPB_API void upb_Arena_Free(upb_Arena* a);
UPB_API bool upb_Arena_AddCleanup(upb_Arena* a, void* ud,
upb_CleanupFunc* func);
UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b);
void upb_Arena_Free(upb_Arena* a);
bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func);
bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b);
void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size);
size_t upb_Arena_SpaceAllocated(upb_Arena* arena);
uint32_t upb_Arena_DebugRefCount(upb_Arena* arena);
@ -578,7 +595,7 @@ UPB_INLINE size_t _upb_ArenaHas(upb_Arena* a) {
return (size_t)(h->end - h->ptr);
}
UPB_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) {
UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) {
size = UPB_ALIGN_MALLOC(size);
if (UPB_UNLIKELY(_upb_ArenaHas(a) < size)) {
return _upb_Arena_SlowMalloc(a, size);
@ -611,8 +628,8 @@ UPB_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) {
// REQUIRES: (ptr, oldsize) was the last malloc/realloc from this arena.
// We could also add a upb_Arena_TryShrinkLast() which is simply a no-op if
// this was not the last alloc.
UPB_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize,
size_t size) {
UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr,
size_t oldsize, size_t size) {
_upb_ArenaHead* h = (_upb_ArenaHead*)a;
oldsize = UPB_ALIGN_MALLOC(oldsize);
size = UPB_ALIGN_MALLOC(size);
@ -621,7 +638,7 @@ UPB_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize,
h->ptr = (char*)ptr + size;
}
UPB_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize,
UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize,
size_t size) {
_upb_ArenaHead* h = (_upb_ArenaHead*)a;
oldsize = UPB_ALIGN_MALLOC(oldsize);
@ -647,7 +664,7 @@ UPB_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize,
return ret;
}
UPB_INLINE upb_Arena* upb_Arena_New(void) {
UPB_API_INLINE upb_Arena* upb_Arena_New(void) {
return upb_Arena_Init(NULL, 0, &upb_alloc_global);
}
@ -2251,17 +2268,17 @@ typedef enum {
extern "C" {
#endif
const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
const upb_MiniTable* table, uint32_t number);
upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field);
UPB_API upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field);
UPB_INLINE bool upb_MiniTableField_IsExtension(
UPB_API_INLINE bool upb_MiniTableField_IsExtension(
const upb_MiniTableField* field) {
return field->mode & kUpb_LabelFlags_IsExtension;
}
UPB_INLINE bool upb_MiniTableField_HasPresence(
UPB_API_INLINE bool upb_MiniTableField_HasPresence(
const upb_MiniTableField* field) {
if (upb_MiniTableField_IsExtension(field)) {
return !upb_IsRepeatedOrMap(field);
@ -2270,12 +2287,12 @@ UPB_INLINE bool upb_MiniTableField_HasPresence(
}
}
UPB_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
const upb_MiniTable* mini_table, const upb_MiniTableField* field) {
return mini_table->subs[field->submsg_index].submsg;
}
UPB_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
const upb_MiniTable* mini_table, const upb_MiniTableField* field) {
return mini_table->subs[field->submsg_index].subenum;
}
@ -2509,17 +2526,17 @@ UPB_INLINE void _upb_MiniTable_ClearField(upb_Message* msg,
// EVERYTHING ABOVE THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
UPB_INLINE void upb_MiniTable_ClearField(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_ClearField(upb_Message* msg,
const upb_MiniTableField* field) {
_upb_MiniTable_ClearNonExtensionField(msg, field);
}
UPB_INLINE bool upb_MiniTable_HasField(const upb_Message* msg,
UPB_API_INLINE bool upb_MiniTable_HasField(const upb_Message* msg,
const upb_MiniTableField* field) {
return _upb_MiniTable_HasNonExtensionField(msg, field);
}
UPB_INLINE bool upb_MiniTable_GetBool(const upb_Message* msg,
UPB_API_INLINE bool upb_MiniTable_GetBool(const upb_Message* msg,
const upb_MiniTableField* field,
bool default_val) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Bool);
@ -2530,7 +2547,7 @@ UPB_INLINE bool upb_MiniTable_GetBool(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
const upb_MiniTableField* field,
bool value) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Bool);
@ -2539,7 +2556,7 @@ UPB_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
UPB_API_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
const upb_MiniTableField* field,
int32_t default_val) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Int32 ||
@ -2553,7 +2570,7 @@ UPB_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
const upb_MiniTableField* field,
int32_t value) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Int32 ||
@ -2564,7 +2581,7 @@ UPB_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE uint32_t upb_MiniTable_GetUInt32(const upb_Message* msg,
UPB_API_INLINE uint32_t upb_MiniTable_GetUInt32(const upb_Message* msg,
const upb_MiniTableField* field,
uint32_t default_val) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_UInt32 ||
@ -2576,7 +2593,7 @@ UPB_INLINE uint32_t upb_MiniTable_GetUInt32(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
const upb_MiniTableField* field,
uint32_t value) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_UInt32 ||
@ -2586,10 +2603,9 @@ UPB_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE void upb_MiniTable_SetEnumProto2(upb_Message* msg,
const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* field,
int32_t value) {
UPB_API_INLINE void upb_MiniTable_SetEnumProto2(
upb_Message* msg, const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* field, int32_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum);
UPB_ASSUME(!upb_IsRepeatedOrMap(field));
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
@ -2598,7 +2614,7 @@ UPB_INLINE void upb_MiniTable_SetEnumProto2(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
UPB_API_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
const upb_MiniTableField* field,
uint64_t default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int64 ||
@ -2611,7 +2627,7 @@ UPB_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
const upb_MiniTableField* field,
int64_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int64 ||
@ -2622,7 +2638,7 @@ UPB_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE uint64_t upb_MiniTable_GetUInt64(const upb_Message* msg,
UPB_API_INLINE uint64_t upb_MiniTable_GetUInt64(const upb_Message* msg,
const upb_MiniTableField* field,
uint64_t default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt64 ||
@ -2634,7 +2650,7 @@ UPB_INLINE uint64_t upb_MiniTable_GetUInt64(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
const upb_MiniTableField* field,
uint64_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt64 ||
@ -2644,7 +2660,7 @@ UPB_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE float upb_MiniTable_GetFloat(const upb_Message* msg,
UPB_API_INLINE float upb_MiniTable_GetFloat(const upb_Message* msg,
const upb_MiniTableField* field,
float default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Float);
@ -2655,7 +2671,7 @@ UPB_INLINE float upb_MiniTable_GetFloat(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
const upb_MiniTableField* field,
float value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Float);
@ -2664,7 +2680,7 @@ UPB_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE double upb_MiniTable_GetDouble(const upb_Message* msg,
UPB_API_INLINE double upb_MiniTable_GetDouble(const upb_Message* msg,
const upb_MiniTableField* field,
double default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Double);
@ -2675,7 +2691,7 @@ UPB_INLINE double upb_MiniTable_GetDouble(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
const upb_MiniTableField* field,
double value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Double);
@ -2684,7 +2700,7 @@ UPB_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE upb_StringView
UPB_API_INLINE upb_StringView
upb_MiniTable_GetString(const upb_Message* msg, const upb_MiniTableField* field,
upb_StringView def_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bytes ||
@ -2696,7 +2712,7 @@ upb_MiniTable_GetString(const upb_Message* msg, const upb_MiniTableField* field,
return ret;
}
UPB_INLINE void upb_MiniTable_SetString(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetString(upb_Message* msg,
const upb_MiniTableField* field,
upb_StringView value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bytes ||
@ -2706,7 +2722,7 @@ UPB_INLINE void upb_MiniTable_SetString(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE const upb_Message* upb_MiniTable_GetMessage(
UPB_API_INLINE const upb_Message* upb_MiniTable_GetMessage(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
@ -2719,7 +2735,7 @@ UPB_INLINE const upb_Message* upb_MiniTable_GetMessage(
return ret;
}
UPB_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
const upb_MiniTable* mini_table,
const upb_MiniTableField* field,
upb_Message* sub_message) {
@ -2732,7 +2748,7 @@ UPB_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &sub_message);
}
UPB_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
UPB_API_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, upb_Arena* arena) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
@ -2749,7 +2765,7 @@ UPB_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
return sub_message;
}
UPB_INLINE const upb_Array* upb_MiniTable_GetArray(
UPB_API_INLINE const upb_Array* upb_MiniTable_GetArray(
const upb_Message* msg, const upb_MiniTableField* field) {
const upb_Array* ret;
const upb_Array* default_val = NULL;
@ -2757,7 +2773,7 @@ UPB_INLINE const upb_Array* upb_MiniTable_GetArray(
return ret;
}
UPB_INLINE upb_Array* upb_MiniTable_GetMutableArray(
UPB_API_INLINE upb_Array* upb_MiniTable_GetMutableArray(
upb_Message* msg, const upb_MiniTableField* field) {
return (upb_Array*)upb_MiniTable_GetArray(msg, field);
}
@ -7100,6 +7116,7 @@ extern "C" {
const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f);
const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f);
upb_CType upb_FieldDef_CType(const upb_FieldDef* f);
upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f);
const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f);
const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f);
const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f);
@ -7815,62 +7832,87 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out);
extern "C" {
#endif
upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f);
/* Returns the value associated with this field. */
upb_MessageValue upb_Message_Get(const upb_Message* msg, const upb_FieldDef* f);
/* Returns a mutable pointer to a map, array, or submessage value. If the given
* arena is non-NULL this will construct a new object if it was not previously
* present. May not be called for primitive fields. */
// Returns a mutable pointer to a map, array, or submessage value. If the given
// arena is non-NULL this will construct a new object if it was not previously
// present. May not be called for primitive fields.
upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg,
const upb_FieldDef* f,
upb_Arena* a);
/* May only be called for fields where upb_FieldDef_HasPresence(f) == true. */
bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f);
/* Returns the field that is set in the oneof, or NULL if none are set. */
// Returns the field that is set in the oneof, or NULL if none are set.
const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg,
const upb_OneofDef* o);
/* Sets the given field to the given value. For a msg/array/map/string, the
* caller must ensure that the target data outlives |msg| (by living either in
* the same arena or a different arena that outlives it).
*
* Returns false if allocation fails. */
bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a);
// Clear all data and unknown fields.
void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m);
/* Clears any field presence and sets the value back to its default. */
void upb_Message_ClearField(upb_Message* msg, const upb_FieldDef* f);
// Clears any field presence and sets the value back to its default.
void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f);
/* Clear all data and unknown fields. */
void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m);
// May only be called for fields where upb_FieldDef_HasPresence(f) == true.
bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f);
/* Iterate over present fields.
*
* size_t iter = kUpb_Message_Begin;
* const upb_FieldDef *f;
* upb_MessageValue val;
* while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) {
* process_field(f, val);
* }
*
* If ext_pool is NULL, no extensions will be returned. If the given symtab
* returns extensions that don't match what is in this message, those extensions
* will be skipped.
*/
// Returns the value in the message associated with this field def.
upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg,
const upb_FieldDef* f);
// Sets the given field to the given value. For a msg/array/map/string, the
// caller must ensure that the target data outlives |msg| (by living either in
// the same arena or a different arena that outlives it).
//
// Returns false if allocation fails.
bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a);
// Iterate over present fields.
//
// size_t iter = kUpb_Message_Begin;
// const upb_FieldDef *f;
// upb_MessageValue val;
// while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) {
// process_field(f, val);
// }
//
// If ext_pool is NULL, no extensions will be returned. If the given symtab
// returns extensions that don't match what is in this message, those extensions
// will be skipped.
#define kUpb_Message_Begin -1
bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
const upb_DefPool* ext_pool, const upb_FieldDef** f,
upb_MessageValue* val, size_t* iter);
/* Clears all unknown field data from this message and all submessages. */
// Clears all unknown field data from this message and all submessages.
bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m,
int maxdepth);
// DEPRECATED FUNCTIONS
// PHP and Ruby need these until we can version-bump them to the current upb.
UPB_INLINE void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m) {
return upb_Message_ClearByDef(msg, m);
}
UPB_INLINE void upb_Message_ClearField(upb_Message* msg,
const upb_FieldDef* f) {
return upb_Message_ClearFieldByDef(msg, f);
}
UPB_INLINE bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f) {
return upb_Message_HasFieldByDef(msg, f);
}
UPB_INLINE upb_MessageValue upb_Message_Get(const upb_Message* msg,
const upb_FieldDef* f) {
return upb_Message_GetFieldByDef(msg, f);
}
UPB_INLINE bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a) {
return upb_Message_SetFieldByDef(msg, f, val, a);
}
#ifdef __cplusplus
} /* extern "C" */
#endif
@ -8160,7 +8202,7 @@ upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len,
upb_MiniTablePlatform platform,
upb_Arena* arena, upb_Status* status);
UPB_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
UPB_API_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status) {
return _upb_MiniTable_Build(data, len, kUpb_MiniTablePlatform_Native, arena,
@ -8173,13 +8215,14 @@ UPB_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
// to link the message field later, at which point it will no longer be treated
// as unknown. However there is no synchronization for this operation, which
// means parallel mutation requires external synchronization.
void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
UPB_API void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
upb_MiniTableField* field,
const upb_MiniTable* sub);
// Links an enum field to a MiniTable for that enum. All enum fields must
// be linked prior to parsing.
void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field,
UPB_API void upb_MiniTable_SetSubEnum(upb_MiniTable* table,
upb_MiniTableField* field,
const upb_MiniTableEnum* sub);
const char* _upb_MiniTableExtension_Build(const char* data, size_t len,
@ -8189,14 +8232,14 @@ const char* _upb_MiniTableExtension_Build(const char* data, size_t len,
upb_MiniTablePlatform platform,
upb_Status* status);
UPB_INLINE const char* upb_MiniTableExtension_Build(
UPB_API_INLINE const char* upb_MiniTableExtension_Build(
const char* data, size_t len, upb_MiniTableExtension* ext,
const upb_MiniTable* extendee, upb_MiniTableSub sub, upb_Status* status) {
return _upb_MiniTableExtension_Build(data, len, ext, extendee, sub,
kUpb_MiniTablePlatform_Native, status);
}
upb_MiniTableEnum* upb_MiniTableEnum_Build(const char* data, size_t len,
UPB_API upb_MiniTableEnum* upb_MiniTableEnum_Build(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status);
@ -8856,7 +8899,7 @@ enum {
#ifndef UPB_WIRE_DECODE_INTERNAL_H_
#define UPB_WIRE_DECODE_INTERNAL_H_
#include "third_party/utf8_range/utf8_range.h"
#include "utf8_range.h"
// Must be last.
@ -9070,7 +9113,10 @@ UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) {
#undef UPB_READ_ONEOF
#undef UPB_WRITE_ONEOF
#undef UPB_MAPTYPE_STRING
#undef UPB_EXPORT
#undef UPB_INLINE
#undef UPB_API
#undef UPB_API_INLINE
#undef UPB_ALIGN_UP
#undef UPB_ALIGN_DOWN
#undef UPB_ALIGN_MALLOC

@ -135,6 +135,6 @@ def protobuf_deps():
_github_archive(
name = "upb",
repo = "https://github.com/protocolbuffers/upb",
commit = "ee56471047ad8619d0c701f894aa1767ca91f5c2",
sha256 = "0c3f86ce497e6cc75e89a0d4a8e32c90ea25aaedabd6d42fb9e2f2ad52d3f4b0",
commit = "b747edb830b0fab524e0063fb2e156c390405dfa",
sha256 = "99f69a3b8a583961e9db8d16d3a654f4bac5f546077e07dfa26c561de5215005",
)

@ -89,11 +89,11 @@ else
else
utf8_root = '../third_party/utf8_range'
end
FileUtils.mkdir_p("ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/naive.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/range2-neon.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.cp(utf8_root+"/range2-sse.c", "ext/google/protobuf_c/third_party/utf8_range")
FileUtils.mkdir_p("ext/google/protobuf_c")
FileUtils.cp(utf8_root+"/utf8_range.h", "ext/google/protobuf_c")
FileUtils.cp(utf8_root+"/naive.c", "ext/google/protobuf_c")
FileUtils.cp(utf8_root+"/range2-neon.c", "ext/google/protobuf_c")
FileUtils.cp(utf8_root+"/range2-sse.c", "ext/google/protobuf_c")
end
Rake::ExtensionTask.new("protobuf_c", spec) do |ext|

@ -811,7 +811,7 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
rb_raise(rb_eArgError, "does not track presence");
}
return upb_Message_Has(msg, self->fielddef) ? Qtrue : Qfalse;
return upb_Message_HasFieldByDef(msg, self->fielddef) ? Qtrue : Qfalse;
}
/*
@ -829,7 +829,7 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
rb_raise(cTypeError, "has method called on wrong message type");
}
upb_Message_ClearField(msg, self->fielddef);
upb_Message_ClearFieldByDef(msg, self->fielddef);
return Qnil;
}
@ -854,7 +854,7 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
msgval = Convert_RubyToUpb(value, upb_FieldDef_Name(self->fielddef),
TypeInfo_get(self->fielddef), arena);
upb_Message_Set(msg, self->fielddef, msgval, arena);
upb_Message_SetFieldByDef(msg, self->fielddef, msgval, arena);
return Qnil;
}

@ -146,7 +146,8 @@ void Message_PrintMessage(StringBuilder* b, const upb_Message* msg,
for (int i = 0; i < n; i++) {
const upb_FieldDef* field = upb_MessageDef_Field(m, i);
if (upb_FieldDef_HasPresence(field) && !upb_Message_Has(msg, field)) {
if (upb_FieldDef_HasPresence(field) &&
!upb_Message_HasFieldByDef(msg, field)) {
continue;
}
@ -156,7 +157,7 @@ void Message_PrintMessage(StringBuilder* b, const upb_Message* msg,
first = false;
}
upb_MessageValue msgval = upb_Message_Get(msg, field);
upb_MessageValue msgval = upb_Message_GetFieldByDef(msg, field);
StringBuilder_Printf(b, "%s: ", upb_FieldDef_Name(field));
@ -279,7 +280,8 @@ static VALUE Message_oneof_accessor(VALUE _self, const upb_OneofDef* o,
return oneof_field == NULL ? Qfalse : Qtrue;
case METHOD_CLEAR:
if (oneof_field != NULL) {
upb_Message_ClearField(Message_GetMutable(_self, NULL), oneof_field);
upb_Message_ClearFieldByDef(Message_GetMutable(_self, NULL),
oneof_field);
}
return Qnil;
case METHOD_GETTER:
@ -302,13 +304,13 @@ static void Message_setfield(upb_Message* msg, const upb_FieldDef* f, VALUE val,
} else {
if (val == Qnil &&
(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_RealContainingOneof(f))) {
upb_Message_ClearField(msg, f);
upb_Message_ClearFieldByDef(msg, f);
return;
}
msgval =
Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
}
upb_Message_Set(msg, f, msgval, arena);
upb_Message_SetFieldByDef(msg, f, msgval, arena);
}
VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
@ -330,12 +332,12 @@ VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
return RepeatedField_GetRubyWrapper(arr, TypeInfo_get(f), self->arena);
} else if (upb_FieldDef_IsSubMessage(f)) {
if (!upb_Message_Has(self->msg, f)) return Qnil;
if (!upb_Message_HasFieldByDef(self->msg, f)) return Qnil;
upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg;
const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
return Message_GetRubyWrapper(submsg, m, self->arena);
} else {
upb_MessageValue msgval = upb_Message_Get(self->msg, f);
upb_MessageValue msgval = upb_Message_GetFieldByDef(self->msg, f);
return Convert_UpbToRuby(msgval, TypeInfo_get(f), self->arena);
}
}
@ -349,23 +351,24 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
Message_setfield(Message_GetMutable(_self, NULL), f, argv[1], arena);
return Qnil;
case METHOD_CLEAR:
upb_Message_ClearField(Message_GetMutable(_self, NULL), f);
upb_Message_ClearFieldByDef(Message_GetMutable(_self, NULL), f);
return Qnil;
case METHOD_PRESENCE:
if (!upb_FieldDef_HasPresence(f)) {
rb_raise(rb_eRuntimeError, "Field does not have presence.");
}
return upb_Message_Has(Message_Get(_self, NULL), f);
return upb_Message_HasFieldByDef(Message_Get(_self, NULL), f);
case METHOD_WRAPPER_GETTER: {
Message* self = ruby_to_Message(_self);
if (upb_Message_Has(self->msg, f)) {
if (upb_Message_HasFieldByDef(self->msg, f)) {
PBRUBY_ASSERT(upb_FieldDef_IsSubMessage(f) &&
!upb_FieldDef_IsRepeated(f));
upb_MessageValue wrapper = upb_Message_Get(self->msg, f);
upb_MessageValue wrapper = upb_Message_GetFieldByDef(self->msg, f);
const upb_MessageDef* wrapper_m = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* value_f =
upb_MessageDef_FindFieldByNumber(wrapper_m, 1);
upb_MessageValue value = upb_Message_Get(wrapper.msg_val, value_f);
upb_MessageValue value =
upb_Message_GetFieldByDef(wrapper.msg_val, value_f);
return Convert_UpbToRuby(value, TypeInfo_get(value_f), self->arena);
} else {
return Qnil;
@ -374,19 +377,20 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
case METHOD_WRAPPER_SETTER: {
upb_Message* msg = Message_GetMutable(_self, NULL);
if (argv[1] == Qnil) {
upb_Message_ClearField(msg, f);
upb_Message_ClearFieldByDef(msg, f);
} else {
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumber(upb_FieldDef_MessageSubDef(f), 1);
upb_MessageValue msgval = Convert_RubyToUpb(
argv[1], upb_FieldDef_Name(f), TypeInfo_get(val_f), arena);
upb_Message* wrapper = upb_Message_Mutable(msg, f, arena).msg;
upb_Message_Set(wrapper, val_f, msgval, arena);
upb_Message_SetFieldByDef(wrapper, val_f, msgval, arena);
}
return Qnil;
}
case METHOD_ENUM_GETTER: {
upb_MessageValue msgval = upb_Message_Get(Message_Get(_self, NULL), f);
upb_MessageValue msgval =
upb_Message_GetFieldByDef(Message_Get(_self, NULL), f);
if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) {
// Map repeated fields to a new type with ints
@ -595,7 +599,7 @@ static void Message_InitFieldFromValue(upb_Message* msg, const upb_FieldDef* f,
} else {
upb_MessageValue msgval =
Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
upb_Message_Set(msg, f, msgval, arena);
upb_Message_SetFieldByDef(msg, f, msgval, arena);
}
}
@ -832,7 +836,8 @@ static VALUE Message_CreateHash(const upb_Message* msg,
VALUE msg_key;
if (!is_proto2 && upb_FieldDef_IsSubMessage(field) &&
!upb_FieldDef_IsRepeated(field) && !upb_Message_Has(msg, field)) {
!upb_FieldDef_IsRepeated(field) &&
!upb_Message_HasFieldByDef(msg, field)) {
// TODO: Legacy behavior, remove when we fix the is_proto2 differences.
msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
rb_hash_aset(hash, msg_key, Qnil);
@ -841,12 +846,12 @@ static VALUE Message_CreateHash(const upb_Message* msg,
// Do not include fields that are not present (oneof or optional fields).
if (is_proto2 && upb_FieldDef_HasPresence(field) &&
!upb_Message_Has(msg, field)) {
!upb_Message_HasFieldByDef(msg, field)) {
continue;
}
msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
msgval = upb_Message_Get(msg, field);
msgval = upb_Message_GetFieldByDef(msg, field);
// Proto2 omits empty map/repeated filds also.
@ -949,7 +954,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
}
val = Convert_RubyToUpb(value, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
upb_Message_Set(Message_GetMutable(_self, NULL), f, val, arena);
upb_Message_SetFieldByDef(Message_GetMutable(_self, NULL), f, val, arena);
return Qnil;
}
@ -1355,8 +1360,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
time = rb_time_timespec(value);
sec.int64_val = time.tv_sec;
nsec.int32_val = time.tv_nsec;
upb_Message_Set(msg, sec_f, sec, arena);
upb_Message_Set(msg, nsec_f, nsec, arena);
upb_Message_SetFieldByDef(msg, sec_f, sec, arena);
upb_Message_SetFieldByDef(msg, nsec_f, nsec, arena);
return msg;
}
case kUpb_WellKnown_Duration: {
@ -1371,8 +1376,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
sec.int64_val = NUM2LL(value);
nsec.int32_val = round((NUM2DBL(value) - NUM2LL(value)) * 1000000000);
upb_Message_Set(msg, sec_f, sec, arena);
upb_Message_Set(msg, nsec_f, nsec, arena);
upb_Message_SetFieldByDef(msg, sec_f, sec, arena);
upb_Message_SetFieldByDef(msg, nsec_f, nsec, arena);
return msg;
}
default:

@ -62,7 +62,14 @@
#define UPB_MAPTYPE_STRING 0
/* UPB_INLINE: inline if possible, emit standalone code if required. */
// UPB_EXPORT: always generate a public symbol.
#if defined(__GNUC__) || defined(__clang__)
#define UPB_EXPORT __attribute__((visibility("default"))) __attribute__((used))
#else
#define UPB_EXPORT
#endif
// UPB_INLINE: inline if possible, emit standalone code if required.
#ifdef __cplusplus
#define UPB_INLINE inline
#elif defined (__GNUC__) || defined(__clang__)
@ -71,6 +78,14 @@
#define UPB_INLINE static
#endif
#ifdef UPB_BUILD_API
#define UPB_API UPB_EXPORT
#define UPB_API_INLINE UPB_EXPORT
#else
#define UPB_API
#define UPB_API_INLINE UPB_INLINE
#endif
#define UPB_MALLOC_ALIGN 8
#define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align))
#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
@ -3020,7 +3035,7 @@ static void jsondec_field(jsondec* d, upb_Message* msg,
jsondec_tomsg(d, submsg, subm);
} else {
upb_MessageValue val = jsondec_value(d, f);
upb_Message_Set(msg, f, val, d->arena);
upb_Message_SetFieldByDef(msg, f, val, d->arena);
}
d->debug_field = preserved;
@ -3173,9 +3188,10 @@ static void jsondec_timestamp(jsondec* d, upb_Message* msg,
jsondec_err(d, "Timestamp out of range");
}
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 1), seconds,
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1),
seconds, d->arena);
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, d->arena);
return;
malformed:
@ -3208,9 +3224,10 @@ static void jsondec_duration(jsondec* d, upb_Message* msg,
nanos.int32_val = -nanos.int32_val;
}
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 1), seconds,
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1),
seconds, d->arena);
upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, d->arena);
}
static void jsondec_listvalue(jsondec* d, upb_Message* msg,
@ -3305,7 +3322,7 @@ static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg,
UPB_UNREACHABLE();
}
upb_Message_Set(msg, f, val, d->arena);
upb_Message_SetFieldByDef(msg, f, val, d->arena);
}
static upb_StringView jsondec_mask(jsondec* d, const char* buf,
@ -3392,7 +3409,7 @@ static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg,
upb_MessageValue val;
val.str_val = type_url;
upb_Message_Set(msg, type_url_f, val, d->arena);
upb_Message_SetFieldByDef(msg, type_url_f, val, d->arena);
/* Find message name after the last '/' */
while (ptr > type_url.data && *--ptr != '/') {
@ -3476,14 +3493,14 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) {
(char**)&encoded.str_val.data, &encoded.str_val.size);
// TODO(b/235839510): We should fail gracefully here on a bad return status.
UPB_ASSERT(status == kUpb_EncodeStatus_Ok);
upb_Message_Set(msg, value_f, encoded, d->arena);
upb_Message_SetFieldByDef(msg, value_f, encoded, d->arena);
}
static void jsondec_wrapper(jsondec* d, upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_MessageValue val = jsondec_value(d, value_f);
upb_Message_Set(msg, value_f, val, d->arena);
upb_Message_SetFieldByDef(msg, value_f, val, d->arena);
}
static void jsondec_wellknown(jsondec* d, upb_Message* msg,
@ -3662,8 +3679,8 @@ static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val;
int L, N, I, J, K, hour, min, sec;
if (seconds < -62135596800) {
@ -3705,8 +3722,8 @@ static void jsonenc_duration(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val;
bool negative = false;
if (seconds > 315576000000 || seconds < -315576000000 ||
@ -3867,7 +3884,7 @@ static void upb_JsonEncode_Float(jsonenc* e, float val) {
static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_MessageValue val = upb_Message_Get(msg, val_f);
upb_MessageValue val = upb_Message_GetFieldByDef(msg, val_f);
jsonenc_scalar(e, val, val_f);
}
@ -3912,8 +3929,8 @@ static void jsonenc_any(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2);
upb_StringView type_url = upb_Message_Get(msg, type_url_f).str_val;
upb_StringView value = upb_Message_Get(msg, value_f).str_val;
upb_StringView type_url = upb_Message_GetFieldByDef(msg, type_url_f).str_val;
upb_StringView value = upb_Message_GetFieldByDef(msg, value_f).str_val;
const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url);
const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m);
upb_Arena* arena = jsonenc_arena(e);
@ -3971,7 +3988,7 @@ static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) {
static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_Array* paths = upb_Message_Get(msg, paths_f).array_val;
const upb_Array* paths = upb_Message_GetFieldByDef(msg, paths_f).array_val;
bool first = true;
size_t i, n = 0;
@ -3992,7 +4009,7 @@ static void jsonenc_struct(jsonenc* e, const upb_Message* msg,
jsonenc_putstr(e, "{");
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_Map* fields = upb_Message_Get(msg, fields_f).map_val;
const upb_Map* fields = upb_Message_GetFieldByDef(msg, fields_f).map_val;
if (fields) {
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f);
@ -4017,7 +4034,7 @@ static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f);
const upb_Array* values = upb_Message_Get(msg, values_f).array_val;
const upb_Array* values = upb_Message_GetFieldByDef(msg, values_f).array_val;
size_t i;
bool first = true;
@ -4257,8 +4274,8 @@ static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg,
int n = upb_MessageDef_FieldCount(m);
for (i = 0; i < n; i++) {
f = upb_MessageDef_Field(m, i);
if (!upb_FieldDef_HasPresence(f) || upb_Message_Has(msg, f)) {
jsonenc_fieldval(e, f, upb_Message_Get(msg, f), &first);
if (!upb_FieldDef_HasPresence(f) || upb_Message_HasFieldByDef(msg, f)) {
jsonenc_fieldval(e, f, upb_Message_GetFieldByDef(msg, f), &first);
}
}
} else {
@ -9129,7 +9146,7 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx,
// Must be last.
bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f) {
bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) {
UPB_ASSERT(upb_FieldDef_HasPresence(f));
return _upb_MiniTable_HasField(msg, upb_FieldDef_MiniTable(f));
}
@ -9139,7 +9156,7 @@ const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg,
const upb_FieldDef* f = upb_OneofDef_Field(o, 0);
if (upb_OneofDef_IsSynthetic(o)) {
UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1);
return upb_Message_Has(msg, f) ? f : NULL;
return upb_Message_HasFieldByDef(msg, f) ? f : NULL;
} else {
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
uint32_t oneof_case = _upb_getoneofcase_field(msg, field);
@ -9149,7 +9166,7 @@ const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg,
}
}
upb_MessageValue upb_Message_Get(const upb_Message* msg,
upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg,
const upb_FieldDef* f) {
upb_MessageValue default_val = upb_FieldDef_Default(f);
upb_MessageValue ret;
@ -9161,12 +9178,12 @@ upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg,
const upb_FieldDef* f,
upb_Arena* a) {
UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f));
if (upb_FieldDef_HasPresence(f) && !upb_Message_Has(msg, f)) {
// We need to skip the upb_Message_Get() call in this case.
if (upb_FieldDef_HasPresence(f) && !upb_Message_HasFieldByDef(msg, f)) {
// We need to skip the upb_Message_GetFieldByDef() call in this case.
goto make;
}
upb_MessageValue val = upb_Message_Get(msg, f);
upb_MessageValue val = upb_Message_GetFieldByDef(msg, f);
if (val.array_val) {
return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val};
}
@ -9191,21 +9208,21 @@ make:
}
val.array_val = ret.array;
upb_Message_Set(msg, f, val, a);
upb_Message_SetFieldByDef(msg, f, val, a);
return ret;
}
bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f,
bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a) {
return _upb_MiniTable_SetField(msg, upb_FieldDef_MiniTable(f), &val, a);
}
void upb_Message_ClearField(upb_Message* msg, const upb_FieldDef* f) {
void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) {
_upb_MiniTable_ClearField(msg, upb_FieldDef_MiniTable(f));
}
void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m) {
void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) {
_upb_Message_Clear(msg, upb_MessageDef_MiniTable(m));
}
@ -9220,11 +9237,11 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
while (++i < n) {
const upb_FieldDef* f = upb_MessageDef_Field(m, i);
const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
upb_MessageValue val = upb_Message_Get(msg, f);
upb_MessageValue val = upb_Message_GetFieldByDef(msg, f);
// Skip field if unset or empty.
if (upb_MiniTableField_HasPresence(field)) {
if (!upb_Message_Has(msg, f)) continue;
if (!upb_Message_HasFieldByDef(msg, f)) continue;
} else {
switch (upb_FieldMode_Get(field)) {
case kUpb_FieldMode_Map:
@ -13247,7 +13264,10 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l,
#undef UPB_READ_ONEOF
#undef UPB_WRITE_ONEOF
#undef UPB_MAPTYPE_STRING
#undef UPB_EXPORT
#undef UPB_INLINE
#undef UPB_API
#undef UPB_API_INLINE
#undef UPB_ALIGN_UP
#undef UPB_ALIGN_DOWN
#undef UPB_ALIGN_MALLOC

@ -63,7 +63,14 @@
#define UPB_MAPTYPE_STRING 0
/* UPB_INLINE: inline if possible, emit standalone code if required. */
// UPB_EXPORT: always generate a public symbol.
#if defined(__GNUC__) || defined(__clang__)
#define UPB_EXPORT __attribute__((visibility("default"))) __attribute__((used))
#else
#define UPB_EXPORT
#endif
// UPB_INLINE: inline if possible, emit standalone code if required.
#ifdef __cplusplus
#define UPB_INLINE inline
#elif defined (__GNUC__) || defined(__clang__)
@ -72,6 +79,14 @@
#define UPB_INLINE static
#endif
#ifdef UPB_BUILD_API
#define UPB_API UPB_EXPORT
#define UPB_API_INLINE UPB_EXPORT
#else
#define UPB_API
#define UPB_API_INLINE UPB_INLINE
#endif
#define UPB_MALLOC_ALIGN 8
#define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align))
#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
@ -281,11 +296,11 @@ typedef struct {
extern "C" {
#endif
const char* upb_Status_ErrorMessage(const upb_Status* status);
bool upb_Status_IsOk(const upb_Status* status);
UPB_API const char* upb_Status_ErrorMessage(const upb_Status* status);
UPB_API bool upb_Status_IsOk(const upb_Status* status);
// These are no-op if |status| is NULL.
void upb_Status_Clear(upb_Status* status);
UPB_API void upb_Status_Clear(upb_Status* status);
void upb_Status_SetErrorMessage(upb_Status* status, const char* msg);
void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...)
UPB_PRINTF(2, 3);
@ -396,7 +411,7 @@ typedef struct {
extern "C" {
#endif
UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
UPB_API_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
size_t size) {
upb_StringView ret;
ret.data = data;
@ -566,11 +581,13 @@ extern "C" {
// Creates an arena from the given initial block (if any -- n may be 0).
// Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this
// is a fixed-size arena and cannot grow.
upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc);
UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc);
UPB_API void upb_Arena_Free(upb_Arena* a);
UPB_API bool upb_Arena_AddCleanup(upb_Arena* a, void* ud,
upb_CleanupFunc* func);
UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b);
void upb_Arena_Free(upb_Arena* a);
bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func);
bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b);
void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size);
size_t upb_Arena_SpaceAllocated(upb_Arena* arena);
uint32_t upb_Arena_DebugRefCount(upb_Arena* arena);
@ -580,7 +597,7 @@ UPB_INLINE size_t _upb_ArenaHas(upb_Arena* a) {
return (size_t)(h->end - h->ptr);
}
UPB_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) {
UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) {
size = UPB_ALIGN_MALLOC(size);
if (UPB_UNLIKELY(_upb_ArenaHas(a) < size)) {
return _upb_Arena_SlowMalloc(a, size);
@ -613,8 +630,8 @@ UPB_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) {
// REQUIRES: (ptr, oldsize) was the last malloc/realloc from this arena.
// We could also add a upb_Arena_TryShrinkLast() which is simply a no-op if
// this was not the last alloc.
UPB_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize,
size_t size) {
UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr,
size_t oldsize, size_t size) {
_upb_ArenaHead* h = (_upb_ArenaHead*)a;
oldsize = UPB_ALIGN_MALLOC(oldsize);
size = UPB_ALIGN_MALLOC(size);
@ -623,7 +640,7 @@ UPB_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize,
h->ptr = (char*)ptr + size;
}
UPB_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize,
UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize,
size_t size) {
_upb_ArenaHead* h = (_upb_ArenaHead*)a;
oldsize = UPB_ALIGN_MALLOC(oldsize);
@ -649,7 +666,7 @@ UPB_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize,
return ret;
}
UPB_INLINE upb_Arena* upb_Arena_New(void) {
UPB_API_INLINE upb_Arena* upb_Arena_New(void) {
return upb_Arena_Init(NULL, 0, &upb_alloc_global);
}
@ -2253,17 +2270,17 @@ typedef enum {
extern "C" {
#endif
const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
const upb_MiniTable* table, uint32_t number);
upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field);
UPB_API upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field);
UPB_INLINE bool upb_MiniTableField_IsExtension(
UPB_API_INLINE bool upb_MiniTableField_IsExtension(
const upb_MiniTableField* field) {
return field->mode & kUpb_LabelFlags_IsExtension;
}
UPB_INLINE bool upb_MiniTableField_HasPresence(
UPB_API_INLINE bool upb_MiniTableField_HasPresence(
const upb_MiniTableField* field) {
if (upb_MiniTableField_IsExtension(field)) {
return !upb_IsRepeatedOrMap(field);
@ -2272,12 +2289,12 @@ UPB_INLINE bool upb_MiniTableField_HasPresence(
}
}
UPB_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
const upb_MiniTable* mini_table, const upb_MiniTableField* field) {
return mini_table->subs[field->submsg_index].submsg;
}
UPB_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
const upb_MiniTable* mini_table, const upb_MiniTableField* field) {
return mini_table->subs[field->submsg_index].subenum;
}
@ -2511,17 +2528,17 @@ UPB_INLINE void _upb_MiniTable_ClearField(upb_Message* msg,
// EVERYTHING ABOVE THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
UPB_INLINE void upb_MiniTable_ClearField(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_ClearField(upb_Message* msg,
const upb_MiniTableField* field) {
_upb_MiniTable_ClearNonExtensionField(msg, field);
}
UPB_INLINE bool upb_MiniTable_HasField(const upb_Message* msg,
UPB_API_INLINE bool upb_MiniTable_HasField(const upb_Message* msg,
const upb_MiniTableField* field) {
return _upb_MiniTable_HasNonExtensionField(msg, field);
}
UPB_INLINE bool upb_MiniTable_GetBool(const upb_Message* msg,
UPB_API_INLINE bool upb_MiniTable_GetBool(const upb_Message* msg,
const upb_MiniTableField* field,
bool default_val) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Bool);
@ -2532,7 +2549,7 @@ UPB_INLINE bool upb_MiniTable_GetBool(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
const upb_MiniTableField* field,
bool value) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Bool);
@ -2541,7 +2558,7 @@ UPB_INLINE void upb_MiniTable_SetBool(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
UPB_API_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
const upb_MiniTableField* field,
int32_t default_val) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Int32 ||
@ -2555,7 +2572,7 @@ UPB_INLINE int32_t upb_MiniTable_GetInt32(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
const upb_MiniTableField* field,
int32_t value) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_Int32 ||
@ -2566,7 +2583,7 @@ UPB_INLINE void upb_MiniTable_SetInt32(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE uint32_t upb_MiniTable_GetUInt32(const upb_Message* msg,
UPB_API_INLINE uint32_t upb_MiniTable_GetUInt32(const upb_Message* msg,
const upb_MiniTableField* field,
uint32_t default_val) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_UInt32 ||
@ -2578,7 +2595,7 @@ UPB_INLINE uint32_t upb_MiniTable_GetUInt32(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
const upb_MiniTableField* field,
uint32_t value) {
UPB_ASSUME(field->descriptortype == kUpb_FieldType_UInt32 ||
@ -2588,10 +2605,9 @@ UPB_INLINE void upb_MiniTable_SetUInt32(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE void upb_MiniTable_SetEnumProto2(upb_Message* msg,
const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* field,
int32_t value) {
UPB_API_INLINE void upb_MiniTable_SetEnumProto2(
upb_Message* msg, const upb_MiniTable* msg_mini_table,
const upb_MiniTableField* field, int32_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum);
UPB_ASSUME(!upb_IsRepeatedOrMap(field));
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_4Byte);
@ -2600,7 +2616,7 @@ UPB_INLINE void upb_MiniTable_SetEnumProto2(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
UPB_API_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
const upb_MiniTableField* field,
uint64_t default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int64 ||
@ -2613,7 +2629,7 @@ UPB_INLINE int64_t upb_MiniTable_GetInt64(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
const upb_MiniTableField* field,
int64_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Int64 ||
@ -2624,7 +2640,7 @@ UPB_INLINE void upb_MiniTable_SetInt64(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE uint64_t upb_MiniTable_GetUInt64(const upb_Message* msg,
UPB_API_INLINE uint64_t upb_MiniTable_GetUInt64(const upb_Message* msg,
const upb_MiniTableField* field,
uint64_t default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt64 ||
@ -2636,7 +2652,7 @@ UPB_INLINE uint64_t upb_MiniTable_GetUInt64(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
const upb_MiniTableField* field,
uint64_t value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_UInt64 ||
@ -2646,7 +2662,7 @@ UPB_INLINE void upb_MiniTable_SetUInt64(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE float upb_MiniTable_GetFloat(const upb_Message* msg,
UPB_API_INLINE float upb_MiniTable_GetFloat(const upb_Message* msg,
const upb_MiniTableField* field,
float default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Float);
@ -2657,7 +2673,7 @@ UPB_INLINE float upb_MiniTable_GetFloat(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
const upb_MiniTableField* field,
float value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Float);
@ -2666,7 +2682,7 @@ UPB_INLINE void upb_MiniTable_SetFloat(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE double upb_MiniTable_GetDouble(const upb_Message* msg,
UPB_API_INLINE double upb_MiniTable_GetDouble(const upb_Message* msg,
const upb_MiniTableField* field,
double default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Double);
@ -2677,7 +2693,7 @@ UPB_INLINE double upb_MiniTable_GetDouble(const upb_Message* msg,
return ret;
}
UPB_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
const upb_MiniTableField* field,
double value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Double);
@ -2686,7 +2702,7 @@ UPB_INLINE void upb_MiniTable_SetDouble(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE upb_StringView
UPB_API_INLINE upb_StringView
upb_MiniTable_GetString(const upb_Message* msg, const upb_MiniTableField* field,
upb_StringView def_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bytes ||
@ -2698,7 +2714,7 @@ upb_MiniTable_GetString(const upb_Message* msg, const upb_MiniTableField* field,
return ret;
}
UPB_INLINE void upb_MiniTable_SetString(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetString(upb_Message* msg,
const upb_MiniTableField* field,
upb_StringView value) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Bytes ||
@ -2708,7 +2724,7 @@ UPB_INLINE void upb_MiniTable_SetString(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &value);
}
UPB_INLINE const upb_Message* upb_MiniTable_GetMessage(
UPB_API_INLINE const upb_Message* upb_MiniTable_GetMessage(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
@ -2721,7 +2737,7 @@ UPB_INLINE const upb_Message* upb_MiniTable_GetMessage(
return ret;
}
UPB_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
UPB_API_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
const upb_MiniTable* mini_table,
const upb_MiniTableField* field,
upb_Message* sub_message) {
@ -2734,7 +2750,7 @@ UPB_INLINE void upb_MiniTable_SetMessage(upb_Message* msg,
_upb_MiniTable_SetNonExtensionField(msg, field, &sub_message);
}
UPB_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
UPB_API_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, upb_Arena* arena) {
UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message ||
@ -2751,7 +2767,7 @@ UPB_INLINE upb_Message* upb_MiniTable_GetMutableMessage(
return sub_message;
}
UPB_INLINE const upb_Array* upb_MiniTable_GetArray(
UPB_API_INLINE const upb_Array* upb_MiniTable_GetArray(
const upb_Message* msg, const upb_MiniTableField* field) {
const upb_Array* ret;
const upb_Array* default_val = NULL;
@ -2759,7 +2775,7 @@ UPB_INLINE const upb_Array* upb_MiniTable_GetArray(
return ret;
}
UPB_INLINE upb_Array* upb_MiniTable_GetMutableArray(
UPB_API_INLINE upb_Array* upb_MiniTable_GetMutableArray(
upb_Message* msg, const upb_MiniTableField* field) {
return (upb_Array*)upb_MiniTable_GetArray(msg, field);
}
@ -7179,6 +7195,7 @@ extern "C" {
const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f);
const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f);
upb_CType upb_FieldDef_CType(const upb_FieldDef* f);
upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f);
const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f);
const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f);
const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f);
@ -7611,62 +7628,87 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out);
extern "C" {
#endif
upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f);
/* Returns the value associated with this field. */
upb_MessageValue upb_Message_Get(const upb_Message* msg, const upb_FieldDef* f);
/* Returns a mutable pointer to a map, array, or submessage value. If the given
* arena is non-NULL this will construct a new object if it was not previously
* present. May not be called for primitive fields. */
// Returns a mutable pointer to a map, array, or submessage value. If the given
// arena is non-NULL this will construct a new object if it was not previously
// present. May not be called for primitive fields.
upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg,
const upb_FieldDef* f,
upb_Arena* a);
/* May only be called for fields where upb_FieldDef_HasPresence(f) == true. */
bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f);
/* Returns the field that is set in the oneof, or NULL if none are set. */
// Returns the field that is set in the oneof, or NULL if none are set.
const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg,
const upb_OneofDef* o);
/* Sets the given field to the given value. For a msg/array/map/string, the
* caller must ensure that the target data outlives |msg| (by living either in
* the same arena or a different arena that outlives it).
*
* Returns false if allocation fails. */
bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a);
// Clear all data and unknown fields.
void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m);
/* Clears any field presence and sets the value back to its default. */
void upb_Message_ClearField(upb_Message* msg, const upb_FieldDef* f);
// Clears any field presence and sets the value back to its default.
void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f);
/* Clear all data and unknown fields. */
void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m);
// May only be called for fields where upb_FieldDef_HasPresence(f) == true.
bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f);
/* Iterate over present fields.
*
* size_t iter = kUpb_Message_Begin;
* const upb_FieldDef *f;
* upb_MessageValue val;
* while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) {
* process_field(f, val);
* }
*
* If ext_pool is NULL, no extensions will be returned. If the given symtab
* returns extensions that don't match what is in this message, those extensions
* will be skipped.
*/
// Returns the value in the message associated with this field def.
upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg,
const upb_FieldDef* f);
// Sets the given field to the given value. For a msg/array/map/string, the
// caller must ensure that the target data outlives |msg| (by living either in
// the same arena or a different arena that outlives it).
//
// Returns false if allocation fails.
bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a);
// Iterate over present fields.
//
// size_t iter = kUpb_Message_Begin;
// const upb_FieldDef *f;
// upb_MessageValue val;
// while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) {
// process_field(f, val);
// }
//
// If ext_pool is NULL, no extensions will be returned. If the given symtab
// returns extensions that don't match what is in this message, those extensions
// will be skipped.
#define kUpb_Message_Begin -1
bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
const upb_DefPool* ext_pool, const upb_FieldDef** f,
upb_MessageValue* val, size_t* iter);
/* Clears all unknown field data from this message and all submessages. */
// Clears all unknown field data from this message and all submessages.
bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m,
int maxdepth);
// DEPRECATED FUNCTIONS
// PHP and Ruby need these until we can version-bump them to the current upb.
UPB_INLINE void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m) {
return upb_Message_ClearByDef(msg, m);
}
UPB_INLINE void upb_Message_ClearField(upb_Message* msg,
const upb_FieldDef* f) {
return upb_Message_ClearFieldByDef(msg, f);
}
UPB_INLINE bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f) {
return upb_Message_HasFieldByDef(msg, f);
}
UPB_INLINE upb_MessageValue upb_Message_Get(const upb_Message* msg,
const upb_FieldDef* f) {
return upb_Message_GetFieldByDef(msg, f);
}
UPB_INLINE bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f,
upb_MessageValue val, upb_Arena* a) {
return upb_Message_SetFieldByDef(msg, f, val, a);
}
#ifdef __cplusplus
} /* extern "C" */
#endif
@ -7956,7 +7998,7 @@ upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len,
upb_MiniTablePlatform platform,
upb_Arena* arena, upb_Status* status);
UPB_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
UPB_API_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status) {
return _upb_MiniTable_Build(data, len, kUpb_MiniTablePlatform_Native, arena,
@ -7969,13 +8011,14 @@ UPB_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
// to link the message field later, at which point it will no longer be treated
// as unknown. However there is no synchronization for this operation, which
// means parallel mutation requires external synchronization.
void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
UPB_API void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
upb_MiniTableField* field,
const upb_MiniTable* sub);
// Links an enum field to a MiniTable for that enum. All enum fields must
// be linked prior to parsing.
void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field,
UPB_API void upb_MiniTable_SetSubEnum(upb_MiniTable* table,
upb_MiniTableField* field,
const upb_MiniTableEnum* sub);
const char* _upb_MiniTableExtension_Build(const char* data, size_t len,
@ -7985,14 +8028,14 @@ const char* _upb_MiniTableExtension_Build(const char* data, size_t len,
upb_MiniTablePlatform platform,
upb_Status* status);
UPB_INLINE const char* upb_MiniTableExtension_Build(
UPB_API_INLINE const char* upb_MiniTableExtension_Build(
const char* data, size_t len, upb_MiniTableExtension* ext,
const upb_MiniTable* extendee, upb_MiniTableSub sub, upb_Status* status) {
return _upb_MiniTableExtension_Build(data, len, ext, extendee, sub,
kUpb_MiniTablePlatform_Native, status);
}
upb_MiniTableEnum* upb_MiniTableEnum_Build(const char* data, size_t len,
UPB_API upb_MiniTableEnum* upb_MiniTableEnum_Build(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status);
@ -8698,7 +8741,7 @@ enum {
#ifndef UPB_WIRE_DECODE_INTERNAL_H_
#define UPB_WIRE_DECODE_INTERNAL_H_
#include "third_party/utf8_range/utf8_range.h"
#include "utf8_range.h"
// Must be last.
@ -8912,7 +8955,10 @@ UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) {
#undef UPB_READ_ONEOF
#undef UPB_WRITE_ONEOF
#undef UPB_MAPTYPE_STRING
#undef UPB_EXPORT
#undef UPB_INLINE
#undef UPB_API
#undef UPB_API_INLINE
#undef UPB_ALIGN_UP
#undef UPB_ALIGN_DOWN
#undef UPB_ALIGN_MALLOC

Loading…
Cancel
Save