Exemple #1
0
static void
ary_concat(mrb_state *mrb, struct RArray *a, struct RArray *a2)
{
  mrb_int len;

  if (ARY_LEN(a) == 0) {
    ary_replace(mrb, a, a2);
    return;
  }
  if (ARY_LEN(a2) > ARY_MAX_SIZE - ARY_LEN(a)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
  }
  len = ARY_LEN(a) + ARY_LEN(a2);

  ary_modify(mrb, a);
  if (ARY_CAPA(a) < len) {
    ary_expand_capa(mrb, a, len);
  }
  array_copy(ARY_PTR(a)+ARY_LEN(a), ARY_PTR(a2), ARY_LEN(a2));
  mrb_write_barrier(mrb, (struct RBasic*)a);
  ARY_SET_LEN(a, len);
}
static mrb_value
mrb_hmac_init(mrb_state *mrb, mrb_value self) {
  unsigned char *s;
  mrb_int len;
  mrb_value digester;
  mrb_value r;
  void *evp_func;
  mrb_digest *digest;
  void *hmac_init_ex;
  void *evp_md;
  mrb_digest_conf *c;

  digest = init(mrb, self);

  mrb_get_args(mrb, "so", &s, &len, &digester);

  r = mrb_funcall(mrb, digester, "to_s", 0);
  evp_func = get_evp_md_func(mrb, digest, RSTRING_PTR(r));

  c = get_digest_conf(RSTRING_PTR(r));
  if (c == NULL) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  }
  digest->block_size = c->block_size;
  digest->digest_size = c->digest_size;

  evp_md = call_digester(mrb, FFI_FN(evp_func));

  hmac_init_ex = get_hmac_init_ex_func(mrb, digest);

  call_hmac_init_ex(mrb, FFI_FN(hmac_init_ex), digest->ctx, s, len, evp_md, NULL);

  digest->handle = dlopen("libcrypto.so", RTLD_LAZY);

  DATA_PTR(self) = digest;
  DATA_TYPE(self) = &mrb_hmac_type;

  return self;
}
/* set_from
 *
 * Parameters:
 * - value: git_object *
 */
mrb_value
mrb_Git_Revspec_set_from(mrb_state* mrb, mrb_value self) {
  git_revspec * native_self = mruby_unbox_git_revspec(self);
  mrb_value from;

  mrb_get_args(mrb, "o", &from);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, from, Object_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Object expected");
    return mrb_nil_value();
  }

  git_object * native_from = (mrb_nil_p(from) ? NULL : mruby_unbox_git_object(from));

  native_self->from = native_from;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
static mrb_value
mrb_uefi_pointer_minus(mrb_state *mrb, mrb_value self)
{
    /* TODO */
    /* If @origin exists, check it. */
    mrb_value rhs;
    struct MRB_UEFI_POINTER_DATA *pd;

    mrb_get_args(mrb, "o", &rhs);
    pd = (struct MRB_UEFI_POINTER_DATA *)mrb_get_datatype(mrb, rhs, &mrb_uefi_pointer_type);
    if (pd){
        VOID *ptr = mrb_uefi_pointer_raw_value(mrb, self);
        return mrb_fixnum_value((mrb_int)((UINTN)ptr - (UINTN)pd->pointer));
    }else if (mrb_fixnum_p(rhs)){
        return mrb_uefi_pointer_plus_helper(mrb, self, -mrb_fixnum(rhs));
    }else{
        mrb_raise(mrb, E_TYPE_ERROR, "argument error");
    }

    /* Do not reach here. */
    return mrb_nil_value();
}
static mrb_value mrb_vedis_append_s(mrb_state *mrb, mrb_value key_obj, mrb_value val_obj, vedis *vstore)
{
    int ret;
    const char *key = NULL;

    switch (mrb_type(key_obj)) {
        case MRB_TT_STRING:
            key = RSTRING_PTR(key_obj);
            break;
        case MRB_TT_SYMBOL:
            key = mrb_sym2name(mrb, mrb_obj_to_sym(mrb, key_obj));
            break;
        default:
            mrb_raise(mrb, E_RUNTIME_ERROR, "vedis key type is string or symbol");
    }
    val_obj = mrb_obj_as_string(mrb, val_obj);
    ret = vedis_kv_append(vstore, key, strlen(key), RSTRING_PTR(val_obj), RSTRING_LEN(val_obj));
    if (ret != VEDIS_OK) {
        mrb_vedis_error(mrb, vstore, 0);
    }
    return mrb_true_value();
}
Exemple #6
0
mrb_value
cfunc_uint64_divide(mrb_state *mrb, mrb_value self)
{
    mrb_value mdivider;
    mrb_int divider;
    uint64_t result;
    struct cfunc_type_data *data = (struct cfunc_type_data*)DATA_PTR(self);
    uint64_t uint64 = data->value._uint64;
    if(data->refer) {
        uint64 = *(uint64_t*)data->value._pointer;
    }
    
    mrb_get_args(mrb, "o", &mdivider);
    divider = mrb_fixnum(mdivider);    
    result = uint64 / divider;
    
    if(result > UINT32_MAX) {
        mrb_raise(mrb, E_TYPE_ERROR, "result too big.");
    }
    
    return int64_to_mrb(mrb, uint64 / divider );
}
/* set_index_to_workdir
 *
 * Parameters:
 * - value: git_diff_delta *
 */
