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

Side by Side Diff: mojo/public/c/bindings/lib/struct.c

Issue 2200843002: C bindings: Implement _DeepCopy() & some unittests. (Closed) Base URL: git@github.com:domokit/mojo.git@cgen_validate
Patch Set: fix tab indent, update sha1 Created 4 years, 4 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
« no previous file with comments | « mojo/public/c/bindings/lib/array.c ('k') | mojo/public/c/bindings/lib/type_descriptor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/c/bindings/struct.h" 5 #include "mojo/public/c/bindings/struct.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <string.h>
8 9
9 #include "mojo/public/c/bindings/lib/type_descriptor.h" 10 #include "mojo/public/c/bindings/lib/type_descriptor.h"
10 #include "mojo/public/c/bindings/union.h" 11 #include "mojo/public/c/bindings/union.h"
11 12
12 size_t MojomStruct_ComputeSerializedSize( 13 size_t MojomStruct_ComputeSerializedSize(
13 const struct MojomTypeDescriptorStruct* in_type_desc, 14 const struct MojomTypeDescriptorStruct* in_type_desc,
14 const struct MojomStructHeader* in_struct) { 15 const struct MojomStructHeader* in_struct) {
15 assert(in_struct); 16 assert(in_struct);
16 assert(in_type_desc); 17 assert(in_type_desc);
17 18
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 elem_data, 157 elem_data,
157 in_struct_size - ((char*)elem_data - (char*)in_struct), 158 in_struct_size - ((char*)elem_data - (char*)in_struct),
158 in_num_handles, 159 in_num_handles,
159 inout_context); 160 inout_context);
160 if (result != MOJOM_VALIDATION_ERROR_NONE) 161 if (result != MOJOM_VALIDATION_ERROR_NONE)
161 return result; 162 return result;
162 } 163 }
163 164
164 return MOJOM_VALIDATION_ERROR_NONE; 165 return MOJOM_VALIDATION_ERROR_NONE;
165 } 166 }
167
168 bool MojomStruct_DeepCopy(
169 struct MojomBuffer* buffer,
170 const struct MojomTypeDescriptorStruct* in_type_desc,
171 const struct MojomStructHeader* in_struct,
172 struct MojomStructHeader** out_struct) {
173 assert(in_type_desc);
174 assert(in_struct);
175 assert(out_struct);
176
177 *out_struct = MojomBuffer_Allocate(buffer, in_struct->num_bytes);
178 if (*out_struct == NULL)
179 return false;
180
181 memcpy(*out_struct, in_struct, in_struct->num_bytes);
182
183 for (size_t i = 0; i < in_type_desc->num_entries; i++) {
184 const struct MojomTypeDescriptorStructEntry* entry =
185 &(in_type_desc->entries[i]);
186
187 if (in_struct->version < entry->min_version)
188 continue;
189
190 void* in_elem_data =
191 ((char*)in_struct + sizeof(struct MojomStructHeader) + entry->offset);
192 void* out_elem_data = ((char*)*out_struct +
193 sizeof(struct MojomStructHeader) + entry->offset);
194 if (!MojomType_DispatchDeepCopy(
195 buffer,
196 entry->elem_type,
197 entry->elem_descriptor,
198 in_elem_data,
199 out_elem_data)) {
200 return false;
201 }
202 }
203
204 return true;
205 }
OLDNEW
« no previous file with comments | « mojo/public/c/bindings/lib/array.c ('k') | mojo/public/c/bindings/lib/type_descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698