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

Side by Side Diff: mojo/public/c/bindings/lib/buffer.c

Issue 2062323002: Mojo C bindings library pt1: MojomBuffer (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 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 2016 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/c/bindings/buffer.h"
6
7 #include <assert.h>
8 #include <stddef.h> // for NULL
9
10 void* MojomBuffer_Allocate(struct MojomBuffer* buf, size_t num_bytes) {
11 assert(buf);
12
13 static const size_t kAlignment = 8;
14 const size_t bytes_used = buf->num_bytes_used;
15 // size = num_bytes aligned to 8 bytes:
16 const size_t size = (num_bytes + (kAlignment-1)) & ~(kAlignment-1);
viettrungluu 2016/06/15 15:00:58 Note that this will lead to sadness if num_bytes i
vardhan 2016/06/15 15:48:00 oof. i think its better to make it a uint32_t rat
17 if (bytes_used + size > buf->buf_size || bytes_used + size <= bytes_used)
viettrungluu 2016/06/15 15:00:57 nit: <= -> <. There's no reason to not allow "allo
vardhan 2016/06/15 15:48:00 Allocations of 0 seem like a programmatic error --
viettrungluu 2016/06/15 15:59:49 It's not necessarily a programmatic error for case
vardhan 2016/06/15 16:10:21 Done.
18 return NULL;
19
20 buf->num_bytes_used += size;
21 return buf->buf + bytes_used;
22 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698