Chromium Code Reviews| 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 623ebb441c69938da26e8489662eb65641f82f5d..e457e61620658d3f00fd241d39a3fc2c21acb918 100644 |
| --- a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl |
| +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl |
| @@ -14,7 +14,21 @@ |
| {%- for packed_field in struct.packed.packed_fields %} |
| {%- set name = packed_field.field.name %} |
| {%- set kind = packed_field.field.kind %} |
| -{%- if kind|is_object_kind %} |
| +{%- if kind|is_union_kind %} |
| +{%- if not kind|is_nullable_kind %} |
|
yzshen1
2015/02/17 19:34:35
(Please note that this part has been under signifi
azani
2015/02/18 00:27:57
Done.
|
| + if (object->{{name}}.is_null()) { |
| + ReportValidationError( |
| + mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
| + "null {{name}} field in {{struct.name}} struct"); |
| + return false; |
| + } |
| +{%- endif %} |
| + // 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, false)) { |
|
yzshen1
2015/02/17 19:34:35
Do you think it make sense to make |false| a templ
azani
2015/02/18 00:27:57
It seems like we would just shift the inconsistenc
|
| + return false; |
| + } |
| +{%- elif kind|is_object_kind %} |
| {%- set wrapper_type = kind|cpp_wrapper_type %} |
| {%- if not kind|is_nullable_kind %} |
| if (!object->{{name}}.offset) { |
| @@ -105,7 +119,9 @@ |
| {%- macro encodes(struct) -%} |
| {%- for pf in struct.packed.packed_fields %} |
| -{%- if pf.field.kind|is_object_kind %} |
| +{%- if pf.field.kind|is_union_kind %} |
| +// 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); |
| @@ -115,7 +131,9 @@ mojo::internal::EncodeHandle(&{{pf.field.name}}, handles); |
| {%- macro decodes(struct) -%} |
| {%- for pf in struct.packed.packed_fields %} |
| -{%- if pf.field.kind|is_object_kind %} |
| +{%- if pf.field.kind|is_union_kind %} |
| +// TODO(azani): Decode pointers and handles. |
| +{%- elif pf.field.kind|is_object_kind %} |
| mojo::internal::Decode(&{{pf.field.name}}, handles); |
| {%- elif pf.field.kind|is_any_handle_kind %} |
| mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); |