示例#1
0
文件: pathname.c 项目: takuto-h/ruby
/*
 * Return the entries (files and subdirectories) in the directory, each as a
 * Pathname object.
 *
 * The results contains just the names in the directory, without any trailing
 * slashes or recursive look-up.
 *
 *   pp Pathname.new('/usr/local').entries
 *   #=> [#<Pathname:share>,
 *   #    #<Pathname:lib>,
 *   #    #<Pathname:..>,
 *   #    #<Pathname:include>,
 *   #    #<Pathname:etc>,
 *   #    #<Pathname:bin>,
 *   #    #<Pathname:man>,
 *   #    #<Pathname:games>,
 *   #    #<Pathname:.>,
 *   #    #<Pathname:sbin>,
 *   #    #<Pathname:src>]
 *
 * The result may contain the current directory <code>#<Pathname:.></code> and
 * the parent directory <code>#<Pathname:..></code>.
 *
 * If you don't want +.+ and +..+ and
 * want directories, consider Pathname#children.
 */
static VALUE
path_entries(VALUE self)
{
    VALUE klass, str, ary;
    long i;
    klass = rb_obj_class(self);
    str = get_strpath(self);
    ary = rb_funcall(rb_cDir, rb_intern("entries"), 1, str);
    ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
    for (i = 0; i < RARRAY_LEN(ary); i++) {
        VALUE elt = RARRAY_PTR(ary)[i];
        elt = rb_class_new_instance(1, &elt, klass);
        rb_ary_store(ary, i, elt);
    }
    return ary;
}
示例#2
0
static VALUE rb_gsl_function_fdf_set_fdf(VALUE obj, VALUE procfdf)
{
  gsl_function_fdf *F = NULL;
  VALUE ary;
  CHECK_PROC(procfdf);
  Data_Get_Struct(obj, gsl_function_fdf, F);
  if (F->params == NULL) {
    ary = rb_ary_new2(4);
    /*    (VALUE) F->params = ary;*/
    F->params = (void *) ary;
  } else {
    ary = (VALUE) F->params;
  }
  rb_ary_store(ary, 2, procfdf);
  return obj;
}
示例#3
0
/*
 * call-seq:
 *    res.fields() -> Array
 *
 * Returns an array of Strings representing the names of the fields in the result.
 */
static VALUE
pgresult_fields(VALUE self)
{
	PGresult *result = pgresult_get( self );
	int n = PQnfields( result );
	VALUE fields = rb_ary_new2( n );
	int i;

	for ( i = 0; i < n; i++ ) {
		VALUE val = rb_tainted_str_new2(PQfname(result, i));
		ASSOCIATE_INDEX(val, self);
		rb_ary_store( fields, i, val );
	}

	return fields;
}
示例#4
0
/*	fetch_fields()	*/
static VALUE fetch_fields(VALUE obj)
{
    MYSQL_RES* res;
    MYSQL_FIELD* f;
    unsigned int n;
    VALUE ret;
    unsigned int i;
    check_free(obj);
    res = GetMysqlRes(obj);
    f = mysql_fetch_fields(res);
    n = mysql_num_fields(res);
    ret = rb_ary_new2(n);
    for (i=0; i<n; i++)
	rb_ary_store(ret, i, make_field_obj(&f[i]));
    return ret;
}
示例#5
0
static VALUE
type_interfaces(VALUE self)
{
    guint n_interfaces;
    GType* types;
    VALUE result;
    int i;

    types = g_type_interfaces(rbgobj_gtype_get(self), &n_interfaces);
    result = rb_ary_new2(n_interfaces);
    for (i = 0; i < n_interfaces; i++)
        rb_ary_store(result, i, rbgobj_gtype_new(types[i]));
    g_free(types);

    return result;
}
示例#6
0
VALUE read_large_tuple(unsigned char **pData) {
  if(read_1(pData) != ERL_LARGE_TUPLE) {
    rb_raise(rb_eStandardError, "Invalid Type, not a large tuple");
  }

  int arity = read_4(pData);

  VALUE array = rb_ary_new2(arity);

  int i;
  for(i = 0; i < arity; ++i) {
    rb_ary_store(array, i, read_any_raw(pData));
  }

  return array;
}
示例#7
0
/*
 * call-seq:
 *     Message.to_h => {}
 *
 * Returns the message as a Ruby Hash object, with keys as symbols.
 */
