From c342cb0c50303ab01a969f34129074cf533b4e6a Mon Sep 17 00:00:00 2001 From: Kevin Viratyosin Date: Wed, 26 Sep 2018 16:24:33 -0700 Subject: [PATCH] Avoid lval notice in ExecutionContext::registerShutdownFunction Summary: This diff avoids the `Lval on missing array element` notice that would result from `register_shutdown_function`. for hhvm-cmake: Reviewed By: billf Differential Revision: D9815993 fbshipit-source-id: 7301f54668847f19e5b547c6fe101083e832ae3a --- hphp/runtime/base/execution-context.cpp | 16 +++++++++++----- .../register_shutdown_function_lval_on_missing_key.php | 13 +++++++++++++ ...ster_shutdown_function_lval_on_missing_key.php.expect | 2 ++ ...r_shutdown_function_lval_on_missing_key.php.hphp_opts | 1 + ...gister_shutdown_function_lval_on_missing_key.php.opts | 2 ++ ...ister_shutdown_function_lval_on_missing_key_dvarr.php | 13 +++++++++++++ ...hutdown_function_lval_on_missing_key_dvarr.php.expect | 2 ++ ...down_function_lval_on_missing_key_dvarr.php.hphp_opts | 2 ++ ..._shutdown_function_lval_on_missing_key_dvarr.php.opts | 3 +++ 9 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key.php create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key.php.opts create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key_dvarr.php create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key_dvarr.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key_dvarr.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key_dvarr.php.opts diff --git a/hphp/runtime/base/execution-context.cpp b/hphp/runtime/base/execution-context.cpp index ae04431a903..24601505b78 100644 --- a/hphp/runtime/base/execution-context.cpp +++ b/hphp/runtime/base/execution-context.cpp @@ -115,6 +115,9 @@ ExecutionContext::ExecutionContext() VariableSerializer::serializationSizeLimit = RuntimeOption::SerializationSizeLimit; tvWriteUninit(m_headerCallback); + + m_shutdowns = Array::CreateDArray(); + m_shutdownsBackup = Array::CreateDArray(); } // See header for why this is required. @@ -539,15 +542,18 @@ void ExecutionContext::registerShutdownFunction(const Variant& function, Array arguments, ShutdownType type) { Array callback = make_map_array(s_name, function, s_args, arguments); + if (!m_shutdowns.exists(type)) { + m_shutdowns.set(type, Array::CreateVArray()); + } auto const funcs = m_shutdowns.lvalAt(type); - forceToArray(funcs).append(callback); + forceToDArray(funcs).append(callback); } bool ExecutionContext::removeShutdownFunction(const Variant& function, ShutdownType type) { bool ret = false; - auto& funcs = forceToArray(m_shutdowns.lvalAt(type)); - PackedArrayInit newFuncs(funcs.size()); + auto& funcs = forceToDArray(m_shutdowns.lvalAt(type)); + VArrayInit newFuncs(funcs.size()); for (ArrayIter iter(funcs); iter; ++iter) { if (!same(iter.second().toArray()[s_name], function)) { @@ -561,7 +567,7 @@ bool ExecutionContext::removeShutdownFunction(const Variant& function, } bool ExecutionContext::hasShutdownFunctions(ShutdownType type) { - return !m_shutdowns.isNull() && m_shutdowns.exists(type) && + return m_shutdowns.exists(type) && m_shutdowns[type].toArray().size() >= 1; } @@ -656,7 +662,7 @@ void ExecutionContext::executeFunctions(ShutdownType type) { RID().resetTimer(RuntimeOption::PspTimeoutSeconds); RID().resetCPUTimer(RuntimeOption::PspCpuTimeoutSeconds); - if (!m_shutdowns.isNull() && m_shutdowns.exists(type)) { + if (m_shutdowns.exists(type)) { SCOPE_EXIT { try { m_shutdowns.remove(type); } catch (...) {} }; diff --git a/hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key.php b/hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key.php new file mode 100644 index 00000000000..770338cf5e9 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/register_shutdown_function_lval_on_missing_key.php @@ -0,0 +1,13 @@ +