Index: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl |
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl |
index 69c85949c293b08d1df51f6c6e6f59dfa8afbfbb..c69f4fb1bc3d605b3b9162cf349acb963c3ebf7b 100644 |
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl |
@@ -10,17 +10,23 @@ |
{%- set kind = packed_field.field.kind %} |
{%- set wrapper_type = kind|cpp_wrapper_type %} |
{%- if not kind|is_nullable_kind %} |
+{%- if kind|is_union_kind %} |
+ if (object->{{name}}.is_null()) { |
+{%- else %} |
if (!object->{{name}}.offset) { |
+{%- endif %} |
ReportValidationError( |
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
"null {{name}} field in {{struct.name}} struct"); |
return false; |
} |
{%- endif %} |
+{%- if not kind|is_union_kind %} |
if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { |
ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER); |
return false; |
} |
+{%- endif %} |
{%- if kind|is_array_kind or kind|is_string_kind %} |
if (!{{wrapper_type}}::Data_::Validate< |
{{kind|get_array_validate_params|indent(10)}}>( |
@@ -35,6 +41,10 @@ |
if (!{{kind|get_name_for_kind}}::Data_::Validate( |
mojo::internal::DecodePointerRaw(&object->{{name}}.offset), |
bounds_checker)) { |
+{%- elif kind|is_union_kind %} |
+ // We already claimed the union's memory as part of the struct, so we don't |
+ // try to claim the union's memory when validating the union. |
+ if (!{{kind.name}}::Data_::Validate(&object->{{name}}, bounds_checker, true)) { |
{%- else %} |
if (!{{wrapper_type}}::Data_::Validate( |
mojo::internal::DecodePointerRaw(&object->{{name}}.offset), |
@@ -167,7 +177,9 @@ |
{%- macro encodes(struct) -%} |
MOJO_CHECK(header_.version == {{struct.versions[-1].version}}); |
{%- for pf in struct.packed.packed_fields_in_ordinal_order %} |
-{%- if pf.field.kind|is_object_kind %} |
+{%- if pf.field.kind|is_union_kind %} |
yzshen1
2015/02/25 21:07:00
Could you please move the "is_union_kind" part int
azani
2015/03/03 00:44:16
Done.
|
+// TODO(azani): Encode pointers and handles. |
+{%- elif pf.field.kind|is_object_kind %} |
mojo::internal::Encode(&{{pf.field.name}}, handles); |
{%- elif pf.field.kind|is_any_handle_kind %} |
mojo::internal::EncodeHandle(&{{pf.field.name}}, handles); |
@@ -195,7 +207,9 @@ |
if (header_.version < {{pf.min_version}}) |
return; |
{%- endif %} |
-{%- if kind|is_object_kind %} |
+{%- if kind|is_union_kind %} |
yzshen1
2015/02/25 21:07:00
ditto
azani
2015/03/03 00:44:16
Done.
|
+// TODO(azani): Decode pointers and handles. |
+{%- elif kind|is_object_kind %} |
mojo::internal::Decode(&{{name}}, handles); |
{%- else %} |
mojo::internal::DecodeHandle(&{{name}}, handles); |
@@ -243,7 +257,10 @@ |
{%- set input_field = input_field_pattern|format(pf.field.name) %} |
{%- set name = pf.field.name %} |
{%- set kind = pf.field.kind %} |
-{%- if kind|is_object_kind %} |
+{%- if kind|is_union_kind %} |
yzshen1
2015/02/25 21:07:00
ditto.
azani
2015/03/03 00:44:15
Done.
|
+ internal::{{pf.field.kind.name}}_Data* {{pf.field.name}}_ptr = &result->{{pf.field.name}}; |
yzshen1
2015/02/25 21:07:00
Please use {{input_field}}, {{buffer}} and {{outpu
azani
2015/03/03 00:44:15
Done.
|
+ Serialize_(mojo::internal::Forward(input->{{pf.field.name}}), buf, &{{pf.field.name}}_ptr); |
+{%- elif kind|is_object_kind %} |
{%- if kind|is_array_kind %} |
mojo::SerializeArray_<{{kind|get_array_validate_params|indent(24)}}>( |
mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr); |
@@ -306,7 +323,9 @@ |
if ({{input}}->header_.version < {{pf.min_version}}) |
break; |
{%- endif %} |
-{%- if kind|is_object_kind %} |
+{%- if kind|is_union_kind %} |
yzshen1
2015/02/25 21:07:00
Please move this if into the if for "is_object_kin
azani
2015/03/03 00:44:16
Done.
|
+ Deserialize_(&input->{{pf.field.name}}, &result->{{pf.field.name}}); |
yzshen1
2015/02/25 21:07:00
Please use {{output_field}}, {{input}}.
Besides,
azani
2015/03/03 00:44:16
Done.
|
+{%- elif kind|is_object_kind %} |
Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}); |
{%- elif kind|is_interface_kind or kind|is_interface_request_kind %} |
{{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(&{{input}}->{{name}}))); |