示例#1
0
文件: digest.c 项目: DashYang/sim
static rb_digest_metadata_t *
get_digest_base_metadata(VALUE klass)
{
    VALUE p;
    VALUE obj;
    rb_digest_metadata_t *algo;

    for (p = klass; !NIL_P(p); p = rb_class_superclass(p)) {
        if (rb_ivar_defined(p, id_metadata)) {
            obj = rb_ivar_get(p, id_metadata);
            break;
        }
    }

    if (NIL_P(p))
        rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");

#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
    Data_Get_Struct(obj, rb_digest_metadata_t, algo);

    switch (algo->api_version) {
      case 3:
        break;

      /*
       * put conversion here if possible when API is updated
       */

      default:
        rb_raise(rb_eRuntimeError, "Incompatible digest API version");
    }

    return algo;
}
示例#2
0
文件: main.cpp 项目: Hanmac/rwx
void registerDataType(VALUE klass, RUBY_DATA_FUNC freefunc, size_t (*sizefunc)(const void *))
{

	if(!NIL_P(klass))
	{

		rb_data_type_t *parent = NULL;
		if(rb_obj_is_kind_of(klass, rb_cClass)) {
			parent = unwrapDataType(rb_class_superclass(klass));
			//if the class does include EvtHandler,
			// add it as a parent if class doesnt already have one
			if(!parent && rb_class_inherited_p(klass, rb_mWXEvtHandler) == Qtrue) {
				parent = unwrapDataType(rb_mWXEvtHandler);
			}
		}

		rb_data_type_t str = {
			rb_class2name(klass),
			{0, freefunc, sizefunc,},
			parent, NULL,
		};

		datatypeholder[klass] = str;
		if(freefunc) {
			rb_data_type_t str_const = {
				(std::string(rb_class2name(klass)) + "(const)").c_str(),
				{0, 0, sizefunc,},
				&datatypeholder[klass], NULL,
			};
			datatypeholder_const[klass] = str_const;
		}else {
			datatypeholder_const[klass] = str;
		}
	}
}
示例#3
0
static VALUE oci8_s_allocate(VALUE klass)
{
    oci8_base_t *base;
    const oci8_base_vtable_t *vptr;
    VALUE superklass;
    VALUE obj;

    superklass = klass;
    while (!RTEST(rb_ivar_defined(superklass, oci8_id_oci8_vtable))) {
        superklass = rb_class_superclass(superklass);
        if (superklass == rb_cObject)
            rb_raise(rb_eRuntimeError, "private method `new' called for %s:Class", rb_class2name(klass));
    }
    obj = rb_ivar_get(superklass, oci8_id_oci8_vtable);
    vptr = DATA_PTR(obj);

    base = xmalloc(vptr->size);
    memset(base, 0, vptr->size);

    obj = Data_Wrap_Struct(klass, oci8_handle_mark, oci8_handle_cleanup, base);
    base->self = obj;
    base->vptr = vptr;
    base->parent = NULL;
    base->next = base;
    base->prev = base;
    base->children = NULL;
    if (vptr->init != NULL) {
        vptr->init(base);
    }
    return obj;
}
示例#4
0
文件: main.cpp 项目: Hanmac/rwx
const wxClassInfo* unwrapClass(VALUE klass)
{
	for(infoholdertype::iterator it = infoklassholder.begin(); it != infoklassholder.end(); ++it)
	{
		if(it->second == klass)
			return it->first;
	}
	return unwrapClass(rb_class_superclass(klass));
}
示例#5
0
/* ================  Helper Functions  =================*/
static VALUE
figure_singleton_name(VALUE klass)
{
    VALUE result = Qnil;

    /* We have come across a singleton object. First
       figure out what it is attached to.*/
    VALUE attached = rb_iv_get(klass, "__attached__");

    /* Is this a singleton class acting as a metaclass? */
    if (BUILTIN_TYPE(attached) == T_CLASS)
    {
        result = rb_str_new2("<Class::");
        rb_str_append(result, rb_inspect(attached));
        rb_str_cat2(result, ">");
    }

    /* Is this for singleton methods on a module? */
    else if (BUILTIN_TYPE(attached) == T_MODULE)
    {
        result = rb_str_new2("<Module::");
        rb_str_append(result, rb_inspect(attached));
        rb_str_cat2(result, ">");
    }

    /* Is this for singleton methods on an object? */
    else if (BUILTIN_TYPE(attached) == T_OBJECT)
    {
        /* Make sure to get the super class so that we don't
           mistakenly grab a T_ICLASS which would lead to
           unknown method errors. */
#ifdef HAVE_RB_CLASS_SUPERCLASS
        // 1.9.3
        VALUE super = rb_class_superclass(klass);
#else
# ifdef RCLASS_SUPER
        VALUE super = rb_class_real(RCLASS_SUPER(klass));
# else
        VALUE super = rb_class_real(RCLASS(klass)->super);
# endif
#endif
        result = rb_str_new2("<Object::");
        rb_str_append(result, rb_inspect(super));
        rb_str_cat2(result, ">");
    }

    /* Ok, this could be other things like an array made put onto
       a singleton object (yeah, it happens, see the singleton
       objects test case). */
    else
    {
        result = rb_inspect(klass);
    }

    return result;
}
示例#6
0
文件: main.cpp 项目: Hanmac/rwx
rb_data_type_t* unwrapDataType(const VALUE& klass)
{
	if(klass == rb_cObject)
		return NULL;

	datatypeholdertype::iterator it = datatypeholder.find(klass);
	if(it != datatypeholder.end())
		return &it->second;

	for(it = datatypeholder.begin(); it != datatypeholder.end(); ++it)
	{
		if(wxString(rb_class2name(it->first)) == wxString(rb_class2name(klass))) {
			//rb_warn("compare broken for %s", rb_class2name(klass));
			return &it->second;
		}
	}

	if(rb_obj_is_kind_of(klass, rb_cClass))
		return unwrapDataType(rb_class_superclass(klass));

	return NULL;
}
示例#7
0
static VALUE class_spec_rb_class_superclass(VALUE self, VALUE klass) {
  return rb_class_superclass(klass);
}