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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl

Issue 923033003: Implement unions as members of structs. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
Index: mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
index c9ea5d0199b1e61d85b979c299b8524c1d27bb87..23e5cfde51bfaeb1321d1f35b2affa7abb11de8a 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
@@ -9,7 +9,8 @@
// static
bool {{class_name}}::Validate(const void* data,
- mojo::internal::BoundsChecker* bounds_checker) {
+ mojo::internal::BoundsChecker* bounds_checker,
+ bool inlined) {
if (!data) {
return true;
}
@@ -19,7 +20,10 @@ bool {{class_name}}::Validate(const void* data,
return false;
}
- if (!bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) {
+ // If the union is inlined in another structure its memory was already claimed.
+ // This ONLY applies to the union itself, NOT anything which the union points
+ // to.
+ if (!inlined && !bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) {
ReportValidationError(
mojo::internal::VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
return false;
@@ -40,6 +44,12 @@ bool {{class_name}}::Validate(const void* data,
}
}
+void {{class_name}}::set_null() {
+ size = 0U;
+ tag = static_cast<{{enum_name}}>(0);
+ data.unknown = 0U;
+}
+
{{class_name}}::{{class_name}}() {
}

Powered by Google App Engine
This is Rietveld 408576698