Example #1
0
static VALUE
singleton_class_clone_int(VALUE obj, VALUE nklass)
{
    VALUE klass = RBASIC(obj)->klass;

    if (!FL_TEST(klass, FL_SINGLETON))
	return klass;
    else {
	/* copy singleton(unnamed) class */
	NEWOBJ(clone, struct RClass);
	OBJSETUP(clone, 0, RBASIC(klass)->flags);

	if (BUILTIN_TYPE(obj) == T_CLASS) {
	    RBASIC(clone)->klass = (VALUE)clone;
	}
	else {
	    RBASIC(clone)->klass = rb_singleton_class_clone(klass);
	}

	clone->super = RCLASS(klass)->super;
	clone->iv_tbl = 0;
	clone->m_tbl = 0;
	if (RCLASS(klass)->iv_tbl) {
	    clone->iv_tbl = st_copy(RCLASS(klass)->iv_tbl);
	}
	clone->m_tbl = st_init_numtable();
	st_foreach(RCLASS(klass)->m_tbl, (int (*)(...))clone_method, NIL_P(nklass) ? (VALUE)clone : nklass);
	rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
	FL_SET(clone, FL_SINGLETON);
	return (VALUE)clone;
    }
}
Example #2
0
// Buffer methods
static VALUE
rb_buffer_alloc(VALUE klass, SEL sel)
{
  NEWOBJ(s, rb_opencl_buffer_t);
  OBJSETUP(s, klass, RUBY_T_NATIVE);
  return (VALUE)s;
}
Example #3
0
static VALUE
struct_alloc(VALUE klass)
{
    VALUE size;
    long n;
    NEWOBJ(st, struct RStruct);
    OBJSETUP(st, klass, T_STRUCT);

    size = rb_struct_iv_get(klass, "__size__");
    n = FIX2LONG(size);

    if (0 < n && n <= RSTRUCT_EMBED_LEN_MAX) {
        RBASIC(st)->flags &= ~RSTRUCT_EMBED_LEN_MASK;
        RBASIC(st)->flags |= n << RSTRUCT_EMBED_LEN_SHIFT;
	rb_mem_clear(st->as.ary, n);
    }
    else {
	if (n > 0) {
	    GC_WB(&st->as.heap.ptr, xmalloc_ptrs(sizeof(VALUE) * n));
	    rb_mem_clear(st->as.heap.ptr, n);
	}
	else {
	    st->as.heap.ptr = NULL;
	}
	st->as.heap.len = n;
    }

    return (VALUE)st;
}
Example #4
0
// Command queue methods
static VALUE
rb_command_queue_alloc(VALUE klass, SEL sel)
{
  NEWOBJ(s, rb_opencl_command_queue_t);
  OBJSETUP(s, klass, RUBY_T_NATIVE);
  return (VALUE)s;
}
Example #5
0
static void add_module(VALUE self, VALUE module)
{
    VALUE super = RCLASS_SUPER(rb_singleton_class(self));

#ifdef RUBY_19
    VALUE klass = class_alloc(T_ICLASS, rb_cClass);
#else
    NEWOBJ(klass, struct RClass);
    OBJSETUP(klass, rb_cClass, T_ICLASS);
#endif

    if (BUILTIN_TYPE(module) == T_ICLASS) {
        module = KLASS_OF(module);
    }
    if (!RCLASS_IV_TBL(module)) {
        RCLASS_IV_TBL(module) = (void*)st_init_numtable();
    }

    RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
    RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
    RCLASS_SUPER(klass) = super;

    if (TYPE(module) == T_ICLASS) {
        KLASS_OF(klass) = KLASS_OF(module);
    } else {
        KLASS_OF(klass) = module;
    }
    OBJ_INFECT(klass, module);
    OBJ_INFECT(klass, super);

    RCLASS_SUPER(rb_singleton_class(self)) = (VALUE)klass;
}
Example #6
0
static VALUE
include_class_new(VALUE module, VALUE super)
{
    NEWOBJ(klass, struct RClass);
    OBJSETUP(klass, rb_cClass, T_ICLASS);

    if (BUILTIN_TYPE(module) == T_ICLASS) {
	module = RBASIC(module)->klass;
    }
    if (!RCLASS(module)->iv_tbl) {
	RCLASS(module)->iv_tbl = st_init_numtable();
    }
    klass->iv_tbl = RCLASS(module)->iv_tbl;
    klass->m_tbl = RCLASS(module)->m_tbl;
    klass->super = super;
    if (TYPE(module) == T_ICLASS) {
	RBASIC(klass)->klass = RBASIC(module)->klass;
    }
    else {
	RBASIC(klass)->klass = module;
    }
    OBJ_INFECT(klass, module);
    OBJ_INFECT(klass, super);

    return (VALUE)klass;
}
Example #7
0
static VALUE
rb_yaml_resolver_alloc(VALUE klass, SEL sel)
{
    NEWOBJ(resolver, struct rb_yaml_resolver_s);
    OBJSETUP(resolver, klass, T_OBJECT);
    resolver->tags = NULL;
    return (VALUE)resolver;
}
Example #8
0
static VALUE
rb_source_alloc(VALUE klass, SEL sel)
{
    NEWOBJ(source, rb_source_t);
    OBJSETUP(source, klass, RUBY_T_NATIVE);
    source->suspension_count = 1;
    return (VALUE)source;
}
Example #9
0
VALUE mtserver_alloc(void)
{
   NEWOBJ(mts,struct MTServer);
   OBJSETUP(mts,radical_mtServer,T_OBJECT);
   mts->workers=0;
   mts->avail=0;
   return (VALUE)mts;
}
Example #10
0
static VALUE
rb_group_alloc(VALUE klass, SEL sel)
{
    NEWOBJ(group, rb_group_t);
    OBJSETUP(group, klass, RUBY_T_NATIVE);
    group->suspension_count = 0;
    return (VALUE)group;
}
Example #11
0
static VALUE 
rb_queue_alloc(VALUE klass, SEL sel)
{
    NEWOBJ(queue, rb_queue_t);
    OBJSETUP(queue, klass, RUBY_T_NATIVE);
    queue->suspension_count = 0;
    queue->should_release_queue = 0;
    return (VALUE)queue;
}
Example #12
0
static VALUE ludicrous_splat_iterate_proc_(VALUE val)
{
  struct Ludicrous_Splat_Iterate_Proc_Data * data =
    (struct Ludicrous_Splat_Iterate_Proc_Data *)val;

  ID varname = rb_intern("ludicrous_splat_iterate_var");

  /* Create a new scope */
  NEWOBJ(scope, struct SCOPE);
  OBJSETUP(scope, 0, T_SCOPE);
  scope->super = ruby_scope->super;
  scope->local_tbl = ALLOC_N(ID, 4);
  scope->local_vars = ALLOC_N(VALUE, 4);
  scope->flags = SCOPE_MALLOC;

  /* Set the names of the scope's local variables */
  scope->local_tbl[0] = 3;
  scope->local_tbl[1] = '_';
  scope->local_tbl[2] = '~';
  scope->local_tbl[3] = varname;

  /* And and their values */
  scope->local_vars[0] = 3;
  scope->local_vars[1] = Qnil;
  scope->local_vars[2] = Qnil;
  scope->local_vars[3] = Qnil;
  ++scope->local_vars;

  scope->local_vars[0] = ruby_scope->local_vars[0]; /* $_ */
  scope->local_vars[1] = ruby_scope->local_vars[1]; /* $~ */

  /* Temporarily set ruby_scope to the new scope, so the proc being
   * created below will pick it up (it will be set back when this
   * function returns) */
  ruby_scope = scope;

  /* Create a new proc */
  VALUE proc = rb_proc_new(
      data->body,
      data->val);

  NODE * * var;
  Data_Get_Struct(proc, NODE *, var);

  /* Set the iterator's assignment node to set a local variable that the
   * iterator's body can retrieve */
  *var = NEW_MASGN(
      0,
      NEW_NODE(
          NODE_LASGN,
          varname,
          0,
          2));

  /* And return the proc */
  return proc;
}
Example #13
0
static VALUE
rb_semaphore_alloc(VALUE klass, SEL sel)
{
    NEWOBJ(s, rb_semaphore_t);
    OBJSETUP(s, klass, RUBY_T_NATIVE);
    s->sem = NULL;
    s->count = 0;
    return (VALUE)s;
}
Example #14
0
static VALUE
rb_yaml_emitter_alloc(VALUE klass, SEL sel)
{
    NEWOBJ(emitter, struct rb_yaml_emitter_s);
    OBJSETUP(emitter, klass, T_OBJECT);
    yaml_emitter_initialize(&emitter->emitter);
    emitter->output = Qnil;
    return (VALUE)emitter;
}
Example #15
0
/*
 * Allocates memory for a new array
 * Note: Implementation almost exactly the same
 * as Ruby 1.9.2 p0 (have to copy because static)
 */
