Exemplo n.º 1
0
static void
rb_export_method(VALUE klass, ID name, rb_method_flag_t noex)
{
    rb_method_entry_t *me;
    VALUE defined_class;

    me = search_method(klass, name, &defined_class);
    if (!me && RB_TYPE_P(klass, T_MODULE)) {
	me = search_method(rb_cObject, name, &defined_class);
    }

    if (UNDEFINED_METHOD_ENTRY_P(me) ||
	UNDEFINED_REFINED_METHOD_P(me->def)) {
	rb_print_undef(klass, name, 0);
    }

    if (me->flag != noex) {
	rb_vm_check_redefinition_opt_method(me, klass);

	if (klass == defined_class ||
	    RCLASS_ORIGIN(klass) == defined_class) {
	    me->flag = noex;
	    if (me->def->type == VM_METHOD_TYPE_REFINED) {
		me->def->body.orig_me->flag = noex;
	    }
	    rb_clear_method_cache_by_class(klass);
	}
	else {
	    rb_add_method(klass, name, VM_METHOD_TYPE_ZSUPER, 0, noex);
	}
    }
}
void
rb_alias(VALUE klass, ID name, ID def)
{
    VALUE target_klass = klass;
    rb_method_entry_t *orig_me;
    rb_method_flag_t flag = NOEX_UNDEF;

    if (NIL_P(klass)) {
	rb_raise(rb_eTypeError, "no class to make alias");
    }

    rb_frozen_class_p(klass);
    if (klass == rb_cObject) {
	rb_secure(4);
    }

  again:
    orig_me = search_method(klass, def);

    if (UNDEFINED_METHOD_ENTRY_P(orig_me)) {
	if ((!RB_TYPE_P(klass, T_MODULE)) ||
	    (orig_me = search_method(rb_cObject, def), UNDEFINED_METHOD_ENTRY_P(orig_me))) {
	    rb_print_undef(klass, def, 0);
	}
    }
    if (orig_me->def->type == VM_METHOD_TYPE_ZSUPER) {
	klass = RCLASS_SUPER(klass);
	def = orig_me->def->original_id;
	flag = orig_me->flag;
	goto again;
    }

    if (flag == NOEX_UNDEF) flag = orig_me->flag;
    rb_method_entry_set(target_klass, name, orig_me, flag);
}
static void
rb_export_method(VALUE klass, ID name, rb_method_flag_t noex)
{
    rb_method_entry_t *me;

    if (klass == rb_cObject) {
	rb_secure(4);
    }

    me = search_method(klass, name);
    if (!me && RB_TYPE_P(klass, T_MODULE)) {
	me = search_method(rb_cObject, name);
    }

    if (UNDEFINED_METHOD_ENTRY_P(me)) {
	rb_print_undef(klass, name, 0);
    }

    if (me->flag != noex) {
	rb_vm_check_redefinition_opt_method(me, klass);

	if (klass == me->klass) {
	    me->flag = noex;
	}
	else {
	    rb_add_method(klass, name, VM_METHOD_TYPE_ZSUPER, 0, noex);
	}
    }
}
Exemplo n.º 4
0
static void
rb_export_method(VALUE klass, ID name, ID noex)
{
    NODE *fbody;
    VALUE origin;

    if (klass == rb_cObject) {
	rb_secure(4);
    }
    fbody = search_method(klass, name, &origin);
    if (!fbody && TYPE(klass) == T_MODULE) {
	fbody = search_method(rb_cObject, name, &origin);
    }
    if (!fbody || !fbody->nd_body) {
	rb_print_undef(klass, name, 0);
    }
    if (fbody->nd_body->nd_noex != noex) {
	if (nd_type(fbody->nd_body->nd_body) == NODE_CFUNC) {
	    rb_vm_check_redefinition_opt_method(fbody);
	}
	if (klass == origin) {
	    fbody->nd_body->nd_noex = noex;
	}
	else {
	    rb_add_method(klass, name, NEW_ZSUPER(), noex);
	}
    }
}
Exemplo n.º 5
0
void
rb_alias(VALUE klass, ID name, ID def)
{
    NODE *orig_fbody, *node, *method;
    VALUE singleton = 0;
    st_data_t data;

    rb_frozen_class_p(klass);
    if (klass == rb_cObject) {
	rb_secure(4);
    }
    orig_fbody = search_method(klass, def, 0);
    if (!orig_fbody || !orig_fbody->nd_body) {
	if (TYPE(klass) == T_MODULE) {
	    orig_fbody = search_method(rb_cObject, def, 0);
	}
    }
    if (!orig_fbody || !orig_fbody->nd_body) {
	rb_print_undef(klass, def, 0);
    }
    if (FL_TEST(klass, FL_SINGLETON)) {
	singleton = rb_iv_get(klass, "__attached__");
    }

    orig_fbody->nd_cnt++;

    if (st_lookup(RCLASS_M_TBL(klass), name, &data)) {
	node = (NODE *)data;
	if (node) {
	    if (RTEST(ruby_verbose) && node->nd_cnt == 0 && node->nd_body) {
		rb_warning("discarding old %s", rb_id2name(name));
	    }
	    if (nd_type(node->nd_body->nd_body) == NODE_CFUNC) {
		rb_vm_check_redefinition_opt_method(node);
	    }
	}
    }

    st_insert(RCLASS_M_TBL(klass), name,
	      (st_data_t) NEW_FBODY(
		  method = NEW_METHOD(orig_fbody->nd_body->nd_body,
			     orig_fbody->nd_body->nd_clss,
			     NOEX_WITH_SAFE(orig_fbody->nd_body->nd_noex)), def));
    method->nd_file = (void *)def;

    rb_clear_cache_by_id(name);

    if (!ruby_running) return;

    if (singleton) {
	rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
    }
    else {
	rb_funcall(klass, added, 1, ID2SYM(name));
    }
}
Exemplo n.º 6
0
EC_API EC_OBJ EcFindMethod( EC_OBJ obj, EC_OBJ *at_class, EcUInt methodid )
{
	EC_OBJ classobj;
	EcInt at;

	ASSERT( EC_OBJECTP(obj) );

	/*ec_fprintf( stderr, "EcFindMethod  methodid: %ld %k\n", (long)methodid, methodid );*/
	if (at_class && EC_NNULLP(*at_class))
		classobj = *at_class;
	else
		classobj = EC_OBJECTCLASS(obj);
	while (EC_NNULLP(classobj))
	{
		at = search_method( EC_CLASSNMETHODS(classobj), EC_CLASSMTABLE(classobj), methodid ); 
		if (at >= 0)
		{
			if (at_class) *at_class = classobj;
			return EC_CLASSMTABLE(classobj)[at].impl;
		}

		classobj = EC_CLASSSUPER(classobj);
	}

	if (at_class) *at_class = EC_NIL;
	return EC_NIL;
}
Exemplo n.º 7
0
jobject convert_vector_to_jobject(JNIEnv *env, std::vector<std::unique_ptr<T>>& array,
                                const char *ctor_prototype)
{
    unsigned int array_size = array.size();

    jmethodID arraylist_add;
    jobject result = get_new_arraylist(env, array_size, &arraylist_add);

    if (array_size == 0)
    {
        return result;
    }

    jclass clazz = search_class(env, T::java_class().c_str());
    jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);

    for (unsigned int i = 0; i < array_size; ++i)
    {
        T *elem = array.at(i).release();
        jobject object = env->NewObject(clazz, clazz_ctor, (jlong)elem);
        if (!object)
        {
            throw std::runtime_error("cannot create instance of class\n");
        }
        env->CallBooleanMethod(result, arraylist_add, object);
    }
    return result;
}
Exemplo n.º 8
0
TEST (ROPSFeature, FeatureExtraction)
{
  float support_radius = 0.0285f;
  unsigned int number_of_partition_bins = 5;
  unsigned int number_of_rotations = 3;

  pcl::search::KdTree<pcl::PointXYZ>::Ptr search_method (new pcl::search::KdTree<pcl::PointXYZ>);
  search_method->setInputCloud (cloud);

  pcl::ROPSEstimation <pcl::PointXYZ, pcl::Histogram <135> > feature_estimator;
  feature_estimator.setSearchMethod (search_method);
  feature_estimator.setSearchSurface (cloud);
  feature_estimator.setInputCloud (cloud);
  feature_estimator.setIndices (indices);
  feature_estimator.setTriangles (triangles);
  feature_estimator.setRadiusSearch (support_radius);
  feature_estimator.setNumberOfPartitionBins (number_of_partition_bins);
  feature_estimator.setNumberOfRotations (number_of_rotations);
  feature_estimator.setSupportRadius (support_radius);

  pcl::PointCloud<pcl::Histogram <135> >::Ptr histograms (new pcl::PointCloud <pcl::Histogram <135> > ());
  feature_estimator.compute (*histograms);

  EXPECT_NE (0, histograms->points.size ());
}
Exemplo n.º 9
0
void
rb_undef(VALUE klass, ID id)
{
    // TODO
#if 0
    VALUE origin;
    NODE *body;

#if 0 // TODO
    if (rb_vm_cbase() == rb_cObject && klass == rb_cObject) {
	rb_secure(4);
    }
#endif
    if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
	rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'",
		 rb_id2name(id));
    }
    rb_frozen_class_p(klass);
    if (id == object_id || id == __send__ || id == idInitialize) {
	rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
    }
    /* TODO: warn if a very important method of NSObject is undefined 
     * by default, pure objc methods are not exposed by introspections API 
     */
    body = search_method(klass, id, &origin);
    if (!body || !body->nd_body) {
	const char *s0 = " class";
	VALUE c = klass;

	if (RCLASS_SINGLETON(c)) {
	    VALUE obj = rb_iv_get(klass, "__attached__");

	    switch (TYPE(obj)) {
	      case T_MODULE:
	      case T_CLASS:
		c = obj;
		s0 = "";
	    }
	}
	else if (TYPE(c) == T_MODULE) {
	    s0 = " module";
	}
	rb_name_error(id, "undefined method `%s' for%s `%s'",
		      rb_id2name(id), s0, rb_class2name(c));
    }

    rb_add_method(klass, id, 0, NOEX_PUBLIC);

    if (RCLASS_SINGLETON(klass)) {
	rb_funcall(rb_iv_get(klass, "__attached__"),
		   singleton_undefined, 1, ID2SYM(id));
    }
    else {
	rb_funcall(klass, undefined, 1, ID2SYM(id));
    }
