コード例 #1
0
ファイル: funcdict.cpp プロジェクト: hakanertug/hiphop-php
bool RenamedFuncDict::rename(const StringData* old, const StringData* n3w) {
  assert(isFunctionRenameable(old) ||
         isFunctionRenameable(n3w));

  NamedEntity *oldNe = const_cast<NamedEntity *>(Unit::GetNamedEntity(old));
  NamedEntity *newNe = const_cast<NamedEntity *>(Unit::GetNamedEntity(n3w));

  Func* func = Unit::lookupFunc(oldNe);
  if (!func) {
      // It's the caller's responsibility to ensure that the old function
      // exists.
      not_reached();
  }

  if (!(func->attrs() & AttrDynamicInvoke)) {
    // When EvalJitEnableRenameFunction is false, the translator may wire
    // non-DynamicInvoke Func*'s into the TC. Don't rename functions.
    if (RuntimeOption::EvalJit && !RuntimeOption::EvalJitEnableRenameFunction) {
      raise_error("You must explicitly enable fb_rename_function in the JIT "
                  "(-v Eval.JitEnableRenameFunction=true)");
    }
  }

  Func *fnew = Unit::lookupFunc(newNe);
  if (fnew && fnew != func) {
    // To match hphpc, we silently ignore functions defined in user code that
    // have the same name as a function defined in a separable extension
    if (!fnew->isAllowOverride()) {
      raise_error("Function already defined: %s", n3w->data());
    } else {
      return false;
    }
  }

  oldNe->setCachedFunc(nullptr);
  if (UNLIKELY(newNe->m_cachedFuncOffset == 0)) {
    Transl::TargetCache::allocFixedFunction(newNe, false);
  }
  newNe->setCachedFunc(func);

  if (RuntimeOption::EvalJit) {
    Transl::TargetCache::invalidateForRename(old);
  }

  return true;
}
コード例 #2
0
ファイル: intercept.cpp プロジェクト: artursmolarek/hhvm
void rename_function(const String& old_name, const String& new_name) {
  auto const old = old_name.get();
  auto const n3w = new_name.get();
  auto const oldNe = const_cast<NamedEntity*>(Unit::GetNamedEntity(old));
  auto const newNe = const_cast<NamedEntity*>(Unit::GetNamedEntity(n3w));

  Func* func = Unit::lookupFunc(oldNe);
  if (!func) {
    // It's the caller's responsibility to ensure that the old function
    // exists.
    not_reached();
  }

  if (!(func->attrs() & AttrDynamicInvoke)) {
    // When EvalJitEnableRenameFunction is false, the translator may wire
    // non-DynamicInvoke Func*'s into the TC. Don't rename functions.
    if (RuntimeOption::EvalJit && !RuntimeOption::EvalJitEnableRenameFunction) {
      raise_error("You must explicitly enable fb_rename_function in the JIT "
                  "(-v Eval.JitEnableRenameFunction=true)");
    }
  }

  Func *fnew = Unit::lookupFunc(newNe);
  if (fnew && fnew != func) {
    // To match hphpc, we silently ignore functions defined in user code that
    // have the same name as a function defined in a separable extension
    if (!fnew->isAllowOverride()) {
      raise_error("Function already defined: %s", n3w->data());
    }
    return;
  }

  oldNe->setCachedFunc(nullptr);
  newNe->m_cachedFunc.bind();
  newNe->setCachedFunc(func);

  if (RuntimeOption::EvalJit) {
    JIT::invalidateForRenameFunction(old);
  }
}