mrb_value
mrb_Git_StatusEntry_set_index_to_workdir(mrb_state* mrb, mrb_value self) {
  git_status_entry * native_self = mruby_unbox_git_status_entry(self);
  mrb_value index_to_workdir;

  mrb_get_args(mrb, "o", &index_to_workdir);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, index_to_workdir, DiffDelta_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "DiffDelta expected");
    return mrb_nil_value();
  }

  git_diff_delta * native_index_to_workdir = (mrb_nil_p(index_to_workdir) ? NULL : mruby_unbox_git_diff_delta(index_to_workdir));

  native_self->index_to_workdir = native_index_to_workdir;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
Exemple #8
0
/*
 *  call-seq:
 *     obj.method_missing(symbol [, *args] )   -> result
 *
 *  Invoked by Ruby when <i>obj</i> is sent a message it cannot handle.
 *  <i>symbol</i> is the symbol for the method called, and <i>args</i>
 *  are any arguments that were passed to it. By default, the interpreter
 *  raises an error when this method is called. However, it is possible
 *  to override the method to provide more dynamic behavior.
 *  If it is decided that a particular method should not be handled, then
 *  <i>super</i> should be called, so that ancestors can pick up the
 *  missing method.
 *  The example below creates
 *  a class <code>Roman</code>, which responds to methods with names
 *  consisting of roman numerals, returning the corresponding integer
 *  values.
 *
 *     class Roman
 *       def romanToInt(str)
 *         # ...
 *       end
 *       def method_missing(methId)
 *         str = methId.id2name
 *         romanToInt(str)
 *       end
 *     end
 *
 *     r = Roman.new
 *     r.iv      #=> 4
 *     r.xxiii   #=> 23
 *     r.mm      #=> 2000
 */
static mrb_value
mrb_bob_missing(mrb_state *mrb, mrb_value mod)
{
  mrb_value name, *a;
  int alen;
  mrb_value inspect;

  mrb_get_args(mrb, "o*", &name, &a, &alen);
  if (!mrb_symbol_p(name)) {
    mrb_raise(mrb, E_TYPE_ERROR, "name should be a symbol");
  }

  inspect = mrb_funcall(mrb, mod, "inspect", 0);
  if (RSTRING_LEN(inspect) > 64) {
    inspect = mrb_any_to_s(mrb, mod);
  }

  mrb_raisef(mrb, E_NOMETHOD_ERROR, "undefined method '%s' for %s",
      mrb_sym2name(mrb, mrb_symbol(name)), RSTRING_PTR(inspect));
  /* not reached */
  return mrb_nil_value();
}
Exemple #9
0
int
mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c)
{
  struct RClass *cl = mrb_class(mrb, obj);

  switch (c->tt) {
    case MRB_TT_MODULE:
    case MRB_TT_CLASS:
    case MRB_TT_ICLASS:
      break;

    default:
      mrb_raise(mrb, E_TYPE_ERROR, "class or module required");
  }

  while (cl) {
    if (cl == c || cl->mt == c->mt)
      return 1/* TRUE */;
    cl = cl->super;
  }
  return 0/* FALSE */;
}
/* set_oldest_commit
 *
 * Parameters:
 * - value: git_oid
 */