#endif
}
Exemplo n.º 10
0
static VALUE
rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
{
    int i;
    ID id;
    NODE *fbody;

    if (TYPE(module) != T_MODULE) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_MODFUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	VALUE m = module;

	id = rb_to_id(argv[i]);
	for (;;) {
	    fbody = search_method(m, id, &m);
	    if (fbody == 0) {
		fbody = search_method(rb_cObject, id, &m);
	    }
	    if (fbody == 0 || fbody->nd_body == 0) {
		rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
	    }
	    if (nd_type(fbody->nd_body->nd_body) != NODE_ZSUPER) {
		break;		/* normal case: need not to follow 'super' link */
	    }
	    m = RCLASS_SUPER(m);
	    if (!m)
		break;
	}
	rb_add_method(rb_singleton_class(module), id, fbody->nd_body->nd_body,
		      NOEX_PUBLIC);
    }
    return module;
}
void QGenieGetRouterWlanInfoThread::run()
{
    if(0==m_soapapi
#ifdef PLATFORM_WIN32
       && 0==setupapi_inf
#endif
       )
    {
        emit getwlaninfo_complete(false,QString(),QString(),QString(),QString());
        return;
    }

    //initialize
    m_bstart_ok         = false;
    m_bgetssid_ok       = false;
    m_bgetkey_ok        = false;
    m_bcontinue         = true;

    m_strnicguid.clear();
    m_strprofilename.clear();
    m_strssid.clear();
    m_strkey.clear();
    //initialize end

    if(false/*setupapi_inf && setupapi_inf->get_export_information(m_strnicguid,m_strssid,m_strprofilename)*/)
    {
         emit getwlaninfo_complete(true,m_strssid,QString(),m_strnicguid,m_strprofilename);
    }
    else
    {
        QString  str_session("f8018c9f-5431-497e-ac5d-511dd0ae7402");
        //get wlan exporting information from router
//        //Start
//        QString start_module("DeviceConfig");
//        QString start_method("ConfigurationStarted");
//        QMap<QString,QString> start_param;
//        QUuid uuid_start ("{14E65BB7-0D3B-4c90-871E-187E58D6712C}");
//        start_param.insert(QString("NewSessionID"), QString("99999999999"));
//        m_soapapi->submitrequest(start_module,start_method ,start_param,uuid_start,
//                                str_session );
//        GeniePlugin_WSetupPlugin::output_log(QString("submit:DeviceConfig ConfigurationStarted UUID:{14E65BB7-0D3B-4c90-871E-187E58D6712C}"));

        QMap<QString,QString> search_param;
        QString  search_module("WLANConfiguration");
        QString  search_method("GetSSID");
        QUuid uuid_ssid( "{CFE911FE-C5E8-4a0e-A073-6FD28B017E41}");
        m_soapapi->submitrequest(search_module,search_method , search_param,uuid_ssid,str_session);
        GeniePlugin_WSetupPlugin::output_log(QString("submit:WLANConfiguration GetSSID UUID:{CFE911FE-C5E8-4a0e-A073-6FD28B017E41}"));

        search_method = "GetWPASecurityKeys";
        QUuid uuid_key("{B8D2DCFD-0A58-4e46-882A-5EB1DC77EBB4}");
        m_soapapi->submitrequest(search_module,search_method , search_param,uuid_key,str_session);
        GeniePlugin_WSetupPlugin::output_log(QString("submit:WLANConfiguration GetWPASecurityKeys UUID:{B8D2DCFD-0A58-4e46-882A-5EB1DC77EBB4}"));
    }
}
Exemplo n.º 12
0
static VALUE
rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
{
    int i;
    ID id;
    const rb_method_entry_t *me;

    if (!RB_TYPE_P(module, T_MODULE)) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_MODFUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	VALUE m = module;

	id = rb_to_id(argv[i]);
	for (;;) {
	    me = search_method(m, id);
	    if (me == 0) {
		me = search_method(rb_cObject, id);
	    }
	    if (UNDEFINED_METHOD_ENTRY_P(me)) {
		rb_print_undef(module, id, 0);
	    }
	    if (me->def->type != VM_METHOD_TYPE_ZSUPER) {
		break; /* normal case: need not to follow 'super' link */
	    }
	    m = RCLASS_SUPER(m);
	    if (!m)
		break;
	}
	rb_method_entry_set(rb_singleton_class(module), id, me, NOEX_PUBLIC);
    }
    return module;
}
Exemplo n.º 13
0
void
rb_alias(VALUE klass, ID name, ID def)
{
    rb_method_entry_t *orig_me;

    rb_frozen_class_p(klass);
    if (klass == rb_cObject) {
	rb_secure(4);
    }

    orig_me = search_method(klass, def);

    if (UNDEFINED_METHOD_ENTRY_P(orig_me)) {
	if ((TYPE(klass) != T_MODULE) ||
	    (orig_me = search_method(rb_cObject, def), UNDEFINED_METHOD_ENTRY_P(orig_me))) {
	    rb_print_undef(klass, def, 0);
	}
    }

    rb_add_method_me(klass, name, orig_me, orig_me->flag);
}
Exemplo n.º 14
0
void
rb_alias(VALUE klass, ID name, ID def)
{
    VALUE target_klass = klass;
    VALUE defined_class;
    rb_method_entry_t *orig_me;
    rb_method_flag_t flag = NOEX_UNDEF;

    if (NIL_P(klass)) {
	rb_raise(rb_eTypeError, "no class to make alias");
    }

    rb_frozen_class_p(klass);

  again:
    orig_me = search_method(klass, def, &defined_class);

    if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
	UNDEFINED_REFINED_METHOD_P(orig_me->def)) {
	if ((!RB_TYPE_P(klass, T_MODULE)) ||
	    (orig_me = search_method(rb_cObject, def, 0),
	     UNDEFINED_METHOD_ENTRY_P(orig_me))) {
	    rb_print_undef(klass, def, 0);
	}
    }
    if (orig_me->def->type == VM_METHOD_TYPE_ZSUPER) {
	klass = RCLASS_SUPER(klass);
	def = orig_me->def->original_id;
	flag = orig_me->flag;
	goto again;
    }
    if (RB_TYPE_P(defined_class, T_ICLASS)) {
	VALUE real_class = RBASIC_CLASS(defined_class);
	if (real_class && RCLASS_ORIGIN(real_class) == defined_class)
	    defined_class = real_class;
    }

    if (flag == NOEX_UNDEF) flag = orig_me->flag;
    method_entry_set(target_klass, name, orig_me, flag, defined_class);
}
Exemplo n.º 15
0
static EcBool does_class_understand( EC_OBJ classobj, EcUInt methodid )
{
	ASSERT( EC_CLASSP(classobj) );

	while (EC_NNULLP(classobj))
	{
		if (search_method( EC_CLASSNCMETHODS(classobj), EC_CLASSCMTABLE(classobj), methodid ) >= 0)
			return TRUE;

		classobj = EC_CLASSSUPER(classobj);
	}

	return FALSE;
}
Exemplo n.º 16
0
EC_API EC_OBJ EcDispatchObjectMessage( EC_OBJ obj, EC_OBJ at_class, EcUInt methodid, EC_OBJ stack )
{
	EC_OBJ classobj, callable;
	EcInt at;

	ASSERT( EC_OBJECTP(obj) );

/*	ec_fprintf( stderr,
				"EcDispatchObjectMessage   receiver: %w.%w  method: %k  nargs: %ld\n",
				at_class, obj, methodid, EC_NNULLP(stack) ? (long)EC_STACKNARGS_LOGICAL(stack) : 0 );*/

	if (EC_BOOLP(at_class))
		classobj = EC_OBJECTCLASS(obj);
	else
		classobj = at_class;

	while (EC_NNULLP(classobj))
	{
		at = search_method( EC_CLASSNMETHODS(classobj), EC_CLASSMTABLE(classobj), methodid ); 
/*		ec_fprintf( stderr,
					"   in class %w  at: %ld\n",
					classobj, (long)at );*/
		if (at >= 0)
		{
			callable = EC_CLASSMTABLE(classobj)[at].impl;
			switch (EC_TYPE(callable))
			{
			case tc_primitive:
				return EC_PRIMITIVE(callable)( stack, EC_PRIMITIVEUSERDATA(callable) );
				break;
			case tc_cmethod:
				return EC_CMETHOD(callable)( obj, classobj, stack );
				break;
			default:
				if (EC_COMPILEDP(callable))
					return EcExecute( obj, classobj, callable, stack );
				ASSERT( FALSE );
			}
		}

		classobj = EC_CLASSSUPER(classobj);
	}

	/* No such a method. Invoke doesNotUnderstand if available */
	return EcUnknownMethod( obj, at_class, methodid, stack );

	/* TODO: Should raise an exception */
	ASSERT( FALSE );
	return Ec_ERROR;
}
Exemplo n.º 17
0
void
rb_undef(VALUE klass, ID id)
{
    VALUE origin;
    NODE *body;

    if (rb_vm_cbase() == rb_cObject && klass == rb_cObject) {
	rb_secure(4);
    }
    if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
	rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'",
		 rb_id2name(id));
    }
    rb_frozen_class_p(klass);
    if (id == object_id || id == __send__ || id == idInitialize) {
	rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
    }
    body = search_method(klass, id, &origin);
    if (!body || !body->nd_body) {
	const char *s0 = " class";
	VALUE c = klass;

	if (FL_TEST(c, FL_SINGLETON)) {
	    VALUE obj = rb_iv_get(klass, "__attached__");

	    switch (TYPE(obj)) {
	      case T_MODULE:
	      case T_CLASS:
		c = obj;
		s0 = "";
	    }
	}
	else if (TYPE(c) == T_MODULE) {
	    s0 = " module";
	}
	rb_name_error(id, "undefined method `%s' for%s `%s'",
		      rb_id2name(id), s0, rb_class2name(c));
    }

    rb_add_method(klass, id, 0, NOEX_PUBLIC);

    if (FL_TEST(klass, FL_SINGLETON)) {
	rb_funcall(rb_iv_get(klass, "__attached__"),
		   singleton_undefined, 1, ID2SYM(id));
    }
    else {
	rb_funcall(klass, undefined, 1, ID2SYM(id));
    }
}
Exemplo n.º 18
0
jobject generic_clone(JNIEnv *env, jobject obj)
{
    T *obj_generic = getInstance<T>(env, obj);
    T *copy_generic = new T(*obj_generic);

    jclass generic_class = search_class(env, *copy_generic);
    jmethodID generic_ctor = search_method(env, generic_class, "<init>", "(J)V", false);

    jobject result = env->NewObject(generic_class, generic_ctor, (jlong)copy_generic);
    if (!result)
    {
        throw std::runtime_error("cannot create instance of class\n");
    }

    return result;
}
Exemplo n.º 19
0
void
rb_undef(VALUE klass, ID id)
{
    rb_method_entry_t *me;

    if (NIL_P(klass)) {
	rb_raise(rb_eTypeError, "no class to undef method");
    }
    if (rb_vm_cbase() == rb_cObject && klass == rb_cObject) {
	rb_secure(4);
    }
    if (rb_safe_level() >= 4 && !OBJ_UNTRUSTED(klass)) {
	rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'", rb_id2name(id));
    }
    rb_frozen_class_p(klass);
    if (id == object_id || id == id__send__ || id == idInitialize) {
	rb_warn("undefining `%s' may cause serious problems", rb_id2name(id));
    }

    me = search_method(klass, id);

    if (UNDEFINED_METHOD_ENTRY_P(me)) {
	const char *s0 = " class";
	VALUE c = klass;

	if (FL_TEST(c, FL_SINGLETON)) {
	    VALUE obj = rb_ivar_get(klass, attached);

	    switch (TYPE(obj)) {
	      case T_MODULE:
	      case T_CLASS:
		c = obj;
		s0 = "";
	    }
	}
	else if (RB_TYPE_P(c, T_MODULE)) {
	    s0 = " module";
	}
	rb_name_error(id, "undefined method `%s' for%s `%s'",
		      rb_id2name(id), s0, rb_class2name(c));
    }

    rb_add_method(klass, id, VM_METHOD_TYPE_UNDEF, 0, NOEX_PUBLIC);

    CALL_METHOD_HOOK(klass, undefined, id);
}
Exemplo n.º 20
0
static EcBool does_object_understand( EC_OBJ obj, EcUInt methodid )
{
	EC_OBJ classobj;

	ASSERT( EC_OBJECTP(obj) );

	classobj = EC_OBJECTCLASS(obj);

	while (EC_NNULLP(classobj))
	{
		if (search_method( EC_CLASSNMETHODS(classobj), EC_CLASSMTABLE(classobj), methodid ) >= 0)
			return TRUE;

		classobj = EC_CLASSSUPER(classobj);
	}

	return FALSE;
}
Exemplo n.º 21
0
/*
 * search method entry without the method cache.
 *
 * if you need method entry with method cache (normal case), use
 * rb_method_entry() simply.
 */
