| Index: mojo/public/c/bindings/lib/union.c
|
| diff --git a/mojo/public/c/bindings/lib/union.c b/mojo/public/c/bindings/lib/union.c
|
| index 99b269394ff90c7e61e8f4277799c598b214c973..3605e9a9a1b1a1c981ee62690992156b6bcda60b 100644
|
| --- a/mojo/public/c/bindings/lib/union.c
|
| +++ b/mojo/public/c/bindings/lib/union.c
|
| @@ -5,6 +5,7 @@
|
| #include "mojo/public/c/bindings/union.h"
|
|
|
| #include <assert.h>
|
| +#include <string.h>
|
|
|
| #include "mojo/public/c/bindings/lib/type_descriptor.h"
|
|
|
| @@ -55,6 +56,8 @@ void MojomUnion_EncodePointersAndHandles(
|
| &inout_union->data,
|
| in_buf_size - ((char*)&inout_union->data - (char*)inout_union),
|
| inout_handles_buffer);
|
| +
|
| + break;
|
| }
|
| }
|
|
|
| @@ -85,6 +88,8 @@ void MojomUnion_DecodePointersAndHandles(
|
| in_union_size - ((char*)&inout_union->data - (char*)inout_union),
|
| inout_handles,
|
| in_num_handles);
|
| +
|
| + break;
|
| }
|
| }
|
|
|
| @@ -108,7 +113,7 @@ MojomValidationResult MojomUnion_Validate(
|
| if (!in_nullable && in_union->size != sizeof(struct MojomUnionLayout))
|
| return MOJOM_VALIDATION_UNEXPECTED_NULL_UNION;
|
|
|
| - MojomValidationResult result = MojomType_DispatchValidate(
|
| + return MojomType_DispatchValidate(
|
| entry->elem_type,
|
| entry->elem_descriptor,
|
| entry->nullable,
|
| @@ -116,8 +121,32 @@ MojomValidationResult MojomUnion_Validate(
|
| in_union_size - ((char*)&(in_union->data) - (char*)in_union),
|
| in_num_handles,
|
| inout_context);
|
| - if (result != MOJOM_VALIDATION_ERROR_NONE)
|
| - return result;
|
| }
|
| return MOJOM_VALIDATION_ERROR_NONE;
|
| }
|
| +
|
| +void MojomUnion_DeepCopy(struct MojomBuffer* buffer,
|
| + const struct MojomTypeDescriptorUnion* in_type_desc,
|
| + struct MojomUnionLayout* in_union_data,
|
| + struct MojomUnionLayout* out_union_data) {
|
| + memcpy(out_union_data, in_union_data, sizeof(struct MojomUnionLayout));
|
| +
|
| + if (in_union_data->size == 0)
|
| + return;
|
| +
|
| + for (size_t i = 0; i < in_type_desc->num_entries; i++) {
|
| + const struct MojomTypeDescriptorUnionEntry* entry =
|
| + &(in_type_desc->entries[i]);
|
| + if (in_union_data->tag != entry->tag)
|
| + continue;
|
| +
|
| + // We should skip non-pointer types.
|
| + if (entry->elem_type == MOJOM_TYPE_DESCRIPTOR_TYPE_POD)
|
| + continue;
|
| +
|
| + MojomType_DispatchDeepCopy(
|
| + buffer, entry->elem_type, entry->elem_descriptor,
|
| + &(in_union_data->data), &(out_union_data->data));
|
| + break;
|
| + }
|
| +}
|
|
|