Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/array.h" | 5 #include "mojo/public/c/bindings/array.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | |
| 10 | 11 |
| 11 #include "mojo/public/c/bindings/buffer.h" | 12 #include "mojo/public/c/bindings/buffer.h" |
| 12 #include "mojo/public/c/bindings/interface.h" | 13 #include "mojo/public/c/bindings/interface.h" |
| 13 #include "mojo/public/c/bindings/lib/type_descriptor.h" | 14 #include "mojo/public/c/bindings/lib/type_descriptor.h" |
| 14 #include "mojo/public/c/bindings/lib/util.h" | 15 #include "mojo/public/c/bindings/lib/util.h" |
| 15 #include "mojo/public/c/bindings/union.h" | 16 #include "mojo/public/c/bindings/union.h" |
| 16 | 17 |
| 17 struct MojomArrayHeader* MojomArray_New(struct MojomBuffer* buf, | 18 struct MojomArrayHeader* MojomArray_New(struct MojomBuffer* buf, |
| 18 uint32_t num_elements, | 19 uint32_t num_elements, |
| 19 uint32_t element_byte_size) { | 20 uint32_t element_byte_size) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 elem_data, | 210 elem_data, |
| 210 in_array_size - (uint32_t)(elem_data - (char*)in_array), | 211 in_array_size - (uint32_t)(elem_data - (char*)in_array), |
| 211 in_num_handles, | 212 in_num_handles, |
| 212 inout_context); | 213 inout_context); |
| 213 if (result != MOJOM_VALIDATION_ERROR_NONE) | 214 if (result != MOJOM_VALIDATION_ERROR_NONE) |
| 214 return result; | 215 return result; |
| 215 } | 216 } |
| 216 | 217 |
| 217 return MOJOM_VALIDATION_ERROR_NONE; | 218 return MOJOM_VALIDATION_ERROR_NONE; |
| 218 } | 219 } |
| 220 | |
| 221 struct MojomArrayHeader* MojomArray_DeepCopy( | |
| 222 struct MojomBuffer* buffer, | |
| 223 const struct MojomTypeDescriptorArray* in_type_desc, | |
| 224 struct MojomArrayHeader* in_array) { | |
| 225 assert(in_type_desc); | |
| 226 assert(in_array); | |
| 227 | |
| 228 struct MojomArrayHeader* out_array = | |
| 229 MojomBuffer_Allocate(buffer, in_array->num_bytes); | |
|
viettrungluu
2016/08/02 20:15:06
E.g., this could fail. Though at least here you ca
| |
| 230 memcpy(out_array, in_array, in_array->num_bytes); | |
| 231 | |
| 232 // Nothing else to copy for POD types. | |
| 233 if (in_type_desc->elem_type == MOJOM_TYPE_DESCRIPTOR_TYPE_POD) | |
| 234 return out_array; | |
| 235 | |
| 236 for (size_t i = 0; i < in_array->num_elements; i++) { | |
| 237 void* in_elem_data = | |
| 238 array_index_by_type(in_array, in_type_desc->elem_type, i); | |
| 239 void* out_elem_data = | |
| 240 array_index_by_type(out_array, in_type_desc->elem_type, i); | |
| 241 | |
| 242 MojomType_DispatchDeepCopy(buffer, in_type_desc->elem_type, | |
|
viettrungluu
2016/08/02 20:15:06
Presumably, this could fail too. But that would po
| |
| 243 in_type_desc->elem_descriptor, in_elem_data, | |
| 244 out_elem_data); | |
| 245 } | |
| 246 | |
| 247 return out_array; | |
| 248 } | |
| OLD | NEW |