Move everything out of GlobalNameValueTableWrapper
This is to clear the runway for getting rid of GlobalNameValueTableWrapper. It moves aside these three items that were in there for no particular reason other than convenience. I moved them aside into another struct that I arena-allocate and initialize at the same time as the global VarEnv (which initializes the GlobalNVTW). I called the struct where these live "EnvConstants" since they look like constants to PHP but their values are determined at startup time (by the environment, like whether we're in server mode). lvalProxy doesn't fit that mold, but oh well.
Esse commit está contido em:
@@ -21,10 +21,7 @@ namespace HPHP {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
static __thread GlobalVariables* g_variables;
|
||||
|
||||
void init_global_variables() {
|
||||
always_assert(false);
|
||||
}
|
||||
static __thread EnvConstants* g_envConstants;
|
||||
|
||||
GlobalVariables* get_global_variables() {
|
||||
assert(g_variables);
|
||||
@@ -39,6 +36,18 @@ void free_global_variables_after_sweep() {
|
||||
g_variables = nullptr;
|
||||
}
|
||||
|
||||
EnvConstants* get_env_constants() {
|
||||
assert(g_envConstants);
|
||||
return g_envConstants;
|
||||
}
|
||||
|
||||
void EnvConstants::requestInit(EnvConstants* gt) {
|
||||
g_envConstants = gt;
|
||||
}
|
||||
void EnvConstants::requestExit() {
|
||||
g_envConstants = nullptr;
|
||||
}
|
||||
|
||||
GlobalNameValueTableWrapper::GlobalNameValueTableWrapper(
|
||||
NameValueTable* tab) : NameValueTableWrapper(tab) {
|
||||
|
||||
@@ -59,7 +68,7 @@ GlobalNameValueTableWrapper::GlobalNameValueTableWrapper(
|
||||
X(http_response_header, init_null_variant);
|
||||
#undef X
|
||||
|
||||
ThreadInfo::s_threadInfo->m_globals = g_variables = this;
|
||||
g_variables = this;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -203,7 +203,7 @@ CVarRef ClassInfo::ConstantInfo::getDeferredValue() const {
|
||||
CVarRef (*f)()=(CVarRef(*)())callback;
|
||||
return (*f)();
|
||||
}
|
||||
GlobalVariables* g = get_global_variables();
|
||||
EnvConstants* g = get_env_constants();
|
||||
return g->stgv_Variant[valueLen];
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,24 @@ extern const char *g_class_map[];
|
||||
*/
|
||||
typedef GlobalNameValueTableWrapper GlobalVariables;
|
||||
extern GlobalVariables *get_global_variables();
|
||||
extern void init_global_variables();
|
||||
extern void free_global_variables();
|
||||
extern void free_global_variables_after_sweep();
|
||||
extern Array get_global_state();
|
||||
|
||||
/**
|
||||
* These are things that look like constants to PHP, but their values aren't
|
||||
* known at compile time and are instead determined at startup time. lvalProxy
|
||||
* is not that (it's a "black hole" for certain types of assignments) but there
|
||||
* isn't really an obviously better place for it to live.
|
||||
*/
|
||||
struct EnvConstants {
|
||||
static void requestInit(EnvConstants* gt);
|
||||
static void requestExit();
|
||||
Variant __lvalProxy;
|
||||
Variant stgv_Variant[2];
|
||||
#define k_SID stgv_Variant[0]
|
||||
#define k_PHP_SAPI stgv_Variant[1]
|
||||
};
|
||||
extern EnvConstants* get_env_constants();
|
||||
|
||||
/**
|
||||
* Precomputed literal strings
|
||||
|
||||
@@ -1328,7 +1328,7 @@ void hphp_session_init() {
|
||||
|
||||
g_vmContext->requestInit();
|
||||
|
||||
GlobalVariables *g = get_global_variables();
|
||||
EnvConstants *g = get_env_constants();
|
||||
g->k_PHP_SAPI = StringData::GetStaticString(RuntimeOption::ExecutionMode);
|
||||
}
|
||||
|
||||
|
||||
@@ -1947,7 +1947,7 @@ head:
|
||||
*tmp = self->getArrayAccess()->offsetGet(key);
|
||||
return *tmp;
|
||||
}
|
||||
Variant& retv = get_global_variables()->__lvalProxy;
|
||||
Variant& retv = get_env_constants()->__lvalProxy;
|
||||
retv = self->getArrayAccess()->offsetGet(key);
|
||||
return retv;
|
||||
}
|
||||
@@ -2052,7 +2052,7 @@ Variant &Variant::lvalInvalid() {
|
||||
}
|
||||
|
||||
Variant &Variant::lvalBlackHole() {
|
||||
Variant &bh = get_global_variables()->__lvalProxy;
|
||||
Variant &bh = get_env_constants()->__lvalProxy;
|
||||
bh.unset();
|
||||
return bh;
|
||||
}
|
||||
|
||||
@@ -326,7 +326,6 @@ public:
|
||||
Profiler *m_profiler;
|
||||
CodeCoverage *m_coverage;
|
||||
|
||||
GlobalVariables *m_globals;
|
||||
Executing m_executing;
|
||||
|
||||
// A C++ exception which will be thrown by the next surprise check.
|
||||
|
||||
@@ -1127,7 +1127,7 @@ static void php_session_reset_id() {
|
||||
PS(send_cookie) = 0;
|
||||
}
|
||||
|
||||
GlobalVariables *g = get_global_variables();
|
||||
EnvConstants *g = get_env_constants();
|
||||
if (PS(define_sid)) {
|
||||
StringBuffer var;
|
||||
var.append(String(PS(session_name)));
|
||||
|
||||
@@ -7292,6 +7292,7 @@ void VMExecutionContext::requestInit() {
|
||||
new (&s_requestArenaStorage) RequestArena();
|
||||
new (&s_varEnvArenaStorage) VarEnvArena();
|
||||
|
||||
EnvConstants::requestInit(new (request_arena()) EnvConstants());
|
||||
VarEnv::createGlobal();
|
||||
m_stack.requestInit();
|
||||
tx64 = nextTx64;
|
||||
@@ -7329,6 +7330,7 @@ void VMExecutionContext::requestExit() {
|
||||
m_stack.requestExit();
|
||||
profileRequestEnd();
|
||||
EventHook::Disable();
|
||||
EnvConstants::requestExit();
|
||||
|
||||
if (m_globalVarEnv) {
|
||||
assert(m_topVarEnv = m_globalVarEnv);
|
||||
|
||||
@@ -151,13 +151,6 @@ private:
|
||||
class GlobalNameValueTableWrapper : public NameValueTableWrapper {
|
||||
public:
|
||||
explicit GlobalNameValueTableWrapper(NameValueTable* tab);
|
||||
|
||||
Variant __realPropProxy;
|
||||
Variant __lvalProxy;
|
||||
|
||||
Variant stgv_Variant[2];
|
||||
#define k_SID stgv_Variant[0]
|
||||
#define k_PHP_SAPI stgv_Variant[1]
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -251,8 +251,8 @@ static void writeConstant(std::ostream& out, const PhpConst& cns) {
|
||||
if (cns.isSystem()) {
|
||||
// Special "magic" constants
|
||||
if ((name == "SID") || (name == "PHP_SAPI")) {
|
||||
out << "(const char *)((offsetof(GlobalVariables, k_" << name << ") - "
|
||||
<< "offsetof(GlobalVariables, stgv_Variant)) / sizeof(Variant)), "
|
||||
out << "(const char *)((offsetof(EnvConstants, k_" << name << ") - "
|
||||
<< "offsetof(EnvConstants, stgv_Variant)) / sizeof(Variant)), "
|
||||
<< castLong(1) << ",\n";
|
||||
return;
|
||||
}
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário