Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: mojo/public/c/bindings/lib/union.c

Issue 2163793002: C bindings: Implement _Validate(), and some pre-requisites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/c/bindings/lib/type_descriptor.c ('k') | mojo/public/c/bindings/lib/util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « mojo/public/c/bindings/lib/type_descriptor.c ('k') | mojo/public/c/bindings/lib/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698