VALUE util_spec_rb_scan_args(VALUE self, VALUE argv, VALUE fmt, VALUE expected, VALUE acc) { int i, result, argc = RARRAY_LEN(argv); VALUE args[4], failed, a1, a2, a3, a4; failed = rb_intern("failed"); a1 = a2 = a2 = a4 = failed; for(i = 0; i < argc; i++) { args[i] = rb_ary_entry(argv, i); } result = rb_scan_args(argc, args, RSTRING_PTR(fmt), &a1, &a2, &a3, &a4); switch(NUM2INT(expected)) { case 4: rb_ary_unshift(acc, a4); case 3: rb_ary_unshift(acc, a3); case 2: rb_ary_unshift(acc, a2); case 1: rb_ary_unshift(acc, a1); break; default: rb_raise(rb_eException, "unexpected number of arguments returned by rb_scan_args"); } return INT2NUM(result); }
static VALUE rg_invoke(VALUE self, VALUE rb_arguments) { GIFunctionInfo *info; VALUE rb_out_args; VALUE rb_return_value; info = SELF(self); /* TODO: use rb_protect() */ rb_out_args = rb_gi_function_info_invoke_raw(info, self, Qnil, rb_arguments, NULL, &rb_return_value); if (NIL_P(rb_out_args)) { return rb_return_value; } else { GICallableInfo *callable_info = (GICallableInfo *)info; GITypeInfo return_value_info; g_callable_info_load_return_type(callable_info, &return_value_info); if (g_type_info_get_tag(&return_value_info) != GI_TYPE_TAG_VOID) { rb_ary_unshift(rb_out_args, rb_return_value); } if (RARRAY_LEN(rb_out_args) == 1) { return RARRAY_PTR(rb_out_args)[0]; } else { return rb_out_args; } } }
/* * call-seq: * each(*args) -> Enumerator * each(*args) { |item| block } -> Enumerator * * Iterate over the collection, passing each item to a given block. * If no block was supplied, return an enumerator for the collection. * */ static VALUE rbpod_collection_each(VALUE self, VALUE argv) { GList *current = NULL, *collection = TYPED_DATA_PTR(self, GList); VALUE klass, item, arguments; /* Return an enumerator if a block was not supplied. */ RETURN_ENUMERATOR(self, 0, 0); /* What sort of items are we casting this data to? */ klass = rb_funcall(self, rb_intern("type"), 0); /* Create a shallow copy of the passed arguments. */ arguments = rb_ary_dup(argv); /* Prepend an empty element as a placeholder. */ rb_ary_unshift(arguments, Qnil); /* If we were supplied a block, enumerate the entire list. */ for (current = collection; current != NULL; current = g_list_next(current)) { /* TODO: Find a better workaround than this or Data_Wrap_Struct. */ item = rb_class_new_instance_with_data(0, NULL, klass, current->data); rb_ary_store(arguments, 0, item); rb_yield_splat(arguments); } return self; }
VALUE do_sqlite3_cConnection_quote_byte_array(VALUE self, VALUE string) { VALUE source = StringValue(string); VALUE array = rb_funcall(source, rb_intern("unpack"), 1, rb_str_new2("H*")); rb_ary_unshift(array, rb_str_new2("X'")); rb_ary_push(array, rb_str_new2("'")); return rb_ary_join(array, Qnil); }
static VALUE rb_queue_marshal_dump(VALUE self) { Queue *queue; VALUE array; Data_Get_Struct(self, Queue, queue); array = array_from_list(&queue->values); rb_ary_unshift(array, ULONG2NUM(queue->capacity)); return rb_marshal_dump(array, Qnil); }
static VALUE initrb_interpreter_begin(VALUE file) { /** `file' may be a symlink or a relative path, expand it and dereference all symlinks **/ VALUE real_name = rb_funcall(rb_cFile, rb_intern("realpath"), 1, file); VALUE dir = rb_file_dirname(real_name); /** Add the file's directory to the library search path **/ rb_ary_unshift(rb_gv_get(":"), dir); /** Run the interpreter */ return initrb_interpreter_boot(real_name); }
static void call_expr_userfnc (ABSTRACT_CALLER* callback_state, ABSTRACT_ARGLIST* arglist, ABSTRACT_USERFUNC* hashvalptr, ABSTRACT_EXPRVAL* exprval) { char* empty = ""; VALUE self = (VALUE)callback_state; VALUE func = (VALUE)hashvalptr; VALUE args = (VALUE)arglist; PSTRING retvalpstr = { empty, empty }; if (hashvalptr==NULL) { rb_raise(rb_eRuntimeError, "FATAL INTERNAL ERROR:Call_EXPR:function called but not exists"); tmplpro_set_expr_as_pstring(exprval, retvalpstr); return; } else if (NIL_P(func) || !rb_obj_is_kind_of(func, rb_cProc)) { rb_raise(rb_eRuntimeError, "FATAL INTERNAL ERROR:Call_EXPR:not a Proc object"); tmplpro_set_expr_as_pstring(exprval, retvalpstr); return; } /* head of args is not a true aruguments(it is a regisotry of args). */ VALUE tmp = rb_ary_shift(args); VALUE retval = rb_proc_call(func, args); rb_ary_unshift(args, tmp); VALUE registory = Qnil; switch (TYPE(retval)) { case T_FIXNUM: tmplpro_set_expr_as_int64(exprval, FIX2LONG(retval)); break; case T_TRUE: tmplpro_set_expr_as_int64(exprval, 1); break; case T_FALSE: tmplpro_set_expr_as_int64(exprval, 0); break; case T_FLOAT: tmplpro_set_expr_as_double(exprval, NUM2DBL(retval)); break; case T_NIL: tmplpro_set_expr_as_null(exprval); break; default: registory = rb_ivar_get(self, rb_intern("@internal_expr_results")); rb_ary_push(registory, retval); retvalpstr.begin = StringValuePtr(retval); retvalpstr.endnext = retvalpstr.begin + RSTRING_LEN(retval); tmplpro_set_expr_as_pstring(exprval, retvalpstr); } return; }
static VALUE rf_mcall(const char *path, ID method, char *methname, VALUE arg) { int error; VALUE result; VALUE methargs; if (!rb_respond_to(FuseRoot,method)) { return Qnil; } if (arg == Qnil) { debug(" root.%s(%s)\n", methname, path ); } else { debug(" root.%s(%s,...)\n", methname, path ); } if (TYPE(arg) == T_ARRAY) { methargs = arg; } else if (arg != Qnil) { methargs = rb_ary_new(); rb_ary_push(methargs,arg); } else { methargs = rb_ary_new(); } rb_ary_unshift(methargs,rb_str_new2(path)); rb_ary_unshift(methargs,ID2SYM(method)); /* Set up the call and make it. */ result = rb_protect(rf_protected, methargs, &error); /* Did it error? */ if (error) return Qnil; return result; }
static VALUE set_backtrace(VALUE exc, const char *file, int line) { char errmsg[64]; VALUE backtrace; #ifdef _WIN32 char *p = strrchr(file, '\\'); if (p != NULL) file = p + 1; #endif backtrace = rb_funcall(rb_cObject, oci8_id_caller, 0); if (TYPE(backtrace) == T_ARRAY) { snprintf(errmsg, sizeof(errmsg), "%s:%d:in " STRINGIZE(oci8lib) DLEXT, file, line); errmsg[sizeof(errmsg) - 1] = '\0'; rb_ary_unshift(backtrace, rb_usascii_str_new_cstr(errmsg)); rb_funcall(exc, oci8_id_set_backtrace, 1, backtrace); } return exc; }
static inline void args_copy(struct args_info *args) { if (args->rest != Qfalse) { int argc = args->argc; args->argc = 0; args->rest = rb_ary_dup(args->rest); /* make dup */ /* * argv: [m0, m1, m2, m3] * rest: [a0, a1, a2, a3, a4, a5] * ^ * rest_index * * #=> first loop * * argv: [m0, m1] * rest: [m2, m3, a2, a3, a4, a5] * ^ * rest_index * * #=> 2nd loop * * argv: [] (argc == 0) * rest: [m0, m1, m2, m3, a2, a3, a4, a5] * ^ * rest_index */ while (args->rest_index > 0 && argc > 0) { RARRAY_ASET(args->rest, --args->rest_index, args->argv[--argc]); } while (argc > 0) { rb_ary_unshift(args->rest, args->argv[--argc]); } } else if (args->argc > 0) { args->rest = rb_ary_new_from_values(args->argc, args->argv); args->rest_index = 0; args->argc = 0; } }
static VALUE rb_struct_s_def(int argc, VALUE *argv, VALUE klass) { VALUE name, rest; long i; VALUE st; ID id; rb_scan_args(argc, argv, "1*", &name, &rest); if (!NIL_P(name) && SYMBOL_P(name)) { rb_ary_unshift(rest, name); name = Qnil; } for (i=0; i<RARRAY_LEN(rest); i++) { id = rb_to_id(RARRAY_PTR(rest)[i]); RARRAY_PTR(rest)[i] = ID2SYM(id); } st = make_struct(name, rest, klass); if (rb_block_given_p()) { rb_mod_module_eval(0, 0, st); } return st; }
static VALUE rb_struct_s_def(VALUE klass, SEL sel, int argc, VALUE *argv) { VALUE name, rest; long i, count; VALUE st; ID id; rb_scan_args(argc, argv, "1*", &name, &rest); if (!NIL_P(name) && SYMBOL_P(name)) { rb_ary_unshift(rest, name); name = Qnil; } for (i = 0, count = RARRAY_LEN(rest); i < count; i++) { id = rb_to_id(RARRAY_AT(rest, i)); rb_ary_store(rest, i, ID2SYM(id)); } st = make_struct(name, rest, klass); if (rb_block_given_p()) { rb_mod_module_eval(st, 0, 0, 0); } return st; }
static VALUE array_spec_rb_ary_unshift(VALUE self, VALUE array, VALUE val) { return rb_ary_unshift(array, val); }