Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl

Issue 303163006: Make mojo handle encoding and validation follow the depth-first traversal order. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 if packed_field.field.kind|is_object_kind %}
16 {%- set wrapper_type = packed_field.field.kind|cpp_wrapper_type %}
17 {%- set name = packed_field.field.name %} 15 {%- set name = packed_field.field.name %}
16 {%- if packed_field.field.kind|is_object_kind %}
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 !{{wrapper_type}}::Data_::Validate( 19 !{{wrapper_type}}::Data_::Validate(
20 mojo::internal::DecodePointerRaw(&object->{{name}}.offset), 20 mojo::internal::DecodePointerRaw(&object->{{name}}.offset),
21 bounds_checker)) { 21 bounds_checker)) {
22 return false; 22 return false;
23 } 23 }
24 {%- endfor %} 24 {%- elif packed_field.field.kind|is_handle_kind %}
25 {%- for packed_field in struct.packed.packed_fields
26 if packed_field.field.kind|is_handle_kind %}
27 {%- set name = packed_field.field.name %}
28 if (!bounds_checker->ClaimHandle(object->{{name}})) 25 if (!bounds_checker->ClaimHandle(object->{{name}}))
29 return false; 26 return false;
27 {%- endif %}
30 {%- endfor %} 28 {%- endfor %}
31 29
32 return true; 30 return true;
33 {%- endmacro %} 31 {%- endmacro %}
34 32
35 {%- macro field_line(field) %} 33 {%- macro field_line(field) %}
36 {%- set type = field.kind|cpp_field_type %} 34 {%- set type = field.kind|cpp_field_type %}
37 {%- set name = field.name -%} 35 {%- set name = field.name -%}
38 {%- if field.kind.spec == 'b' -%} 36 {%- if field.kind.spec == 'b' -%}
39 uint8_t {{name}} : 1; 37 uint8_t {{name}} : 1;
(...skipping 21 matching lines...) Expand all
61 {%- set last_field = struct.packed.packed_fields[num_fields - 1] %} 59 {%- set last_field = struct.packed.packed_fields[num_fields - 1] %}
62 {%- set offset = last_field.offset + last_field.size %} 60 {%- set offset = last_field.offset + last_field.size %}
63 {%- set pad = offset|get_pad(8) -%} 61 {%- set pad = offset|get_pad(8) -%}
64 {%- if pad > 0 %} 62 {%- if pad > 0 %}
65 uint8_t padfinal_[{{pad}}]; 63 uint8_t padfinal_[{{pad}}];
66 {%- endif %} 64 {%- endif %}
67 {%- endif %} 65 {%- endif %}
68 {%- endmacro %} 66 {%- endmacro %}
69 67
70 {%- macro encodes(struct) -%} 68 {%- macro encodes(struct) -%}
71 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind -%} 69 {%- for pf in struct.packed.packed_fields %}
70 {%- if pf.field.kind|is_object_kind %}
72 mojo::internal::Encode(&{{pf.field.name}}, handles); 71 mojo::internal::Encode(&{{pf.field.name}}, handles);
73 {% endfor %} 72 {%- elif pf.field.kind|is_handle_kind %}
74 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_handle_kind -%}
75 mojo::internal::EncodeHandle(&{{pf.field.name}}, handles); 73 mojo::internal::EncodeHandle(&{{pf.field.name}}, handles);
76 {% endfor %} 74 {%- endif %}
75 {%- endfor %}
77 {%- endmacro -%} 76 {%- endmacro -%}
78 77
79 {%- macro decodes(struct) -%} 78 {%- macro decodes(struct) -%}
80 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind -%} 79 {%- for pf in struct.packed.packed_fields %}
80 {%- if pf.field.kind|is_object_kind %}
81 mojo::internal::Decode(&{{pf.field.name}}, handles); 81 mojo::internal::Decode(&{{pf.field.name}}, handles);
82 {% endfor %} 82 {%- elif pf.field.kind|is_handle_kind %}
83 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_handle_kind -%}
84 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); 83 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles);
85 {% endfor %} 84 {%- endif %}
85 {%- endfor %}
86 {%- endmacro -%} 86 {%- endmacro -%}
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698