static VALUE my_ary_alloc (VALUE klass)
{
  NEWOBJ(ary, struct RArray);
  OBJSETUP((VALUE)ary, klass, T_ARRAY);
  FL_SET_EMBED((VALUE)ary);
  ARY_SET_EMBED_LEN((VALUE)ary, 0);

  return (VALUE)ary;
}
Example #16
0
inline static VALUE
nucomp_s_new_internal(VALUE klass, VALUE real, VALUE imag)
{
    NEWOBJ(obj, struct RComplex);
    OBJSETUP(obj, klass, T_COMPLEX);

    obj->real = real;
    obj->imag = imag;

    return (VALUE)obj;
}
Example #17
0
inline static VALUE
nurat_s_new_internal(VALUE klass, VALUE num, VALUE den)
{
    NEWOBJ(obj, struct RRational);
    OBJSETUP(obj, klass, T_RATIONAL);

    obj->num = num;
    obj->den = den;

    return (VALUE)obj;
}
Example #18
0
static VALUE
ary_alloc(void)
{
  NEWOBJ(ary, struct RArray);
  OBJSETUP(ary, rb_cArray, T_ARRAY);

  ary->len = 0;
  ary->ptr = 0;
  ary->aux.capa = 0;

  return (VALUE)ary;
}
Example #19
0
VALUE
rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
{
    NEWOBJ(data, struct RData);
    if (klass) Check_Type(klass, T_CLASS);
    OBJSETUP(data, klass, T_DATA);
    GC_WB(&data->data, datap);
    data->dfree = dfree;
    data->dmark = dmark;

    return (VALUE)data;
}
Example #20
0
static VALUE
rb_yaml_parser_alloc(VALUE klass, SEL sel)
{
    NEWOBJ(parser, struct rb_yaml_parser_s);
    OBJSETUP(parser, klass, T_OBJECT);

    GC_WB(&parser->resolver, rb_oDefaultResolver);
    parser->event_valid = false;

    yaml_parser_initialize(&parser->parser);
    return (VALUE)parser;
}
Example #21
0
VALUE
rb_module_new()
{
    NEWOBJ(mdl, struct RClass);
    OBJSETUP(mdl, rb_cModule, T_MODULE);

    mdl->super = 0;
    mdl->iv_tbl = 0;
    mdl->m_tbl = 0;
    mdl->m_tbl = st_init_numtable();

    return (VALUE)mdl;
}
Example #22
0
/**
 * Allocates a struct RClass for a new class.
 *
 * \param flags     initial value for basic.flags of the returned class.
 * \param klass     the class of the returned class.
 * \return          an uninitialized Class object.
 * \pre  \p klass must refer \c Class class or an ancestor of Class.
 * \pre  \code (flags | T_CLASS) != 0  \endcode
 * \post the returned class can safely be \c #initialize 'd.
 *
 * \note this function is not Class#allocate.
 */
