コード例 #1
0
ファイル: struct.c プロジェクト: Chatto/VGdesk
static VALUE
rb_struct_s_members_m(VALUE klass)
{
    VALUE members = rb_struct_s_members(klass);

    return rb_ary_dup(members);
}
コード例 #2
0
ファイル: rbgtkactiongroup.c プロジェクト: msakai/ruby-gnome2
static VALUE
rbg_rval2gtkradioactionentries_body(VALUE value)
{
    long i;
    struct rbg_rval2gtkradioactionentries_args *args = (struct rbg_rval2gtkradioactionentries_args *)value;

    for (i = 0; i < args->n; i++) {
        VALUE entry;
        long n;

        RARRAY_PTR(args->ary)[i] = rb_ary_dup(rb_ary_to_ary(RARRAY_PTR(args->ary)[i]));
        entry = RARRAY_PTR(args->ary)[i];
        n = RARRAY_LEN(entry);

        switch (n) {
        case 6:
            args->result[i].value = NUM2INT(RARRAY_PTR(entry)[5]);
        case 5:
            args->result[i].tooltip = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[4]);
        case 4:
            args->result[i].accelerator = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[3]);
        case 3:
            args->result[i].label = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[2]);
        case 2:
            args->result[i].stock_id = RVAL2CSTR_ACCEPT_SYMBOL_ACCEPT_NIL(RARRAY_PTR(entry)[1]);
        case 1:
            args->result[i].name = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[0]);
        default:
            rb_raise(rb_eArgError, "entry does not contain right number of entries %ld (1..6)", n);
        }
    }

    return Qnil;
}
コード例 #3
0
ファイル: collection.c プロジェクト: jmkeyes/rbpod
/*
 * 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;
}
コード例 #4
0
ファイル: StructLayout.c プロジェクト: Flameeyes/ffi
static VALUE
struct_layout_initialize(VALUE self, VALUE field_names, VALUE fields, VALUE size, VALUE align)
{
    StructLayout* layout;
    ffi_type* ltype;
    int i;

    Data_Get_Struct(self, StructLayout, layout);
    layout->rbFieldMap = rb_hash_new();
    layout->rbFieldNames = rb_ary_dup(field_names);
    layout->size = NUM2INT(size);
    layout->align = NUM2INT(align);
    layout->fieldCount = RARRAY_LEN(field_names);
    layout->fields = xcalloc(layout->fieldCount, sizeof(StructField *));
    layout->ffiTypes = xcalloc(layout->fieldCount + 1, sizeof(ffi_type *));
    layout->rbFields = rb_ary_new2(layout->fieldCount);
    layout->base.ffiType->elements = layout->ffiTypes;
    layout->base.ffiType->size = 0;
    layout->base.ffiType->alignment = 1;

    ltype = layout->base.ffiType;
    for (i = 0; i < (int) layout->fieldCount; ++i) {
        VALUE rbName = rb_ary_entry(field_names, i);
        VALUE rbField = rb_hash_aref(fields, rbName);
        StructField* field;
        ffi_type* ftype;


        if (!rb_obj_is_kind_of(rbField, rbffi_StructLayoutFieldClass)) {
            rb_raise(rb_eTypeError, "wrong type for field %d.", i);
        }

        Data_Get_Struct(rbField, StructField, field = layout->fields[i]);

        if (field->type == NULL || field->type->ffiType == NULL) {
            rb_raise(rb_eRuntimeError, "type of field %d not supported", i);
        }

        ftype = field->type->ffiType;
        if (ftype->size == 0) {
            rb_raise(rb_eTypeError, "type of field %d has zero size", i);
        }

        rb_hash_aset(layout->rbFieldMap, rbName, rbField);
        layout->ffiTypes[i] = ftype;
        rb_ary_push(layout->rbFields, rbField);
        ltype->size = MAX(ltype->size, field->offset + ftype->size);
        ltype->alignment = MAX(ltype->alignment, ftype->alignment);
    }

    if (ltype->size == 0) {
        rb_raise(rb_eRuntimeError, "Struct size is zero");
    }

    // Include tail padding
    ltype->size = FFI_ALIGN(ltype->size, ltype->alignment);

    return self;
}
コード例 #5
0
ファイル: FunctionInfo.c プロジェクト: Atastor/ffi
static VALUE
fntype_param_types(VALUE self)
{
    FunctionType* ft;

    Data_Get_Struct(self, FunctionType, ft);

    return rb_ary_dup(ft->rbParameterTypes);
}
コード例 #6
0
VALUE method_dup_state(VALUE self, VALUE state) {
    int height = (int)RARRAY_LEN(state);
    VALUE dup =  rb_ary_new2(height);
    for(int y = 0; y < height; y++) {
        VALUE row = rb_ary_dup(rb_ary_entry(state, y));
        rb_ary_push(dup, row);
    }
    return dup;
}
コード例 #7
0
/*
 * call-seq: members
 * @return [Array<Symbol>]
 * Get list of field names.
 */
