| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/public/c/bindings/union.h" | 5 #include "mojo/public/c/bindings/union.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 #include "mojo/public/c/bindings/lib/type_descriptor.h" | 9 #include "mojo/public/c/bindings/lib/type_descriptor.h" |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 MojomType_DispatchDecodePointersAndHandles( | 80 MojomType_DispatchDecodePointersAndHandles( |
| 81 entry->elem_type, | 81 entry->elem_type, |
| 82 entry->elem_descriptor, | 82 entry->elem_descriptor, |
| 83 entry->nullable, | 83 entry->nullable, |
| 84 &inout_union->data, | 84 &inout_union->data, |
| 85 in_union_size - ((char*)&inout_union->data - (char*)inout_union), | 85 in_union_size - ((char*)&inout_union->data - (char*)inout_union), |
| 86 inout_handles, | 86 inout_handles, |
| 87 in_num_handles); | 87 in_num_handles); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 |
| 91 MojomValidationResult MojomUnion_Validate( |
| 92 const struct MojomTypeDescriptorUnion* in_type_desc, |
| 93 bool in_nullable, |
| 94 const struct MojomUnionLayout* in_union, |
| 95 uint32_t in_union_size, |
| 96 uint32_t in_num_handles, |
| 97 struct MojomValidationContext* inout_context) { |
| 98 for (size_t i = 0; i < in_type_desc->num_entries; i++) { |
| 99 const struct MojomTypeDescriptorUnionEntry* entry = |
| 100 &(in_type_desc->entries[i]); |
| 101 |
| 102 if (in_union->tag != entry->tag) |
| 103 continue; |
| 104 |
| 105 if (entry->elem_type == MOJOM_TYPE_DESCRIPTOR_TYPE_POD) |
| 106 continue; |
| 107 |
| 108 if (!in_nullable && in_union->size != sizeof(struct MojomUnionLayout)) |
| 109 return MOJOM_VALIDATION_UNEXPECTED_NULL_UNION; |
| 110 |
| 111 MojomValidationResult result = MojomType_DispatchValidate( |
| 112 entry->elem_type, |
| 113 entry->elem_descriptor, |
| 114 entry->nullable, |
| 115 &(in_union->data), |
| 116 in_union_size - ((char*)&(in_union->data) - (char*)in_union), |
| 117 in_num_handles, |
| 118 inout_context); |
| 119 if (result != MOJOM_VALIDATION_ERROR_NONE) |
| 120 return result; |
| 121 } |
| 122 return MOJOM_VALIDATION_ERROR_NONE; |
| 123 } |
| OLD | NEW |