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

Unified 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, 5 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6b93b1ef70941849c51aaaf132d60f939bdef3f8..99b269394ff90c7e61e8f4277799c598b214c973 100644
--- a/mojo/public/c/bindings/lib/union.c
+++ b/mojo/public/c/bindings/lib/union.c
@@ -87,3 +87,37 @@ void MojomUnion_DecodePointersAndHandles(
in_num_handles);
}
}
+
+MojomValidationResult MojomUnion_Validate(
+ const struct MojomTypeDescriptorUnion* in_type_desc,
+ bool in_nullable,
+ const struct MojomUnionLayout* in_union,
+ uint32_t in_union_size,
+ uint32_t in_num_handles,
+ struct MojomValidationContext* inout_context) {
+ for (size_t i = 0; i < in_type_desc->num_entries; i++) {
+ const struct MojomTypeDescriptorUnionEntry* entry =
+ &(in_type_desc->entries[i]);
+
+ if (in_union->tag != entry->tag)
+ continue;
+
+ if (entry->elem_type == MOJOM_TYPE_DESCRIPTOR_TYPE_POD)
+ continue;
+
+ if (!in_nullable && in_union->size != sizeof(struct MojomUnionLayout))
+ return MOJOM_VALIDATION_UNEXPECTED_NULL_UNION;
+
+ MojomValidationResult result = MojomType_DispatchValidate(
+ entry->elem_type,
+ entry->elem_descriptor,
+ entry->nullable,
+ &(in_union->data),
+ 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;
+}
« 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