From: Feross Aboukhadijeh Date: Tue, 30 Jun 2015 23:20:18 +0000 (-0700) Subject: Increase max buffer size to 2GB X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=77fed38184d770ef343a81637a28a11c158f5d00;p=buffer.git Increase max buffer size to 2GB There's no reason to match the limitation in node, plus this limitation is going away soon with the buffer refactor for V8 4.4. --- diff --git a/bin/download-node-tests.js b/bin/download-node-tests.js index 883ab98..da100d1 100755 --- a/bin/download-node-tests.js +++ b/bin/download-node-tests.js @@ -78,7 +78,10 @@ function testfixer (filename) { line = line.replace(/(.*)require\('buffer'\)(.*)/, '$1require(\'../../\')$2') // smalloc is only used for kMaxLength - line = line.replace(/require\('smalloc'\)/, '{ kMaxLength: 0x3FFFFFFF }') + line = line.replace( + /require\('smalloc'\)/, + '{ kMaxLength: process.env.OBJECT_IMPL ? 0x3fffffff : 0x7fffffff }' + ) // comment out console logs line = line.replace(/(.*console\..*)/, '// $1') diff --git a/index.js b/index.js index fac60da..da0a496 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,6 @@ exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 Buffer.poolSize = 8192 // not used by this implementation -var kMaxLength = 0x3fffffff var rootParent = {} /** @@ -52,6 +51,12 @@ Buffer.TYPED_ARRAY_SUPPORT = (function () { } })() +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} + /** * Class: Buffer * ============= @@ -202,9 +207,9 @@ function allocate (that, length) { function checked (length) { // Note: cannot use `length < kMaxLength` here because that fails when // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength) { + if (length >= kMaxLength()) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength.toString(16) + ' bytes') + 'size: 0x' + kMaxLength().toString(16) + ' bytes') } return length | 0 } diff --git a/test/node/test-buffer.js b/test/node/test-buffer.js index 77932a6..551f883 100644 --- a/test/node/test-buffer.js +++ b/test/node/test-buffer.js @@ -6,7 +6,7 @@ var assert = require('assert'); var Buffer = require('../../').Buffer; var SlowBuffer = require('../../').SlowBuffer; -var smalloc = { kMaxLength: 0x3FFFFFFF }; +var smalloc = { kMaxLength: process.env.OBJECT_IMPL ? 0x3fffffff : 0x7fffffff }; // counter to ensure unique value is always copied var cntr = 0;