| OLD | NEW |
| 1 {%- macro validate(struct, class_name) %} | 1 {%- macro validate(struct, class_name) %} |
| 2 if (!data) | 2 if (!data) |
| 3 return true; | 3 return true; |
| 4 | 4 |
| 5 if (!ValidateStructHeader( | 5 if (!ValidateStructHeader( |
| 6 data, sizeof({{class_name}}), | 6 data, sizeof({{class_name}}), |
| 7 {{struct.packed.packed_fields|length}}, bounds_checker)) { | 7 {{struct.packed.packed_fields|length}}, bounds_checker)) { |
| 8 return false; | 8 return false; |
| 9 } | 9 } |
| 10 | 10 |
| 11 const {{class_name}}* MOJO_ALLOW_UNUSED object = | 11 const {{class_name}}* MOJO_ALLOW_UNUSED object = |
| 12 static_cast<const {{class_name}}*>(data); | 12 static_cast<const {{class_name}}*>(data); |
| 13 | 13 |
| 14 {%- for packed_field in struct.packed.packed_fields %} | 14 {%- for packed_field in struct.packed.packed_fields %} |
| 15 {%- set name = packed_field.field.name %} | 15 {%- set name = packed_field.field.name %} |
| 16 {%- if packed_field.field.kind|is_object_kind %} | 16 {%- if packed_field.field.kind|is_object_kind %} |
| 17 {%- set wrapper_type = packed_field.field.kind|cpp_wrapper_type %} | 17 {%- set wrapper_type = packed_field.field.kind|cpp_wrapper_type %} |
| 18 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { | 18 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { |
| 19 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER); | 19 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER); |
| 20 return false; | 20 return false; |
| 21 } | 21 } |
| 22 if (!{{wrapper_type}}::Data_::Validate( | 22 if (!{{wrapper_type}}::Data_::Validate( |
| 23 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), | 23 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), |
| 24 bounds_checker | 24 bounds_checker |
| 25 {%- if packed_field.field.kind|is_array_kind -%} | 25 {%- if packed_field.field.kind|is_any_array_kind -%} |
| 26 , {{packed_field.field.kind|expected_array_size}} | 26 , {{packed_field.field.kind|expected_array_size}} |
| 27 {%- endif -%} | 27 {%- endif -%} |
| 28 )) { | 28 )) { |
| 29 return false; | 29 return false; |
| 30 } | 30 } |
| 31 {%- elif packed_field.field.kind|is_handle_kind %} | 31 {%- elif packed_field.field.kind|is_any_handle_kind %} |
| 32 if (!bounds_checker->ClaimHandle(object->{{name}})) { | 32 if (!bounds_checker->ClaimHandle(object->{{name}})) { |
| 33 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE); | 33 ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_HANDLE); |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| 36 {%- endif %} | 36 {%- endif %} |
| 37 {%- endfor %} | 37 {%- endfor %} |
| 38 | 38 |
| 39 return true; | 39 return true; |
| 40 {%- endmacro %} | 40 {%- endmacro %} |
| 41 | 41 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 71 {%- if pad > 0 %} | 71 {%- if pad > 0 %} |
| 72 uint8_t padfinal_[{{pad}}]; | 72 uint8_t padfinal_[{{pad}}]; |
| 73 {%- endif %} | 73 {%- endif %} |
| 74 {%- endif %} | 74 {%- endif %} |
| 75 {%- endmacro %} | 75 {%- endmacro %} |
| 76 | 76 |
| 77 {%- macro encodes(struct) -%} | 77 {%- macro encodes(struct) -%} |
| 78 {%- for pf in struct.packed.packed_fields %} | 78 {%- for pf in struct.packed.packed_fields %} |
| 79 {%- if pf.field.kind|is_object_kind %} | 79 {%- if pf.field.kind|is_object_kind %} |
| 80 mojo::internal::Encode(&{{pf.field.name}}, handles); | 80 mojo::internal::Encode(&{{pf.field.name}}, handles); |
| 81 {%- elif pf.field.kind|is_handle_kind %} | 81 {%- elif pf.field.kind|is_any_handle_kind %} |
| 82 mojo::internal::EncodeHandle(&{{pf.field.name}}, handles); | 82 mojo::internal::EncodeHandle(&{{pf.field.name}}, handles); |
| 83 {%- endif %} | 83 {%- endif %} |
| 84 {%- endfor %} | 84 {%- endfor %} |
| 85 {%- endmacro -%} | 85 {%- endmacro -%} |
| 86 | 86 |
| 87 {%- macro decodes(struct) -%} | 87 {%- macro decodes(struct) -%} |
| 88 {%- for pf in struct.packed.packed_fields %} | 88 {%- for pf in struct.packed.packed_fields %} |
| 89 {%- if pf.field.kind|is_object_kind %} | 89 {%- if pf.field.kind|is_object_kind %} |
| 90 mojo::internal::Decode(&{{pf.field.name}}, handles); | 90 mojo::internal::Decode(&{{pf.field.name}}, handles); |
| 91 {%- elif pf.field.kind|is_handle_kind %} | 91 {%- elif pf.field.kind|is_any_handle_kind %} |
| 92 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); | 92 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); |
| 93 {%- endif %} | 93 {%- endif %} |
| 94 {%- endfor %} | 94 {%- endfor %} |
| 95 {%- endmacro -%} | 95 {%- endmacro -%} |
| OLD | NEW |