rb_method_entry_t *
rb_method_entry_get_without_cache(VALUE klass, ID id,
				  VALUE *defined_class_ptr)
{
    VALUE defined_class;
    rb_method_entry_t *me = search_method(klass, id, &defined_class);

    if (me && me->klass) {
	switch (BUILTIN_TYPE(me->klass)) {
	  case T_CLASS:
	    if (RBASIC(klass)->flags & FL_SINGLETON) break;
	    /* fall through */
	  case T_ICLASS:
	    defined_class = me->klass;
	}
    }

    if (ruby_running) {
	if (OPT_GLOBAL_METHOD_CACHE) {
	    struct cache_entry *ent;
	    ent = GLOBAL_METHOD_CACHE(klass, id);
	    ent->class_serial = RCLASS_SERIAL(klass);
	    ent->method_state = GET_GLOBAL_METHOD_STATE();
	    ent->defined_class = defined_class;
	    ent->mid = id;

	    if (UNDEFINED_METHOD_ENTRY_P(me)) {
		ent->me = 0;
		me = 0;
	    }
	    else {
		ent->me = me;
	    }
	}
	else if (UNDEFINED_METHOD_ENTRY_P(me)) {
	    me = 0;
	}
    }

    if (defined_class_ptr)
	*defined_class_ptr = defined_class;
    return me;
}
Exemplo n.º 22
0
TEST (ROPSFeature, InvalidParameters)
{
  float support_radius = 0.0285f;
  unsigned int number_of_partition_bins = 5;
  unsigned int number_of_rotations = 3;

  pcl::search::KdTree<pcl::PointXYZ>::Ptr search_method (new pcl::search::KdTree<pcl::PointXYZ>);
  search_method->setInputCloud (cloud);

  pcl::ROPSEstimation <pcl::PointXYZ, pcl::Histogram <135> > feature_estimator;
  feature_estimator.setSearchMethod (search_method);
  feature_estimator.setSearchSurface (cloud);
  feature_estimator.setInputCloud (cloud);
  feature_estimator.setIndices (indices);
  feature_estimator.setTriangles (triangles);
  feature_estimator.setRadiusSearch (support_radius);
  feature_estimator.setNumberOfPartitionBins (number_of_partition_bins);
  feature_estimator.setNumberOfRotations (number_of_rotations);
  feature_estimator.setSupportRadius (support_radius);

  pcl::PointCloud<pcl::Histogram <135> >::Ptr histograms (new pcl::PointCloud <pcl::Histogram <135> > ());

  support_radius = -support_radius;
  feature_estimator.setSupportRadius (support_radius);
  support_radius = feature_estimator.getSupportRadius ();
  EXPECT_LT (0.0f, support_radius);

  number_of_partition_bins = 0;
  feature_estimator.setNumberOfPartitionBins (number_of_partition_bins);
  number_of_partition_bins = feature_estimator.getNumberOfPartitionBins ();
  EXPECT_LT (0, number_of_partition_bins);

  number_of_rotations = 0;
  feature_estimator.setNumberOfRotations (number_of_rotations);
  number_of_rotations = feature_estimator.getNumberOfRotations ();
  EXPECT_LT (0, number_of_rotations);

  std::vector <pcl::Vertices> empty_triangles;
  feature_estimator.setTriangles (empty_triangles);
  feature_estimator.compute (*histograms);
  EXPECT_EQ (0, histograms->points.size ());
}
Exemplo n.º 23
0
EC_API EC_OBJ EcFindClassMethod( EC_OBJ classobj, EC_OBJ *at_class, EcUInt methodid )
{
	EcInt at;

	ASSERT( EC_CLASSP(classobj) );

	while (EC_NNULLP(classobj))
	{
		at = search_method( EC_CLASSNCMETHODS(classobj), EC_CLASSCMTABLE(classobj), methodid ); 
		if (at >= 0)
		{
			if (at_class) *at_class = classobj;
			return EC_CLASSCMTABLE(classobj)[at].impl;
		}

		classobj = EC_CLASSSUPER(classobj);
	}

	return EC_NIL;
}
Exemplo n.º 24
0
/*
 * search method body (NODE_METHOD)
 *   with    : klass and id
 *   without : method cache
 *
 * if you need method node with method cache, use
 * rb_method_node()
 */
