static VALUE get_stack_tail(VALUE stack, long len) { if (len < 0) return Qnil; /* system error */ if (len > RARRAY_LEN(stack)) len = RARRAY_LEN(stack); return rb_ary_subseq(stack, RARRAY_LEN(stack) - len, len); }
static VALUE initialize(int argc, VALUE argv[], VALUE self) { ffi_cif * cif; ffi_type **arg_types, *rtype; ffi_status result; VALUE ptr, args, ret_type, abi, kwds, ary; int i, len; int nabi; void *cfunc; rb_scan_args(argc, argv, "31:", &ptr, &args, &ret_type, &abi, &kwds); ptr = rb_Integer(ptr); cfunc = NUM2PTR(ptr); PTR2NUM(cfunc); nabi = NIL_P(abi) ? FFI_DEFAULT_ABI : NUM2INT(abi); abi = INT2FIX(nabi); i = NUM2INT(ret_type); rtype = INT2FFI_TYPE(i); ret_type = INT2FIX(i); Check_Type(args, T_ARRAY); len = RARRAY_LENINT(args); Check_Max_Args("args", len); ary = rb_ary_subseq(args, 0, len); for (i = 0; i < RARRAY_LEN(args); i++) { VALUE a = RARRAY_PTR(args)[i]; int type = NUM2INT(a); (void)INT2FFI_TYPE(type); /* raise */ if (INT2FIX(type) != a) rb_ary_store(ary, i, INT2FIX(type)); } OBJ_FREEZE(ary); rb_iv_set(self, "@ptr", ptr); rb_iv_set(self, "@args", args); rb_iv_set(self, "@return_type", ret_type); rb_iv_set(self, "@abi", abi); if (!NIL_P(kwds)) rb_hash_foreach(kwds, parse_keyword_arg_i, self); TypedData_Get_Struct(self, ffi_cif, &function_data_type, cif); arg_types = xcalloc(len + 1, sizeof(ffi_type *)); for (i = 0; i < RARRAY_LEN(args); i++) { int type = NUM2INT(RARRAY_AREF(args, i)); arg_types[i] = INT2FFI_TYPE(type); } arg_types[len] = NULL; result = ffi_prep_cif(cif, nabi, len, rtype, arg_types); if (result) rb_raise(rb_eRuntimeError, "error creating CIF %d", result); return self; }
PRIMITIVE VALUE vm_masgn_get_splat(VALUE ary, int before_splat_count, int after_splat_count) { const int len = RARRAY_LEN(ary); if (len > before_splat_count + after_splat_count) { return rb_ary_subseq(ary, before_splat_count, len - before_splat_count - after_splat_count); } else { return rb_ary_new(); } }
static inline VALUE args_rest_array(struct args_info *args) { VALUE ary; if (args->rest) { ary = rb_ary_subseq(args->rest, args->rest_index, RARRAY_LEN(args->rest) - args->rest_index); args->rest = 0; } else { ary = rb_ary_new(); } return ary; }
static VALUE array_spec_rb_ary_subseq(VALUE self, VALUE ary, VALUE begin, VALUE len) { return rb_ary_subseq(ary, FIX2LONG(begin), FIX2LONG(len)); }