Пример #1
0
String concat3(const String& s1, const String& s2, const String& s3) {
  StringSlice r1 = s1.slice();
  StringSlice r2 = s2.slice();
  StringSlice r3 = s3.slice();
  int len = r1.len + r2.len + r3.len;
  StringData* str = StringData::Make(len);
  auto const r = str->bufferSlice();
  memcpy(r.ptr,                   r1.ptr, r1.len);
  memcpy(r.ptr + r1.len,          r2.ptr, r2.len);
  memcpy(r.ptr + r1.len + r2.len, r3.ptr, r3.len);
  str->setSize(len);
  return str;
}
Пример #2
0
ScenarioList::ScenarioList() {
    linked_ptr<Entry> factory_scenario(new Entry);
    factory_scenario->identifier.assign("com.biggerplanet.ares");
    factory_scenario->title.assign("Ares");
    factory_scenario->download_url.assign("http://www.arescentral.com");
    factory_scenario->author.assign("Bigger Planet");
    factory_scenario->author_url.assign("http://www.biggerplanet.com");
    u32_to_version(0x01010100, factory_scenario->version);
    _scenarios.push_back(factory_scenario);

    ScopedGlob g;
    const String home(utf8::decode(getenv("HOME")));
    const StringSlice scenarios("Library/Application Support/Antares/Scenarios");
    const StringSlice info("scenario-info/128.nlAG");
    String str(format("{0}/{1}/*/{2}", home, scenarios, info));
    CString c_str(str);
    glob(c_str.data(), 0, NULL, &g.data);

    size_t prefix_len = home.size() + scenarios.size() + 2;
    size_t suffix_len = info.size() + 1;
    for (int i = 0; i < g.data.gl_matchc; ++i) {
        const String path(utf8::decode(g.data.gl_pathv[i]));
        StringSlice identifier = path.slice(prefix_len, path.size() - prefix_len - suffix_len);
        if (identifier == factory_scenario->identifier) {
            continue;
        }

        MappedFile file(path);
        BytesSlice data(file.data());
        scenarioInfoType info;
        read(data, info);
        linked_ptr<Entry> entry(new Entry);
        entry->identifier.assign(identifier);
        entry->title.assign(info.titleString);
        entry->download_url.assign(info.downloadURLString);
        entry->author.assign(info.authorNameString);
        entry->author_url.assign(info.authorURLString);
        u32_to_version(info.version, entry->version);
        _scenarios.push_back(entry);
    }
}
Пример #3
0
CachedUnit createUnitFromString(const char* path,
                                const String& contents,
                                Unit** releaseUnit,
                                OptLog& ent,
                                const Native::FuncTable& nativeFuncs,
                                const RepoOptions& options,
                                FileLoadFlags& flags) {
  auto const sha1 = SHA1{mangleUnitSha1(string_sha1(contents.slice()),
                                        options)};
  // Try the repo; if it's not already there, invoke the compiler.
  if (auto unit = Repo::get().loadUnit(path, sha1, nativeFuncs)) {
    flags = FileLoadFlags::kHitDisk;
    return CachedUnit { unit.release(), rds::allocBit() };
  }
  LogTimer compileTimer("compile_ms", ent);
  rqtrace::EventGuard trace{"COMPILE_UNIT"};
  trace.annotate("file_size", folly::to<std::string>(contents.size()));
  flags = FileLoadFlags::kCompiled;
  auto const unit = compile_file(contents.data(), contents.size(), sha1, path,
                                 nativeFuncs, options, releaseUnit);
  return CachedUnit { unit, rds::allocBit() };
}
Пример #4
0
bool StatCache::mergePath(const std::string& path, bool follow) {
  String canonicalPath = FileUtil::canonicalize(path);
  std::vector<std::string> pvec;
  folly::split('/', canonicalPath.slice(), pvec);
  assertx((pvec[0].size() == 0)); // path should be absolute.
  // Lazily initialize so that if StatCache never gets used, no kernel
  // resources are consumed.
  if (m_ifd == -1 && init()) {
    return true;
  }
  NodePtr curNode = m_root;
  std::string curPath = "/";
  for (unsigned i = 1; i < pvec.size(); ++i) {
    // Follow links unless 'follow' is false and this is the last path
    // component.
    bool curFollow = (follow || i + 1 < pvec.size());
    curPath += pvec[i];
    NodePtr child = curNode->getChild(pvec[i], curFollow);
    if (child.get() == nullptr) {
      child = getNode(curPath, curFollow);
      if (child.get() == nullptr) {
        return true;
      }
      curNode->insertChild(pvec[i], child, curFollow);
    }
    curNode = child;
    curPath += "/";
  }
  NameNodeMap::accessor acc;
  NameNodeMap& p2n = follow ? m_path2Node : m_lpath2Node;
  if (p2n.insert(acc, path)) {
    acc->second = curNode;
    TRACE(1, "StatCache: merge '%s' --> %p (follow=%s)\n",
             path.c_str(), curNode.get(), follow ? "true" : "false");
  }
  return false;
}
Пример #5
0
HOT_FUNC
String operator+(const String & lhs, const String & rhs) {
  if (lhs.empty()) return rhs;
  if (rhs.empty()) return lhs;
  return NEW(StringData)(lhs.slice(), rhs.slice());
}
Пример #6
0
HOT_FUNC
String operator+(const String & lhs, String&& rhs) {
  return NEW(StringData)(lhs.slice(), rhs.slice());
}
Пример #7
0
String operator+(const String & lhs, litstr rhs) {
  if (lhs.empty()) return rhs;
  if (!rhs || !*rhs) return lhs;
  return NEW(StringData)(lhs.slice(), rhs);
}
Пример #8
0
String operator+(const String & lhs, const String & rhs) {
  if (lhs.empty()) return rhs;
  if (rhs.empty()) return lhs;
  return String::attach(StringData::Make(lhs.slice(), rhs.slice()));
}
Пример #9
0
String operator+(const String & lhs, String&& rhs) {
  return String::attach(StringData::Make(lhs.slice(), rhs.slice()));
}
Пример #10
0
HOT_FUNC
String operator+(const String & lhs, String&& rhs) {
    return StringData::Make(lhs.slice(), rhs.slice());
}
Пример #11
0
bool HHVM_FUNCTION(hphp_set_hardware_events,
                    const Variant& events /* = null */) {
  String ev = events.toString();
  ev = url_decode(ev.data(), ev.size());
  return HardwareCounter::SetPerfEvents(ev.slice());
}
Пример #12
0
req::ptr<File>
PhpStreamWrapper::open(const String& filename, const String& mode,
                       int options, const req::ptr<StreamContext>& context) {
  if (strncasecmp(filename.c_str(), "php://", 6)) {
    return nullptr;
  }

  const char *req = filename.c_str() + sizeof("php://") - 1;

  if (!strcasecmp(req, "stdin")) {
    return req::make<PlainFile>(dup(STDIN_FILENO), true, s_php);
  }
  if (!strcasecmp(req, "stdout")) {
    return req::make<PlainFile>(dup(STDOUT_FILENO), true, s_php);
  }
  if (!strcasecmp(req, "stderr")) {
    return req::make<PlainFile>(dup(STDERR_FILENO), true, s_php);
  }
  if (!strncasecmp(req, "fd/", sizeof("fd/") - 1)) {
    return openFD(req + sizeof("fd/") - 1);
  }
  if (!strncasecmp(req, "filter/", sizeof("filter/") - 1)) {
    return phpStreamOpenFilter(req + sizeof("filter") - 1, mode,
                               options, context);
  }

  if (!strncasecmp(req, "temp", sizeof("temp") - 1)) {
    auto file = req::make<TempFile>(true, s_php, s_temp);
    if (!file->valid()) {
      raise_warning("Unable to create temporary file");
      return nullptr;
    }
    return file;
  }
  if (!strcasecmp(req, "memory")) {
    auto file = req::make<TempFile>(true, s_php, s_memory);
    if (!file->valid()) {
      raise_warning("Unable to create temporary file");
      return nullptr;
    }

    file->getData()->m_mode = [mode] {
      if (mode.empty()) {
        return "w+b";
      }
      for (auto c : mode.slice()) {
        switch (c) {
          case '+':
          case 'w':
          case 'a':
          case 'x':
          case 'c':
            return "w+b";
          default:
            break;
        }
      }
      return "rb";
    }();
    return file;
  }

  if (!strcasecmp(req, "input")) {
    auto raw_post = g_context->getRawPostData();
    return req::make<MemFile>(
      raw_post.c_str(), raw_post.size(), s_php, s_input);
  }

  if (!strcasecmp(req, "output")) {
    return req::make<OutputFile>(filename);
  }

  return nullptr;
}