mrb_value
mrb_Git_BlameOptions_set_oldest_commit(mrb_state* mrb, mrb_value self) {
    git_blame_options * native_self = mruby_unbox_git_blame_options(self);
    mrb_value oldest_commit;

    mrb_get_args(mrb, "o", &oldest_commit);

    /* type checking */
    if (!mrb_obj_is_kind_of(mrb, oldest_commit, Oid_class(mrb))) {
        mrb_raise(mrb, E_TYPE_ERROR, "Oid expected");
        return mrb_nil_value();
    }

    git_oid native_oldest_commit = *(mruby_unbox_git_oid(oldest_commit));

    native_self->oldest_commit = native_oldest_commit;

    /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
    mrb_value value_as_mrb_value;
    mrb_get_args(mrb, "o", &value_as_mrb_value);
    return value_as_mrb_value;
}
mrb_value ruby_cocos2dx_experimental_video_VideoPlayer_create_static(mrb_state* mrb, mrb_value self)
{
    mrb_value* argv;
    int argc;
    mrb_get_args(mrb, "*", &argv, &argc);

    do {
        if (argc == 0) {
            std::map<std::string, mrb_value> callbacks;
            cocos2d::experimental::ui::VideoPlayer* retval = cocos2d::experimental::ui::VideoPlayer::create();
            mrb_value ret;
            RClass* rclass = mrb_class_ptr(self);
            ret = object_to_rubyval<cocos2d::experimental::ui::VideoPlayer>(mrb, "CCExp::VideoPlayer", (cocos2d::experimental::ui::VideoPlayer*)retval, rclass);
            mrb_funcall(mrb, ret, "initialize", 0);
            return ret;
        }
    } while (0);

    mrb_raise(mrb, E_RUNTIME_ERROR, "undefined static method : cocos2d::experimental::ui::VideoPlayer#create");

    return mrb_nil_value();
}
/* set_backend
 *
 * Parameters:
 * - value: git_odb_backend *
 */
mrb_value
mrb_Git_OdbStream_set_backend(mrb_state* mrb, mrb_value self) {
    git_odb_stream * native_self = mruby_unbox_git_odb_stream(self);
    mrb_value backend;

    mrb_get_args(mrb, "o", &backend);

    /* type checking */
    if (!mrb_obj_is_kind_of(mrb, backend, OdbBackend_class(mrb))) {
        mrb_raise(mrb, E_TYPE_ERROR, "OdbBackend expected");
        return mrb_nil_value();
    }

    git_odb_backend * native_backend = (mrb_nil_p(backend) ? NULL : mruby_unbox_git_odb_backend(backend));

    native_self->backend = native_backend;

    /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
    mrb_value value_as_mrb_value;
    mrb_get_args(mrb, "o", &value_as_mrb_value);
    return value_as_mrb_value;
}
Exemple #13
0
static mrb_value ngx_stream_mrb_errlogger(mrb_state *mrb, mrb_value self)
{
  mrb_value msg;
  mrb_int log_level;
  ngx_stream_mruby_internal_ctx_t *ictx = mrb->ud;
  ngx_stream_session_t *s = ictx->s;

  if (s == NULL) {
    mrb_raise(mrb, E_RUNTIME_ERROR, "can't use logger at this phase. only use at session stream phase");
  }

  mrb_get_args(mrb, "io", &log_level, &msg);
  if (log_level < 0) {
    ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "%s ERROR %s: log level is not positive number", MODULE_NAME,
                  __func__);
    return self;
  }
  msg = mrb_obj_as_string(mrb, msg);
  ngx_log_error((ngx_uint_t)log_level, s->connection->log, 0, "%s", mrb_str_to_cstr(mrb, msg));

  return self;
}
Exemple #14
0
static mrb_value
mrb_basicsocket_getpeereid(mrb_state *mrb, mrb_value self)
{ 
#ifdef HAVE_GETPEEREID
  mrb_value ary;
  gid_t egid;
  uid_t euid;
  int s;
  
  s = socket_fd(mrb, self);
  if (getpeereid(s, &euid, &egid) != 0)
    mrb_sys_fail(mrb, "getpeereid");

  ary = mrb_ary_new_capa(mrb, 2);
  mrb_ary_push(mrb, ary, mrb_fixnum_value((mrb_int)euid));
  mrb_ary_push(mrb, ary, mrb_fixnum_value((mrb_int)egid));
  return ary;
#else
  mrb_raise(mrb, E_RUNTIME_ERROR, "getpeereid is not avaialble on this system");
  return mrb_nil_value();
#endif
}
/* set_orig_signature
 *
 * Parameters:
 * - value: git_signature *
 */
