Skip to content

Commit

Permalink
correcting issue facebook#4797
Browse files Browse the repository at this point in the history
  • Loading branch information
gwen committed Feb 22, 2016
1 parent c72c876 commit d187690
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hphp/runtime/base/execution-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ struct ExecutionContext {
// destroying the context, so C++ order of destruction is not an issue.
req::hash_map<const ObjectData*,ArrayNoDtor> dynPropTable;
VarEnv* m_globalVarEnv;
req::hash_map<const StringData*,Unit*,string_data_hash,string_data_same>
req::hash_map<const StringData*,std::pair<Unit*,time_t>,string_data_hash,string_data_same>
m_evaledFiles;
req::vector<const StringData*> m_evaledFilesOrder;
req::vector<Unit*> m_createdFuncs;
Expand Down
10 changes: 5 additions & 5 deletions hphp/runtime/base/unit-cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ Unit* lookupUnit(StringData* path, const char* currentDir, bool* initial_opt) {

// Check if this file has already been included.
auto it = eContext->m_evaledFiles.find(spath.get());
if (it != end(eContext->m_evaledFiles)) {
initial = false;
return it->second;
if (it != end(eContext->m_evaledFiles) && it->second.second >= s.st_mtime) {
initial = false;
return it->second.first;
}

// This file hasn't been included yet, so we need to parse the file
Expand All @@ -499,10 +499,10 @@ Unit* lookupUnit(StringData* path, const char* currentDir, bool* initial_opt) {
// if parsing was successful, update the mappings for spath and
// rpath (if it exists).
eContext->m_evaledFilesOrder.push_back(cunit.unit->filepath());
eContext->m_evaledFiles[spath.get()] = cunit.unit;
eContext->m_evaledFiles[spath.get()] = std::make_pair(cunit.unit,time(NULL));
spath.get()->incRefCount();
if (!cunit.unit->filepath()->same(spath.get())) {
eContext->m_evaledFiles[cunit.unit->filepath()] = cunit.unit;
eContext->m_evaledFiles[cunit.unit->filepath()] = std::make_pair(cunit.unit,time(NULL));
}
if (g_system_profiler) {
g_system_profiler->fileLoadCallBack(path->toCppString());
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/debugger/debugger_hook_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void proxySetBreakPoints(DebuggerProxy* proxy) {
auto fileName = bp->m_file;
if (!fileName.empty()) {
for (auto& kv : g_context->m_evaledFiles) {
auto const unit = kv.second;
auto const unit = kv.second.first;
if (!BreakPointInfo::MatchFile(fileName,
unit->filepath()->toCppString())) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/ext/xdebug/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static const Unit* find_unit(String filename) {
// Search the given filename in the list of evaled files. We translate each
// unit's filename to a canonical format, which is slow, but necessary.
for (auto& kv : g_context->m_evaledFiles) {
auto const unit = kv.second;
auto const unit = kv.second.first;
String ufilename(const_cast<StringData*>(unit->filepath()));
if (filename == File::TranslatePath(ufilename)) {
return unit;
Expand Down
11 changes: 11 additions & 0 deletions hphp/test/slow/include/included_twice_different.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

file_put_contents('foo.php', "<?php \n\$i=1;\n");
include 'foo.php';
echo $i;
sleep(2); // just to make sure that timestamp is different
file_put_contents('foo.php', "<?php \n\$i=2;\n");
include 'foo.php';
echo $i;

?>
1 change: 1 addition & 0 deletions hphp/test/slow/include/included_twice_different.php.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12

0 comments on commit d187690

Please sign in to comment.