Пример #1
0
bool f_xml_parser_set_option(CObjRef parser, int option, CVarRef value) {
  XmlParser * p = parser.getTyped<XmlParser>();
  switch (option) {
  case PHP_XML_OPTION_CASE_FOLDING:
    p->case_folding = value.toInt64();
    break;
  case PHP_XML_OPTION_SKIP_TAGSTART:
    p->toffset = value.toInt64();
    break;
  case PHP_XML_OPTION_SKIP_WHITE:
    p->skipwhite = value.toInt64();
    break;
  case PHP_XML_OPTION_TARGET_ENCODING: {
    xml_encoding *enc;
    enc = xml_get_encoding((const XML_Char*)value.toString().data());
    if (enc == NULL) {
      raise_warning("Unsupported target encoding \"%s\"",
                    value.toString().data());
      return false;
    }
    p->target_encoding = enc->name;
    break;
  }
  default:
    raise_warning("Unknown option");
    return false;
  }
  return true;
}
Пример #2
0
static bool ctype(CVarRef v, int (*iswhat)(int)) {
  if (v.isInteger()) {
    int64_t n = v.toInt64();
    if (n <= 255 && n >= 0) {
      return iswhat(n);
    }

    if (n >= -128 && n < 0) {
      return iswhat(n + 256);
    }

    return ctype(v.toString(), iswhat);
  }

  if (v.isString()) {
    String s = v.toString();
    if (!s.empty()) {
      const char *p = s.data();
      const char *e = s.data() + s.size();
      while (p < e) {
        if (!iswhat((int)*(unsigned char *)(p++))) {
          return false;
        }
      }
      return true;
    }
  }
  return false;
}
Пример #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);
}
Пример #4
0
Variant f_json_decode(CStrRef json, bool assoc /* = false */,
                      CVarRef options /* = 0 */) {
  if (json.empty()) {
    return null;
  }

  int64 json_options = options.toInt64();;
  if (options.isBoolean() && options.toBooleanVal()) {
    json_options = k_JSON_FB_LOOSE;
  }

  Variant z;
  if (JSON_parser(z, json.data(), json.size(), assoc, (json_options & k_JSON_FB_LOOSE))) {
    return z;
  }

  if (json.size() == 4) {
    if (!strcasecmp(json.data(), "null")) return null;
    if (!strcasecmp(json.data(), "true")) return true;
  } else if (json.size() == 5 && !strcasecmp(json.data(), "false")) {
    return false;
  }

  int64 p;
  double d;
  DataType type = json->isNumericWithVal(p, d, 0);
  if (type == KindOfInt64) {
    return p;
  } else if (type == KindOfDouble) {
    return d;
  }

  return null;
}
bool UnaryOpExpression::preCompute(CVarRef value, Variant &result) {
  switch(m_op) {
  case '!':
    result = (!toBoolean(value)); break;
  case '+':
    result = value.unary_plus(); break;
  case '-':
    result = value.negate(); break;
  case '~':
    result = ~value; break;
  case '(':
  case '@':
    result = value; break;
  case T_INT_CAST:
    result = value.toInt64(); break;
  case T_DOUBLE_CAST:
    result = toDouble(value); break;
  case T_STRING_CAST:
    result = toString(value); break;
  case T_BOOL_CAST:
    result = toBoolean(value); break;
  case T_INC:
  case T_DEC:
    ASSERT(false);
  default:
    return false;
  }
  return true;
}
Пример #6
0
void MapVariant::insertKeyAtPos(int pos) {
    const std::vector<Variant> &keys = getKeyVector();

    HphpMapVariantToInt newmap;
    m_nextIndex = 0;
    for (int i = 0; i <= (int)keys.size(); i++) {
        if (i == pos) {
            Variant newkey((int64)m_nextIndex++);
            newmap[newkey] = pos;
        } else {
            CVarRef key = keys[i > pos ? i-1 : i];
            int value = m_map[key];
            if (value >= pos) value++;
            if (key.isInteger() && key.toInt64() >= 0) {
                Variant newkey((int64)m_nextIndex++);
                newmap[newkey] = value;
            } else {
                newmap[key] = value;
            }
        }
    }
    m_map.swap(newmap);

    resetKeyVector();
}
Пример #7
0
HOT_FUNC
void ImmutableMap::add(int pos, CVarRef key, CVarRef val, bool unserializeObj) {
  int64_t ikey;
  StringData* skey;
  int32_t hash;
  Bucket* b = buckets() + pos;

  switch (key.getType()) {
    case KindOfInt64: {
      hash = ikey = key.toInt64();
      b->setIntKey(ikey);
      break;
    }
    case KindOfString: {
      skey = StringData::GetStaticString(key.getStringData());
      goto static_case;
    }
    case KindOfStaticString: {
      skey = key.getStringData();
static_case:
      hash = skey->hash();
      b->setStrKey(skey, hash);
      break;
    }
    default: not_reached();
  }
  addVal(pos, hash & m.m_capacity_mask, val, unserializeObj);
}
Пример #8
0
int64 HphpMap::hash(CVarRef s) {
  int64 hash;
  switch (s.getType()) {
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    hash = hash_int64(s.toInt64());
    break;
  case LiteralString:
    {
      const char* d = s.getLiteralString();
      hash = hash_string(d, strlen(d));
    }
    break;
  case KindOfString:
    {
      StringData *st = s.getStringData();
      hash = hash_string(st->data(), st->size());
    }
    break;
  default:
    ASSERT(false);
    return 0;
  }
  return hash;
}
Пример #9
0
bool f_pcntl_signal(int signo, CVarRef handler,
                    bool restart_syscalls /* = true */) {
  /* Special long value case for SIG_DFL and SIG_IGN */
  if (handler.isInteger()) {
    int64_t handle = handler.toInt64();
    if (handle != (long)SIG_DFL && handle != (long)SIG_IGN) {
      raise_warning("Invalid value for handle argument specified");
    }
    if (php_signal(signo, (Sigfunc *)handle, restart_syscalls) == SIG_ERR) {
      raise_warning("Error assigning signal");
      return false;
    }
    return true;
  }

  if (!f_is_callable(handler)) {
    raise_warning("%s is not a callable function name error",
                    handler.toString().data());
    return false;
  }

  s_signal_handlers->handlers.set(signo, handler);

  if (php_signal(signo, pcntl_signal_handler, restart_syscalls) == SIG_ERR) {
    raise_warning("Error assigning signal");
    return false;
  }
  return true;
}
Пример #10
0
static Variant HHVM_STATIC_METHOD(IntlTimeZone, createTimeZoneIDEnumeration,
                                  int64_t zoneType,
                                  const String& region,
                                  CVarRef offset) {
  if (zoneType != UCAL_ZONE_TYPE_ANY &&
      zoneType != UCAL_ZONE_TYPE_CANONICAL &&
      zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
    s_intl_error->set(U_ILLEGAL_ARGUMENT_ERROR,
                      "intltz_create_time_zone_id_enumeration: bad zone type");
    return false;
  }

  int32_t *pofs = nullptr;
  int32_t   ofs = 0;
  if (offset.isInitialized()) {
    ofs = offset.toInt64();
    pofs = &ofs;
  }

  UErrorCode error = U_ZERO_ERROR;
  auto se = icu::TimeZone::createTimeZoneIDEnumeration(
                                 (USystemTimeZoneType)zoneType,
                                 region.c_str(), pofs, error);
  if (U_FAILURE(error)) {
    s_intl_error->set(error, "intltz_create_time_zone_id_enumeration: "
                             "Error obtaining time zone id enumeration");
    return false;
  }
  return IntlIterator::newInstance(se);
}
Пример #11
0
bool BaseVector::containskey(CVarRef key) {
  if (key.isInteger()) {
    return contains(key.toInt64());
  }
  throwBadKeyType();
  return false;
}
Пример #12
0
Variant BaseVector::at(CVarRef key) {
  if (key.isInteger()) {
    return tvAsCVarRef(at(key.toInt64()));
  }
  throwBadKeyType();
  return uninit_null();
}
Пример #13
0
ssize_t GlobalArrayWrapper::getIndex(CVarRef k,
                                     int64 prehash /* = -1*/) const {
  if (k.isInteger()) {
    return ((Array*)m_globals)->get()->getIndex(k.toInt64(), prehash) +
      m_globals->size();
  }
  return m_globals->getIndex(k.toString().data(), prehash);
}
Пример #14
0
bool PDOSqliteConnection::setAttribute(int64_t attr, CVarRef value) {
  switch (attr) {
  case PDO_ATTR_TIMEOUT:
    sqlite3_busy_timeout(m_db, value.toInt64() * 1000);
    return true;
  }
  return false;
}
Пример #15
0
String f_json_encode(CVarRef value, CVarRef options /* = 0 */) {
  int64 json_options = options.toInt64();
  if (options.isBoolean() && options.toBooleanVal()) {
    json_options = k_JSON_FB_LOOSE;
  }

  VariableSerializer vs(VariableSerializer::JSON, json_options);
  return vs.serialize(value, true);
}
Пример #16
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;
}
Пример #17
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;
}
Пример #18
0
String f_json_encode(CVarRef value, CVarRef options /* = 0 */) {
  int64_t json_options = options.toInt64();
  if (options.isBoolean() && options.toBooleanVal()) {
    json_options = k_JSON_FB_LOOSE;
  }

  VariableSerializer vs(VariableSerializer::Type::JSON, json_options);
  return vs.serializeValue(value, !(json_options & k_JSON_FB_UNLIMITED));
}
Пример #19
0
Variant f_json_decode(const String& json, bool assoc /* = false */,
                      CVarRef options /* = 0 */) {

  json_set_last_error_code(json_error_codes::JSON_ERROR_NONE);

  if (json.empty()) {
    return uninit_null();
  }

  int64_t json_options = options.toInt64();
  if (options.isBoolean() && options.toBooleanVal()) {
    json_options = k_JSON_FB_LOOSE;
  }

  const int64_t supported_options =
    k_JSON_FB_LOOSE | k_JSON_FB_COLLECTIONS | k_JSON_FB_STABLE_MAPS;
  Variant z;
  if (JSON_parser(z, json.data(), json.size(), assoc,
                  (json_options & supported_options))) {
    return z;
  }

  if (json.size() == 4) {
    if (!strcasecmp(json.data(), "null")) return uninit_null();
    if (!strcasecmp(json.data(), "true")) return true;
  } else if (json.size() == 5 && !strcasecmp(json.data(), "false")) {
    return false;
  }

  int64_t p;
  double d;
  DataType type = json->isNumericWithVal(p, d, 0);
  if (type == KindOfInt64) {
    return p;
  } else if (type == KindOfDouble) {
    return d;
  }

  char ch0 = json.charAt(0);
  if (json.size() > 1 && ch0 == '"' && json.charAt(json.size() - 1) == '"') {
    return json.substr(1, json.size() - 2);
  }

  if ((json_options & k_JSON_FB_LOOSE) && json.size() > 1 &&
      ch0 == '\'' && json.charAt(json.size() - 1) == '\'') {
    return json.substr(1, json.size() - 2);
  }

  if (ch0 == '{' || ch0 == '[') { /* invalid JSON string */
    json_set_last_error_code(json_error_codes::JSON_ERROR_SYNTAX);
  }

  assert(json_get_last_error_code() != json_error_codes::JSON_ERROR_NONE);
  return uninit_null();
}
Пример #20
0
bool UnaryOpExpression::preCompute(CVarRef value, Variant &result) {
  bool ret = true;
  try {
    g_context->setThrowAllErrors(true);
    switch(m_op) {
      case '!':
        result = (!toBoolean(value)); break;
      case '+':
        cellSet(cellAdd(make_tv<KindOfInt64>(0), *value.asCell()),
                *result.asCell());
        break;
      case '-':
        cellSet(cellSub(make_tv<KindOfInt64>(0), *value.asCell()),
                *result.asCell());
        break;
      case '~':
        tvSet(*value.asCell(), *result.asTypedValue());
        cellBitNot(*result.asCell());
        break;
      case '@':
        result = value;
        break;
      case T_INT_CAST:
        result = value.toInt64();
        break;
      case T_DOUBLE_CAST:
        result = toDouble(value);
        break;
      case T_STRING_CAST:
        result = toString(value);
        break;
      case T_BOOL_CAST:
        result = toBoolean(value);
        break;
      case T_EMPTY:
        result = !toBoolean(value);
        break;
      case T_ISSET:
        result = is_not_null(value);
        break;
      case T_INC:
      case T_DEC:
        assert(false);
      default:
        ret = false;
        break;
    }
  } catch (...) {
    ret = false;
  }
  g_context->setThrowAllErrors(false);
  return ret;
}
Пример #21
0
Variant BaseVector::get(CVarRef key) {
  if (key.isInteger()) {
    TypedValue* tv = get(key.toInt64());
    if (tv) {
      return tvAsCVarRef(tv);
    } else {
      return uninit_null();
    }
  }
  throwBadKeyType();
  return uninit_null();
}
Пример #22
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);
}
Пример #23
0
void c_DebuggerClientCmdUser::t_addcompletion(CVarRef list) {
  INSTANCE_METHOD_INJECTION_BUILTIN(DebuggerClientCmdUser, DebuggerClientCmdUser::addcompletion);
  if (list.isInteger()) {
    m_client->addCompletion((DebuggerClient::AutoComplete)list.toInt64());
  } else {
    Array arr = list.toArray(); // handles string, array and iterators
    std::vector<std::string> items;
    for (ArrayIter iter(arr); iter; ++iter) {
      items.push_back(iter.second().toString()->toCPPString());
    }
    m_client->addCompletion(items);
  }
}
Пример #24
0
void Array::remove(CVarRef key) {
  switch(key.getType()) {
  case KindOfBoolean:
  case KindOfInt64:
    removeImpl(key.toInt64());
    return;
  default:
    break;
  }
  VarNR k(key.toKey());
  if (!k.isNull()) {
    removeImpl(k);
  }
}
Пример #25
0
int MapVariant::insertKey(CVarRef key, int64 prehash /* = -1 */) {
    int res;
    ASSERT(key.isInteger() || key.isString());
    if (m_map.insert(key, m_elems.size(), res, prehash)) {
        if (m_keys) {
            m_keys->push_back(key);
        }
        if (key.isInteger()) {
            int64 index = key.toInt64();
            if (index + 1 > m_nextIndex) m_nextIndex = index + 1;
        }
    }
    return res;
}
Пример #26
0
Variant f_json_decode(CStrRef json, bool assoc /* = false */,
                      CVarRef options /* = 0 */) {
  if (json.empty()) {
    return uninit_null();
  }

  int64_t json_options = options.toInt64();
  if (options.isBoolean() && options.toBooleanVal()) {
    json_options = k_JSON_FB_LOOSE;
  }

  Variant z;
  if (JSON_parser(z, json.data(), json.size(), assoc,
                  (json_options & k_JSON_FB_LOOSE))) {
    return z;
  }

  if (json.size() == 4) {
    if (!strcasecmp(json.data(), "null")) return uninit_null();
    if (!strcasecmp(json.data(), "true")) return true;
  } else if (json.size() == 5 && !strcasecmp(json.data(), "false")) {
    return false;
  }

  int64_t p;
  double d;
  DataType type = json->isNumericWithVal(p, d, 0);
  if (type == KindOfInt64) {
    return p;
  } else if (type == KindOfDouble) {
    return d;
  }

  char ch0 = json.charAt(0);
  if (json.size() > 1 && ch0 == '"' && json.charAt(json.size() - 1) == '"') {
    return json.substr(1, json.size() - 2);
  }

  if ((json_options & k_JSON_FB_LOOSE) && json.size() > 1 &&
      ch0 == '\'' && json.charAt(json.size() - 1) == '\'') {
    return json.substr(1, json.size() - 2);
  }

  if (ch0 == '{' || ch0 == '[') { /* invalid JSON string */
    return uninit_null();
  }

  return json;
}
Пример #27
0
bool Array::exists(CVarRef key, bool isKey /* = false */) const {
    switch(key.getType()) {
    case KindOfBoolean:
    case KindOfInt64:
        return existsImpl(key.toInt64());
    default:
        break;
    }
    if (isKey) return existsImpl(key);
    VarNR k(key.toKey());
    if (!k.isNull()) {
        return existsImpl(k);
    }
    return false;
}
Пример #28
0
void Array::remove(CVarRef key, int64 prehash /* = -1 */) {
  switch(key.getType()) {
  case KindOfBoolean:
  case KindOfByte:
  case KindOfInt16:
  case KindOfInt32:
  case KindOfInt64:
    removeImpl(key.toInt64(), prehash);
    return;
  default:
    break;
  }
  Variant k = key.toKey();
  if (!k.isNull()) {
    removeImpl(k, prehash);
  }
}
Пример #29
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);
}
Пример #30
0
static bool HHVM_METHOD(IntlCalendar, roll, int64_t field, CVarRef value) {
  CAL_FETCH(data, this_, false);
  CAL_CHECK_FIELD(field, "intlcal_roll");
  UErrorCode error = U_ZERO_ERROR;
  if (value.isBoolean()) {
    data->calendar()->roll((UCalendarDateFields)field,
                           (UBool)value.toBoolean(), error);
  } else {
    data->calendar()->roll((UCalendarDateFields)field,
                           (int32_t)value.toInt64(), error);
  }
  if (U_FAILURE(error)) {
    data->setError(error, "intlcal_roll: Error calling ICU Calendar::roll");
    return false;
  }
  return true;
}