コード例 #1
0
ファイル: module.c プロジェクト: shmulim/ruby-internal
static VALUE superclass_name(VALUE module)
{
  if(TYPE(module) == T_MODULE)
  {
    return Qnil;
  }
  else
  {
    VALUE super = RCLASS_SUPER(module);

    while(TYPE(super) == T_ICLASS)
    {
      super = RCLASS_SUPER(super);
    }

    if(!super)
    {
      return Qnil;
    }

    if(FL_TEST(super, FL_SINGLETON))
    {
      VALUE v = rb_iv_get(super, "__attached__");
      VALUE name = rb_mod_name(v);
      rb_str_cat2(name, "::<Singleton>");
      return name;
    }
    else
    {
      return rb_mod_name(super);
    }
  }
}
コード例 #2
0
ファイル: breakpoint.c プロジェクト: GernotUllrich/debase
extern VALUE
catchpoint_hit_count(VALUE catchpoints, VALUE exception, VALUE *exception_name) {
  VALUE ancestors;
  VALUE expn_class;
  VALUE aclass;
  VALUE mod_name;
  VALUE hit_count;
  int i;

  if (catchpoints == Qnil /*|| st_get_num_entries(RHASH_TBL(rdebug_catchpoints)) == 0)*/)
    return Qnil;
  expn_class = rb_obj_class(exception);
  ancestors = rb_mod_ancestors(expn_class);
  for(i = 0; i < RARRAY_LEN(ancestors); i++)
  {
    aclass    = rb_ary_entry(ancestors, i);
    mod_name  = rb_mod_name(aclass);
    hit_count = rb_hash_aref(catchpoints, mod_name);
    if(hit_count != Qnil)
    {
      *exception_name = mod_name;	
      return hit_count;
    }
  }
  return Qnil;
}
コード例 #3
0
ファイル: mri.c プロジェクト: Epictetus/looksee
VALUE Looksee_module_name(VALUE self, VALUE module) {
  if (BUILTIN_TYPE(module) == T_CLASS || BUILTIN_TYPE(module) == T_MODULE) {
    VALUE name = rb_mod_name(module);
    return name == Qnil ? rb_str_new2("") : name;
  } else {
    rb_raise(rb_eTypeError, "expected module, got %s", rb_obj_classname(module));
  }
}
コード例 #4
0
ファイル: byebug.c プロジェクト: 7310510/sample_app
static void
raise_event(VALUE trace_point, void *data)
{
  VALUE expn_class, ancestors;
  VALUE path, lineno, binding, post_mortem_context;
  int i;
  debug_context_t *new_dc;

  EVENT_SETUP;

  path = rb_tracearg_path(trace_arg);
  lineno = rb_tracearg_lineno(trace_arg);
  binding = rb_tracearg_binding(trace_arg);
  raised_exception = rb_tracearg_raised_exception(trace_arg);

  if (post_mortem == Qtrue)
  {
    post_mortem_context = context_dup(dc);
    rb_ivar_set(raised_exception, rb_intern("@__bb_file"), path);
    rb_ivar_set(raised_exception, rb_intern("@__bb_line"), lineno);
    rb_ivar_set(raised_exception, rb_intern("@__bb_binding"), binding);
    rb_ivar_set(raised_exception, rb_intern("@__bb_context"),
                post_mortem_context);

    Data_Get_Struct(post_mortem_context, debug_context_t, new_dc);
    rb_debug_inspector_open(context_backtrace_set, (void *)new_dc);
  }

  if (catchpoints == Qnil || dc->calced_stack_size == 0
      || RHASH_TBL(catchpoints)->num_entries == 0)
  {
    EVENT_TEARDOWN;
    return;
  }

  expn_class = rb_obj_class(raised_exception);
  ancestors = rb_mod_ancestors(expn_class);
  for (i = 0; i < RARRAY_LENINT(ancestors); i++)
  {
    VALUE ancestor_class, module_name, hit_count;

    ancestor_class = rb_ary_entry(ancestors, i);
    module_name = rb_mod_name(ancestor_class);
    hit_count = rb_hash_aref(catchpoints, module_name);

    /* increment exception */
    if (hit_count != Qnil)
    {
      rb_hash_aset(catchpoints, module_name, INT2FIX(FIX2INT(hit_count) + 1));
      call_at_catchpoint(context, dc, raised_exception);
      call_at_line(context, dc, path, lineno);
      break;
    }
  }

  EVENT_TEARDOWN;
}
コード例 #5
0
int
classname_cmp(VALUE name, VALUE klass)
{
  VALUE mod_name;
  VALUE class_name = NIL_P(name) ? rb_str_new2("main") : name;

  if (NIL_P(klass))
    return 0;

  mod_name = rb_mod_name(klass);
  return (!NIL_P(mod_name) && rb_str_cmp(class_name, mod_name) == 0);
}
コード例 #6
0
ファイル: pg_coder.c プロジェクト: willbryant/ruby-pg
void
pg_define_coder( const char *name, void *func, VALUE klass, VALUE nsp )
{
  VALUE type_obj = Data_Wrap_Struct( klass, NULL, NULL, func );
	VALUE objname = rb_str_dup(rb_mod_name(nsp));
	rb_str_cat2( objname, "::");
	rb_str_cat2( objname, name);

  rb_iv_set( type_obj, "@name", rb_obj_freeze(objname) );
  rb_define_const( nsp, name, rb_obj_freeze(type_obj) );

  RB_GC_GUARD(type_obj);
}
コード例 #7
0
ファイル: byebug.c プロジェクト: Alex-Aralis/davey-rails-app
static void
trace_print(rb_trace_arg_t * trace_arg, debug_context_t * dc,
            const char *file_filter, const char *debug_msg)
{
  char *fullpath = NULL;
  const char *basename;
  int filtered = 0;
  const char *event = rb_id2name(SYM2ID(rb_tracearg_event(trace_arg)));

  VALUE rb_path = rb_tracearg_path(trace_arg);
  const char *path = NIL_P(rb_path) ? "" : RSTRING_PTR(rb_path);

  int line = NUM2INT(rb_tracearg_lineno(trace_arg));

  VALUE rb_mid = rb_tracearg_method_id(trace_arg);
  const char *mid = NIL_P(rb_mid) ? "(top level)" : rb_id2name(SYM2ID(rb_mid));

  VALUE rb_cl = rb_tracearg_defined_class(trace_arg);
  VALUE rb_cl_name = NIL_P(rb_cl) ? rb_cl : rb_mod_name(rb_cl);
  const char *defined_class = NIL_P(rb_cl_name) ? "" : RSTRING_PTR(rb_cl_name);

  if (!trace_arg)
    return;

  if (file_filter)
  {
#ifndef _WIN32
    fullpath = realpath(path, NULL);
#endif
    basename = fullpath ? strrchr(fullpath, '/') : path;

    if (!basename || strncmp(basename + 1, file_filter, strlen(file_filter)))
      filtered = 1;

#ifndef _WIN32
    free(fullpath);
#endif
  }

  if (!filtered)
  {
    if (debug_msg)
      rb_funcall(mByebug, idPuts, 1,
                 rb_sprintf("[#%d] %s\n", dc->thnum, debug_msg));
    else
      rb_funcall(mByebug, idPuts, 1,
                 rb_sprintf("%*s [#%d] %s@%s:%d %s#%s\n", dc->calced_stack_size,
                            "", dc->thnum, event, path, line, defined_class,
                            mid));
  }
}
コード例 #8
0
ファイル: mri.c プロジェクト: hkraji/looksee
VALUE Looksee_module_name(VALUE self, VALUE module) {
  if (BUILTIN_TYPE(module) == T_CLASS || BUILTIN_TYPE(module) == T_MODULE) {
    VALUE name = rb_mod_name(module);
    return name == Qnil ? rb_str_new2("") : name;
  } else if (BUILTIN_TYPE(module) == T_ICLASS) {
    VALUE wrapped = RBASIC(module)->klass;
    VALUE name = Looksee_module_name(self, wrapped);
    if (BUILTIN_TYPE(wrapped) == T_CLASS)
      name = rb_str_cat2(name, " (origin)");
    return name;
  } else {
    rb_raise(rb_eTypeError, "expected module, got %s", rb_obj_classname(module));
  }
}
コード例 #9
0
ファイル: module.c プロジェクト: shmulim/ruby-internal
static VALUE included_modules_list(VALUE module)
{
  VALUE included_modules = rb_mod_included_modules(module);
  VALUE included_module_list = rb_ary_new();
  long j;

  for(j = 0; j < RARRAY_LEN(included_modules); ++j)
  {
    rb_ary_push(
        included_module_list,
        rb_mod_name(RARRAY_PTR(included_modules)[j]));
  }

  return included_module_list;
}
コード例 #10
0
ファイル: class.c プロジェクト: botvs/LoadSo
const char *rb_obj_classname(VALUE obj) {
  /* TODO: rb_obj_classname is not equal rb_mod_name exactly. */
  VALUE name = rb_mod_name(CLASS_OF(obj));
  /* TODO: Is GC safe? */
  return RSTRING_PTR(name);
}