Example #1
0
static void
features_index_add_single(VALUE short_feature, VALUE offset)
{
    struct st_table *features_index;
    VALUE this_feature_index = Qnil;
    char *short_feature_cstr;

    Check_Type(offset, T_FIXNUM);
    Check_Type(short_feature, T_STRING);
    short_feature_cstr = StringValueCStr(short_feature);

    features_index = get_loaded_features_index_raw();
    st_lookup(features_index, (st_data_t)short_feature_cstr, (st_data_t *)&this_feature_index);

    if (NIL_P(this_feature_index)) {
	st_insert(features_index, (st_data_t)ruby_strdup(short_feature_cstr), (st_data_t)offset);
    }
    else if (RB_TYPE_P(this_feature_index, T_FIXNUM)) {
	VALUE feature_indexes[2];
	feature_indexes[0] = this_feature_index;
	feature_indexes[1] = offset;
	this_feature_index = (VALUE)xcalloc(1, sizeof(struct RArray));
	RBASIC(this_feature_index)->flags = T_ARRAY; /* fake VALUE, do not mark/sweep */
	rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes));
	st_insert(features_index, (st_data_t)short_feature_cstr, (st_data_t)this_feature_index);
    }
    else {
	Check_Type(this_feature_index, T_ARRAY);
	rb_ary_push(this_feature_index, offset);
    }
}
Example #2
0
static VALUE
lazy_init_iterator(VALUE val, VALUE m, int argc, VALUE *argv)
{
    VALUE result;
    if (argc == 1) {
	VALUE args[2];
	args[0] = m;
	args[1] = val;
	result = rb_yield_values2(2, args);
    }
    else {
	VALUE args;
	int len = rb_long2int((long)argc + 1);

	args = rb_ary_tmp_new(len);
	rb_ary_push(args, m);
	if (argc > 0) {
	    rb_ary_cat(args, argv, argc);
	}
	result = rb_yield_values2(len, RARRAY_PTR(args));
	RB_GC_GUARD(args);
    }
    if (result == Qundef) rb_iter_break();
    return Qnil;
}
Example #3
0
static void
features_index_add_single(const char* str, size_t len, VALUE offset)
{
    struct st_table *features_index;
    VALUE this_feature_index = Qnil;
    st_data_t short_feature_key;

    Check_Type(offset, T_FIXNUM);
    short_feature_key = feature_key(str, len);

    features_index = get_loaded_features_index_raw();
    st_lookup(features_index, short_feature_key, (st_data_t *)&this_feature_index);

    if (NIL_P(this_feature_index)) {
	st_insert(features_index, short_feature_key, (st_data_t)offset);
    }
    else if (RB_TYPE_P(this_feature_index, T_FIXNUM)) {
	VALUE feature_indexes[2];
	feature_indexes[0] = this_feature_index;
	feature_indexes[1] = offset;
	this_feature_index = (VALUE)xcalloc(1, sizeof(struct RArray));
	RBASIC(this_feature_index)->flags = T_ARRAY; /* fake VALUE, do not mark/sweep */
	rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes));
	st_insert(features_index, short_feature_key, (st_data_t)this_feature_index);
    }
    else {
	Check_Type(this_feature_index, T_ARRAY);
	rb_ary_push(this_feature_index, offset);
    }
}
Example #4
0
/* :nodoc: */
static VALUE
generator_each(int argc, VALUE *argv, VALUE obj)
{
    struct generator *ptr = generator_ptr(obj);
    VALUE args = rb_ary_new2(argc + 1);

    rb_ary_push(args, yielder_new());
    if (argc > 0) {
	rb_ary_cat(args, argv, argc);
    }

    return rb_proc_call(ptr->proc, args);
}
Example #5
0
/*
 * 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);
}
Example #6
0
static VALUE
lazy_cycle(int argc, VALUE *argv, VALUE obj)
{
    VALUE args;
    int len = rb_long2int((long)argc + 2);

    if (rb_block_given_p()) {
	return rb_call_super(argc, argv);
    }
    args = rb_ary_tmp_new(len);
    rb_ary_push(args, obj);
    rb_ary_push(args, sym_cycle);
    if (argc > 0) {
	rb_ary_cat(args, argv, argc);
    }
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, len,
					 RARRAY_PTR(args), lazy_cycle_func,
					 args /* prevent from GC */),
			   rb_ary_new4(argc, argv));
}