예제 #1
0
bool Array::more(CArrRef v2, bool flip /* = true */) const {
  if (m_px == nullptr || v2.get() == nullptr) {
    return HPHP::more(toBoolean(), v2.toBoolean());
  }
  if (flip) {
    return v2.get()->compare(m_px) < 0;
  }
  return m_px->compare(v2.get()) > 0;
}
예제 #2
0
/* SRC: ../../util/helper.php line 3 */
void f_print_arr(CVarRef v_the_arr) {
    FUNCTION_INJECTION(print_arr);
    INTERCEPT_INJECTION("print_arr", (Array(ArrayInit(1, true).set(0, v_the_arr).create())), r);
    String v_to_print;
    Variant v_element;

    v_to_print = NAMSTR(s_ss00000000, "");
    {
        LOOP_COUNTER(1);
        for (ArrayIterPtr iter3 = v_the_arr.begin(null_string, true); !iter3->end(); iter3->next()) {
            LOOP_COUNTER_CHECK(1);
            iter3->second(v_element);
            {
                v_to_print = concat3(v_to_print, toString(v_element), NAMSTR(s_ss00000000_1, " "));
            }
        }
    }
    v_to_print = concat(v_to_print, NAMSTR(s_ss66d2232c, "\n"));
    print(v_to_print);
} /* function */
Variant i_print_arr(void *extra, CArrRef params) {
    int count __attribute__((__unused__)) = params.size();
    if (count < 1) throw_missing_arguments("print_arr", count+1);
    {
        ArrayData *ad(params.get());
        ssize_t pos = ad ? ad->iter_begin() : ArrayData::invalid_index;
        CVarRef arg0(count <= 0 ? null_variant : (ad->getValue(pos)));
        return (f_print_arr(arg0), null);
    }
}
예제 #3
0
파일: ext.cpp 프로젝트: ckwalsh/hiphop-php
Variant EvalFunctionExists::InvokeImpl(VariableEnvironment &env,
                                       CArrRef params) {

  if (params.size() != 1) {
    return invalid_function_call("function_exists");
  }
  String fn = params.rvalAt(0).toString();
  if (s_blacklist.find(fn.data()) != s_blacklist.end()) return false;
  return f_function_exists(fn);
}
예제 #4
0
static void url_encode_array(StringBuffer &ret, CArrRef arr,
                             std::set<void*> &seen_arrs,
                             CStrRef num_prefix, CStrRef key_prefix,
                             CStrRef key_suffix, CStrRef arg_sep) {
  if (seen_arrs.find((void*)arr.get()) != seen_arrs.end()) {
    return; // recursive
  }
  seen_arrs.insert((void*)arr.get());

  for (ArrayIter iter(arr); iter; ++iter) {
    Variant data = iter.second();
    if (data.isNull() || data.isResource()) continue;

    String key = iter.first();
    bool numeric = key.isNumeric();

    if (data.is(KindOfArray) || data.is(KindOfObject)) {
      String encoded;
      if (numeric) {
        encoded = key;
      } else {
        encoded = StringUtil::UrlEncode(key);
      }
      StringBuffer new_prefix(key_prefix.size() + num_prefix.size() +
                              encoded.size() + key_suffix.size() + 4);
      new_prefix += key_prefix;
      if (numeric) new_prefix += num_prefix;
      new_prefix += encoded;
      new_prefix += key_suffix;
      new_prefix += "%5B";
      url_encode_array(ret, data.toArray(), seen_arrs, String(), new_prefix,
                       String("%5D", AttachLiteral), arg_sep);
    } else {
      if (!ret.empty()) {
        ret += arg_sep;
      }
      ret += key_prefix;
      if (numeric) {
        ret += num_prefix;
        ret += key;
      } else {
        ret += StringUtil::UrlEncode(key);
      }
      ret += key_suffix;
      ret += "=";
      if (data.isInteger() || data.is(KindOfBoolean)) {
        ret += String(data.toInt64());
      } else if (data.is(KindOfDouble)) {
        ret += String(data.toDouble());
      } else {
        ret += StringUtil::UrlEncode(data.toString());
      }
    }
  }
}
예제 #5
0
Variant EvalExtract::InvokeImpl(VariableEnvironment &env,
                                CArrRef params) {
  int size = params.size();
  switch (size) {
  case 1: return extract(&env,params.rvalAt(0));
  case 2: return extract(&env,params.rvalAt(0), params.rvalAt(1));
  case 3: return extract(&env,params.rvalAt(0), params.rvalAt(1),
                         params.rvalAt(2));
  default: throw InvalidFunctionCallException("extract");
  }
}
예제 #6
0
Variant EvalInterfaceExists::Invoke(CArrRef params) {
  String cname = params.rvalAt(0);
  if (!f_interface_exists(cname, false)) {
    if ((params.size() == 1 || params.rvalAt(1).toBoolean()) &&
        !f_class_exists(cname, false) &&
        eval_try_autoload(cname.data())) {
      return f_interface_exists(cname, false);
    }
    return false;
  }
  return true;
}
예제 #7
0
Variant EvalFuncGetArg::InvokeImpl(VariableEnvironment &env,
                                   CArrRef params) {
  int size = params.size();
  switch (size) {
  case 1: {
    int n = params.rvalAt(0);
    if (n >= 0 && n < env.getParams().size()) {
      return env.getParams().rvalAt(n);
    }
    return false;
  }
  default: throw InvalidFunctionCallException("func_get_arg");
  }
}
예제 #8
0
Array ArrayUtil::Combine(CArrRef keys, CArrRef values) {
  if (keys.size() != values.size()) {
    throw InvalidArgumentException("keys and values", "(not same count)");
  }
  if (keys.empty()) {
    throw InvalidArgumentException("keys and values", "(empty)");
  }

  Array ret = Array::Create();
  for (ArrayIter iter1(keys), iter2(values); iter1; ++iter1, ++iter2) {
    ret.set(iter1.second(), iter2.second());
  }
  return ret;
}
예제 #9
0
Variant c_Directory::i___construct(MethodCallPackage &mcp, CArrRef params) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::i_dummy(mcp, params, i___construct, coo_Directory);
  }
  c_Directory *self ATTRIBUTE_UNUSED (static_cast<c_Directory*>(mcp.obj));
  int count ATTRIBUTE_UNUSED = params.size();
  if (UNLIKELY(count != 1)) return throw_wrong_arguments("Directory::__construct", count, 1, 1, 2);
  {
    ArrayData *ad(params.get());
    ssize_t pos = ad ? ad->iter_begin() : ArrayData::invalid_index;
    CVarRef arg0((ad->getValue(pos)));
    return (self->t___construct(arg0), null);
  }
}
예제 #10
0
void VariableSerializer::write(CArrRef v) {
  if (m_type == APCSerialize && !v.isNull() && v->isStatic()) {
    union {
      char buf[8];
      ArrayData *ad;
    } u;
    u.ad = v.get();
    m_buf->append("A:");
    m_buf->append(u.buf, 8);
    m_buf->append(';');
  } else {
    v.serialize(this);
  }
}
예제 #11
0
void StreamContext::mergeParams(CArrRef params) {
  if (m_params.isNull()) {
    m_params = Array::Create();
  }
  const String& notification_key = String::FromCStr("notification");
  if (params.exists(notification_key)) {
    m_params.set(notification_key, params[notification_key]);
  }
  const String& options_key = String::FromCStr("options");
  if (params.exists(options_key)) {
    assert(params[options_key].isArray());
    mergeOptions(params[options_key].toArray());
  }
}
SharedVariant* SharedVariant::convertObj(CVarRef var) {
  if (!var.is(KindOfObject) || getObjAttempted()) {
    return NULL;
  }
  setObjAttempted();
  PointerSet seen;
  ObjectData *obj = var.getObjectData();
  CArrRef arr = obj->o_toArray();
  if (arr->hasInternalReference(seen, true)) {
    return NULL;
  }
  SharedVariant *tmp = new SharedVariant(var, false, true, true);
  tmp->setObjAttempted();
  return tmp;
}
예제 #13
0
void f_var_dump(int _argc, CVarRef expression,
                CArrRef _argv /* = null_array */) {
  f_var_dump(expression);
  for (int i = 0; i < _argv.size(); i++) {
    f_var_dump(_argv[i]);
  }
}
예제 #14
0
Variant c___php_incomplete_class::o_invoke(MethodIndex methodIndex, const char *s, CArrRef params, int64 hash, bool fatal) {
  int count __attribute__((__unused__)) = params.size();
#ifdef FMCGEN
#else
#endif
  return c_ObjectData::o_invoke(methodIndex, s, params, hash, fatal);
}
예제 #15
0
Variant ArrayUtil::Pad(CArrRef input, CVarRef pad_value, int pad_size,
                       bool pad_right /* = true */) {
  int input_size = input.size();
  if (input_size >= pad_size) {
    return input;
  }

  Array ret = Array::Create();
  if (pad_right) {
    ret = input;
    for (int i = input_size; i < pad_size; i++) {
      ret.append(pad_value);
    }
  } else {
    for (int i = input_size; i < pad_size; i++) {
      ret.append(pad_value);
    }
    for (ArrayIter iter(input); iter; ++iter) {
      Variant key(iter.first());
      if (key.isNumeric()) {
        ret.appendWithRef(iter.secondRef());
      } else {
        ret.setWithRef(key, iter.secondRef(), true);
      }
    }
  }
  return ret;
}
예제 #16
0
Variant c_stdClass::os_invoke(const char *c, MethodIndex methodIndex, const char *s,  CArrRef params, int64 hash, bool fatal) {
  int count __attribute__((__unused__)) = params.size();
  #ifndef NOFMCGEN
  #else
  #endif
  return c_ObjectData::os_invoke(c, methodIndex, s, params, hash, fatal);
}
예제 #17
0
void binary_deserialize_spec(CObjRef zthis, PHPInputTransport& transport,
                             CArrRef spec) {
  // SET and LIST have 'elem' => array('type', [optional] 'class')
  // MAP has 'val' => array('type', [optiona] 'class')
  while (true) {
    Variant val;

    int8_t ttype = transport.readI8();
    if (ttype == T_STOP) return;
    int16_t fieldno = transport.readI16();
    if (!(val = spec.rvalAt(fieldno)).isNull()) {
      Array fieldspec = val.toArray();
      // pull the field name
      // zend hash tables use the null at the end in the length... so strlen(hash key) + 1.
      String varname = fieldspec.rvalAt(PHPTransport::s_var).toString();

      // and the type
      int8_t expected_ttype = fieldspec.rvalAt(PHPTransport::s_type).toInt64();

      if (ttypes_are_compatible(ttype, expected_ttype)) {
        Variant rv = binary_deserialize(ttype, transport, fieldspec);
        zthis->o_set(varname, rv, zthis->o_getClassName());
      } else {
        skip_element(ttype, transport);
      }
    } else {
      skip_element(ttype, transport);
    }
  }
}
예제 #18
0
// TODO: Switch to AcrRec API once it lands
static bool HHVM_METHOD(IntlCalendar, __set_array, CArrRef args) {
  assert(args.size() == 6);
  CAL_FETCH(data, this_, false);

  // Assume at least two args because of PHP signature
  int32_t numargs;
  for (numargs = 2; numargs < 6; ++numargs) {
    if (args[numargs].isNull()) {
      break;
    }
  }

  if (numargs > 6) {
    data->setError(U_ILLEGAL_ARGUMENT_ERROR,
                   "intlcal_set: too many arguments");
    return false;
  }

  if (numargs == 2) {
    int32_t field = args[0].toInt64();
    CAL_CHECK_FIELD(field, "intcal_set");
    data->calendar()->set((UCalendarDateFields)field,
                          (int32_t)args[1].toInt64());
    return true;
  }

  int32_t intargs[6];
  assert(numargs <= 6);
  for (int i = 0; i < numargs; ++i) {
    int64_t arg = args[i].toInt64();
    if ((arg < INT32_MIN) || (arg > INT32_MAX)) {
      data->setError(U_ILLEGAL_ARGUMENT_ERROR,
                     "intlcal_set: at least one of the arguments has an "
                     "absolute value that is too large");
      return false;
    }
    intargs[i] = (int32_t)arg;
  }

  switch (numargs) {
    case 3: // year, month, day
      data->calendar()->set(intargs[0], intargs[1], intargs[2]);
      return true;
    case 4:
      data->setError(U_ILLEGAL_ARGUMENT_ERROR,
                     "intlcal_set: bad arguments");
      return false;
    case 5: // ..., hour, minute
      data->calendar()->set(intargs[0], intargs[1], intargs[2],
                            intargs[3], intargs[4]);
      return true;
    case 6: // ..., second
      data->calendar()->set(intargs[0], intargs[1], intargs[2],
                            intargs[3], intargs[4], intargs[5]);
      return true;
    default:
      not_reached();
      return false;
  }
}
예제 #19
0
void binary_serialize_spec(CObjRef zthis, PHPOutputTransport& transport,
                           CArrRef spec) {
  for (ArrayIter key_ptr = spec.begin(); !key_ptr.end(); ++key_ptr) {
    Variant key = key_ptr.first();
    if (!key.isInteger()) {
      throw_tprotocolexception("Bad keytype in TSPEC (expected 'long')", INVALID_DATA);
      return;
    }
    unsigned long fieldno = key.toInt64();
    Array fieldspec = key_ptr.second().toArray();

    // field name
    String varname = fieldspec.rvalAt(PHPTransport::s_var,
                                      AccessFlags::Error_Key).toString();

    // thrift type
    int8_t ttype = fieldspec.rvalAt(PHPTransport::s_type,
                                    AccessFlags::Error_Key).toByte();

    Variant prop = zthis->o_get(varname, true, zthis->o_getClassName());
    if (!prop.isNull()) {
      transport.writeI8(ttype);
      transport.writeI16(fieldno);
      binary_serialize(ttype, transport, prop, fieldspec);
    }
  }
  transport.writeI8(T_STOP); // struct end
}
예제 #20
0
Variant f_stream_context_create(CArrRef options /* = null_array */,
                                CArrRef params /* = null_array */) {
  if (!options.isNull() && !StreamContext::validateOptions(options)) {
    return false;
  }
  return Resource(NEWOBJ(StreamContext)(options, params));
}
예제 #21
0
Variant ArrayUtil::Slice(CArrRef input, int offset, int64_t length,
                         bool preserve_keys) {
  int num_in = input.size();
  if (offset > num_in) {
    offset = num_in;
  } else if (offset < 0 && (offset = (num_in + offset)) < 0) {
    offset = 0;
  }

  if (length < 0) {
    length = num_in - offset + length;
  } else if (((unsigned)offset + (unsigned)length) > (unsigned)num_in) {
    length = num_in - offset;
  }

  Array out_hash = Array::Create();
  int pos = 0;
  ArrayIter iter(input);
  for (; pos < offset && iter; ++pos, ++iter) {}
  for (; pos < offset + length && iter; ++pos, ++iter) {
    Variant key(iter.first());
    bool doAppend = !preserve_keys && key.isNumeric();
    CVarRef v = iter.secondRef();
    if (doAppend) {
      out_hash.appendWithRef(v);
    } else {
      out_hash.addLval(key, true).setWithRef(v);
    }
  }
  return out_hash;
}
예제 #22
0
Variant ArrayUtil::CreateArray(CArrRef keys, CVarRef value) {
  ArrayInit ai(keys.size());
  for (ArrayIter iter(keys); iter; ++iter) {
    ai.set(iter.secondRef(), value);
  }
  return ai.create();
}
예제 #23
0
void f_pcntl_exec(CStrRef path, CArrRef args /* = null_array */,
                  CArrRef envs /* = null_array */) {
  // build argumnent list
  std::vector<String> sargs; // holding those char *
  int size = args.size();
  char **argv = (char **)malloc((size + 2) * sizeof(char *));
  *argv = (char *)path.data();
  int i = 1;
  if (size) {
    sargs.reserve(size);
    for (ArrayIter iter(args); iter; ++iter, ++i) {
      String arg = iter.second().toString();
      sargs.push_back(arg);
      *(argv + i) = (char *)arg.data();
    }
  }
  *(argv + i) = NULL;

  // build environment pair list
  std::vector<String> senvs; // holding those char *
  char **envp = build_envp(envs, senvs);
  if (execve(path, argv, envp) == -1) {
    raise_warning("Error has occured: (errno %d) %s",
                    errno, Util::safe_strerror(errno).c_str());
  }

  free(envp);
  free(argv);
}
예제 #24
0
파일: pdo_sqlite.cpp 프로젝트: Dx3webs/hhvm
bool PDOSqliteConnection::create(CArrRef options) {
  String filename = data_source.substr(0,1) == ":" ? String(data_source) :
                    File::TranslatePath(data_source);
  if (filename.empty()) {
    throw_pdo_exception(0, Array(),
                        "safe_mode/open_basedir prohibits opening %s",
                        data_source.c_str());
    return false;
  }

  if (sqlite3_open(filename.data(), &m_db) != SQLITE_OK) {
    handleError(__FILE__, __LINE__);
    return false;
  }

  sqlite3_set_authorizer(m_db, authorizer, NULL);

  long timeout = 60;
  if (options.exists(PDO_ATTR_TIMEOUT)) {
    timeout = options[PDO_ATTR_TIMEOUT].toInt64();
  }
  sqlite3_busy_timeout(m_db, timeout * 1000);

  return true;
}
예제 #25
0
Variant EvalHphpGetClassInfo::Invoke(CArrRef params) {
  String cname = params.rvalAt(0);
  if (!f_class_exists(cname) && !f_interface_exists(cname)) {
    eval_try_autoload(cname.data());
  }
  return f_hphp_get_class_info(cname);
}
예제 #26
0
bool Array::MultiSort(std::vector<SortData> &data, bool renumber) {
  ASSERT(!data.empty());

  int count = -1;
  for (unsigned int k = 0; k < data.size(); k++) {
    SortData &opaque = data[k];

    ASSERT(opaque.array);
    ASSERT(opaque.cmp_func);
    int size = opaque.array->size();
    if (count == -1) {
      count = size;
    } else if (count != size) {
      throw_invalid_argument("arrays: (inconsistent sizes)");
      return false;
    }

    opaque.positions.reserve(size);
    CArrRef arr = *opaque.array;
    if (!arr.empty()) {
      for (ssize_t pos = arr->iter_begin(); pos != ArrayData::invalid_index;
           pos = arr->iter_advance(pos)) {
        opaque.positions.push_back(pos);
      }
    }
  }
  if (count == 0) {
    return true;
  }

  int *indices = (int *)malloc(sizeof(int) * count);
  for (int i = 0; i < count; i++) {
    indices[i] = i;
  }

  zend_qsort(indices, count, sizeof(int), multi_compare_func, (void *)&data);

  for (unsigned int k = 0; k < data.size(); k++) {
    SortData &opaque = data[k];
    CArrRef arr = *opaque.array;

    Array sorted;
    for (int i = 0; i < count; i++) {
      ssize_t pos = opaque.positions[indices[i]];
      Variant k(arr->getKey(pos));
      if (renumber && k.isInteger()) {
        sorted.append(arr->getValueRef(pos));
      } else {
        sorted.set(k, arr->getValueRef(pos));
      }
    }
    *opaque.original = sorted;
  }

  free(indices);
  return true;
}
예제 #27
0
파일: ext.cpp 프로젝트: Jostein/hiphop-php
Variant EvalFuncGetArg::InvokeImpl(VariableEnvironment &env,
                                   CArrRef params) {
  int size = params.size();
  switch (size) {
  case 1: {
    int n = params.rvalAt(0);
    if (ObjectData *cont = env.getContinuation()) {
      return cont->o_invoke("get_arg", CREATE_VECTOR1(n));
    }
    if (n >= 0 && n < env.getParams().size()) {
      return env.getParams().rvalAt(n);
    }
    return false;
  }
  default: return invalid_function_call("func_get_arg");
  }
}
예제 #28
0
void ArrayIter::begin(CArrRef map, CStrRef context) {
    try {
        new (this) ArrayIter(map.get());
    } catch (...) {
        m_data = NULL;
        throw;
    }
}
예제 #29
0
Variant ArrayUtil::Combine(CArrRef keys, CArrRef values) {
  if (keys.size() != values.size()) {
    throw_invalid_argument("keys and values not same count");
    return false;
  }
  if (keys.empty()) {
    throw_invalid_argument("keys and values empty");
    return false;
  }

  Array ret = Array::Create();
  for (ArrayIter iter1(keys), iter2(values); iter1; ++iter1, ++iter2) {
    CVarRef v(iter2.secondRef());
    ret.lvalAt(iter1.secondRef()).setWithRef(v);
  }
  return ret;
}
예제 #30
0
Variant f_sscanf(int _argc, CStrRef str, CStrRef format, CArrRef _argv /* = null_array */) {
  Variant ret;
  int result;
  result = string_sscanf(str, format, _argv.size(), ret);
  if (SCAN_ERROR_WRONG_PARAM_COUNT == result) return null;
  if (_argv.empty()) return ret;

  if (ret.isArray()) {
    Array retArray = ret.toArray();
    for (int i = 0; i < retArray.size(); i++) {
      ((Array&)_argv).lvalAt(i) = retArray[i];
    }
    return retArray.size();
  }
  if (ret.isNull()) return 0;
  return ret;
}