Permalink
Browse files

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
  • Loading branch information...
Kevin Viratyosin authored and hhvm-bot committed Sep 26, 2018
1 parent 047cb6d commit c342cb0c50303ab01a969f34129074cf533b4e6a
@@ -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 (...) {}
};
@@ -0,0 +1,13 @@
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function foo() {
var_dump('foo');
}
function bar() {
var_dump('bar');
}
register_postsend_function('bar');
register_shutdown_function('foo');
@@ -0,0 +1 @@
-vRuntime.Eval.HackArrCompatNotices=true -d hhvm.php7.all=0
@@ -0,0 +1,2 @@
-vEval.HackArrCompatNotices=true
-vEval.HackArrCompatCheckFalseyPromote=true
@@ -0,0 +1,13 @@
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function foo() {
var_dump('foo');
}
function bar() {
var_dump('bar');
}
register_postsend_function('bar');
register_shutdown_function('foo');
@@ -0,0 +1,2 @@
-vRuntime.Eval.HackArrCompatNotices=true -d hhvm.php7.all=0
-vHackArrDVArrs=1
@@ -0,0 +1,3 @@
-vEval.HackArrCompatNotices=true
-vEval.HackArrCompatCheckFalseyPromote=true
-vEval.HackArrDVArrs=true

0 comments on commit c342cb0

Please sign in to comment.