diff --git a/hphp/compiler/expression/unary_op_expression.cpp b/hphp/compiler/expression/unary_op_expression.cpp index be9d0c601..a11311bf5 100644 --- a/hphp/compiler/expression/unary_op_expression.cpp +++ b/hphp/compiler/expression/unary_op_expression.cpp @@ -256,10 +256,10 @@ bool UnaryOpExpression::preCompute(CVarRef value, Variant &result) { result = toBoolean(value); break; case T_EMPTY: - result = empty(value); + result = !toBoolean(value); break; case T_ISSET: - result = isset(value); + result = is_not_null(value); break; case T_INC: case T_DEC: @@ -335,7 +335,7 @@ ExpressionPtr UnaryOpExpression::preOptimize(AnalysisResultConstPtr ar) { for (; i < n; i++) { ExpressionPtr e((*el)[i]); if (!e || !e->isScalar() || !e->getScalarValue(value)) break; - if (!isset(value)) { + if (value.isNull()) { result = false; } } diff --git a/hphp/runtime/base/builtin-functions.cpp b/hphp/runtime/base/builtin-functions.cpp index a2ec5141f..2d7977d48 100644 --- a/hphp/runtime/base/builtin-functions.cpp +++ b/hphp/runtime/base/builtin-functions.cpp @@ -1057,7 +1057,7 @@ AutoloadHandler::Result AutoloadHandler::loadFromMap(CStrRef name, return Success; } CVarRef &func = m_map.get()->get(s_failure); - if (!isset(func)) return Failure; + if (func.isNull()) return Failure; // can throw, otherwise // - true means the map was updated. try again // - false means we should stop applying autoloaders (only affects classes) diff --git a/hphp/runtime/base/builtin-functions.h b/hphp/runtime/base/builtin-functions.h index 8e380fc75..a7ae1557c 100644 --- a/hphp/runtime/base/builtin-functions.h +++ b/hphp/runtime/base/builtin-functions.h @@ -63,30 +63,6 @@ extern const StaticString s_self; extern const StaticString s_parent; extern const StaticString s_static; -// empty -inline bool empty(CVarRef v) { return !v.toBoolean();} - -bool empty(bool) = delete; -bool empty(char) = delete; -bool empty(short) = delete; -bool empty(int) = delete; -bool empty(int64_t) = delete; -bool empty(double) = delete; -bool empty(litstr) = delete; -bool empty(const StringData*) = delete; -bool empty(CStrRef) = delete; -bool empty(CArrRef) = delete; -bool empty(CObjRef) = delete; - -bool empty(CVarRef v, bool) = delete; -bool empty(CVarRef v, int64_t) = delete; -bool empty(CVarRef v, int) = delete; -bool empty(CVarRef v, double) = delete; -bool empty(CVarRef v, CArrRef) = delete; -bool empty(CVarRef v, CObjRef) = delete; -bool empty(CVarRef v, CVarRef) = delete; -bool empty(CVarRef v, CStrRef, bool = false) = delete; - /////////////////////////////////////////////////////////////////////////////// // operators @@ -113,53 +89,11 @@ void NEVER_INLINE throw_null_get_object_prop(); void NEVER_INLINE raise_null_object_prop(); void throw_exception(CObjRef e); -/////////////////////////////////////////////////////////////////////////////// -// isset/unset - -inline bool isInitialized(CVarRef v) { return v.isInitialized();} - -inline bool isset(CVarRef v) { return !v.isNull(); } - -bool isset(bool v) = delete; -bool isset(char v) = delete; -bool isset(short v) = delete; -bool isset(int v) = delete; -bool isset(int64_t v) = delete; -bool isset(double v) = delete; -bool isset(CObjRef v) = delete; -bool isset(CStrRef v) = delete; -bool isset(CArrRef v) = delete; -bool isset(CVarRef v, bool) = delete; -bool isset(CVarRef v, int64_t) = delete; -bool isset(CVarRef v, int) = delete; -bool isset(CVarRef v, double) = delete; -bool isset(CVarRef v, CArrRef) = delete; -bool isset(CVarRef v, CObjRef) = delete; -bool isset(CVarRef v, CVarRef) = delete; -bool isset(CVarRef v, CStrRef, bool = false) = delete; - -bool isset(CArrRef v, int64_t) = delete; -bool isset(CArrRef v, bool) = delete; -bool isset(CArrRef v, int) = delete; -bool isset(CArrRef v, double) = delete; -bool isset(CArrRef v, CArrRef) = delete; -bool isset(CArrRef v, CObjRef) = delete; -bool isset(CArrRef v, CVarRef) = delete; -bool isset(CArrRef v, CStrRef, bool = false) = delete; - -inline Variant unset(Variant &v) { v.unset(); return uninit_null();} -inline Variant unset(CVarRef v) { return uninit_null();} -inline Variant setNull(Variant &v) { v.setNull(); return uninit_null();} -inline Object setNull(Object &v) { v.reset(); return Object();} -inline Array setNull(Array &v) { v.reset(); return Array();} -inline String setNull(String &v) { v.reset(); return String();} -inline Variant unset(Object &v) { v.reset(); return uninit_null();} -inline Variant unset(Array &v) { v.reset(); return uninit_null();} - /////////////////////////////////////////////////////////////////////////////// // type testing inline bool is_null(CVarRef v) { return v.isNull();} +inline bool is_not_null(CVarRef v) { return !v.isNull();} inline bool is_bool(CVarRef v) { return v.is(KindOfBoolean);} inline bool is_int(CVarRef v) { return v.isInteger();} inline bool is_double(CVarRef v) { return v.is(KindOfDouble);} diff --git a/hphp/runtime/base/execution-context.cpp b/hphp/runtime/base/execution-context.cpp index cb70aa20f..e11d79772 100644 --- a/hphp/runtime/base/execution-context.cpp +++ b/hphp/runtime/base/execution-context.cpp @@ -905,31 +905,5 @@ const ResourceMap &PersistentObjectStore::getMap(const char *type) { return m_objects[type]; } -/////////////////////////////////////////////////////////////////////////////// -// silencer - - -Silencer::Silencer(bool e) : m_active(false) { - if (e) enable(); -} - -void Silencer::enable() { - m_errorReportingValue = g_context->getErrorReportingLevel(); - g_context->setErrorReportingLevel(0); - m_active = true; -} - -void Silencer::disableHelper() { - if (m_active) { - if (g_context->getErrorReportingLevel() == 0) - g_context->setErrorReportingLevel(m_errorReportingValue); - } -} - -Variant Silencer::disable(CVarRef v) { - disable(); - return v; -} - /////////////////////////////////////////////////////////////////////////////// } diff --git a/hphp/runtime/base/execution-context.h b/hphp/runtime/base/execution-context.h index 4adcb0f1f..e92d26463 100644 --- a/hphp/runtime/base/execution-context.h +++ b/hphp/runtime/base/execution-context.h @@ -805,23 +805,6 @@ private: /////////////////////////////////////////////////////////////////////////////// -class Silencer { -public: - explicit Silencer(bool); - - ~Silencer() { if (m_active) disableHelper(); } - void enable(); - void disable() { disableHelper(); m_active = false; } - Variant disable(CVarRef v); - -private: - void disableHelper(); - bool m_active; - int m_errorReportingValue; -}; - -/////////////////////////////////////////////////////////////////////////////// - extern DECLARE_THREAD_LOCAL_NO_CHECK(ExecutionContext, g_context); extern DECLARE_THREAD_LOCAL_NO_CHECK(PersistentObjectStore, g_persistentObjects); diff --git a/hphp/runtime/base/object-data.cpp b/hphp/runtime/base/object-data.cpp index 2a01d9800..f5c7da72d 100644 --- a/hphp/runtime/base/object-data.cpp +++ b/hphp/runtime/base/object-data.cpp @@ -1023,7 +1023,7 @@ bool ObjectData::propIsset(Class* ctx, const StringData* key) { bool visible, accessible, unset; TypedValue* propVal = getProp(ctx, key, visible, accessible, unset); if (visible && accessible && !unset) { - return isset(tvAsCVarRef(propVal)); + return !tvIsNull(tvToCell(propVal)); } if (!getAttribute(UseIsset)) { return false; @@ -1039,7 +1039,7 @@ bool ObjectData::propEmpty(Class* ctx, const StringData* key) { bool visible, accessible, unset; TypedValue* propVal = getProp(ctx, key, visible, accessible, unset); if (visible && accessible && !unset) { - return empty(tvAsCVarRef(propVal)); + return !cellToBool(*tvToCell(propVal)); } if (!getAttribute(UseIsset)) { return true; @@ -1053,7 +1053,7 @@ bool ObjectData::propEmpty(Class* ctx, const StringData* key) { } if (getAttribute(UseGet)) { invokeGet(&tv, key); - bool emptyResult = empty(tvAsCVarRef(&tv)); + bool emptyResult = !cellToBool(*tvToCell(&tv)); tvRefcountedDecRef(&tv); return emptyResult; } diff --git a/hphp/runtime/base/tv-helpers.h b/hphp/runtime/base/tv-helpers.h index 8d7e21baa..3773918e8 100644 --- a/hphp/runtime/base/tv-helpers.h +++ b/hphp/runtime/base/tv-helpers.h @@ -442,6 +442,10 @@ inline void tvDupFlattenVars(const TypedValue* fr, TypedValue* to, } } +inline bool tvIsNull(const TypedValue* tv) { + return IS_NULL_TYPE(tv->m_type); +} + inline bool tvIsString(const TypedValue* tv) { return (tv->m_type & KindOfStringBit) != 0; } diff --git a/hphp/runtime/ext/ext_collections.cpp b/hphp/runtime/ext/ext_collections.cpp index cdbcce4d8..08f8e08f7 100644 --- a/hphp/runtime/ext/ext_collections.cpp +++ b/hphp/runtime/ext/ext_collections.cpp @@ -857,7 +857,7 @@ bool c_Vector::OffsetIsset(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? isset(tvAsCVarRef(result)) : false; + return result ? !tvIsNull(tvToCell(result)) : false; } bool c_Vector::OffsetEmpty(ObjectData* obj, TypedValue* key) { @@ -870,7 +870,7 @@ bool c_Vector::OffsetEmpty(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? empty(tvAsCVarRef(result)) : true; + return result ? !cellToBool(*result) : true; } bool c_Vector::OffsetContains(ObjectData* obj, TypedValue* key) { @@ -1943,7 +1943,7 @@ bool c_Map::OffsetIsset(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? isset(tvAsCVarRef(result)) : false; + return result ? !tvIsNull(tvToCell(result)) : false; } bool c_Map::OffsetEmpty(ObjectData* obj, TypedValue* key) { @@ -1958,7 +1958,7 @@ bool c_Map::OffsetEmpty(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? empty(tvAsCVarRef(result)) : true; + return result ? !cellToBool(*result) : true; } bool c_Map::OffsetContains(ObjectData* obj, TypedValue* key) { @@ -3184,7 +3184,7 @@ bool c_StableMap::OffsetIsset(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? isset(tvAsCVarRef(result)) : false; + return result ? !tvIsNull(tvToCell(result)) : false; } bool c_StableMap::OffsetEmpty(ObjectData* obj, TypedValue* key) { @@ -3199,7 +3199,7 @@ bool c_StableMap::OffsetEmpty(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? empty(tvAsCVarRef(result)) : true; + return result ? !cellToBool(*result) : true; } bool c_StableMap::OffsetContains(ObjectData* obj, TypedValue* key) { @@ -4336,7 +4336,7 @@ bool c_Pair::OffsetIsset(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? isset(tvAsCVarRef(result)) : false; + return result ? !tvIsNull(tvToCell(result)) : false; } bool c_Pair::OffsetEmpty(ObjectData* obj, TypedValue* key) { @@ -4349,7 +4349,7 @@ bool c_Pair::OffsetEmpty(ObjectData* obj, TypedValue* key) { throwBadKeyType(); result = nullptr; } - return result ? empty(tvAsCVarRef(result)) : true; + return result ? !cellToBool(*result) : true; } bool c_Pair::OffsetContains(ObjectData* obj, TypedValue* key) { diff --git a/hphp/runtime/ext/ext_domdocument.cpp b/hphp/runtime/ext/ext_domdocument.cpp index a274f390e..fe59a6451 100644 --- a/hphp/runtime/ext/ext_domdocument.cpp +++ b/hphp/runtime/ext/ext_domdocument.cpp @@ -1547,7 +1547,7 @@ public: const_iterator iter = find(name.data()); if (iter == end()) return false; return !iter->second->test_isset || - HPHP::isset(iter->second->getter(obj)); + !iter->second->getter(obj).isNull(); } }; diff --git a/hphp/runtime/ext/ext_xml.cpp b/hphp/runtime/ext/ext_xml.cpp index 776137d73..65794c71e 100644 --- a/hphp/runtime/ext/ext_xml.cpp +++ b/hphp/runtime/ext/ext_xml.cpp @@ -315,7 +315,7 @@ static Variant php_xml_parser_create_impl(CStrRef encoding_param, parser->target_encoding = encoding; parser->case_folding = 1; - setNull(parser->object); + parser->object.reset(); parser->isparsing = 0; XML_SetUserData(parser->parser, parser); diff --git a/hphp/runtime/vm/bytecode.cpp b/hphp/runtime/vm/bytecode.cpp index e60e52fc1..8d0a60f4e 100644 --- a/hphp/runtime/vm/bytecode.cpp +++ b/hphp/runtime/vm/bytecode.cpp @@ -687,7 +687,7 @@ static std::string toStringElm(const TypedValue* tv) { os << tv->m_data.pobj << "c(" << tv->m_data.pobj->getCount() << ")" << ":Object(" - << tvAsCVarRef(tv).asCObjRef().get()->o_getClassName().get()->data() + << tv->m_data.pobj->o_getClassName().get()->data() << ")"; break; case KindOfResource: @@ -4450,7 +4450,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopIssetN(PC& pc) { if (tv == nullptr) { e = false; } else { - e = isset(tvAsCVarRef(tv)); + e = !tvIsNull(tvToCell(tv)); } tvRefcountedDecRefCell(tv1); tv1->m_data.num = e; @@ -4468,7 +4468,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopIssetG(PC& pc) { if (tv == nullptr) { e = false; } else { - e = isset(tvAsCVarRef(tv)); + e = !tvIsNull(tvToCell(tv)); } tvRefcountedDecRefCell(tv1); tv1->m_data.num = e; @@ -4483,7 +4483,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopIssetS(PC& pc) { if (!(visible && accessible)) { e = false; } else { - e = isset(tvAsCVarRef(val)); + e = !tvIsNull(tvToCell(val)); } m_stack.popA(); output->m_data.num = e; @@ -4555,7 +4555,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopIs ## what ## C(PC& pc) { \ IOP_TYPE_CHECK_INSTR_L(checkInit, what, predicate) \ IOP_TYPE_CHECK_INSTR_C(checkInit, what, predicate) \ -IOP_TYPE_CHECK_INSTR_L(false, set, isset) +IOP_TYPE_CHECK_INSTR_L(false, set, is_not_null) IOP_TYPE_CHECK_INSTR(true, Null, is_null) IOP_TYPE_CHECK_INSTR(true, Array, is_array) IOP_TYPE_CHECK_INSTR(true, String, is_string) @@ -4569,7 +4569,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopEmptyL(PC& pc) { NEXT(); DECODE_HA(local); TypedValue* loc = frame_local(m_fp, local); - bool e = empty(tvAsCVarRef(loc)); + bool e = !cellToBool(*tvToCell(loc)); TypedValue* tv1 = m_stack.allocTV(); tv1->m_data.num = e; tv1->m_type = KindOfBoolean; @@ -4585,7 +4585,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopEmptyN(PC& pc) { if (tv == nullptr) { e = true; } else { - e = empty(tvAsCVarRef(tv)); + e = !cellToBool(*tvToCell(tv)); } tvRefcountedDecRefCell(tv1); tv1->m_data.num = e; @@ -4603,7 +4603,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopEmptyG(PC& pc) { if (tv == nullptr) { e = true; } else { - e = empty(tvAsCVarRef(tv)); + e = !cellToBool(*tvToCell(tv)); } tvRefcountedDecRefCell(tv1); tv1->m_data.num = e; @@ -4618,7 +4618,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopEmptyS(PC& pc) { if (!(visible && accessible)) { e = true; } else { - e = empty(tvAsCVarRef(val)); + e = !cellToBool(*tvToCell(val)); } m_stack.popA(); output->m_data.num = e; @@ -6028,7 +6028,7 @@ inline void OPTBLD_INLINE VMExecutionContext::iopCufSafeArray(PC& pc) { inline void OPTBLD_INLINE VMExecutionContext::iopCufSafeReturn(PC& pc) { NEXT(); - bool ok = tvAsVariant(m_stack.top() + 1).toBoolean(); + bool ok = cellToBool(*tvToCell(m_stack.top() + 1)); tvRefcountedDecRef(m_stack.top() + 1); tvRefcountedDecRef(m_stack.top() + (ok ? 2 : 0)); if (ok) m_stack.top()[2] = m_stack.top()[0]; diff --git a/hphp/runtime/vm/member-operations.cpp b/hphp/runtime/vm/member-operations.cpp index 2f27b5eec..0d96f4760 100644 --- a/hphp/runtime/vm/member-operations.cpp +++ b/hphp/runtime/vm/member-operations.cpp @@ -77,7 +77,7 @@ bool objOffsetEmpty(TypedValue& tvRef, ObjectData* base, CVarRef offset, } TypedValue* result = objOffsetGet(tvRef, base, offset, false); assert(result); - return empty(tvAsCVarRef(result)); + return !cellToBool(*tvToCell(result)); } void objOffsetAppend(ObjectData* base, TypedValue* val, diff --git a/hphp/runtime/vm/member-operations.h b/hphp/runtime/vm/member-operations.h index cac0d31db..ac3a66acd 100644 --- a/hphp/runtime/vm/member-operations.h +++ b/hphp/runtime/vm/member-operations.h @@ -1501,9 +1501,9 @@ inline bool IssetEmptyElem(TypedValue& tvScratch, TypedValue& tvRef, } if (useEmpty) { - return empty(tvAsCVarRef(result)); + return !cellToBool(*tvToCell(result)); } else { - return isset(tvAsCVarRef(result)); + return !tvIsNull(tvToCell(result)); } } diff --git a/hphp/test/ext/test_cpp_base.cpp b/hphp/test/ext/test_cpp_base.cpp index f2d02e8fb..6c1f3e71d 100644 --- a/hphp/test/ext/test_cpp_base.cpp +++ b/hphp/test/ext/test_cpp_base.cpp @@ -266,8 +266,8 @@ bool TestCppBase::TestArray() { { Variant arr = CREATE_MAP2("n1", "v1", "n2", "v2"); arr.escalate(); - for (ArrayIterPtr iter = arr.begin(arr, true); !iter->end(); iter->next()){ - unset(arr.lvalAt(iter->first())); + for (ArrayIter iter = arr.begin(arr, true); !iter->end(); iter->next()){ + arr.lvalAt(iter->first()).reset(); } VS(arr, Array::Create()); }