| OLD | NEW |
| 1 {%- import "validation_macros.tmpl" as validation_macros %} | 1 {%- import "validation_macros.tmpl" as validation_macros %} |
| 2 {%- set class_name = union.name ~ "_Data" %} | 2 {%- set class_name = union.name ~ "_Data" %} |
| 3 {%- set enum_name = union.name ~ "_Tag" -%} | 3 {%- set enum_name = union.name ~ "_Tag" -%} |
| 4 | 4 |
| 5 // static | 5 // static |
| 6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { | 6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { |
| 7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); | 7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); |
| 8 } | 8 } |
| 9 | 9 |
| 10 // static | 10 // static |
| 11 bool {{class_name}}::Validate(const void* data, | 11 bool {{class_name}}::Validate(const void* data, |
| 12 mojo::internal::BoundsChecker* bounds_checker) { | 12 mojo::internal::BoundsChecker* bounds_checker, |
| 13 bool inlined) { |
| 13 if (!data) { | 14 if (!data) { |
| 14 return true; | 15 return true; |
| 15 } | 16 } |
| 16 | 17 |
| 17 if (!mojo::internal::IsAligned(data)) { | 18 if (!mojo::internal::IsAligned(data)) { |
| 18 ReportValidationError(mojo::internal::VALIDATION_ERROR_MISALIGNED_OBJECT); | 19 ReportValidationError(mojo::internal::VALIDATION_ERROR_MISALIGNED_OBJECT); |
| 19 return false; | 20 return false; |
| 20 } | 21 } |
| 21 | 22 |
| 22 if (!bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) { | 23 // If the union is inlined in another structure its memory was already claimed
. |
| 24 // This ONLY applies to the union itself, NOT anything which the union points |
| 25 // to. |
| 26 if (!inlined && !bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) { |
| 23 ReportValidationError( | 27 ReportValidationError( |
| 24 mojo::internal::VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 28 mojo::internal::VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| 25 return false; | 29 return false; |
| 26 } | 30 } |
| 27 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); | 31 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); |
| 28 MOJO_ALLOW_UNUSED_LOCAL(object); | 32 MOJO_ALLOW_UNUSED_LOCAL(object); |
| 29 | 33 |
| 30 switch (object->tag) { | 34 switch (object->tag) { |
| 31 {% for field in union.fields %} | 35 {% for field in union.fields %} |
| 32 case {{enum_name}}::{{field.name|upper}}: | 36 case {{enum_name}}::{{field.name|upper}}: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 45 | 49 |
| 46 void {{class_name}}::EncodePointersAndHandles( | 50 void {{class_name}}::EncodePointersAndHandles( |
| 47 std::vector<mojo::Handle>* handles) { | 51 std::vector<mojo::Handle>* handles) { |
| 48 // TODO(azani): Implement pointers and handles. | 52 // TODO(azani): Implement pointers and handles. |
| 49 } | 53 } |
| 50 | 54 |
| 51 void {{class_name}}::DecodePointersAndHandles( | 55 void {{class_name}}::DecodePointersAndHandles( |
| 52 std::vector<mojo::Handle>* handles) { | 56 std::vector<mojo::Handle>* handles) { |
| 53 // TODO(azani): Implement pointers and handles. | 57 // TODO(azani): Implement pointers and handles. |
| 54 } | 58 } |
| OLD | NEW |