static VALUE
class_alloc(VALUE flags, VALUE klass)
{
    rb_classext_t *ext = ALLOC(rb_classext_t);
    NEWOBJ(obj, struct RClass);
    OBJSETUP(obj, klass, flags);
    obj->ptr = ext;
    RCLASS_IV_TBL(obj) = 0;
    RCLASS_M_TBL(obj) = 0;
    RCLASS_SUPER(obj) = 0;
    RCLASS_IV_INDEX_TBL(obj) = 0;
    return (VALUE)obj;
}
Example #23
0
VALUE
rb_class_boot(VALUE super)
{
    NEWOBJ(klass, struct RClass);
    OBJSETUP(klass, rb_cClass, T_CLASS);

    klass->super = super;
    klass->iv_tbl = 0;
    klass->m_tbl = 0;		/* safe GC */
    klass->m_tbl = st_init_numtable();

    OBJ_INFECT(klass, super);
    return (VALUE)klass;
}
Example #24
0
static VALUE
range_dumper(VALUE range)
{
    VALUE v;
    NEWOBJ(m, struct RObject);
    OBJSETUP(m, rb_cObject, T_OBJECT);

    v = (VALUE)m;

    rb_ivar_set(v, id_excl, RANGE_EXCL(range));
    rb_ivar_set(v, id_beg, RANGE_BEG(range));
    rb_ivar_set(v, id_end, RANGE_END(range));
    return v;
}
Example #25
0
static VALUE callwith_cleanup(VALUE self)
{
  /* We don't want to keep the ivar table pointer around indefinitely,
   * because if we do, the GC will free the ivar table, which is
   * undesirable, since the original object still references it.  So we
   * set the ivar table back to something that won't get freed, instead.
   */

  NEWOBJ(dummy, struct RObject);
  OBJSETUP(dummy, rb_cCallWith, T_OBJECT);

  struct RBasic basic = *(RBASIC(self));
  *(ROBJECT(self)) = *(ROBJECT(dummy));
  *(RBASIC(self)) = basic;
}
Example #26
0
/* a modified version of include_class_new from class.c */
static VALUE
j_class_new(VALUE module, VALUE sup)
{

#ifdef RUBY_19
    VALUE klass = class_alloc(T_ICLASS, rb_cClass);
#else
    NEWOBJ(klass, struct RClass);
    OBJSETUP(klass, rb_cClass, T_ICLASS);
#endif

    if (BUILTIN_TYPE(module) == T_ICLASS) {
        module = KLASS_OF(module);
    }

    if (!RCLASS_IV_TBL(module)) {

        RCLASS_IV_TBL(module) = (struct st_table *)st_init_numtable();
    }

    /* assign iv_tbl, m_tbl and super */
    RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
    RCLASS_SUPER(klass) = sup;
    if(TYPE(module) != T_OBJECT) {

        RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
    }
    else {
        RCLASS_M_TBL(klass) = RCLASS_M_TBL(CLASS_OF(module));
    }

    /* */

    if (TYPE(module) == T_ICLASS) {
        KLASS_OF(klass) = KLASS_OF(module);
    }
    else {
        KLASS_OF(klass) = module;
    }

    if(TYPE(module) != T_OBJECT) {
        OBJ_INFECT(klass, module);
        OBJ_INFECT(klass, sup);
    }
    return (VALUE)klass;
}
Example #27
0
static VALUE
struct_alloc(VALUE klass)
{
    VALUE size;
    long n;
    NEWOBJ(st, struct RStruct);
    OBJSETUP(st, klass, T_STRUCT);

    size = rb_struct_iv_get(klass, "__size__");
    n = FIX2LONG(size);

    st->ptr = ALLOC_N(VALUE, n);
    rb_mem_clear(st->ptr, n);
    st->len = n;

    return (VALUE)st;
}
Example #28
0
static VALUE class_alloc(VALUE flags, VALUE klass)
{
#ifdef RUBY_193
    rb_deprecated_classext_t *ext = ALLOC(rb_deprecated_classext_t);
#else
    rb_classext_t *ext = ALLOC(rb_classext_t);
#endif
    NEWOBJ(obj, struct RClass);
    OBJSETUP(obj, klass, flags);
    obj->ptr = ext;
    RCLASS_IV_TBL(obj) = 0;
    RCLASS_M_TBL(obj) = 0;
    RCLASS_SUPER(obj) = 0;
#ifndef RUBY_193
    RCLASS_IV_INDEX_TBL(obj) = 0;
#endif
    return (VALUE)obj;
}
Example #29
0
/* note: this code is magical: */
static VALUE rb_str_new_move(char* data, size_t length)
{
    NEWOBJ(str, struct RString);
    OBJSETUP(str, rb_cString, T_STRING);

    str->as.heap.ptr = data;
    str->as.heap.len = length;
    str->as.heap.aux.capa = length;

    FL_SET(str, FL_USER1);  /* set STR_NOEMBED */
    RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;

    /* this is safe. see msgpack_postmem_alloc() */
    data[length] = '\0';

    /* ???: unknown whether this is needed or not */
    OBJ_FREEZE(str);

    return (VALUE) str;
}
Example #30
0
File: gc.c Project: 1nueve/MacRuby
VALUE
rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark,
	RUBY_DATA_FUNC dfree)
{
    if (klass) {
	Check_Type(klass, T_CLASS);
    }

    NEWOBJ(data, struct RData);
    OBJSETUP(data, klass, T_DATA);
    GC_WB(&data->data, datap);
    data->dfree = dfree;
    data->dmark = dmark;

    if (dfree != NULL) {
	rb_objc_install_method2((Class)klass, "finalize", (IMP)rdata_finalize);
    }

    return (VALUE)data;
}