VALUE Message_to_h(VALUE _self) {
  MessageHeader* self;
  VALUE hash;
  upb_msg_field_iter it;
  TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);

  hash = rb_hash_new();

  for (upb_msg_field_begin(&it, self->descriptor->msgdef);
       !upb_msg_field_done(&it);
       upb_msg_field_next(&it)) {
    const upb_fielddef* field = upb_msg_iter_field(&it);

    // For proto2, do not include fields which are not set.
    if (upb_msgdef_syntax(self->descriptor->msgdef) == UPB_SYNTAX_PROTO2 &&
	field_contains_hasbit(self->descriptor->layout, field) &&
	!layout_has(self->descriptor->layout, Message_data(self), field)) {
      continue;
    }

    VALUE msg_value = layout_get(self->descriptor->layout, Message_data(self),
                                 field);
    VALUE msg_key   = ID2SYM(rb_intern(upb_fielddef_name(field)));
    if (is_map_field(field)) {
      msg_value = Map_to_h(msg_value);
    } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
      msg_value = RepeatedField_to_ary(msg_value);
      if (upb_msgdef_syntax(self->descriptor->msgdef) == UPB_SYNTAX_PROTO2 &&
          RARRAY_LEN(msg_value) == 0) {
        continue;
      }

      if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
        for (int i = 0; i < RARRAY_LEN(msg_value); i++) {
          VALUE elem = rb_ary_entry(msg_value, i);
          rb_ary_store(msg_value, i, Message_to_h(elem));
        }
      }

    } else if (msg_value != Qnil &&
               upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
      msg_value = Message_to_h(msg_value);
    }
    rb_hash_aset(hash, msg_key, msg_value);
  }
  return hash;
}
示例#8
0
static VALUE objectid_from_string(VALUE self, VALUE str)
{
    VALUE oid;
    int i;

    if (!legal_objectid_str(str)) {
        rb_raise(InvalidObjectId, "illegal ObjectId format: %s", RSTRING_PTR(str));
    }

    oid = rb_ary_new2(12);

    for(i = 0; i < 12; i++) {
        rb_ary_store(oid, i, INT2FIX( (unsigned)(hexbyte( RSTRING_PTR(str)[2*i] ) << 4 ) | hexbyte( RSTRING_PTR(str)[2*i + 1] )));
    }

    return rb_class_new_instance(1, &oid, ObjectId);
}
示例#9
0
static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int symbolize_keys) {
  mysql2_result_wrapper * wrapper;
  VALUE rb_field;
  GetMysql2Result(self, wrapper);

  if (wrapper->fields == Qnil) {
    wrapper->numberOfFields = mysql_num_fields(wrapper->result);
    wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
  }

  rb_field = rb_ary_entry(wrapper->fields, idx);
  if (rb_field == Qnil) {
    MYSQL_FIELD *field = NULL;
#ifdef HAVE_RUBY_ENCODING_H
    rb_encoding *default_internal_enc = rb_default_internal_encoding();
    rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding);
#endif

    field = mysql_fetch_field_direct(wrapper->result, idx);
    if (symbolize_keys) {
      char buf[field->name_length+1];
      memcpy(buf, field->name, field->name_length);
      buf[field->name_length] = 0;

#ifdef HAVE_RB_INTERN3
      rb_field = rb_intern3(buf, field->name_length, rb_utf8_encoding());
      rb_field = ID2SYM(rb_field);
#else
      VALUE colStr;
      colStr = rb_str_new2(buf);
      rb_field = ID2SYM(rb_to_id(colStr));
#endif
    } else {
      rb_field = rb_str_new(field->name, field->name_length);
#ifdef HAVE_RUBY_ENCODING_H
      rb_enc_associate(rb_field, conn_enc);
      if (default_internal_enc) {
        rb_field = rb_str_export_to_enc(rb_field, default_internal_enc);
      }
#endif
    }
    rb_ary_store(wrapper->fields, idx, rb_field);
  }

  return rb_field;
}
示例#10
0
VALUE read_string(unsigned char **pData) {
  if(read_1(pData) != ERL_STRING) {
    rb_raise(rb_eStandardError, "Invalid Type, not an erlang string");
  }

  int length = read_2(pData);
  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
  VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(length));

  int i = 0;
  for(i; i < length; ++i) {
    rb_ary_store(array, i, INT2NUM(**pData));
    *pData += 1;
  }

  return array;
}
示例#11
0
文件: talib.c 项目: edbond/talib-ruby
static VALUE ta_func_setup_out_integer(VALUE self, VALUE param_index, VALUE out_array)
{
  TA_RetCode ret_code;
  ParamHolder *param_holder;
  long idx = FIX2INT(param_index);
  if (idx > 2)
    rb_raise(rb_eRuntimeError, "param_index must be 0..2");
  Data_Get_Struct(self, ParamHolder, param_holder);
  rb_ary_store(rb_iv_get(self, "@result"), idx, out_array);
  // FIXME: malloc w/o free FIXED: [email protected]
  int **ip = &(param_holder->out_int[idx]);
  if (*ip) free(*ip); // not true only very 1st time in
  *ip = (int*)malloc(RARRAY_LEN(out_array) * sizeof(int));
  ret_code=TA_SetOutputParamIntegerPtr( param_holder->p, idx, *ip);
  if ( ret_code != TA_SUCCESS )
    rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOutputParamIntegerPtr");
}
示例#12
0
/* Return one dimensinal array which has strings converted elements to. */
static VALUE r_mpfi_matrix_str_ary_for_inspect (VALUE self) {
  MPFIMatrix *ptr_self;
  char *tmp_str;
  VALUE ret_ary;
  int i;
  r_mpfi_get_matrix_struct(ptr_self, self);
  ret_ary = rb_ary_new2(ptr_self->size);
  for (i = 0; i < ptr_self->size; i++) {
    if (!mpfr_asprintf(&tmp_str, "%.Re %.Re",
                       r_mpfi_left_ptr((ptr_self->data + i)), r_mpfi_right_ptr(ptr_self->data + i))) {
      rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
    }
    rb_ary_store(ret_ary, i, rb_str_new2(tmp_str));
    mpfr_free_str(tmp_str);
  }
  return ret_ary;
}
示例#13
0
文件: menu.c 项目: Shoes3/shoes3
// Add menuitem to the menu at the end
VALUE shoes_menu_append(VALUE self, VALUE miv) {
  shoes_menu *mn;
  shoes_menuitem *mi;
  Data_Get_Struct(self, shoes_menu, mn);
  if (rb_obj_is_kind_of(miv, cShoesMenuitem)) {
    Data_Get_Struct(miv, shoes_menuitem, mi);
    mi->parent = mn;
    shoes_native_menu_append(mn, mi);
    int cnt = RARRAY_LEN(mn->items);
    rb_ary_store(mn->items, cnt, miv);
  } else if (rb_obj_is_kind_of(miv, cShoesMenu)) {
    rb_raise(rb_eArgError, "menu cannot be appended to menu");
  } else {
    rb_raise(rb_eArgError, "not a menuitem");
  }
  return self;
}
示例#14
0
static VALUE bert_read_string(struct bert_buf *buf)
{
	uint16_t i, length;
	VALUE rb_string;

	bert_buf_ensure(buf, 2);
	length = bert_buf_read16(buf);

	bert_buf_ensure(buf, length);
	rb_string = rb_ary_new2(length);

	for (i = 0; i < length; ++i)
		rb_ary_store(rb_string, i, INT2FIX(buf->data[i]));

	buf->data += length;
	return rb_string;
}
示例#15
0
文件: talib.c 项目: edbond/talib-ruby
/*
 * call-seq: out_real(index, array)
 *
 * Set output parameter (array of real) for the given parameter index.
 */