NODE *
rb_get_method_body(VALUE klass, ID id, ID *idp)
{
    NODE *volatile fbody, *body;
    NODE *method;

    if ((fbody = search_method(klass, id, 0)) == 0 || !fbody->nd_body) {
	/* store empty info in cache */
	struct cache_entry *ent;
	ent = cache + EXPR1(klass, id);
	ent->klass = klass;
	ent->mid = ent->mid0 = id;
	ent->method = 0;
	ent->oklass = 0;
	return 0;
    }

    method = fbody->nd_body;

    if (ruby_running) {
	/* store in cache */
	struct cache_entry *ent;
	ent = cache + EXPR1(klass, id);
	ent->klass = klass;
	ent->mid = id;
	ent->mid0 = fbody->nd_oid;
	ent->method = body = method;
	ent->oklass = method->nd_clss;
    }
    else {
	body = method;
    }

    if (idp) {
	*idp = fbody->nd_oid;
    }

    return body;
}
Exemplo n.º 25
0
void
rb_undef(VALUE klass, ID id)
{
    rb_method_entry_t *me;

    if (NIL_P(klass)) {
	rb_raise(rb_eTypeError, "no class to undef method");
    }
    rb_frozen_class_p(klass);
    if (id == object_id || id == id__send__ || id == idInitialize) {
	rb_warn("undefining `%s' may cause serious problems", rb_id2name(id));
    }

    me = search_method(klass, id, 0);

    if (UNDEFINED_METHOD_ENTRY_P(me) ||
	UNDEFINED_REFINED_METHOD_P(me->def)) {
	const char *s0 = " class";
	VALUE c = klass;

	if (FL_TEST(c, FL_SINGLETON)) {
	    VALUE obj = rb_ivar_get(klass, attached);

	    if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {
		c = obj;
		s0 = "";
	    }
	}
	else if (RB_TYPE_P(c, T_MODULE)) {
	    s0 = " module";
	}
	rb_name_error(id, "undefined method `%"PRIsVALUE"' for%s `%"PRIsVALUE"'",
		      QUOTE_ID(id), s0, rb_class_name(c));
    }

    rb_add_method(klass, id, VM_METHOD_TYPE_UNDEF, 0, NOEX_PUBLIC);

    CALL_METHOD_HOOK(klass, undefined, id);
}
Exemplo n.º 26
0
EC_API EC_OBJ EcDispatchClassMessage( EC_OBJ obj, EcUInt methodid, EC_OBJ stack )
{
	EcInt at;
	EC_OBJ callable;

	ASSERT( EC_CLASSP(obj) );

	while (EC_NNULLP(obj))
	{
		at = search_method( EC_CLASSNCMETHODS(obj), EC_CLASSCMTABLE(obj), methodid ); 
		if (at >= 0)
		{
			callable = EC_CLASSCMTABLE(obj)[at].impl;
			switch (EC_TYPE(callable))
			{
			case tc_primitive:
				return EC_PRIMITIVE(callable)( stack, EC_PRIMITIVEUSERDATA(callable) );
				break;
			case tc_cmethod:
				return EC_CMETHOD(callable)( obj, EC_NIL, stack );
				break;
			default:
				if (EC_COMPILEDP(callable))
					return EcExecute( EC_NIL, obj, callable, stack );
				ASSERT( FALSE );
			}
		}

		obj = EC_CLASSSUPER(obj);
	}

	/* No such a method. Invoke doesNotUnderstand if available */
	return EcUnknownMethod( obj, EC_NIL, methodid, stack );

	/* TODO: Should raise an exception */
	ASSERT( FALSE );
	return Ec_ERROR;
}
Exemplo n.º 27
0
/*
 * search method entry without method cache.
 *
 * if you need method entry with method cache, use
 * rb_method_entry()
 */
