| 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/bindings/lib/buffer.h" | 5 #include "mojo/public/bindings/lib/buffer.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "mojo/public/bindings/lib/bindings_serialization.h" | 13 #include "mojo/public/bindings/lib/bindings_serialization.h" |
| 14 #include "mojo/public/bindings/lib/bindings_support.h" | 14 #include "mojo/public/environment/buffer_tls.h" |
| 15 | 15 |
| 16 // Scrub memory in debug builds to help catch use-after-free bugs. | 16 // Scrub memory in debug builds to help catch use-after-free bugs. |
| 17 #ifdef NDEBUG | 17 #ifdef NDEBUG |
| 18 #define DEBUG_SCRUB(address, size) (void) (address), (void) (size) | 18 #define DEBUG_SCRUB(address, size) (void) (address), (void) (size) |
| 19 #else | 19 #else |
| 20 #define DEBUG_SCRUB(address, size) memset(address, 0xCD, size) | 20 #define DEBUG_SCRUB(address, size) memset(address, 0xCD, size) |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 namespace mojo { | 23 namespace mojo { |
| 24 | 24 |
| 25 //----------------------------------------------------------------------------- | 25 //----------------------------------------------------------------------------- |
| 26 | 26 |
| 27 Buffer::Buffer() { | 27 Buffer::Buffer() { |
| 28 previous_ = BindingsSupport::Get()->SetCurrentBuffer(this); | 28 previous_ = internal::SetCurrentBuffer(this); |
| 29 } | 29 } |
| 30 | 30 |
| 31 Buffer::~Buffer() { | 31 Buffer::~Buffer() { |
| 32 Buffer* buf MOJO_ALLOW_UNUSED = | 32 Buffer* buf MOJO_ALLOW_UNUSED = internal::SetCurrentBuffer(previous_); |
| 33 BindingsSupport::Get()->SetCurrentBuffer(previous_); | |
| 34 assert(buf == this); | 33 assert(buf == this); |
| 35 } | 34 } |
| 36 | 35 |
| 37 Buffer* Buffer::current() { | 36 Buffer* Buffer::current() { |
| 38 return BindingsSupport::Get()->GetCurrentBuffer(); | 37 return internal::GetCurrentBuffer(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 //----------------------------------------------------------------------------- | 40 //----------------------------------------------------------------------------- |
| 42 | 41 |
| 43 namespace internal { | 42 namespace internal { |
| 44 | 43 |
| 45 ScratchBuffer::ScratchBuffer() | 44 ScratchBuffer::ScratchBuffer() |
| 46 : overflow_(NULL) { | 45 : overflow_(NULL) { |
| 47 fixed_.next = NULL; | 46 fixed_.next = NULL; |
| 48 fixed_.cursor = fixed_data_; | 47 fixed_.cursor = fixed_data_; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 void* FixedBuffer::Leak() { | 146 void* FixedBuffer::Leak() { |
| 148 char* ptr = ptr_; | 147 char* ptr = ptr_; |
| 149 ptr_ = NULL; | 148 ptr_ = NULL; |
| 150 cursor_ = 0; | 149 cursor_ = 0; |
| 151 size_ = 0; | 150 size_ = 0; |
| 152 return ptr; | 151 return ptr; |
| 153 } | 152 } |
| 154 | 153 |
| 155 } // namespace internal | 154 } // namespace internal |
| 156 } // namespace mojo | 155 } // namespace mojo |
| OLD | NEW |