mrb_value
mrb_Git_BlameHunk_set_orig_signature(mrb_state* mrb, mrb_value self) {
  git_blame_hunk * native_self = mruby_unbox_git_blame_hunk(self);
  mrb_value orig_signature;

  mrb_get_args(mrb, "o", &orig_signature);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, orig_signature, Signature_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Signature expected");
    return mrb_nil_value();
  }

  git_signature * native_orig_signature = (mrb_nil_p(orig_signature) ? NULL : mruby_unbox_git_signature(orig_signature));

  native_self->orig_signature = native_orig_signature;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
/* set_orig_commit_id
 *
 * Parameters:
 * - value: git_oid
 */
mrb_value
mrb_Git_BlameHunk_set_orig_commit_id(mrb_state* mrb, mrb_value self) {
  git_blame_hunk * native_self = mruby_unbox_git_blame_hunk(self);
  mrb_value orig_commit_id;

  mrb_get_args(mrb, "o", &orig_commit_id);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, orig_commit_id, Oid_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Oid expected");
    return mrb_nil_value();
  }

  git_oid native_orig_commit_id = *(mruby_unbox_git_oid(orig_commit_id));

  native_self->orig_commit_id = native_orig_commit_id;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
Exemple #17
0
static mrb_value h2o_mrb_set_request_headers_out(mrb_state *mrb, mrb_value self)
{
    h2o_mruby_internal_context_t *mruby_ctx = (h2o_mruby_internal_context_t *)mrb->ud;
    mrb_value key, val;
    char *key_cstr, *val_cstr;

    if (mruby_ctx->state != H2O_MRUBY_STATE_UNDETERMINED)
        mrb_raise(mrb, E_RUNTIME_ERROR, "response already sent");

    mrb_get_args(mrb, "oo", &key, &val);
    key = mrb_funcall(mrb, key, "downcase", 0);

    key_cstr = h2o_mem_alloc_pool(&mruby_ctx->req->pool, RSTRING_LEN(key));
    val_cstr = h2o_mem_alloc_pool(&mruby_ctx->req->pool, RSTRING_LEN(val));
    memcpy(key_cstr, RSTRING_PTR(key), RSTRING_LEN(key));
    memcpy(val_cstr, RSTRING_PTR(val), RSTRING_LEN(val));

    h2o_set_header_by_str(&mruby_ctx->req->pool, &mruby_ctx->req->res.headers, key_cstr, RSTRING_LEN(key), 0, val_cstr,
                          RSTRING_LEN(val), 1);

    return key;
}
Exemple #18
0
static mrb_value
mrb_str_byteslice(mrb_state *mrb, mrb_value str)
{
  mrb_value a1;
  mrb_int len;
  int argc;

  argc = mrb_get_args(mrb, "o|i", &a1, &len);
  if (argc == 2) {
    return mrb_str_substr(mrb, str, mrb_fixnum(a1), len);
  }
  switch (mrb_type(a1)) {
  case MRB_TT_RANGE:
    {
      mrb_int beg;

      len = RSTRING_LEN(str);
      switch (mrb_range_beg_len(mrb, a1, &beg, &len, len, TRUE)) {
      case 0:                   /* not range */
        break;
      case 1:                   /* range */
        return mrb_str_substr(mrb, str, beg, len);
      case 2:                   /* out of range */
        mrb_raisef(mrb, E_RANGE_ERROR, "%S out of range", a1);
        break;
      }
      return mrb_nil_value();
    }
  case MRB_TT_FLOAT:
    a1 = mrb_fixnum_value((mrb_int)mrb_float(a1));
    /* fall through */
  case MRB_TT_FIXNUM:
    return mrb_str_substr(mrb, str, mrb_fixnum(a1), 1);
  default:
    mrb_raise(mrb, E_TYPE_ERROR, "wrong type of argument");
  }
  /* not reached */
  return mrb_nil_value();
}
Exemple #19
0
mrb_value mrb_redis_connect(mrb_state *mrb, mrb_value self)
{
    mrb_value host, port;

    mrb_get_args(mrb, "oo", &host, &port);

    redisContext *rc = redisConnect(RSTRING_PTR(host), mrb_fixnum(port));
    if (rc->err)
        mrb_raise(mrb, E_RUNTIME_ERROR, "redis connection faild.");

    mrb_iv_set(mrb
        , self
        , mrb_intern(mrb, "redis_c")
        , mrb_obj_value(Data_Wrap_Struct(mrb
            , mrb->object_class
            , &redisContext_type
            , (void*) rc)
        )
    );

    return self;
}
Exemple #20
0
static mrb_value
mrb_hash_init(mrb_state *mrb, mrb_value hash)
{
  mrb_value block, ifnone;
  mrb_bool ifnone_p;

  ifnone = mrb_nil_value();
  mrb_get_args(mrb, "&|o?", &block, &ifnone, &ifnone_p);
  mrb_hash_modify(mrb, hash);
  if (!mrb_nil_p(block)) {
    if (ifnone_p) {
      mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
    }
    RHASH(hash)->flags |= MRB_HASH_PROC_DEFAULT;
    ifnone = block;
  }
  if (!mrb_nil_p(ifnone)) {
    RHASH(hash)->flags |= MRB_HASH_DEFAULT;
    mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone);
  }
  return hash;
}
Exemple #21
0
static struct timeval
time2timeval(mrb_state *mrb, mrb_value time)
{
  struct timeval t = { 0, 0 };

  switch (mrb_type(time)) {
    case MRB_TT_FIXNUM:
      t.tv_sec = mrb_fixnum(time);
      t.tv_usec = 0;
      break;

    case MRB_TT_FLOAT:
      t.tv_sec = mrb_float(time);
      t.tv_usec = (mrb_float(time) - t.tv_sec) * 1000000.0;
      break;

    default:
      mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }

  return t;
}
/* set_paths
 *
 * Parameters:
 * - value: git_strarray
 */
