| 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 0e5119323996ee8044a009aaa3eaaccd1c5fb21b..4182c625535e0d113fb4de17854185e93f97bb77 100644
|
| --- a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
|
| +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
|
| @@ -1,73 +1,85 @@
|
| -{%- macro validate(struct, class_name) %}
|
| - if (!data)
|
| - return true;
|
| -
|
| - if (!ValidateStructHeader(
|
| - data, sizeof({{class_name}}),
|
| - {{struct.packed.packed_fields|length}}, bounds_checker)) {
|
| - return false;
|
| - }
|
| -
|
| - const {{class_name}}* MOJO_ALLOW_UNUSED object =
|
| - static_cast<const {{class_name}}*>(data);
|
| -
|
| -{%- 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 %}
|
| -{%- set wrapper_type = kind|cpp_wrapper_type %}
|
| -{%- if not kind|is_nullable_kind %}
|
| +{%- macro validate_field(struct, name, kind) %}
|
| +{%- if kind|is_map_kind %}
|
| +{%- set name_keys = name + "_keys" %}
|
| +{%- set name_values = name + "_values" %}
|
| +{{ validate_field(struct, name_keys, kind.key_kind) }}
|
| +{{ validate_field(struct, name_values, kind.value_kind) }}
|
| +{%- elif kind|is_object_kind %}
|
| +{%- set wrapper_type = kind|cpp_wrapper_type %}
|
| +{%- if not kind|is_nullable_kind %}
|
| if (!object->{{name}}.offset) {
|
| ReportValidationError(
|
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
|
| "null {{name}} field in {{struct.name}} struct");
|
| return false;
|
| }
|
| -{%- endif %}
|
| +{%- endif %}
|
| if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) {
|
| ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER);
|
| return false;
|
| }
|
| -{%- if kind|is_any_array_kind or kind|is_string_kind %}
|
| +{%- if kind|is_any_array_kind or kind|is_string_kind %}
|
| if (!{{wrapper_type}}::Data_::Validate<
|
| {{kind|get_array_validate_params|indent(10)}}>(
|
| mojo::internal::DecodePointerRaw(&object->{{name}}.offset),
|
| bounds_checker)) {
|
| -{%- else %}
|
| +{%- else %}
|
| if (!{{wrapper_type}}::Data_::Validate(
|
| mojo::internal::DecodePointerRaw(&object->{{name}}.offset),
|
| bounds_checker)) {
|
| -{%- endif %}
|
| +{%- endif %}
|
| return false;
|
| }
|
| -{%- elif kind|is_any_handle_kind %}
|
| -{%- if not kind|is_nullable_kind %}
|
| +{%- elif kind|is_any_handle_kind %}
|
| +{%- if not kind|is_nullable_kind %}
|
| if (object->{{name}}.value() == mojo::internal::kEncodedInvalidHandleValue) {
|
| ReportValidationError(
|
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
|
| "invalid {{name}} field in {{struct.name}} struct");
|
| return false;
|
| }
|
| -{%- endif %}
|
| +{%- endif %}
|
| if (!bounds_checker->ClaimHandle(object->{{name}})) {
|
| ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE);
|
| return false;
|
| }
|
| -{%- endif %}
|
| +{%- endif %}
|
| +{%- endmacro -%}
|
| +
|
| +
|
| +{%- macro validate(struct, class_name) %}
|
| + if (!data)
|
| + return true;
|
| +
|
| + if (!ValidateStructHeader(
|
| + data, sizeof({{class_name}}),
|
| + {{struct.packed.packed_fields|length}}, bounds_checker)) {
|
| + return false;
|
| + }
|
| +
|
| + const {{class_name}}* MOJO_ALLOW_UNUSED object =
|
| + static_cast<const {{class_name}}*>(data);
|
| +
|
| +{%- for packed_field in struct.packed.packed_fields %}
|
| +{%- set name = packed_field.field.name %}
|
| +{%- set kind = packed_field.field.kind %}
|
| +{{ validate_field(struct, name, kind) }}
|
| {%- endfor %}
|
|
|
| return true;
|
| {%- endmacro %}
|
|
|
| {%- macro field_line(field) %}
|
| -{%- set type = field.kind|cpp_field_type %}
|
| {%- set name = field.name -%}
|
| {%- if field.kind.spec == 'b' -%}
|
| uint8_t {{name}} : 1;
|
| {%- elif field.kind|is_enum_kind -%}
|
| int32_t {{name}};
|
| +{%- elif field.kind|is_map_kind -%}
|
| + mojo::internal::ArrayPointer<{{field.kind.key_kind|cpp_type}}> {{name}}_keys;
|
| + mojo::internal::ArrayPointer<{{field.kind.value_kind|cpp_type}}> {{name}}_values;
|
| {%- else -%}
|
| - {{type}} {{name}};
|
| + {{field.kind|cpp_field_type}} {{name}};
|
| {%- endif %}
|
| {%- endmacro %}
|
|
|
| @@ -96,7 +108,10 @@
|
|
|
| {%- macro encodes(struct) -%}
|
| {%- for pf in struct.packed.packed_fields %}
|
| -{%- if pf.field.kind|is_object_kind %}
|
| +{%- if pf.field.kind|is_map_kind %}
|
| +mojo::internal::Encode(&{{pf.field.name}}_keys, handles);
|
| +mojo::internal::Encode(&{{pf.field.name}}_values, 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);
|
| @@ -106,7 +121,10 @@ 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_map_kind %}
|
| +mojo::internal::Decode(&{{pf.field.name}}_keys, handles);
|
| +mojo::internal::Decode(&{{pf.field.name}}_values, 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);
|
|
|