From 333f0a76f4ef94ec6d1afcb4d82cf4a3438dcc1b Mon Sep 17 00:00:00 2001 From: Sean Cannella Date: Tue, 11 Jun 2013 13:53:32 -0700 Subject: [PATCH] Fix a zend compat issue in array_slice - Fix the behavior of array_slice when using PHP_INT_MAX --- hphp/runtime/base/array/array_util.cpp | 4 ++-- hphp/runtime/base/array/array_util.h | 6 +++--- hphp/test/slow/max_int/array_slice.php | 3 +++ hphp/test/slow/max_int/array_slice.php.expect | 8 ++++++++ hphp/test/slow/max_int/array_splice.php | 3 +++ hphp/test/slow/max_int/array_splice.php.expect | 8 ++++++++ .../ext-standard-array/array_slice_variation3.php | 4 ++-- .../ext-standard-array/array_slice_variation3.php.expectf | 0 8 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 hphp/test/slow/max_int/array_slice.php create mode 100644 hphp/test/slow/max_int/array_slice.php.expect create mode 100644 hphp/test/slow/max_int/array_splice.php create mode 100644 hphp/test/slow/max_int/array_splice.php.expect rename hphp/test/zend/{bad => good}/ext-standard-array/array_slice_variation3.php (95%) rename hphp/test/zend/{bad => good}/ext-standard-array/array_slice_variation3.php.expectf (100%) diff --git a/hphp/runtime/base/array/array_util.cpp b/hphp/runtime/base/array/array_util.cpp index 8e827a606..a1abd81a5 100644 --- a/hphp/runtime/base/array/array_util.cpp +++ b/hphp/runtime/base/array/array_util.cpp @@ -94,7 +94,7 @@ Variant ArrayUtil::Chunk(CArrRef input, int size, return ret; } -Variant ArrayUtil::Slice(CArrRef input, int offset, int length, +Variant ArrayUtil::Slice(CArrRef input, int offset, int64_t length, bool preserve_keys) { int num_in = input.size(); if (offset > num_in) { @@ -126,7 +126,7 @@ Variant ArrayUtil::Slice(CArrRef input, int offset, int length, return out_hash; } -Variant ArrayUtil::Splice(CArrRef input, int offset, int length /* = 0 */, +Variant ArrayUtil::Splice(CArrRef input, int offset, int64_t length /* = 0 */, CVarRef replacement /* = null_variant */, Array *removed /* = NULL */) { int num_in = input.size(); diff --git a/hphp/runtime/base/array/array_util.h b/hphp/runtime/base/array/array_util.h index 5ff6620dd..f1cab6cbe 100644 --- a/hphp/runtime/base/array/array_util.h +++ b/hphp/runtime/base/array/array_util.h @@ -59,14 +59,14 @@ public: * into numerically keyed map. When "preserve_keys" is false, a map will * turn into vectors, unless keys are not numeric. */ - static Variant Slice(CArrRef input, int offset, int length, + static Variant Slice(CArrRef input, int offset, int64_t length, bool preserve_keys); /** * Removes the elements designated by offset and length and replace them * with supplied array. */ - static Variant Splice(CArrRef input, int offset, int length = 0, + static Variant Splice(CArrRef input, int offset, int64_t length = 0, CVarRef replacement = null_variant, Array *removed = nullptr); @@ -111,7 +111,7 @@ public: /** * Returns input as a numerically indexed array starting from zero - * with no gaps. Is optimized for the case where input is already + * with no gaps. Is optimized for the case where input is already * correct. Assumes input is not null. */ static Array EnsureIntKeys(CArrRef input); diff --git a/hphp/test/slow/max_int/array_slice.php b/hphp/test/slow/max_int/array_slice.php new file mode 100644 index 000000000..3aa212ee0 --- /dev/null +++ b/hphp/test/slow/max_int/array_slice.php @@ -0,0 +1,3 @@ + + int(1) + [1]=> + int(2) + [2]=> + int(3) +} diff --git a/hphp/test/slow/max_int/array_splice.php b/hphp/test/slow/max_int/array_splice.php new file mode 100644 index 000000000..129459974 --- /dev/null +++ b/hphp/test/slow/max_int/array_splice.php @@ -0,0 +1,3 @@ + + int(1) + [1]=> + int(2) + [2]=> + int(3) +} diff --git a/hphp/test/zend/bad/ext-standard-array/array_slice_variation3.php b/hphp/test/zend/good/ext-standard-array/array_slice_variation3.php similarity index 95% rename from hphp/test/zend/bad/ext-standard-array/array_slice_variation3.php rename to hphp/test/zend/good/ext-standard-array/array_slice_variation3.php index e4df3377c..64f5e6bb0 100644 --- a/hphp/test/zend/bad/ext-standard-array/array_slice_variation3.php +++ b/hphp/test/zend/good/ext-standard-array/array_slice_variation3.php @@ -1,6 +1,6 @@