Beispiel #1
0
Object f_hphp_splfileobject___construct(CObjRef obj, CStrRef filename, CStrRef open_mode, bool use_include_path, CVarRef context) {
  Variant f = f_fopen(filename, open_mode, use_include_path,
                      context.isNull() ? null_object : context.toObject());
  c_SplFileObject *c_splfo = obj.getTyped<c_SplFileObject>();
  c_splfo->m_rsrc = NEWOBJ(SplFileObject)(f);
  return c_splfo;
}
Beispiel #2
0
ImmutableObj::ImmutableObj(ObjectData *obj) {
  // This function assumes the object and object/array down the tree have no
  // internal reference and does not implements serializable interface.
  assert(!obj->instanceof(SystemLib::s_SerializableClass));
  m_cls = obj->o_getClassName()->copy(true);
  Array props;
  ClassInfo::GetArray(obj, props, ClassInfo::GetArrayAll);
  m_propCount = 0;
  if (props.empty()) {
    m_props = nullptr;
  } else {
    m_props = (Prop*)malloc(sizeof(Prop) * props.size());
    for (ArrayIter it(props); !it.end(); it.next()) {
      assert(m_propCount < props.size());
      Variant key(it.first());
      assert(key.isString());
      CVarRef value = it.secondRef();
      SharedVariant *val = nullptr;
      if (!value.isNull()) {
        val = new SharedVariant(value, false, true, true);
      }
      m_props[m_propCount].val = val;
      m_props[m_propCount].name = key.getStringData()->copy(true);
      m_propCount++;
    }
  }
}
Beispiel #3
0
Variant f_array_slice(CVarRef array, int offset,
                      CVarRef length /* = null_variant */,
                      bool preserve_keys /* = false */) {
  getCheckedArray(array);
  int64_t len = length.isNull() ? 0x7FFFFFFF : length.toInt64();
  return ArrayUtil::Slice(arr_array, offset, len, preserve_keys);
}
Beispiel #4
0
int64_t f_error_reporting(CVarRef level /* = null */) {
  int oldErrorReportingLevel = g_context->getErrorReportingLevel();
  if (!level.isNull()) {
    g_context->setErrorReportingLevel(level.toInt32());
  }
  return oldErrorReportingLevel;
}
Beispiel #5
0
void f_asio_set_on_failed_callback(CVarRef on_failed_cb) {
  if (!on_failed_cb.isNull() && !on_failed_cb.instanceof(c_Closure::s_cls)) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Unable to set asio on failed callback: on_failed_cb not a closure"));
    throw e;
  }
  AsioSession::Get()->setOnFailedCallback(on_failed_cb.getObjectDataOrNull());
}
Beispiel #6
0
void c_WaitHandle::ti_setonjoincallback(CVarRef callback) {
  if (!callback.isNull() && !callback.instanceof(c_Closure::classof())) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Unable to set WaitHandle::onJoin: on_join_cb not a closure"));
    throw e;
  }
  AsioSession::Get()->setOnJoinCallback(callback.getObjectDataOrNull());
}
Beispiel #7
0
int64_t f_error_reporting(CVarRef level /* = null */) {
  auto& id = ThreadInfo::s_threadInfo.getNoCheck()->m_reqInjectionData;
  int oldErrorReportingLevel = id.getErrorReportingLevel();
  if (!level.isNull()) {
    id.setErrorReportingLevel(level.toInt32());
  }
  return oldErrorReportingLevel;
}
void c_ContinuationWaitHandle::ti_setonfailcallback(CVarRef callback) {
  if (!callback.isNull() && !callback.instanceof(c_Closure::s_cls)) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Unable to set ContinuationWaitHandle::onFail: on_fail_cb not a closure"));
    throw e;
  }
  AsioSession::Get()->setOnContinuationFailCallback(callback.getObjectDataOrNull());
}
void c_SetResultToRefWaitHandle::ti_setoncreatecallback(CVarRef callback) {
  if (!callback.isNull() && !callback.instanceof(c_Closure::classof())) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Unable to set SetResultToRefWaitHandle::onCreate: on_create_cb not a closure"));
    throw e;
  }
  AsioSession::Get()->setOnSetResultToRefCreateCallback(callback.getObjectDataOrNull());
}
Beispiel #10
0
String HHVM_FUNCTION(preg_quote, const String& str,
                                 CVarRef delimiter /* = null_string */) {
  if (delimiter.isNull()) {
    return preg_quote(str, null_string);
  } else {
    return preg_quote(str, delimiter.toString());
  }
}
void c_AsyncFunctionWaitHandle::ti_setonsuccesscallback(CVarRef callback) {
  if (!callback.isNull() && !callback.instanceof(c_Closure::classof())) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Unable to set AsyncFunctionWaitHandle::onSuccess: on_success_cb not a closure"));
    throw e;
  }
  AsioSession::Get()->setOnAsyncFunctionSuccessCallback(callback.getObjectDataOrNull());
}
Beispiel #12
0
bool same(CVarRef v1, const StringData* v2) {
  bool null1 = v1.isNull();
  bool null2 = (v2 == nullptr);
  if (null1 && null2) return true;
  if (null1 || null2) return false;
  if (!v1.isString()) return false;
  auto const sdata = v1.getStringData();
  return sdata == v2 || v2->same(sdata);
}
Beispiel #13
0
static bool HHVM_METHOD(IntlCalendar, clear, CVarRef field) {
  CAL_FETCH(data, this_, false);
  if (field.isNull()) {
    data->calendar()->clear();
  } else {
    data->calendar()->clear((UCalendarDateFields)field.toInt64());
  }
  return true;
}
Beispiel #14
0
bool same(CVarRef v1, CResRef v2) {
  bool null1 = v1.isNull();
  bool null2 = v2.isNull();
  if (null1 && null2) return true;
  if (null1 || null2) return false;
  if (!v1.isResource()) return false;
  auto const rd = v1.getResourceData();
  return rd == v2.get();
}
Beispiel #15
0
bool same(CVarRef v1, CArrRef v2) {
  bool null1 = v1.isNull();
  bool null2 = v2.isNull();
  if (null1 && null2) return true;
  if (null1 || null2) return false;
  if (!v1.isArray()) return false;
  auto const ad = v1.getArrayData();
  return v2->equal(ad, true);
}
Beispiel #16
0
Variant f_array_splice(VRefParam input, int offset,
                       CVarRef length /* = null_variant */,
                       CVarRef replacement /* = null_variant */) {
  getCheckedArray(input);
  Array ret(Array::Create());
  int64_t len = length.isNull() ? 0x7FFFFFFF : length.toInt64();
  input = ArrayUtil::Splice(arr_input, offset, len, replacement, &ret);
  return ret;
}
Beispiel #17
0
bool Array::more(CVarRef v2) const {
  if (m_px == NULL || v2.isNull()) {
    return HPHP::more(toBoolean(), v2.toBoolean());
  }
  if (v2.getType() == KindOfArray) {
    return v2.toArray().get()->compare(m_px) < 0;
  }
  return v2.less(*this);
}
Beispiel #18
0
bool Array::less(CVarRef v2) const {
  if (m_px == nullptr || v2.isNull()) {
    return HPHP::less(toBoolean(), v2.toBoolean());
  }
  if (v2.getType() == KindOfArray) {
    return m_px->compare(v2.toArray().get()) < 0;
  }
  return v2.more(*this);
}
Beispiel #19
0
bool same(CVarRef v1, CObjRef v2) {
  bool null1 = v1.isNull();
  bool null2 = v2.isNull();
  if (null1 && null2) return true;
  if (null1 || null2) return false;
  if (!v1.isObject()) return false;
  auto const od = v1.getObjectData();
  return od == v2.get();
}
Beispiel #20
0
Variant f_socket_select(VRefParam read, VRefParam write, VRefParam except,
                        CVarRef vtv_sec, int tv_usec /* = 0 */) {
  int count = 0;
  if (!read.isNull()) {
    count += read.toArray().size();
  }
  if (!write.isNull()) {
    count += write.toArray().size();
  }
  if (!except.isNull()) {
    count += except.toArray().size();
  }
  if (!count) {
    return false;
  }

  struct pollfd *fds = (struct pollfd *)calloc(count, sizeof(struct pollfd));
  count = 0;
  if (!read.isNull()) {
    sock_array_to_fd_set(read.toArray(), fds, count, POLLIN);
  }
  if (!write.isNull()) {
    sock_array_to_fd_set(write.toArray(), fds, count, POLLOUT);
  }
  if (!except.isNull()) {
    sock_array_to_fd_set(except.toArray(), fds, count, POLLPRI);
  }

  IOStatusHelper io("socket_select");
  int timeout_ms = -1;
  if (!vtv_sec.isNull()) {
    timeout_ms = vtv_sec.toInt32() * 1000 + tv_usec / 1000;
  }
  int retval = poll(fds, count, timeout_ms);
  if (retval == -1) {
    raise_warning("unable to select [%d]: %s", errno,
                  Util::safe_strerror(errno).c_str());
    free(fds);
    return false;
  }

  count = 0;
  int nfds = 0;
  if (!read.isNull()) {
    sock_array_from_fd_set(read, fds, nfds, count, POLLIN|POLLERR);
  }
  if (!write.isNull()) {
    sock_array_from_fd_set(write, fds, nfds, count, POLLOUT|POLLERR);
  }
  if (!except.isNull()) {
    sock_array_from_fd_set(except, fds, nfds, count, POLLPRI|POLLERR);
  }

  free(fds);
  return count;
}
Beispiel #21
0
Variant f_strtr(CStrRef str, CVarRef from, CVarRef to /* = null_variant */) {
  if (str.empty()) {
    return str;
  }

  if (!to.isNull()) {
    return StringUtil::Translate(str, from.toString(), to.toString());
  }

  if (!from.is(KindOfArray)) {
    throw_invalid_argument("2nd argument: (not array)");
    return false;
  }

  int maxlen = 0;
  int minlen = -1;
  Array arr = from.toArray();
  for (ArrayIter iter(arr); iter; ++iter) {
    String search = iter.first();
    int len = search.size();
    if (len < 1) return false;
    if (maxlen < len) maxlen = len;
    if (minlen == -1 || minlen > len) minlen = len;
  }

  const char *s = str.data();
  int slen = str.size();
  char *key = (char *)malloc(maxlen+1);

  StringBuffer result(slen);
  for (int pos = 0; pos < slen; ) {
    if ((pos + maxlen) > slen) {
      maxlen = slen - pos;
    }
    bool found = false;
    memcpy(key, s + pos, maxlen);
    for (int len = maxlen; len >= minlen; len--) {
      key[len] = 0;
      if (arr.exists(key)) {
        String replace = arr[key].toString();
        if (!replace.empty()) {
          result += replace;
        }
        pos += len;
        found = true;
        break;
      }
    }
    if (!found) {
      result += s[pos++];
    }
  }
  free(key);

  return result.detach();
}
Beispiel #22
0
void f_mt_srand(CVarRef seed /* = null_variant */) {
  if (seed.isNull()) {
    return math_mt_srand(math_generate_seed());
  }
  if (seed.isNumeric(true)) {
    math_mt_srand(seed.toInt32());
  } else {
    raise_warning("mt_srand() expects parameter 1 to be long");
  }
}
Beispiel #23
0
APCHandle* APCObject::Construct(ObjectData* objectData) {
    // This function assumes the object and object/array down the tree
    // have no internal references and do not implement the serializable
    // interface.
    assert(!objectData->instanceof(SystemLib::s_SerializableClass));

    Array odProps;
    objectData->o_getArray(odProps, false);
    auto const propCount = odProps.size();

    auto const apcObj = new (
        std::malloc(sizeof(APCObject) + sizeof(Prop) * propCount)
    ) APCObject(objectData, propCount);
    if (!propCount) return apcObj->getHandle();

    auto prop = apcObj->props();
    for (ArrayIter it(odProps); !it.end(); it.next()) {
        Variant key(it.first());
        assert(key.isString());
        CVarRef value = it.secondRef();
        APCHandle *val = nullptr;
        if (!value.isNull()) {
            val = APCHandle::Create(value, false, true, true);
        }

        const String& keySD = key.asCStrRef();

        if (!keySD->empty() && *keySD->data() == '\0') {
            int32_t subLen = keySD.find('\0', 1) + 1;
            String cls = keySD.substr(1, subLen - 2);
            if (cls.size() == 1 && cls[0] == '*') {
                // Protected.
                prop->ctx = ClassOrString{nullptr};
            } else {
                // Private.
                prop->ctx = ClassOrString{Unit::lookupClass(cls.get())};
            }

            prop->name = makeStaticString(keySD.substr(subLen));
        } else {
            prop->ctx = ClassOrString{nullptr};
            prop->name = makeStaticString(keySD.get());
        }

        prop->val = val;

        ++prop;
    }
    assert(prop == apcObj->props() + propCount);

    return apcObj->getHandle();
}
Beispiel #24
0
static String HHVM_METHOD(IntlDateFormatter, getLocale, CVarRef which) {
  ULocDataLocaleType whichloc = ULOC_ACTUAL_LOCALE;
  if (!which.isNull()) whichloc = (ULocDataLocaleType)which.toInt64();

  DATFMT_GET(data, this_, null_string);
  UErrorCode error = U_ZERO_ERROR;
  const char *loc = udat_getLocaleByType(data->datefmt(), whichloc, &error);
  if (U_FAILURE(error)) {
    data->setError(error);
    return null_string;
  }
  return String(loc, CopyString);
}
Beispiel #25
0
static bool HHVM_METHOD(IntlCalendar, isWeekend, CVarRef date) {
  CAL_FETCH(data, this_, false);
  if (date.isNull()) {
    return data->calendar()->isWeekend();
  }
  UErrorCode error = U_ZERO_ERROR;
  bool ret = data->calendar()->isWeekend((UDate)date.toDouble(), error);
  if (U_FAILURE(error)) {
    data->setError(error, "intlcal_is_weekend: Error calling ICU method");
    return false;
  }
  return ret;
}
void c_Continuation::t___construct(
  int64_t func, CStrRef origFuncName, CVarRef obj, CArrRef args) {
  m_vmFunc       = (VM::Func*)func;
  assert(m_vmFunc);
  m_origFuncName = origFuncName;

  if (!obj.isNull()) {
    m_obj = obj.toObject();
    assert(!m_obj.isNull());
  } else {
    assert(m_obj.isNull());
  }
  m_args = args;
}
Beispiel #27
0
Variant f_array_filter(CVarRef input, CVarRef callback /* = null_variant */) {
  getCheckedArray(input);

  if (callback.isNull()) {
    return ArrayUtil::Filter(arr_input);
  }
  CallCtx ctx;
  EagerCallerFrame cf;
  vm_decode_function(callback, cf(), false, ctx);
  if (ctx.func == NULL) {
    return uninit_null();
  }
  return ArrayUtil::Filter(arr_input, filter_func, &ctx);
}
Beispiel #28
0
bool f_ob_start(CVarRef callback /* = uninit_null() */,
                int chunk_size /* = 0 */, bool erase /* = true */) {
  // ignoring chunk_size and erase

  if (!callback.isNull()) {
    CallCtx ctx;
    vm_decode_function(callback, nullptr, false, ctx);
    if (!ctx.func) {
      return false;
    }
  }
  g_context->obStart(callback);
  return true;
}
Beispiel #29
0
Variant f_strtok(CStrRef str, CVarRef token /* = null_variant */) {
  String stoken;
  if (!token.isNull()) {
    s_tokenizer_data->str = str;
    s_tokenizer_data->pos = 0;
    stoken = token.toString();
  } else {
    stoken = str;
  }

  String sstr = s_tokenizer_data->str;
  int pos = s_tokenizer_data->pos;
  if (pos >= sstr.size()) {
    return false;
  }

  // set up mask
  int *mask = s_tokenizer_data->mask;
  for (int i = 0; i < stoken.size(); i++) {
    mask[(unsigned char)stoken.data()[i]] = 1;
  }

  // skip leading delimiters
  const char *s0 = sstr.data();
  int i = pos;
  for (; i < sstr.size(); i++) {
    if (!mask[(unsigned char)s0[i]]) {
      break;
    }
  }
  int pos0 = i;
  for (; i < sstr.size(); i++) {
    if (mask[(unsigned char)s0[i]]) {
      break;
    }
  }

  String ret(s0 + pos0, i - pos0, CopyString);
  s_tokenizer_data->pos = i + 1;

  // reset mask
  for (int i = 0; i < stoken.size(); i++) {
    mask[(unsigned char)stoken.data()[i]] = 0;
  }
  return ret;
}
Beispiel #30
0
static Variant HHVM_STATIC_METHOD(IntlTimeZone, createEnumeration,
                                  CVarRef countryRawOffset) {
  icu::StringEnumeration *se = nullptr;

  if (countryRawOffset.isNull()) {
    se = icu::TimeZone::createEnumeration();
  } else if (countryRawOffset.isNumeric(true)) {
    se = icu::TimeZone::createEnumeration((int32_t)countryRawOffset.toInt64());
  } else if (countryRawOffset.isString() || countryRawOffset.isObject()) {
    se = icu::TimeZone::createEnumeration(countryRawOffset.toString().c_str());
  } else {
    s_intl_error->set(U_ILLEGAL_ARGUMENT_ERROR,
                      "intltz_create_enumeration: invalid argument type");
    return false;
  }
  return IntlIterator::newInstance(se);
}