static VALUE
struct_layout_members(VALUE self)
{
    StructLayout* layout;

    Data_Get_Struct(self, StructLayout, layout);

    return rb_ary_dup(layout->rbFieldNames);
}
コード例 #8
0
/*
 * call-seq: to_a
 * @return [Array<StructLayout::Field>]
 * Get an array of fields.
 */
static VALUE
struct_layout_to_a(VALUE self)
{
    StructLayout* layout;

    Data_Get_Struct(self, StructLayout, layout);

    return rb_ary_dup(layout->rbFields);
}
コード例 #9
0
ファイル: slave.c プロジェクト: flipback/libmodbus4r
VALUE mb_sl_set_input_status(VALUE self, VALUE value)
{
    modbus_slave_t *mb_slave;
    Data_Get_Struct(self, modbus_slave_t, mb_slave);

    value = rb_funcall(value, rb_intern("to_a"), 0);
    mb_slave->input_status = rb_ary_dup(value);
        
    return mb_slave->input_status;
}
コード例 #10
0
ファイル: coverage_peeker.c プロジェクト: cyril/what_to_run
static int
coverage_peek_result_i(st_data_t key, st_data_t val, st_data_t h)
{
  VALUE path = (VALUE)key;
  VALUE coverage = (VALUE)val;
  VALUE coverages = (VALUE)h;
  coverage = rb_ary_dup(coverage);
  rb_ary_freeze(coverage);
  rb_hash_aset(coverages, path, coverage);
  return ST_CONTINUE;
}
コード例 #11
0
ファイル: ruby.c プロジェクト: Shoes3/shoes3
void shoes_ele_remove_all(VALUE contents) {
    if (!NIL_P(contents)) {
        long i;
        VALUE ary;
        ary = rb_ary_dup(contents);
        rb_gc_register_address(&ary);
        for (i = 0; i < RARRAY_LEN(ary); i++)
            if (!NIL_P(rb_ary_entry(ary, i)))
                rb_funcall(rb_ary_entry(ary, i), s_remove, 0);
        rb_gc_unregister_address(&ary);
        rb_ary_clear(contents);
    }
}
コード例 #12
0
static VALUE
each_cons_i(VALUE val, VALUE *memo)
{
    VALUE ary = memo[0];
    VALUE v = Qnil;
    long size = (long)memo[1];

    if (RARRAY_LEN(ary) == size) {
        rb_ary_shift(ary);
    }
    rb_ary_push(ary, val);
    if (RARRAY_LEN(ary) == size) {
        v = rb_yield(rb_ary_dup(ary));
    }
    return v;
}
コード例 #13
0
ファイル: slave.c プロジェクト: flipback/libmodbus4r
VALUE mb_sl_set_input_registers(VALUE self, VALUE value)
{
    modbus_slave_t *mb_slave;
    Data_Get_Struct(self, modbus_slave_t, mb_slave);

    value = rb_funcall(value, rb_intern("to_a"), 0);
    mb_slave->input_registers = rb_ary_dup(value);
    VALUE *reg = RARRAY_PTR(mb_slave->input_registers);
    
    int i;
    for (i = 0; i < RARRAY_LEN(mb_slave->input_registers); i++) {
         *reg = rb_funcall(*reg, rb_intern("to_i"), 0);
    }
        
    return mb_slave->input_registers;
}
コード例 #14
0
ファイル: rbgtkactiongroup.c プロジェクト: msakai/ruby-gnome2
static GtkRadioActionEntry *
rbg_rval2gtkradioactionentries(volatile VALUE *value, long *n)
{
    struct rbg_rval2gtkradioactionentries_args args;

    args.ary = *value = rb_ary_dup(rb_ary_to_ary(*value));
    args.n = RARRAY_LEN(args.ary);
    args.result = g_new0(GtkRadioActionEntry, args.n + 1);

    rb_rescue(rbg_rval2gtkradioactionentries_body, (VALUE)&args,
              rbg_rval2gtkradioactionentries_rescue, (VALUE)&args);

    *n = args.n;

    return args.result;
}
コード例 #15
0
ファイル: enumerator.c プロジェクト: takuto-h/ruby
/*
 * call-seq:
 *   enum.each {...}
 *
 * Iterates over the block according to how this Enumerable was constructed.
 * If no block is given, returns self.
 *
 */
