OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cpp/bindings/lib/bindings_serialization.h" | 5 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 | 8 |
9 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 9 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
| 14 namespace { |
| 15 |
| 16 template<typename T> |
| 17 T AlignImpl(T t) { |
| 18 const size_t kAlignment = 8; |
| 19 return t + (kAlignment - (t % kAlignment)) % kAlignment; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
14 size_t Align(size_t size) { | 24 size_t Align(size_t size) { |
15 const size_t kAlignment = 8; | 25 return AlignImpl(size); |
16 return size + (kAlignment - (size % kAlignment)) % kAlignment; | 26 } |
| 27 |
| 28 char* AlignPointer(char* ptr) { |
| 29 return reinterpret_cast<char*>(AlignImpl(reinterpret_cast<uintptr_t>(ptr))); |
17 } | 30 } |
18 | 31 |
19 void EncodePointer(const void* ptr, uint64_t* offset) { | 32 void EncodePointer(const void* ptr, uint64_t* offset) { |
20 if (!ptr) { | 33 if (!ptr) { |
21 *offset = 0; | 34 *offset = 0; |
22 return; | 35 return; |
23 } | 36 } |
24 | 37 |
25 const char* p_obj = reinterpret_cast<const char*>(ptr); | 38 const char* p_obj = reinterpret_cast<const char*>(ptr); |
26 const char* p_slot = reinterpret_cast<const char*>(offset); | 39 const char* p_slot = reinterpret_cast<const char*>(offset); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 77 } |
65 if (handle->value() >= handles->size()) | 78 if (handle->value() >= handles->size()) |
66 return false; | 79 return false; |
67 // Just leave holes in the vector so we don't screw up other indices. | 80 // Just leave holes in the vector so we don't screw up other indices. |
68 *handle = FetchAndReset(&handles->at(handle->value())); | 81 *handle = FetchAndReset(&handles->at(handle->value())); |
69 return true; | 82 return true; |
70 } | 83 } |
71 | 84 |
72 } // namespace internal | 85 } // namespace internal |
73 } // namespace mojo | 86 } // namespace mojo |
OLD | NEW |