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

Side by Side Diff: mojo/public/cpp/bindings/lib/fixed_buffer.cc

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
6
7 #include <stdlib.h>
8
9 #include <algorithm>
10
11 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
12 #include "mojo/public/cpp/environment/logging.h"
13
14 namespace mojo {
15 namespace internal {
16
17 FixedBuffer::FixedBuffer(size_t size)
18 : ptr_(nullptr), cursor_(0), size_(internal::Align(size)) {
19 // calloc() required to zero memory and thus avoid info leaks.
20 ptr_ = static_cast<char*>(calloc(size_, 1));
21 }
22
23 FixedBuffer::~FixedBuffer() {
24 free(ptr_);
25 }
26
27 void* FixedBuffer::Allocate(size_t delta) {
28 delta = internal::Align(delta);
29
30 if (delta == 0 || delta > size_ - cursor_) {
31 MOJO_DCHECK(false) << "Not reached";
32 return nullptr;
33 }
34
35 char* result = ptr_ + cursor_;
36 cursor_ += delta;
37
38 return result;
39 }
40
41 void* FixedBuffer::Leak() {
42 char* ptr = ptr_;
43 ptr_ = nullptr;
44 cursor_ = 0;
45 size_ = 0;
46 return ptr;
47 }
48
49 } // namespace internal
50 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/fixed_buffer.h ('k') | mojo/public/cpp/bindings/lib/interface_ptr_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698