mrb_value
mrb_Git_CheckoutOptions_set_paths(mrb_state* mrb, mrb_value self) {
  git_checkout_options * native_self = mruby_unbox_git_checkout_options(self);
  mrb_value paths;

  mrb_get_args(mrb, "o", &paths);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, paths, Strarray_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Strarray expected");
    return mrb_nil_value();
  }

  git_strarray native_paths = *(mruby_unbox_git_strarray(paths));

  native_self->paths = native_paths;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
Exemple #23
0
mrb_value
convert_type(mrb_state *mrb, mrb_value val, const char *tname, const char *method, int raise)
{
  mrb_sym m = 0;

  m = mrb_intern(mrb, method);
  if (!mrb_respond_to(mrb, val, m)) {
    if (raise) {
      mrb_raise(mrb, E_TYPE_ERROR, "can't convert %s into %s",
         mrb_nil_p(val) ? "nil" :
         (mrb_type(val) == MRB_TT_TRUE) ? "true" :
         (mrb_type(val) == MRB_TT_FALSE) ? "false" :
         mrb_obj_classname(mrb, val),
         tname);
      return mrb_nil_value();
    }
    else {
      return mrb_nil_value();
    }
  }
  return mrb_funcall(mrb, val, method, 0);
}
/* set_baseline_index
 *
 * Parameters:
 * - value: git_index *
 */
