summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2015-08-21 12:48:10 -0700
committerFedor Indutny <fedor@indutny.com>2015-08-21 14:12:49 -0700
commit43660ad37b7f3fffee65805f652ad4735f6e77cf (patch)
tree1bd4d0fcd9c5b78510f61b6ac93f20ad1c7221b0 /lib
parent68e53ddcbad4ce4a2f44362411b6960c716b7e3e (diff)
downloadandroid-node-v8-43660ad37b7f3fffee65805f652ad4735f6e77cf.tar.gz
android-node-v8-43660ad37b7f3fffee65805f652ad4735f6e77cf.tar.bz2
android-node-v8-43660ad37b7f3fffee65805f652ad4735f6e77cf.zip
buffer: reapply 07c0667
Original commit message: buffer: align chunks on 8-byte boundary When slicing global pool - ensure that the underlying buffer's data ptr is 8-byte alignment to do not ruin expectations of 3rd party C++ addons. NOTE: 0.10 node.js always returned aligned pointers and io.js should do this too for compatibility. PR-URL: https://github.com/nodejs/node/pull/2487 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index 403c344bdb..4166724b73 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -21,6 +21,15 @@ function createPool() {
}
+function alignPool() {
+ // Ensure aligned slices
+ if (poolOffset & 0x7) {
+ poolOffset |= 0x7;
+ poolOffset++;
+ }
+}
+
+
function Buffer(arg) {
// Common case.
if (typeof arg === 'number') {
@@ -66,6 +75,7 @@ function allocate(size) {
createPool();
var b = binding.slice(allocPool, poolOffset, poolOffset + size);
poolOffset += size;
+ alignPool();
return b;
} else {
return binding.create(size);
@@ -86,6 +96,7 @@ function fromString(string, encoding) {
var actual = allocPool.write(string, poolOffset, encoding);
var b = binding.slice(allocPool, poolOffset, poolOffset + actual);
poolOffset += actual;
+ alignPool();
return b;
}