| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/pickle.h" | 5 #include "base/pickle.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <algorithm> // for max() | 9 #include <algorithm> // for max() |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 201 } |
| 202 | 202 |
| 203 bool PickleIterator::ReadBytes(const char** data, int length) { | 203 bool PickleIterator::ReadBytes(const char** data, int length) { |
| 204 const char* read_from = GetReadPointerAndAdvance(length); | 204 const char* read_from = GetReadPointerAndAdvance(length); |
| 205 if (!read_from) | 205 if (!read_from) |
| 206 return false; | 206 return false; |
| 207 *data = read_from; | 207 *data = read_from; |
| 208 return true; | 208 return true; |
| 209 } | 209 } |
| 210 | 210 |
| 211 Pickle::Attachment::Attachment() {} |
| 212 |
| 213 Pickle::Attachment::~Attachment() {} |
| 214 |
| 211 // Payload is uint32_t aligned. | 215 // Payload is uint32_t aligned. |
| 212 | 216 |
| 213 Pickle::Pickle() | 217 Pickle::Pickle() |
| 214 : header_(NULL), | 218 : header_(NULL), |
| 215 header_size_(sizeof(Header)), | 219 header_size_(sizeof(Header)), |
| 216 capacity_after_header_(0), | 220 capacity_after_header_(0), |
| 217 write_offset_(0) { | 221 write_offset_(0) { |
| 218 static_assert((Pickle::kPayloadUnit & (Pickle::kPayloadUnit - 1)) == 0, | 222 static_assert((Pickle::kPayloadUnit & (Pickle::kPayloadUnit - 1)) == 0, |
| 219 "Pickle::kPayloadUnit must be a power of two"); | 223 "Pickle::kPayloadUnit must be a power of two"); |
| 220 Resize(kPayloadUnit); | 224 Resize(kPayloadUnit); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 DCHECK_GE(data_len, length); | 319 DCHECK_GE(data_len, length); |
| 316 #ifdef ARCH_CPU_64_BITS | 320 #ifdef ARCH_CPU_64_BITS |
| 317 DCHECK_LE(data_len, std::numeric_limits<uint32_t>::max()); | 321 DCHECK_LE(data_len, std::numeric_limits<uint32_t>::max()); |
| 318 #endif | 322 #endif |
| 319 DCHECK_LE(write_offset_, std::numeric_limits<uint32_t>::max() - data_len); | 323 DCHECK_LE(write_offset_, std::numeric_limits<uint32_t>::max() - data_len); |
| 320 size_t new_size = write_offset_ + data_len; | 324 size_t new_size = write_offset_ + data_len; |
| 321 if (new_size > capacity_after_header_) | 325 if (new_size > capacity_after_header_) |
| 322 Resize(capacity_after_header_ * 2 + new_size); | 326 Resize(capacity_after_header_ * 2 + new_size); |
| 323 } | 327 } |
| 324 | 328 |
| 329 bool Pickle::WriteAttachment(scoped_refptr<Attachment> attachment) { |
| 330 NOTREACHED(); |
| 331 return false; |
| 332 } |
| 333 |
| 334 bool Pickle::ReadAttachment(base::PickleIterator* iter, |
| 335 scoped_refptr<Attachment>* attachment) const { |
| 336 NOTREACHED(); |
| 337 return false; |
| 338 } |
| 339 |
| 325 void Pickle::Resize(size_t new_capacity) { | 340 void Pickle::Resize(size_t new_capacity) { |
| 326 CHECK_NE(capacity_after_header_, kCapacityReadOnly); | 341 CHECK_NE(capacity_after_header_, kCapacityReadOnly); |
| 327 capacity_after_header_ = bits::Align(new_capacity, kPayloadUnit); | 342 capacity_after_header_ = bits::Align(new_capacity, kPayloadUnit); |
| 328 void* p = realloc(header_, GetTotalAllocatedSize()); | 343 void* p = realloc(header_, GetTotalAllocatedSize()); |
| 329 CHECK(p); | 344 CHECK(p); |
| 330 header_ = reinterpret_cast<Header*>(p); | 345 header_ = reinterpret_cast<Header*>(p); |
| 331 } | 346 } |
| 332 | 347 |
| 333 void* Pickle::ClaimBytes(size_t num_bytes) { | 348 void* Pickle::ClaimBytes(size_t num_bytes) { |
| 334 void* p = ClaimUninitializedBytesInternal(num_bytes); | 349 void* p = ClaimUninitializedBytesInternal(num_bytes); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 434 |
| 420 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { | 435 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { |
| 421 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) | 436 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) |
| 422 << "oops: pickle is readonly"; | 437 << "oops: pickle is readonly"; |
| 423 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); | 438 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); |
| 424 void* write = ClaimUninitializedBytesInternal(length); | 439 void* write = ClaimUninitializedBytesInternal(length); |
| 425 memcpy(write, data, length); | 440 memcpy(write, data, length); |
| 426 } | 441 } |
| 427 | 442 |
| 428 } // namespace base | 443 } // namespace base |
| OLD | NEW |