示例#1
0
文件: runtime.cpp 项目: derickr/hhvm
std::string mangleSystemMd5(const std::string& fileMd5) {
  // This resembles mangleUnitMd5(...), however, only settings that HHBBC is
  // aware of may be used here or it will be unable to load systemlib!
  std::string t = fileMd5 + '\0'
    + (RuntimeOption::PHP7_IntSemantics ? '1' : '0')
    + (RuntimeOption::AutoprimeGenerators ? '1' : '0')
    ;
  return string_md5(t.c_str(), t.size());
}
示例#2
0
文件: scanner.cpp 项目: BwRy/hhvm
void Scanner::computeMd5() {
  int startpos = m_stream->tellg();
  m_stream->seekg(0, std::ios::end);
  int length = m_stream->tellg();
  m_stream->seekg(0, std::ios::beg);
  char *ptr = (char*)malloc(length);
  m_stream->read(ptr, length);
  m_stream->seekg(startpos, std::ios::beg);
  m_md5 = string_md5(ptr, length);
  free(ptr);
}
示例#3
0
std::string mangleUnitMd5(const std::string& fileMd5) {
  std::string t = fileMd5 + '\0'
    + (RuntimeOption::EnableEmitSwitch ? '1' : '0')
    + (RuntimeOption::EnableHipHopExperimentalSyntax ? '1' : '0')
    + (RuntimeOption::EnableHipHopSyntax ? '1' : '0')
    + (RuntimeOption::EnableXHP ? '1' : '0')
    + (RuntimeOption::EvalAllowHhas ? '1' : '0')
    + (RuntimeOption::EvalJitEnableRenameFunction ? '1' : '0')
    + (RuntimeOption::IntsOverflowToInts ? '1' : '0');
  return string_md5(t.c_str(), t.size());
}
示例#4
0
CachedUnit createUnitFromString(const char* path,
                                const String& contents) {
  auto const md5 = MD5 {
    mangleUnitMd5(string_md5(contents.data(), contents.size())).c_str()
  };
  // Try the repo; if it's not already there, invoke the compiler.
  if (auto const unit = Repo::get().loadUnit(path, md5)) {
    return CachedUnit { unit, RDS::allocBit() };
  }
  auto const unit = compile_file(contents.data(), contents.size(), md5, path);
  return CachedUnit { unit, RDS::allocBit() };
}
示例#5
0
文件: runtime.cpp 项目: StetHD/hhvm
Unit* compile_string(const char* s,
                     size_t sz,
                     const char* fname /* = nullptr */) {
  auto const md5 = MD5{mangleSystemMd5(string_md5(folly::StringPiece{s, sz}))};
  if (auto u = Repo::get().loadUnit(fname ? fname : "", md5).release()) {
    return u;
  }
  // NB: fname needs to be long-lived if generating a bytecode repo because it
  // can be cached via a Location ultimately contained by ErrorInfo for printing
  // code errors.
  return g_hphp_compiler_parse(s, sz, md5, fname);
}
示例#6
0
Unit* compile_string(const char* s,
                     size_t sz,
                     const char* fname /* = nullptr */) {
  auto md5string = string_md5(s, sz);
  MD5 md5(md5string.c_str());
  Unit* u = Repo::get().loadUnit(fname ? fname : "", md5).release();
  if (u != nullptr) {
    return u;
  }
  // NB: fname needs to be long-lived if generating a bytecode repo because it
  // can be cached via a Location ultimately contained by ErrorInfo for printing
  // code errors.
  return g_hphp_compiler_parse(s, sz, md5, fname);
}
示例#7
0
文件: runtime.cpp 项目: StetHD/hhvm
Unit* compile_systemlib_string(const char* s, size_t sz, const char* fname) {
  if (RuntimeOption::RepoAuthoritative) {
    String systemName = String("/:") + fname;
    auto md5 = MD5{mangleSystemMd5(string_md5(folly::StringPiece{s,sz}))};
    if (Repo::get().findFile(systemName.data(),
                             SourceRootInfo::GetCurrentSourceRoot(),
                             md5)) {
      if (auto u = Repo::get().loadUnit(fname, md5)) {
        return u.release();
      }
    }
  }
  return compile_string(s, sz, fname);
}
示例#8
0
string FileRepository::unitMd5(const string& fileMd5) {
  // Incorporate relevant options into the unit md5 (there will be more)
  char* md5str;
  int md5len;
  std::ostringstream opts;
  string t = fileMd5 + '\0'
    + (RuntimeOption::EnableHipHopSyntax ? '1' : '0')
    + (RuntimeOption::EnableEmitSwitch ? '1' : '0')
    + (RuntimeOption::EvalJitEnableRenameFunction ? '1' : '0');
  md5str = string_md5(t.c_str(), t.size(), false, md5len);
  string s = string(md5str, md5len);
  free(md5str);
  return s;
}
示例#9
0
文件: scanner.cpp 项目: bd808/hhvm
void Scanner::computeMd5() {
  size_t startpos = m_stream->tellg();
  always_assert(startpos != -1 &&
                startpos <= std::numeric_limits<int32_t>::max());
  m_stream->seekg(0, std::ios::end);
  size_t length = m_stream->tellg();
  always_assert(length != -1 &&
                length <= std::numeric_limits<int32_t>::max());
  m_stream->seekg(0, std::ios::beg);
  char *ptr = (char*)malloc(length);
  m_stream->read(ptr, length);
  m_stream->seekg(startpos, std::ios::beg);
  m_md5 = string_md5(ptr, length);
  free(ptr);
}
示例#10
0
Unit* compile_string(const char* s,
                     size_t sz,
                     const char* fname,
                     const Native::FuncTable& nativeFuncs,
                     bool forDebuggerEval) {
  auto const md5 = MD5{mangleUnitMd5(string_md5(folly::StringPiece{s, sz}))};
  if (auto u = Repo::get().loadUnit(
        fname ? fname : "",
        md5, nativeFuncs).release()) {
    return u;
  }
  // NB: fname needs to be long-lived if generating a bytecode repo because it
  // can be cached via a Location ultimately contained by ErrorInfo for printing
  // code errors.
  return g_hphp_compiler_parse(s, sz, md5, fname, nativeFuncs, nullptr,
                               forDebuggerEval);
}
示例#11
0
std::string mangleUnitMd5(const std::string& fileMd5) {
  std::string t = fileMd5 + '\0'
    + (RuntimeOption::EvalEmitSwitch ? '1' : '0')
    + (RuntimeOption::EnableHipHopExperimentalSyntax ? '1' : '0')
    + (RuntimeOption::EnableHipHopSyntax ? '1' : '0')
    + (RuntimeOption::EnableXHP ? '1' : '0')
    + (RuntimeOption::EvalAllowHhas ? '1' : '0')
    + (RuntimeOption::EvalJitEnableRenameFunction ? '1' : '0')
    + (RuntimeOption::IntsOverflowToInts ? '1' : '0')
    + (RuntimeOption::EvalEnableCallBuiltin ? '1' : '0')
    + (RuntimeOption::AssertEmitted ? '1' : '0')
    + RuntimeOption::EvalUseExternalEmitter + '\0'
    + (RuntimeOption::EvalExternalEmitterFallback ? '1' : '0')
    + (RuntimeOption::EvalExternalEmitterAllowPartial ? '1' : '0')
    + (RuntimeOption::AutoprimeGenerators ? '1' : '0')
    + mangleUnitPHP7Options();
  return string_md5(t.c_str(), t.size());
}
示例#12
0
void FileRepository::setFileInfo(const StringData *name,
                                 const string& md5,
                                 FileInfo &fileInfo,
                                 bool fromRepo) {
  int md5len;
  char* md5str;
  // Incorporate the path into the md5 that is used as the key for file
  // repository lookups.  This assures that even if two PHP files have
  // identical content, separate units exist for them (so that
  // Unit::filepath() and Unit::dirpath() work correctly).
  string s = md5 + '\0' + name->data();
  md5str = string_md5(s.c_str(), s.size(), false, md5len);
  fileInfo.m_md5 = string(md5str, md5len);
  free(md5str);

  if (fromRepo) {
    fileInfo.m_unitMd5 = md5;
  } else {
    fileInfo.m_unitMd5 = unitMd5(md5);
  }

  fileInfo.m_srcRoot = SourceRootInfo::GetCurrentSourceRoot();
  int srcRootLen = fileInfo.m_srcRoot.size();
  if (srcRootLen) {
    if (!strncmp(name->data(), fileInfo.m_srcRoot.c_str(), srcRootLen)) {
      fileInfo.m_relPath = string(name->data() + srcRootLen);
    }
  }

  ReadLock lock(s_md5Lock);
  Md5FileMap::iterator it = s_md5Files.find(fileInfo.m_md5);
  if (it != s_md5Files.end()) {
    PhpFile *f = it->second;
    if (!fileInfo.m_relPath.empty() &&
        fileInfo.m_relPath == f->getRelPath()) {
      assert(fileInfo.m_md5 == f->getMd5());
      fileInfo.m_phpFile = f;
    }
  }
}
示例#13
0
String StringUtil::MD5(CStrRef input, bool raw /* = false */) {
  int len;
  char *ret = string_md5(input.data(), input.size(), raw, len);
  return String(ret, len, AttachString);
}