static VALUE ta_func_setup_out_real(VALUE self, VALUE param_index, VALUE out_array)
{
  TA_RetCode ret_code;
  ParamHolder *param_holder;
  long idx = FIX2INT(param_index);
  if (idx > 2)
    rb_raise(rb_eRuntimeError, "param_index must be 0..2");
  Data_Get_Struct(self, ParamHolder, param_holder);
  rb_ary_store(rb_iv_get(self, "@result"), idx, out_array);
  // FIXME: malloc w/o free: [email protected] fixed
  double **dp = &(param_holder->out[idx]);
  if (*dp) free(*dp); // not true only 1st time called (reusing same ptrs)
  *dp = (double*)malloc(RARRAY_LEN(out_array) * sizeof(double));
  ret_code = TA_SetOutputParamRealPtr(param_holder->p, idx, *dp);
  if ( ret_code != TA_SUCCESS )
    rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOutputParamRealPtr");
}
示例#16
0
static VALUE rb_git_commit_parents_GET(VALUE self)
{
	git_commit *commit;
	git_commit *parent;
	unsigned int n;
	VALUE ret_arr, owner;

	RUGGED_OBJ_UNWRAP(self, git_commit, commit);
	RUGGED_OBJ_OWNER(self, owner);

	ret_arr = rb_ary_new();
	for (n = 0; (parent = git_commit_parent(commit, n)) != NULL; n++) {
		rb_ary_store(ret_arr, n, rugged_object_new(owner, (git_object *)parent));
	}

	return ret_arr;
}
示例#17
0
static VALUE rb_gsl_multifit_ndlinear_alloc(int argc, VALUE *argv, VALUE klass)
{
  gsl_multifit_ndlinear_workspace *w;
  int istart = 0;
  size_t n_dim = 0, *N, i;
  struct ufunc_struct *p;
  VALUE params, wspace, pp;
  switch (argc) {
  case 4:
    istart = 1;
    CHECK_FIXNUM(argv[0]);
    n_dim = FIX2INT(argv[0]);
    /* no break */
  case 3:  
    if (TYPE(argv[istart]) != T_ARRAY) {
      rb_raise(rb_eTypeError, "Wrong argument type %s (Array expected)",
        rb_class2name(CLASS_OF(argv[istart])));
    }
    if (TYPE(argv[istart+1]) != T_ARRAY) {
      rb_raise(rb_eTypeError, "Wrong argument type %s (Array expected)",
        rb_class2name(CLASS_OF(argv[istart+1])));
    }
    //    n_dim = RARRAY(argv[istart])->len;
    n_dim = RARRAY_LEN(argv[istart]);
    N = (size_t*) malloc(sizeof(size_t)*n_dim);
    break;
  default:
    rb_raise(rb_eArgError, "Wrong number of arguments (%d for 3 or 4)", argc);
  }
  for (i = 0; i < n_dim; i++) {
    N[i] = FIX2INT(rb_ary_entry(argv[istart], i));
  }

  params = rb_ary_new2(NDLINEAR_ARY_SIZE);
  rb_ary_store(params, INDEX_NDIM, INT2FIX((int) n_dim));
  rb_ary_store(params, INDEX_N, argv[istart]);   /* N */
  rb_ary_store(params, INDEX_PROCS, argv[istart+1]); /* procs */
  rb_ary_store(params, INDEX_PARAMS, argv[istart+2]); /* params */  
  rb_ary_store(params, INDEX_NDIM_I, INT2FIX(0)); /* for the first parameter */    
  
  p = ufunc_struct_alloc(n_dim);
  for (i = 0; i < n_dim; i++) p->fptr[i] = func_u;
  pp = Data_Wrap_Struct(cUFunc, 0, ufunc_struct_free, p);  
  rb_ary_store(params, INDEX_FUNCS, pp);  

  w = gsl_multifit_ndlinear_alloc(n_dim, N, p->fptr, (void*) params);
    
  free((size_t*) N);

  wspace = Data_Wrap_Struct(cWorkspace, multifit_ndlinear_mark, gsl_multifit_ndlinear_free, w);

  return wspace;
}
示例#18
0
/*	fetch_lengths()		*/
static VALUE fetch_lengths(VALUE obj)
{
    MYSQL_RES* res;
    unsigned int n;
    unsigned long* lengths;
    VALUE ary;
    unsigned int i;
    check_free(obj);
    res = GetMysqlRes(obj);
    n = mysql_num_fields(res);
    lengths = mysql_fetch_lengths(res);
    if (lengths == NULL)
	return Qnil;
    ary = rb_ary_new2(n);
    for (i=0; i<n; i++)
	rb_ary_store(ary, i, INT2NUM(lengths[i]));
    return ary;
}
示例#19
0
static VALUE bert_read_list(struct bert_buf *buf)
{
	uint32_t i, length;
	VALUE rb_list;

	bert_buf_ensure(buf, 4);
	length = bert_buf_read32(buf);
	rb_list = rb_ary_new2(length);

	for(i = 0; i < length; ++i)
		rb_ary_store(rb_list, i, bert_read(buf));

	/* disregard tail; adquire currency */
	bert_buf_ensure(buf, 1);
	(void)bert_buf_read8(buf);

	return rb_list;
}
示例#20
0
VALUE oci8_bind_get_data(VALUE self)
{
    oci8_bind_t *obind = DATA_PTR(self);

    if (obind->maxar_sz == 0) {
        obind->curar_idx = 0;
        return rb_funcall(self, oci8_id_get, 0);
    } else {
        volatile VALUE ary = rb_ary_new2(obind->curar_sz);
        ub4 idx;

        for (idx = 0; idx < obind->curar_sz; idx++) {
            obind->curar_idx = idx;
            rb_ary_store(ary, idx, rb_funcall(self, oci8_id_get, 0));
        }
        return ary;
    }
}
示例#21
0
VALUE read_list(unsigned char **pData) {
  if(read_1(pData) != ERL_LIST) {
    rb_raise(rb_eStandardError, "Invalid Type, not an erlang list");
  }
  
  int size = read_4(pData);
  
  VALUE array = rb_ary_new2(size);
  
  int i;
  for(i = 0; i < size; ++i) {
    rb_ary_store(array, i, read_any_raw(pData));
  }
  
  read_1(pData);
  
  return array;
}
示例#22
0
文件: main.c 项目: Distrotech/rrdtool
VALUE rb_rrd_xport(
    VALUE self,
    VALUE args)
{
    string_arr a;
    unsigned long i, j, k, step, col_cnt;
    int xxsize;
    rrd_value_t *data;
    char **legend_v;
    VALUE legend, result, rdata;
    time_t start, end;

    a = string_arr_new(args);
    reset_rrd_state();
    rrd_xport(a.len, a.strings, &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data);
    string_arr_delete(a);

    RRD_CHECK_ERROR;
            
    legend = rb_ary_new();
    for (i = 0; i < col_cnt; i++) {
        rb_ary_push(legend, rb_str_new2(legend_v[i]));
        free(legend_v[i]);
    }
    free(legend_v);

    k = 0;
    rdata = rb_ary_new();
    for (i = start; i <= end; i += step) {
        VALUE line = rb_ary_new2(col_cnt);
        for (j = 0; j < col_cnt; j++) {
            rb_ary_store(line, j, rb_float_new(data[k]));
            k++;
        }
        rb_ary_push(rdata, line);
    }
    free(data);

    result = rb_ary_new2(6);
    rb_ary_store(result, 0, INT2FIX(start));
    rb_ary_store(result, 1, INT2FIX(end));
    rb_ary_store(result, 2, INT2FIX(step));
    rb_ary_store(result, 3, INT2FIX(col_cnt));
    rb_ary_store(result, 4, legend);
    rb_ary_store(result, 5, rdata);
    return result;
}
示例#23
0
VALUE psd_native_layer_raw_parse_raw_bang(VALUE self) {
  psd_logger("debug", "Attempting to parse RAW encoded channel with native code...");

  int chan_pos = FIX2INT(rb_iv_get(self, "@chan_pos"));
  int chan_length = FIX2INT(rb_hash_aref(rb_iv_get(self, "@ch_info"), ID2SYM(rb_intern("length"))));
  VALUE channel_data = rb_iv_get(self, "@channel_data");

  VALUE data = psd_file_read_bytes(self, chan_length - 2);

  int i, j = 0;
  for (i = chan_pos; i < (chan_pos + chan_length - 2); i++) {
    rb_ary_store(channel_data, i, rb_ary_entry(data, j++));
  }

  rb_iv_set(self, "@chan_pos", INT2FIX(chan_pos + chan_length - 2));

  return Qnil;
}
示例#24
0
VALUE read_new_reference(unsigned char **pData) {
  if(read_1(pData) != ERL_NEW_REF) {
    rb_raise(rb_eStandardError, "Invalid Type, not a new-style reference");
  }
  
  int size = read_2(pData);
  VALUE node = read_atom(pData);
  VALUE creation = INT2FIX(read_1(pData));
  
  VALUE id = rb_ary_new2(size);
  int i;
  for(i = 0; i < size; ++i) {
    rb_ary_store(id, i, INT2NUM(read_4(pData)));
  }
  
  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("NewReference"));
  return rb_funcall(newref_class, rb_intern("new"), 3, node, creation, id);
}
示例#25
0
/*
 * call-seq:
 *   codes -> array(contain fixnum)
 *
 * Return Freeman chain codes.
 */