mrb_value
mrb_Git_CheckoutOptions_set_baseline_index(mrb_state* mrb, mrb_value self) {
  git_checkout_options * native_self = mruby_unbox_git_checkout_options(self);
  mrb_value baseline_index;

  mrb_get_args(mrb, "o", &baseline_index);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, baseline_index, Index_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Index expected");
    return mrb_nil_value();
  }

  git_index * native_baseline_index = (mrb_nil_p(baseline_index) ? NULL : mruby_unbox_git_index(baseline_index));

  native_self->baseline_index = native_baseline_index;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
Exemple #25
0
/*
 *  call-seq:
 *     obj.instance_eval {| | block }                       -> obj
 *
 *  Evaluates the given block,within  the context of the receiver (_obj_). 
 *  In order to set the context, the variable +self+ is set to _obj_ while
 *  the code is executing, giving the code access to _obj_'s
 *  instance variables. In the version of <code>instance_eval</code>
 *  that takes a +String+, the optional second and third
 *  parameters supply a filename and starting line number that are used
 *  when reporting compilation errors.
 *
 *     class KlassWithSecret
 *       def initialize
 *         @secret = 99
 *       end
 *     end
 *     k = KlassWithSecret.new
 *     k.instance_eval { @secret }   #=> 99
 */
mrb_value
mrb_obj_instance_eval(mrb_state *mrb, mrb_value self)
{
  mrb_value a, b;
  mrb_value cv;
  struct RClass *c;

  if (mrb_get_args(mrb, "|S&", &a, &b) == 1) {
    mrb_raise(mrb, E_NOTIMP_ERROR, "instance_eval with string not implemented");
  }
  switch (mrb_type(self)) {
  case MRB_TT_SYMBOL:
  case MRB_TT_FIXNUM:
  case MRB_TT_FLOAT:
    c = 0;
    break;
  default:
    cv = mrb_singleton_class(mrb, self);
    c = mrb_class_ptr(cv);
  }
  return mrb_yield_internal(mrb, b, 0, 0, self, c);
}
/* set_parent
 *
 * Parameters:
 * - value: git_cred
 */
