From e413634d5d3de0e098d11b65dfe477f4ac8e60f6 Mon Sep 17 00:00:00 2001 From: Joseph Griego Date: Mon, 17 Dec 2018 15:57:28 -0800 Subject: [PATCH] Various and sundry intish casts in ext_array Summary: Most of these are calls to toArray that I didn't audit before Reviewed By: mxw Differential Revision: D13494203 fbshipit-source-id: 0188ec0432b0d78fb6c155bc47822d0be47bbae4 --- hphp/runtime/ext/array/ext_array.cpp | 21 ++++++++++++++------- hphp/runtime/ext/array/ext_array.h | 8 +++++--- .../slow/hack_arr_compat/array_change_key_case.php | 7 +++++++ .../array_change_key_case.php.expect | 8 ++++++++ .../array_change_key_case.php.hphp_opts | 2 ++ .../hack_arr_compat/array_change_key_case.php.opts | 2 ++ hphp/test/slow/hack_arr_compat/array_column_map.php | 6 ++++++ .../hack_arr_compat/array_column_map.php.expect | 4 ++++ .../hack_arr_compat/array_column_map.php.hphp_opts | 3 +++ .../slow/hack_arr_compat/array_column_map.php.opts | 3 +++ .../slow/hack_arr_compat/array_count_values.php | 6 ++++++ .../hack_arr_compat/array_count_values.php.expect | 4 ++++ .../array_count_values.php.hphp_opts | 2 ++ .../hack_arr_compat/array_count_values.php.opts | 2 ++ .../slow/hack_arr_compat/array_diff_empty_opt.php | 7 +++++++ .../hack_arr_compat/array_diff_empty_opt.php.expect | 8 ++++++++ .../array_diff_empty_opt.php.hphp_opts | 2 ++ .../hack_arr_compat/array_diff_empty_opt.php.opts | 2 ++ .../slow/hack_arr_compat/array_merge_recursive.php | 9 +++++++++ .../array_merge_recursive.php.expect | 12 ++++++++++++ .../array_merge_recursive.php.hphp_opts | 2 ++ .../hack_arr_compat/array_merge_recursive.php.opts | 2 ++ .../hack_arr_compat/array_replace_recursive.php | 9 +++++++++ .../array_replace_recursive.php.expect | 7 +++++++ .../array_replace_recursive.php.hphp_opts | 2 ++ .../array_replace_recursive.php.opts | 2 ++ hphp/test/slow/hack_arr_compat/array_unshift.php | 9 +++++++++ .../slow/hack_arr_compat/array_unshift.php.expect | 7 +++++++ .../hack_arr_compat/array_unshift.php.hphp_opts | 2 ++ .../slow/hack_arr_compat/array_unshift.php.opts | 2 ++ 30 files changed, 152 insertions(+), 10 deletions(-) create mode 100644 hphp/test/slow/hack_arr_compat/array_change_key_case.php create mode 100644 hphp/test/slow/hack_arr_compat/array_change_key_case.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/array_change_key_case.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/array_change_key_case.php.opts create mode 100644 hphp/test/slow/hack_arr_compat/array_column_map.php create mode 100644 hphp/test/slow/hack_arr_compat/array_column_map.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/array_column_map.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/array_column_map.php.opts create mode 100644 hphp/test/slow/hack_arr_compat/array_count_values.php create mode 100644 hphp/test/slow/hack_arr_compat/array_count_values.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/array_count_values.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/array_count_values.php.opts create mode 100644 hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php create mode 100644 hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.opts create mode 100644 hphp/test/slow/hack_arr_compat/array_merge_recursive.php create mode 100644 hphp/test/slow/hack_arr_compat/array_merge_recursive.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/array_merge_recursive.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/array_merge_recursive.php.opts create mode 100644 hphp/test/slow/hack_arr_compat/array_replace_recursive.php create mode 100644 hphp/test/slow/hack_arr_compat/array_replace_recursive.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/array_replace_recursive.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/array_replace_recursive.php.opts create mode 100644 hphp/test/slow/hack_arr_compat/array_unshift.php create mode 100644 hphp/test/slow/hack_arr_compat/array_unshift.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/array_unshift.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/array_unshift.php.opts diff --git a/hphp/runtime/ext/array/ext_array.cpp b/hphp/runtime/ext/array/ext_array.cpp index 14900f22191..4bdeb522594 100644 --- a/hphp/runtime/ext/array/ext_array.cpp +++ b/hphp/runtime/ext/array/ext_array.cpp @@ -141,7 +141,7 @@ TypedValue HHVM_FUNCTION(array_column, for (ArrayIter it(arr_input); it; ++it) { Array sub; if (UNLIKELY(RuntimeOption::PHP7_Builtins && it.second().isObject())) { - sub = it.second().toObject().toArray(); + sub = it.second().toObject().get()->toArray(); } else if (it.second().isArray()) { sub = it.second().toArray(); } else { @@ -222,7 +222,9 @@ TypedValue HHVM_FUNCTION(array_count_values, ? input.asCArrRef() // If this isn't exactly an Array, then it must be a hack collection, // so it is safe to get the object data - : collections::toArray(input.getObjectData()))); + : collections::toArray( + input.getObjectData() + ))); } TypedValue HHVM_FUNCTION(array_fill_keys, @@ -468,11 +470,14 @@ static void php_array_merge_recursive(PointerSet &seen, bool check, } else if (arr1.exists(key, true)) { // There is no need to do toKey() conversion, for a key that is already // in the array. - auto const lval = arr1.lvalAt(key, AccessFlags::Key); - auto subarr1 = tvCastToArrayLike(lval.tv()).toPHPArray(); + auto const arrkey = + arr1.convertKey(*key.asTypedValue()); + auto const lval = arr1.lvalAt(arrkey, AccessFlags::Key); + auto subarr1 = tvCastToArrayLike(lval.tv()) + .toPHPArray(); php_array_merge_recursive( seen, couldRecur(lval, subarr1.get()), subarr1, - tvCastToArrayLike(iter.secondVal()) + tvCastToArrayLike(iter.secondVal()) ); tvUnset(lval); // avoid contamination of the value that was strongly bound tvSet(make_tv(subarr1.get()), lval); @@ -662,7 +667,9 @@ static void php_array_replace_recursive(PointerSet &seen, bool check, if (arr1.exists(key, true) && isArrayLikeType(rval.type())) { auto const lval = arr1.lvalAt(key, AccessFlags::Key); if (isArrayLikeType(lval.unboxed().type())) { - Array subarr1 = tvCastToArrayLike(lval.tv()).toPHPArray(); + Array subarr1 = tvCastToArrayLike( + lval.tv() + ).toPHPArrayIntishCast(); php_array_replace_recursive(seen, couldRecur(lval, subarr1.get()), subarr1, ArrNR(rval.val().parr)); tvSet(make_tv(subarr1.get()), lval); @@ -1871,7 +1878,7 @@ static void containerKeysToSetHelper(const req::ptr& st, if (isArrayLikeType(c1.m_type)) { \ return tvReturn(container1); \ } else { \ - return tvReturn(container1.toArray()); \ + return tvReturn(container1.toArray()); \ } \ } \ Array ret = Array::Create(); diff --git a/hphp/runtime/ext/array/ext_array.h b/hphp/runtime/ext/array/ext_array.h index 2a38a4e38ad..8b968e33c67 100644 --- a/hphp/runtime/ext/array/ext_array.h +++ b/hphp/runtime/ext/array/ext_array.h @@ -291,9 +291,11 @@ inline int64_t countHelper(TypedValue tv) { return make_tv(); \ } \ Variant var_##input(input); \ - tvCastToArrayInPlace(var_##input.asTypedValue()); \ - assertx(var_##input.isArray()); \ - auto arr_##input = var_##input.toArray(); + tvCastToArrayInPlace( \ + var_##input.asTypedValue() \ + ); \ + assertx(var_##input.isArray()); \ + auto arr_##input = var_##input.toArray(); #define getCheckedArray(input) \ getCheckedArrayRet(input, make_tv()) diff --git a/hphp/test/slow/hack_arr_compat/array_change_key_case.php b/hphp/test/slow/hack_arr_compat/array_change_key_case.php new file mode 100644 index 00000000000..c147c07955e --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_change_key_case.php @@ -0,0 +1,7 @@ +> +function main() { + var_dump(array_change_key_case(Map{"1" => 42})); + var_dump(array_change_key_case(dict["1" => 42])); +} diff --git a/hphp/test/slow/hack_arr_compat/array_change_key_case.php.expect b/hphp/test/slow/hack_arr_compat/array_change_key_case.php.expect new file mode 100644 index 00000000000..f34c866d623 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_change_key_case.php.expect @@ -0,0 +1,8 @@ +array(1) { + [1]=> + int(42) +} +array(1) { + [1]=> + int(42) +} diff --git a/hphp/test/slow/hack_arr_compat/array_change_key_case.php.hphp_opts b/hphp/test/slow/hack_arr_compat/array_change_key_case.php.hphp_opts new file mode 100644 index 00000000000..8e9f46ff387 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_change_key_case.php.hphp_opts @@ -0,0 +1,2 @@ +-vRuntime.Eval.HackArrCompatNotices=1 +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_change_key_case.php.opts b/hphp/test/slow/hack_arr_compat/array_change_key_case.php.opts new file mode 100644 index 00000000000..9fb11cee416 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_change_key_case.php.opts @@ -0,0 +1,2 @@ +-vEval.HackArrCompatNotices=1 +-vEval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_column_map.php b/hphp/test/slow/hack_arr_compat/array_column_map.php new file mode 100644 index 00000000000..92ddcb75a0e --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_column_map.php @@ -0,0 +1,6 @@ +> +function main() { + var_dump(array_column(Vector{Map{"1" => 42}}, 1)); +} diff --git a/hphp/test/slow/hack_arr_compat/array_column_map.php.expect b/hphp/test/slow/hack_arr_compat/array_column_map.php.expect new file mode 100644 index 00000000000..3b96657cb56 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_column_map.php.expect @@ -0,0 +1,4 @@ +array(1) { + [0]=> + int(42) +} diff --git a/hphp/test/slow/hack_arr_compat/array_column_map.php.hphp_opts b/hphp/test/slow/hack_arr_compat/array_column_map.php.hphp_opts new file mode 100644 index 00000000000..64388fdd065 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_column_map.php.hphp_opts @@ -0,0 +1,3 @@ +-vRuntime.Eval.HackArrCompatNotices=1 +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 +-dhhvm.php7.all=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_column_map.php.opts b/hphp/test/slow/hack_arr_compat/array_column_map.php.opts new file mode 100644 index 00000000000..f70aae3585f --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_column_map.php.opts @@ -0,0 +1,3 @@ +-vEval.HackArrCompatNotices=1 +-vEval.HackArrCompatCheckIntishCast=1 +-dhhvm.php7.all=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_count_values.php b/hphp/test/slow/hack_arr_compat/array_count_values.php new file mode 100644 index 00000000000..3bc8a1f67a3 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_count_values.php @@ -0,0 +1,6 @@ +> +function main() { + var_dump(array_count_values(Map{"1" => 42})); +} diff --git a/hphp/test/slow/hack_arr_compat/array_count_values.php.expect b/hphp/test/slow/hack_arr_compat/array_count_values.php.expect new file mode 100644 index 00000000000..257318eb20a --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_count_values.php.expect @@ -0,0 +1,4 @@ +array(1) { + [42]=> + int(1) +} diff --git a/hphp/test/slow/hack_arr_compat/array_count_values.php.hphp_opts b/hphp/test/slow/hack_arr_compat/array_count_values.php.hphp_opts new file mode 100644 index 00000000000..8e9f46ff387 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_count_values.php.hphp_opts @@ -0,0 +1,2 @@ +-vRuntime.Eval.HackArrCompatNotices=1 +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_count_values.php.opts b/hphp/test/slow/hack_arr_compat/array_count_values.php.opts new file mode 100644 index 00000000000..9fb11cee416 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_count_values.php.opts @@ -0,0 +1,2 @@ +-vEval.HackArrCompatNotices=1 +-vEval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php new file mode 100644 index 00000000000..2f7ee8cefa3 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php @@ -0,0 +1,7 @@ +> +function main() { + var_dump(array_diff(Map{"1" => 42}, dict[])); + var_dump(array_diff_key(Map{"1" => 42}, dict[])); +} diff --git a/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.expect b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.expect new file mode 100644 index 00000000000..f34c866d623 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.expect @@ -0,0 +1,8 @@ +array(1) { + [1]=> + int(42) +} +array(1) { + [1]=> + int(42) +} diff --git a/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.hphp_opts b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.hphp_opts new file mode 100644 index 00000000000..8e9f46ff387 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.hphp_opts @@ -0,0 +1,2 @@ +-vRuntime.Eval.HackArrCompatNotices=1 +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.opts b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.opts new file mode 100644 index 00000000000..9fb11cee416 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_diff_empty_opt.php.opts @@ -0,0 +1,2 @@ +-vEval.HackArrCompatNotices=1 +-vEval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_merge_recursive.php b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php new file mode 100644 index 00000000000..2964b87156b --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php @@ -0,0 +1,9 @@ +> +function main() { + var_dump(array_merge_recursive( + dict[ "1" => Map{ "1" => 42 }], + dict[ "1" => Map{ "1" => 42 }] + )); +} diff --git a/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.expect b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.expect new file mode 100644 index 00000000000..e23627203ce --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.expect @@ -0,0 +1,12 @@ +array(2) { + ["1"]=> + object(HH\Map)#1 (1) { + ["1"]=> + int(42) + } + [1]=> + array(1) { + [0]=> + int(42) + } +} diff --git a/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.hphp_opts b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.hphp_opts new file mode 100644 index 00000000000..8e9f46ff387 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.hphp_opts @@ -0,0 +1,2 @@ +-vRuntime.Eval.HackArrCompatNotices=1 +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.opts b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.opts new file mode 100644 index 00000000000..9fb11cee416 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_merge_recursive.php.opts @@ -0,0 +1,2 @@ +-vEval.HackArrCompatNotices=1 +-vEval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_replace_recursive.php b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php new file mode 100644 index 00000000000..cfff7115b04 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php @@ -0,0 +1,9 @@ +> +function main() { + var_dump(array_replace_recursive( + dict["1" => dict[ "1" => 42]], + dict["1" => dict[ "1" => 3]] + )); +} diff --git a/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.expect b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.expect new file mode 100644 index 00000000000..042399010f1 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.expect @@ -0,0 +1,7 @@ +array(1) { + [1]=> + array(1) { + [1]=> + int(3) + } +} diff --git a/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.hphp_opts b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.hphp_opts new file mode 100644 index 00000000000..8e9f46ff387 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.hphp_opts @@ -0,0 +1,2 @@ +-vRuntime.Eval.HackArrCompatNotices=1 +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.opts b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.opts new file mode 100644 index 00000000000..9fb11cee416 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_replace_recursive.php.opts @@ -0,0 +1,2 @@ +-vEval.HackArrCompatNotices=1 +-vEval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_unshift.php b/hphp/test/slow/hack_arr_compat/array_unshift.php new file mode 100644 index 00000000000..403c9a76c27 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_unshift.php @@ -0,0 +1,9 @@ +> +function main() { + $a = dict["1" => 42]; + var_dump(array_unshift(&$a, 2)); + var_dump($a); +} diff --git a/hphp/test/slow/hack_arr_compat/array_unshift.php.expect b/hphp/test/slow/hack_arr_compat/array_unshift.php.expect new file mode 100644 index 00000000000..4f533c3af40 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_unshift.php.expect @@ -0,0 +1,7 @@ +int(2) +dict(2) { + [0]=> + int(2) + ["1"]=> + int(42) +} diff --git a/hphp/test/slow/hack_arr_compat/array_unshift.php.hphp_opts b/hphp/test/slow/hack_arr_compat/array_unshift.php.hphp_opts new file mode 100644 index 00000000000..8e9f46ff387 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_unshift.php.hphp_opts @@ -0,0 +1,2 @@ +-vRuntime.Eval.HackArrCompatNotices=1 +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 \ No newline at end of file diff --git a/hphp/test/slow/hack_arr_compat/array_unshift.php.opts b/hphp/test/slow/hack_arr_compat/array_unshift.php.opts new file mode 100644 index 00000000000..9fb11cee416 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/array_unshift.php.opts @@ -0,0 +1,2 @@ +-vEval.HackArrCompatNotices=1 +-vEval.HackArrCompatCheckIntishCast=1 \ No newline at end of file -- 2.11.4.GIT