rb_method_entry_t *
rb_get_method_entry(VALUE klass, ID id)
{
    rb_method_entry_t *me = search_method(klass, id);

    if (ruby_running) {
	struct cache_entry *ent;
	ent = cache + EXPR1(klass, id);
	ent->klass = klass;

	if (UNDEFINED_METHOD_ENTRY_P(me)) {
	    ent->mid = id;
	    ent->me = 0;
	    me = 0;
	}
	else {
	    ent->mid = id;
	    ent->me = me;
	}
    }

    return me;
}
Exemplo n.º 28
0
/*
 * search method entry without the method cache.
 *
 * if you need method entry with method cache (normal case), use
 * rb_method_entry() simply.
 */
rb_method_entry_t *
rb_method_entry_get_without_cache(VALUE klass, ID id)
{
    rb_method_entry_t *me = search_method(klass, id);

    if (ruby_running) {
	struct cache_entry *ent;
	ent = cache + EXPR1(klass, id);
	ent->filled_version = GET_VM_STATE_VERSION();
	ent->klass = klass;

	if (UNDEFINED_METHOD_ENTRY_P(me)) {
	    ent->mid = id;
	    ent->me = 0;
	    me = 0;
	}
	else {
	    ent->mid = id;
	    ent->me = me;
	}
    }

    return me;
}
Exemplo n.º 29
0
static rb_method_entry_t *
rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
		     rb_method_definition_t *def, rb_method_flag_t noex,
		     VALUE defined_class)
{
    rb_method_entry_t *me;
#if NOEX_NOREDEF
    VALUE rklass;
#endif
    st_table *mtbl;
    st_data_t data;
    int make_refined = 0;

    if (NIL_P(klass)) {
	klass = rb_cObject;
    }
    if (!FL_TEST(klass, FL_SINGLETON) &&
	type != VM_METHOD_TYPE_NOTIMPLEMENTED &&
	type != VM_METHOD_TYPE_ZSUPER) {
	switch (mid) {
	  case idInitialize:
	  case idInitialize_copy:
	  case idInitialize_clone:
	  case idInitialize_dup:
	  case idRespond_to_missing:
	    noex |= NOEX_PRIVATE;
	}
    }

    rb_frozen_class_p(klass);
#if NOEX_NOREDEF
    rklass = klass;
#endif
    if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
	VALUE refined_class =
	    rb_refinement_module_get_refined_class(klass);

	rb_add_refined_method_entry(refined_class, mid);
    }
    if (type == VM_METHOD_TYPE_REFINED) {
	rb_method_entry_t *old_me =
	    lookup_method_table(RCLASS_ORIGIN(klass), mid);
	if (old_me) rb_vm_check_redefinition_opt_method(old_me, klass);
    }
    else {
	klass = RCLASS_ORIGIN(klass);
    }
    mtbl = RCLASS_M_TBL(klass);

    /* check re-definition */
    if (st_lookup(mtbl, mid, &data)) {
	rb_method_entry_t *old_me = (rb_method_entry_t *)data;
	rb_method_definition_t *old_def = old_me->def;

	if (rb_method_definition_eq(old_def, def)) return old_me;
#if NOEX_NOREDEF
	if (old_me->flag & NOEX_NOREDEF) {
	    rb_raise(rb_eTypeError, "cannot redefine %"PRIsVALUE"#%"PRIsVALUE,
		     rb_class_name(rklass), rb_id2str(mid));
	}
#endif
	rb_vm_check_redefinition_opt_method(old_me, klass);
	if (old_def->type == VM_METHOD_TYPE_REFINED)
	    make_refined = 1;

	if (RTEST(ruby_verbose) &&
	    type != VM_METHOD_TYPE_UNDEF &&
	    old_def->alias_count == 0 &&
	    old_def->type != VM_METHOD_TYPE_UNDEF &&
	    old_def->type != VM_METHOD_TYPE_ZSUPER) {
	    rb_iseq_t *iseq = 0;

	    rb_warning("method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
	    switch (old_def->type) {
	      case VM_METHOD_TYPE_ISEQ:
		iseq = old_def->body.iseq;
		break;
	      case VM_METHOD_TYPE_BMETHOD:
		iseq = rb_proc_get_iseq(old_def->body.proc, 0);
		break;
	      default:
		break;
	    }
	    if (iseq && !NIL_P(iseq->location.path)) {
		int line = iseq->line_info_table ? FIX2INT(rb_iseq_first_lineno(iseq->self)) : 0;
		rb_compile_warning(RSTRING_PTR(iseq->location.path), line,
				   "previous definition of %"PRIsVALUE" was here",
				   rb_id2str(old_def->original_id));
	    }
	}

	rb_unlink_method_entry(old_me);
    }

    me = ALLOC(rb_method_entry_t);

    rb_clear_method_cache_by_class(klass);

    me->flag = NOEX_WITH_SAFE(noex);
    me->mark = 0;
    me->called_id = mid;
    RB_OBJ_WRITE(klass, &me->klass, defined_class);
    me->def = def;

    if (def) {
	def->alias_count++;

	switch(def->type) {
	  case VM_METHOD_TYPE_ISEQ:
	    RB_OBJ_WRITTEN(klass, Qundef, def->body.iseq->self);
	    break;
	  case VM_METHOD_TYPE_IVAR:
	    RB_OBJ_WRITTEN(klass, Qundef, def->body.attr.location);
	    break;
	  case VM_METHOD_TYPE_BMETHOD:
	    RB_OBJ_WRITTEN(klass, Qundef, def->body.proc);
	    break;
	  default:;
	    /* ignore */
	}
    }

    /* check mid */
    if (klass == rb_cObject && mid == idInitialize) {
	rb_warn("redefining Object#initialize may cause infinite loop");
    }
    /* check mid */
    if (mid == object_id || mid == id__send__) {
	if (type == VM_METHOD_TYPE_ISEQ && search_method(klass, mid, 0)) {
	    rb_warn("redefining `%s' may cause serious problems", rb_id2name(mid));
	}
    }

    if (make_refined) {
	make_method_entry_refined(me);
    }

    st_insert(mtbl, mid, (st_data_t) me);

    return me;
}
Exemplo n.º 30
0
/*
 * search method body (NODE_METHOD)
 *   with    : klass and id
 *   without : method cache
 *
 * if you need method node with method cache, use
 * rb_method_node()
 */
NODE *
rb_get_method_body(VALUE klass, ID id, ID *idp)
{
    return search_method(klass, id, NULL);
}