Chromium Code Reviews| 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..57f478f791ed4fbcb9ed82cc78fdd82bd580f870 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,34 @@ 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; |
| } |
| + |
| +bool MojomUnion_DeepCopy(struct MojomBuffer* buffer, |
| + const struct MojomTypeDescriptorUnion* in_type_desc, |
| + const struct MojomUnionLayout* in_union_data, |
| + struct MojomUnionLayout* out_union_data) { |
| + memcpy(out_union_data, in_union_data, sizeof(struct MojomUnionLayout)); |
| + |
| + // Unions with size 0 are null. |
| + if (in_union_data->size == 0) |
| + return true; |
| + |
| + 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; |
|
viettrungluu
2016/08/03 16:43:24
"
(Or maybe |return true;|?)
|
| + |
| + return MojomType_DispatchDeepCopy( |
| + buffer, entry->elem_type, entry->elem_descriptor, |
| + &(in_union_data->data), &(out_union_data->data)); |
| + } |
| + |
| + return true; |
|
viettrungluu
2016/08/03 16:43:24
Hmmm, returning true is a little odd: It means tha
vardhan
2016/08/03 23:11:01
My assumption was that it shouldn't fail, but disc
|
| +} |