From 3873385fa60d21fe075fcdfae612e97ba81ea29d Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Fri, 6 Jul 2018 15:22:10 -0700 Subject: [PATCH] Don't assert on new Closure Summary: We're about to fatal anyway. Reviewed By: ricklavoie Differential Revision: D8723974 fbshipit-source-id: 94def4f2ce21e4660af2426f0c61734be0037a58 --- hphp/runtime/ext/std/ext_std_closure.cpp | 2 +- hphp/runtime/ext/std/ext_std_closure.h | 4 ++++ hphp/test/slow/closure/new_closure.php | 5 +++++ hphp/test/slow/closure/new_closure.php.expectf | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 hphp/test/slow/closure/new_closure.php create mode 100644 hphp/test/slow/closure/new_closure.php.expectf diff --git a/hphp/runtime/ext/std/ext_std_closure.cpp b/hphp/runtime/ext/std/ext_std_closure.cpp index 02806b33c1b..412ecbe11f4 100644 --- a/hphp/runtime/ext/std/ext_std_closure.cpp +++ b/hphp/runtime/ext/std/ext_std_closure.cpp @@ -293,7 +293,7 @@ static Variant HHVM_METHOD(Closure, call, static ObjectData* closureInstanceCtorRepoAuth(Class* cls) { assertx(!(cls->attrs() & (AttrAbstract|AttrInterface|AttrTrait|AttrEnum))); assertx(!cls->needInitialization()); - assertx(cls->parent() == c_Closure::classof()); + assertx(cls->parent() == c_Closure::classof() || cls == c_Closure::classof()); // ensure c_Closure and ClosureHdr ptrs are scanned inside other types (void)type_scan::getIndexForMalloc(); (void)type_scan::getIndexForMalloc(); diff --git a/hphp/runtime/ext/std/ext_std_closure.h b/hphp/runtime/ext/std/ext_std_closure.h index 2e0d47d4bec..598c68ff56b 100644 --- a/hphp/runtime/ext/std/ext_std_closure.h +++ b/hphp/runtime/ext/std/ext_std_closure.h @@ -34,6 +34,10 @@ extern const StaticString s_Closure; struct ClosureHdr : HeapObject { explicit ClosureHdr(uint32_t size) { initHeader_32(HeaderKind::ClosureHdr, size); + // we need to set this here, because the next thing 'new Closure' + // will do is call the constructor, which will throw, and the + // destructor will examine this field. + ctx_bits = 0; } uint32_t& size() { return m_aux32; } uint32_t size() const { return m_aux32; } diff --git a/hphp/test/slow/closure/new_closure.php b/hphp/test/slow/closure/new_closure.php new file mode 100644 index 00000000000..a85efc0d792 --- /dev/null +++ b/hphp/test/slow/closure/new_closure.php @@ -0,0 +1,5 @@ +