mrb_value
mrb_Git_CredSshCustom_set_parent(mrb_state* mrb, mrb_value self) {
  git_cred_ssh_custom * native_self = mruby_unbox_git_cred_ssh_custom(self);
  mrb_value parent;

  mrb_get_args(mrb, "o", &parent);

  /* type checking */
  if (!mrb_obj_is_kind_of(mrb, parent, Cred_class(mrb))) {
    mrb_raise(mrb, E_TYPE_ERROR, "Cred expected");
    return mrb_nil_value();
  }

  git_cred native_parent = *(mruby_unbox_git_cred(parent));

  native_self->parent = native_parent;
  
  /* Hacky way to return whatever was passed in. Mirrors typical assignment semantics. */
  mrb_value value_as_mrb_value;
  mrb_get_args(mrb, "o", &value_as_mrb_value);
  return value_as_mrb_value;
}
Exemple #27
0
static mrb_value
mrb_ary_unshift_m(mrb_state *mrb, mrb_value self)
{
  struct RArray *a = mrb_ary_ptr(self);
  mrb_value *vals, *ptr;
  mrb_int alen, len;

  mrb_get_args(mrb, "*!", &vals, &alen);
  if (alen == 0) {
    ary_modify_check(mrb, a);
    return self;
  }
  len = ARY_LEN(a);
  if (alen > ARY_MAX_SIZE - len) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
  }
  if (ARY_SHARED_P(a)
      && a->as.heap.aux.shared->refcnt == 1 /* shared only referenced from this array */
      && a->as.heap.ptr - a->as.heap.aux.shared->ptr >= alen) /* there's room for unshifted item */ {
    ary_modify_check(mrb, a);
    a->as.heap.ptr -= alen;
    ptr = a->as.heap.ptr;
  }
  else {
    ary_modify(mrb, a);
    if (ARY_CAPA(a) < len + alen)
      ary_expand_capa(mrb, a, len + alen);
    ptr = ARY_PTR(a);
    value_move(ptr + alen, ptr, len);
  }
  array_copy(ptr, vals, alen);
  ARY_SET_LEN(a, len+alen);
  while (alen--) {
    mrb_field_write_barrier_value(mrb, (struct RBasic*)a, vals[alen]);
  }

  return self;
}
Exemple #28
0
static mrb_value mrb_ecdsa_load_pem(mrb_state *mrb, mrb_value self) {
  ecdsa_context *ecdsa;
  pk_context pkey;
  mrb_value pem;
  int ret = 0;

  mrb_get_args(mrb, "S", &pem);

  pk_init( &pkey );

  ret = pk_parse_key(&pkey, RSTRING_PTR(pem), RSTRING_LEN(pem), NULL, 0);
  if (ret == 0) {
    ecdsa = DATA_CHECK_GET_PTR(mrb, self, &mrb_ecdsa_type, ecdsa_context);
    ret = ecdsa_from_keypair(ecdsa, pk_ec(pkey));
    if (ret == 0) {
      return mrb_true_value();
    }
  }

  pk_free( &pkey );
  mrb_raise(mrb, E_RUNTIME_ERROR, "can't parse pem");
  return mrb_false_value();
}
Exemple #29
0
void
mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val) /* rb_ary_store */
{
  struct RArray *a = mrb_ary_ptr(ary);

  ary_modify(mrb, a);
  /* range check */
  if (n < 0) {
    n += a->len;
    if (n < 0) {
      mrb_raise(mrb, E_INDEX_ERROR, "index %ld out of array", n - a->len);
    }
  }
  if (a->len <= (int)n) {
    if (a->aux.capa <= (int)n)
      ary_expand_capa(mrb, a, n + 1);
    ary_fill_with_nil(a->ptr + a->len, n + 1 - a->len);
    a->len = n + 1;
  }

  a->ptr[n] = val;
  mrb_write_barrier(mrb, (struct RBasic*)a);
}
Exemple #30
0
/*
 *  call-seq:
 *     raise
 *     raise(string)
 *     raise(exception [, string])
 *
 *  With no arguments, raises a <code>RuntimeError</code>
 *  With a single +String+ argument, raises a
 *  +RuntimeError+ with the string as a message. Otherwise,
 *  the first parameter should be the name of an +Exception+
 *  class (or an object that returns an +Exception+ object when sent
 *  an +exception+ message). The optional second parameter sets the
 *  message associated with the exception, and the third parameter is an
 *  array of callback information. Exceptions are caught by the
 *  +rescue+ clause of <code>begin...end</code> blocks.
 *
 *     raise "Failed to create socket"
 *     raise ArgumentError, "No parameters", caller
 */
mrb_value
mrb_f_raise(mrb_state *mrb, mrb_value self)
{
  mrb_value a[2];
  int argc;

  argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]);
  switch (argc) {
  case 0:
    mrb_raise(mrb, E_RUNTIME_ERROR, "");
    break;
  case 1:
    a[1] = mrb_check_string_type(mrb, a[0]);
    if (!mrb_nil_p(a[1])) {
      argc = 2;
      a[0] = mrb_obj_value(E_RUNTIME_ERROR);
    }
    /* fall through */
  default:
    mrb_exc_raise(mrb, mrb_make_exception(mrb, argc, a));
  }
  return mrb_nil_value();            /* not reached */
}