static VALUE
enumerator_each(int argc, VALUE *argv, VALUE obj)
{
    if (argc > 0) {
	struct enumerator *e = enumerator_ptr(obj = rb_obj_dup(obj));
	VALUE args = e->args;
	if (args) {
	    args = rb_ary_dup(args);
	    rb_ary_cat(args, argv, argc);
	}
	else {
	    args = rb_ary_new4(argc, argv);
	}
	e->args = args;
    }
    if (!rb_block_given_p()) return obj;
    return enumerator_block_call(obj, 0, obj);
}
コード例 #16
0
ファイル: vm_args.c プロジェクト: hayaken8112/.emacs.d
static inline void
args_extend(struct args_info *args, const int min_argc)
{
    int i;

    if (args->rest) {
	args->rest = rb_ary_dup(args->rest);
	VM_ASSERT(args->rest_index == 0);
	for (i=args->argc + RARRAY_LENINT(args->rest); i<min_argc; i++) {
	    rb_ary_push(args->rest, Qnil);
	}
    }
    else {
	for (i=args->argc; i<min_argc; i++) {
	    args->argv[args->argc++] = Qnil;
	}
    }
}
コード例 #17
0
ファイル: vm_args.c プロジェクト: hayaken8112/.emacs.d
static VALUE
args_pop_keyword_hash(struct args_info *args, VALUE *kw_hash_ptr, rb_thread_t *th)
{
    VALUE rest_hash;

    if (args->rest == Qfalse) {
      from_argv:
	VM_ASSERT(args->argc > 0);
	*kw_hash_ptr = args->argv[args->argc-1];

	if (keyword_hash_p(kw_hash_ptr, &rest_hash, th)) {
	    if (rest_hash) {
		args->argv[args->argc-1] = rest_hash;
	    }
	    else {
		args->argc--;
		return TRUE;
	    }
	}
    }
    else {
	long len = RARRAY_LEN(args->rest);

	if (len > 0) {
	    *kw_hash_ptr = RARRAY_AREF(args->rest, len - 1);

	    if (keyword_hash_p(kw_hash_ptr, &rest_hash, th)) {
		if (rest_hash) {
		    RARRAY_ASET(args->rest, len - 1, rest_hash);
		}
		else {
		    args->rest = rb_ary_dup(args->rest);
		    rb_ary_pop(args->rest);
		    return TRUE;
		}
	    }
	}
	else {
	    goto from_argv;
	}
    }

    return FALSE;
}
コード例 #18
0
ファイル: enumerator.c プロジェクト: takuto-h/ruby
static VALUE
ary2sv(VALUE args, int dup)
{
    if (!RB_TYPE_P(args, T_ARRAY))
        return args;

    switch (RARRAY_LEN(args)) {
      case 0:
        return Qnil;

      case 1:
        return RARRAY_AREF(args, 0);

      default:
        if (dup)
            return rb_ary_dup(args);
        return args;
    }
}
コード例 #19
0
static VALUE
ary2sv(VALUE args, int dup)
{
    if (TYPE(args) != T_ARRAY)
        return args;

    switch (RARRAY_LEN(args)) {
      case 0:
        return Qnil;

      case 1:
        return RARRAY_PTR(args)[0];

      default:
        if (dup)
            return rb_ary_dup(args);
        return args;
    }
}
コード例 #20
0
ファイル: rbgtkactiongroup.c プロジェクト: msakai/ruby-gnome2
static VALUE
rbg_rval2gtktoggleactionentries_body(VALUE value)
{
    long i;
    struct rbg_rval2gtktoggleactionentries_args *args = (struct rbg_rval2gtktoggleactionentries_args *)value;

    for (i = 0; i < args->n; i++) {
        VALUE entry;
        long n;

        RARRAY_PTR(args->ary)[i] = rb_ary_dup(rb_ary_to_ary(RARRAY_PTR(args->ary)[i]));
        entry = RARRAY_PTR(args->ary)[i];
        n = RARRAY_LEN(entry);

        args->result[i].callback = G_CALLBACK(activate_toggle_action);

        if (n < 1 || n > 7)
            rb_raise(rb_eArgError, "entry does not contain right number of entries %ld (1..7)", n);

        args->result[i].name = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[0]);

        switch (n) {
        case 7:
            args->result[i].is_active = RVAL2CBOOL(RARRAY_PTR(entry)[6]);
        case 6:
            /* TODO: Call #to_proc on entry 5? */
            rb_hash_aset(args->procs, RARRAY_PTR(entry)[0], RARRAY_PTR(entry)[5]);
        case 5:
            args->result[i].tooltip = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[4]);
        case 4:
            args->result[i].accelerator = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[3]);
        case 3:
            args->result[i].label = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[2]);
        case 2:
            args->result[i].stock_id = RVAL2CSTR_ACCEPT_SYMBOL_ACCEPT_NIL(RARRAY_PTR(entry)[1]);
            break;
        default:
            break;
        }
    }

    return Qnil;
}
コード例 #21
0
ファイル: vm_args.c プロジェクト: hayaken8112/.emacs.d
static inline void
args_reduce(struct args_info *args, int over_argc)
{
    if (args->rest) {
	const long len = RARRAY_LEN(args->rest);

	if (len > over_argc) {
	    args->rest = rb_ary_dup(args->rest);
	    rb_ary_resize(args->rest, len - over_argc);
	    return;
	}
	else {
	    args->rest = Qfalse;
	    over_argc -= len;
	}
    }

    VM_ASSERT(args->argc >= over_argc);
    args->argc -= over_argc;
}
コード例 #22
0
ファイル: struct.c プロジェクト: 1nueve/MacRuby
static VALUE
rb_struct_s_members_m(VALUE klass)
{
#if WITH_OBJC
    return rb_ary_dup(rb_struct_s_members(klass));
#else
    VALUE members, ary;
    VALUE *p, *pend;

    members = rb_struct_s_members(klass);
    ary = rb_ary_new2(RARRAY_LEN(members));
    p = RARRAY_PTR(members); pend = p + RARRAY_LEN(members);
    while (p < pend) {
	rb_ary_push(ary, *p);
	p++;
    }

    return ary;
#endif
}
コード例 #23
0
ファイル: vm_args.c プロジェクト: hayaken8112/.emacs.d
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;
    }
}
コード例 #24
0
ファイル: vm_args.c プロジェクト: hayaken8112/.emacs.d
static void
args_stored_kw_argv_to_hash(struct args_info *args)
{
    VALUE h = rb_hash_new();
    int i;
    const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
    const VALUE *const passed_keywords = kw_arg->keywords;
    const int passed_keyword_len = kw_arg->keyword_len;

    for (i=0; i<passed_keyword_len; i++) {
	rb_hash_aset(h, passed_keywords[i], args->kw_argv[i]);
    }
    args->kw_argv = NULL;

    if (args->rest) {
	args->rest = rb_ary_dup(args->rest);
	rb_ary_push(args->rest, h);
    }
    else {
	args->argv[args->argc++] = h;
    }
}
コード例 #25
0
ファイル: kernel.c プロジェクト: silicon/MacRuby
PRIMITIVE VALUE
vm_ary_dup(VALUE ary)
{
    return rb_ary_dup(ary);
}
コード例 #26
0
ファイル: app.c プロジェクト: gensym/shoes
VALUE
shoes_apps_get(VALUE self)
{
  return rb_ary_dup(shoes_world->apps);
}
コード例 #27
0
ファイル: thread.c プロジェクト: 1nueve/MacRuby
VALUE
rb_thread_list(VALUE rcv, SEL sel)
{
    return rb_ary_dup(rb_vm_threads());
}
コード例 #28
0
ファイル: enumerator.c プロジェクト: takuto-h/ruby
static VALUE
enumerator_peek_values_m(VALUE obj)
{
    return rb_ary_dup(enumerator_peek_values(obj));
}
コード例 #29
0
ファイル: labeling.cpp プロジェクト: zophos/Rim
//
// Rim::Image#labelinfo
//
VALUE rb_rim_image_labelinfo(VALUE self)
{
    VALUE ar=rb_iv_get(self,"@labelinfo");
    Check_Type(ar,T_ARRAY);
    return rb_ary_dup(ar);
}
コード例 #30
0
ファイル: array_spec.c プロジェクト: DanielVartanov/rubinius
static VALUE array_spec_rb_ary_dup(VALUE self, VALUE array) {
  return rb_ary_dup(array);
}