VALUE
rb_codes(VALUE self)
{
  CvChain *chain = CVCHAIN(self);
  CvChainPtReader reader;
  int total = chain->total;
  VALUE ary = rb_ary_new2(total);
  try {
    cvStartReadChainPoints(chain, &reader);
    for (int i = 0; i < total; ++i) {
      CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
      rb_ary_store(ary, i, CHR2FIX(reader.code));
    }
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return ary;
}
示例#26
0
/*	list_dbs(db=nil)	*/
static VALUE list_dbs(int argc, VALUE* argv, VALUE obj)
{
    unsigned int i, n;
    VALUE db, ret;
    MYSQL* m = GetHandler(obj);
    MYSQL_RES* res;

    rb_scan_args(argc, argv, "01", &db);
    res = mysql_list_dbs(m, NILorSTRING(db));
    if (res == NULL)
	mysql_raise(m);

    n = mysql_num_rows(res);
    ret = rb_ary_new2(n);
    for (i=0; i<n; i++)
	rb_ary_store(ret, i, rb_tainted_str_new2(mysql_fetch_row(res)[0]));
    mysql_free_result(res);
    return ret;
}
示例#27
0
文件: ool.c 项目: vesselinv/rb-gsl
static void set_functions(int argc, VALUE *argv, ool_conmin_function *F)
{
  VALUE ary;
  size_t i;
  if (F->params == NULL) {
    ary = rb_ary_new2(5);
    /*    (VALUE) F->params = ary;*/
    F->params = (void *) ary;
  } else {
    ary = (VALUE) F->params;
  }
  switch (argc) {
	case 4:
		for (i = 0; i < argc; i++) rb_ary_store(ary, i, argv[i]);
		break;
	default:
		rb_raise(rb_eArgError,"Wrong number of arguments (%d for 4)", argc);
	}
}
示例#28
0
VALUE read_string(unsigned char **pData) {
  if(read_1(pData) != ERL_STRING) {
    rb_raise(rb_eStandardError, "Invalid Type, not an erlang string");
  }
  
  int length = read_2(pData);
  
  unsigned char buf[length + 1];
  read_string_raw(buf, pData, length);
  
  VALUE array = rb_ary_new2(length);
  
  int i = 0;
  for(i; i < length; ++i) {
    rb_ary_store(array, i, INT2NUM(*(buf + i)));
  }
  
  return array;
}
示例#29
0
VALUE read_list(unsigned char **pData) {
  if(read_1(pData) != ERL_LIST) {
    rb_raise(rb_eStandardError, "Invalid Type, not an erlang list");
  }

  unsigned int size = read_4(pData);

  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
  VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(size));

  int i;
  for(i = 0; i < size; ++i) {
    rb_ary_store(array, i, read_any_raw(pData));
  }

  read_1(pData);

  return array;
}
示例#30
0
static VALUE call_function_internal(VALUE _fcall)
{
    ruby_fcall_t*fcall = (ruby_fcall_t*)_fcall;
    language_interpreter_t*li = fcall->li;
    row_t*row = fcall->row;

    rb_internal_t*rb = (rb_internal_t*)li->internal;

    volatile VALUE array = rb_ary_new2(row->num_inputs);
    int i;
    for(i=0;i<row->num_inputs;i++) {
        assert(row->inputs[i].type == CONTINUOUS);
        rb_ary_store(array, i, rb_float_new(row->inputs[i].value));
    }

    volatile ID fname = rb_intern("predict");
    volatile VALUE object = rb_eval_string("Object");
    return rb_funcall(object, fname, 1, array);
}