• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_intern函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rb_intern函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_intern函数的具体用法?C++ rb_intern怎么用?C++ rb_intern使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rb_intern函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main( int argc, char** argv ) 
{
  int state  = 0;
  int rc     = 0;
  int opt_mv = 0;

  crate_app ca;

  /** startup items from ruby's original main.c */
#ifdef _WIN32
  NtInitialize(&argc, &argv);
#endif
#if defined(__MACOS__) && defined(__MWERKS__)
  argc = ccommand(&argv);
#endif

  /* setup ruby */
  ruby_init();
  ruby_script( argv[0] );
  ruby_init_loadpath();

  /* strip out the crate specific arguments from argv using --crate- */
  opt_mv = crate_init_from_options( &ca, argc, argv );
  argc -= opt_mv;
  argv += opt_mv;
 
  /* printf("crate file  : %s\n", ca.file_name);   */
  /* printf("crate class : %s\n", ca.class_name);  */
  /* printf("crate method: %s\n", ca.method_name); */

  /* make ARGV available */
  ruby_set_argv( argc, argv );

  /* initialize all extensions */
  Init_ext();

  /* load up the amalgalite libs */
  am_bootstrap_lift( cARB, Qnil );
 
  /* remove the current LOAD_PATH */
  rb_ary_clear( rb_gv_get( "$LOAD_PATH" ) );

  /* invoke the class / method passing in ARGV and ENV */
  rb_protect( crate_wrap_app, (VALUE)&ca, &state );

  /* check the results */
  if ( state ) {

    /* exception was raised, check the $! var */
    VALUE lasterr  = rb_gv_get("$!");
   
    /* system exit was called so just propogate that up to our exit */
    if ( rb_obj_is_instance_of( lasterr, rb_eSystemExit ) ) {

      rc = NUM2INT( rb_attr_get( lasterr, rb_intern("status") ) );
      /*printf(" Caught SystemExit -> $? will be %d\n", rc ); */

    } else {

      /* some other exception was raised so dump that out */
      VALUE klass     = rb_class_path( CLASS_OF( lasterr ) );
      VALUE message   = rb_obj_as_string( lasterr );
      VALUE backtrace = rb_funcall( lasterr, rb_intern("backtrace"), 0 );

      fprintf( stderr, "%s: %s\n", RSTRING( klass )->ptr, RSTRING( message )->ptr );
      rb_iterate( rb_each, backtrace, dump_backtrace, Qnil );

      rc = state;
    }
  } 

  free( ca.file_name );
  free( ca.class_name );
  free( ca.method_name );

  /* shut down ruby */
  ruby_finalize();

  /* exit the program */
  exit( rc );
}
开发者ID:Epictetus,项目名称:crate,代码行数:81,代码来源:crate_boot.c


示例2: syserr_errno

static VALUE
syserr_errno(VALUE self)
{
    return rb_attr_get(self, rb_intern("errno"));
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:5,代码来源:error.c


示例3: rb_exc_new_str

VALUE
rb_exc_new_str(VALUE etype, VALUE str)
{
    StringValue(str);
    return rb_funcall(etype, rb_intern("new"), 1, str);
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:6,代码来源:error.c


示例4: rldap_search

static VALUE rldap_search(int argc, VALUE *argv, VALUE obj)
{
	RLDAP_WRAP *wrapper;
	char *base, *filter;
	int retval, count, i, scope;
	LDAPMessage *res, *msg;
	VALUE ary, rbase, rfilter, rscope;
	ID iscope;
	
	rb_scan_args(argc, argv, "21", &rbase, &rfilter, &rscope);

	switch(TYPE(rscope)) {
		case T_NIL:
			scope = LDAP_SCOPE_SUBTREE;
			break;
		case T_FIXNUM:
			scope = FIX2INT(rscope);
			break;
		case T_SYMBOL:
		case T_STRING:
			iscope = rb_to_id(rscope);
			if (iscope == rb_intern("subtree"))
				scope = LDAP_SCOPE_SUBTREE;
			if (iscope == rb_intern("base"))
				scope = LDAP_SCOPE_BASE;
			if (iscope == rb_intern("one"))
				scope = LDAP_SCOPE_ONE;
			break;
		default:
			rb_raise(rb_eTypeError, "not a valid scope");
			break;
	}
	
	wrapper = get_wrapper(obj);
	base = StringValuePtr(rbase);
	filter = StringValuePtr(rfilter);

	retval = ldap_search_ext_s(wrapper->ld, base, scope, filter, NULL, 0, NULL, NULL, NULL, 0, &res);

	if (retval != LDAP_SUCCESS)
		rldap_raise(retval);

	count = ldap_count_entries(wrapper->ld, res);
	
	if (count == -1) {
		int errno;
		ldap_get_option(wrapper->ld, LDAP_OPT_RESULT_CODE, &errno);
		rldap_raise(errno);
	}
	
	ary = rb_ary_new2((long)count);
	
	msg = ldap_first_entry(wrapper->ld, res);
	
	for (i=0; i<count; i++) {
		rb_ary_store(ary, (long)i, ldapmessage2obj(wrapper->ld, msg));
		msg = ldap_next_entry(wrapper->ld, msg);
	}
	
	return ary;
}
开发者ID:henrikhodne,项目名称:rldap,代码行数:61,代码来源:ldap.c


示例5: name_err_name

static VALUE
name_err_name(VALUE self)
{
    return rb_attr_get(self, rb_intern("name"));
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:5,代码来源:error.c


示例6: RHO_TRACE

jobject event_cast<jobject, VALUE>(VALUE rEvent)
{
    if (NIL_P(rEvent))
        return NULL;

    RHO_TRACE("eventFromRuby (1)");
    JNIEnv *env = jnienv();
    if (!init_event_stuff(env))
        return NULL;

    RHO_TRACE("eventFromRuby (2)");
    VALUE rId = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_ID));
    if (NIL_P(rId))
        rId = rb_str_new2("");
    Check_Type(rId, T_STRING);

    RHO_TRACE("eventFromRuby (3)");
    jmethodID mid = getJNIClassMethod(env, clsEvent, "<init>", "(Ljava/lang/String;)V");
    if (!mid) return NULL;

    jhstring jhId = rho_cast<jstring>(env, rId);
    jobject jEvent = env->NewObject(clsEvent, mid, jhId.get());
    if (!jEvent) return NULL;

    RHO_TRACE("eventFromRuby (4)");
    VALUE rTitle = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_TITLE));
    if (!NIL_P(rTitle))
    {
        Check_Type(rTitle, T_STRING);
        jhstring jhTitle = rho_cast<jstring>(env, rTitle);
        env->SetObjectField(jEvent, fidTitle, jhTitle.get());
    }

    RHO_TRACE("eventFromRuby (5)");
    VALUE rStartDate = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_START_DATE));
    if (!NIL_P(rStartDate))
        env->SetObjectField(jEvent, fidStartDate, date_cast<jobject>(rStartDate));

    RHO_TRACE("eventFromRuby (6)");
    VALUE rEndDate = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_END_DATE));
    if (!NIL_P(rEndDate))
        env->SetObjectField(jEvent, fidEndDate, date_cast<jobject>(rEndDate));

    RHO_TRACE("eventFromRuby (7)");
    VALUE rLastModified = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_LAST_MODIFIED));
    if (!NIL_P(rLastModified))
        env->SetObjectField(jEvent, fidLastModified, date_cast<jobject>(rLastModified));

    RHO_TRACE("eventFromRuby (8)");
    VALUE rLocation = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_LOCATION));
    if (!NIL_P(rLocation))
    {
        Check_Type(rLocation, T_STRING);
        jhstring jhLocation = rho_cast<jstring>(env, rLocation);
        env->SetObjectField(jEvent, fidLocation, jhLocation.get());
    }

    RHO_TRACE("eventFromRuby (9)");
    VALUE rNotes = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_NOTES));
    if (!NIL_P(rNotes))
    {
        Check_Type(rNotes, T_STRING);
        jhstring jhNotes = rho_cast<jstring>(env, rNotes);
        env->SetObjectField(jEvent, fidNotes, jhNotes.get());
    }

    RHO_TRACE("eventFromRuby privacy");
    VALUE rPrivacy = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_PRIVACY));
    if (!NIL_P(rPrivacy))
    {
        Check_Type(rPrivacy, T_STRING);
        jhstring jhPrivacy = rho_cast<jstring>(env, rPrivacy);
        env->SetObjectField(jEvent, fidPrivacy, jhPrivacy.get());
    }

    RHO_TRACE("eventFromRuby recurrence");
    VALUE rRecurrence = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_RECURRENCE));
    if (!NIL_P(rRecurrence)) {
        Check_Type(rRecurrence, T_HASH);

        VALUE rFrequency = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_FREQUENCY));
        Check_Type(rFrequency, T_STRING);
        const char *frequency = RSTRING_PTR(rFrequency);
        if (   strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_DAILY) != 0
        	&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_WEEKLY) != 0
        	&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_MONTHLY) != 0
        	&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_YEARLY) != 0)
        {
        	rb_raise(rb_eArgError, "Wrong recurrence frequency: %s", frequency);
        }
        jhstring jhFreq = rho_cast<jstring>(env, rFrequency);
        env->SetObjectField(jEvent, fidFrequency, jhFreq.get());

        VALUE rInterval = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_INTERVAL));
        rInterval = rb_funcall(rInterval, rb_intern("to_i"), 0);
        int interval = NUM2INT(rInterval);
        env->SetIntField(jEvent, fidInterval, interval);
        RAWTRACE1("eventFromRuby recurrence interval: %d", interval);

        VALUE rUntilDate = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_END));
//.........这里部分代码省略.........
开发者ID:CSanshulgandhi,项目名称:rhodes,代码行数:101,代码来源:event.cpp


示例7: NIO_Selector_initialize

/* Create a new selector. This is more or less the pure Ruby version
   translated into an MRI cext */
static VALUE NIO_Selector_initialize(int argc, VALUE *argv, VALUE self)
{
    ID backend_id;
    VALUE backend;
    VALUE lock;

    struct NIO_Selector *selector;
    unsigned int flags = 0;

    Data_Get_Struct(self, struct NIO_Selector, selector);

    rb_scan_args(argc, argv, "01", &backend);

    if(backend != Qnil) {
        if(!rb_ary_includes(NIO_Selector_supported_backends(CLASS_OF(self)), backend)) {
            rb_raise(rb_eArgError, "unsupported backend: %s",
                RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
        }

        backend_id = SYM2ID(backend);

        if(backend_id == rb_intern("epoll")) {
            flags = EVBACKEND_EPOLL;
        } else if(backend_id == rb_intern("poll")) {
            flags = EVBACKEND_POLL;
        } else if(backend_id == rb_intern("kqueue")) {
            flags = EVBACKEND_KQUEUE;
        } else if(backend_id == rb_intern("select")) {
            flags = EVBACKEND_SELECT;
        } else if(backend_id == rb_intern("port")) {
            flags = EVBACKEND_PORT;
        } else {
            rb_raise(rb_eArgError, "unsupported backend: %s",
                RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
        }
    }

    /* Ensure the selector loop has not yet been initialized */
    assert(!selector->ev_loop);

    selector->ev_loop = ev_loop_new(flags);
    if(!selector->ev_loop) {
        rb_raise(rb_eIOError, "error initializing event loop");
    }

    ev_io_start(selector->ev_loop, &selector->wakeup);

    rb_ivar_set(self, rb_intern("selectables"), rb_hash_new());
    rb_ivar_set(self, rb_intern("lock_holder"), Qnil);

    lock = rb_class_new_instance(0, 0, rb_const_get(rb_cObject, rb_intern("Mutex")));
    rb_ivar_set(self, rb_intern("lock"), lock);
    rb_ivar_set(self, rb_intern("lock_holder"), Qnil);

    return Qnil;
}
开发者ID:zanaka,项目名称:Grama,代码行数:58,代码来源:selector.c


示例8: NIO_Selector_is_empty

/* True if there are monitors on the loop */
static VALUE NIO_Selector_is_empty(VALUE self)
{
    VALUE selectables = rb_ivar_get(self, rb_intern("selectables"));

    return rb_funcall(selectables, rb_intern("empty?"), 0) == Qtrue ? Qtrue : Qfalse;
}
开发者ID:zanaka,项目名称:Grama,代码行数:7,代码来源:selector.c


示例9: Init_Enumerator

void
Init_Enumerator(void)
{
    id_rewind = rb_intern("rewind");
    id_each = rb_intern("each");
    id_call = rb_intern("call");
    id_size = rb_intern("size");
    id_yield = rb_intern("yield");
    id_new = rb_intern("new");
    id_initialize = rb_intern("initialize");
    id_next = rb_intern("next");
    id_result = rb_intern("result");
    id_lazy = rb_intern("lazy");
    id_eqq = rb_intern("===");
    id_receiver = rb_intern("receiver");
    id_arguments = rb_intern("arguments");
    id_memo = rb_intern("memo");
    id_method = rb_intern("method");
    id_force = rb_intern("force");
    id_to_enum = rb_intern("to_enum");
    sym_each = ID2SYM(id_each);
    sym_cycle = ID2SYM(rb_intern("cycle"));

    InitVM(Enumerator);
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:25,代码来源:enumerator.c


示例10: rb_fastadd_add_one

static VALUE rb_fastadd_add_one(int argc, VALUE *argv, VALUE self)
{
  int n = NUM2INT(rb_funcall(self, rb_intern("n"), 0));
  return INT2NUM(n + 1);
}
开发者ID:saranyan,项目名称:SwePh,代码行数:5,代码来源:fastadd.c


示例11: GravityFind

/* GravityFind {{{ */
static VALUE
GravityFind(char *source,
  int flags)
{
  int ngravities = 0;
  char **gravities = NULL;
  VALUE ret = Qnil;

  subSubtlextConnect(NULL); ///< Implicit open connection

  /* Get gravity list */
  if((gravities = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
      XInternAtom(display, "SUBTLE_GRAVITY_LIST", False), &ngravities)))
    {
      int i, selid = -1;
      XRectangle geometry = { 0 };
      char buf[30] = { 0 };
      VALUE klass_grav = Qnil, klass_geom = Qnil, meth = Qnil;
      VALUE gravity = Qnil, geom = Qnil;
      regex_t *preg = NULL;

      /* Fetch data */
      klass_grav = rb_const_get(mod, rb_intern("Gravity"));
      klass_geom = rb_const_get(mod, rb_intern("Geometry"));
      meth       = rb_intern("new");

      /* Create if source is given */
      if(source)
        {
          if(isdigit(source[0])) selid = atoi(source);
          preg = subSharedRegexNew(source);
        }

      /* Create gravity list */
      for(i = 0; i < ngravities; i++)
        {
          sscanf(gravities[i], "%hdx%hd+%hd+%hd#%s", &geometry.x, &geometry.y,
            &geometry.width, &geometry.height, buf);

          /* Check if gravity matches */
          if(!source || (source && (selid == i || (-1 == selid &&
              ((flags & SUB_MATCH_EXACT && 0 == strcmp(source, buf)) ||
              (preg && !(flags & SUB_MATCH_EXACT) &&
                subSharedRegexMatch(preg, buf)))))))
            {
              /* Create new gravity */
              gravity = rb_funcall(klass_grav, meth, 1, rb_str_new2(buf));
              geom    = rb_funcall(klass_geom, meth, 4, INT2FIX(geometry.x),
                INT2FIX(geometry.y), INT2FIX(geometry.width),
                INT2FIX(geometry.height));

              rb_iv_set(gravity, "@id",       INT2FIX(i));
              rb_iv_set(gravity, "@geometry", geom);

              ret = subSubtlextOneOrMany(gravity, ret);
            }
        }

      if(preg)    subSharedRegexKill(preg);
      XFreeStringList(gravities);
    }
  else rb_raise(rb_eStandardError, "Failed getting gravity list");

  return NIL_P(ret) ? rb_ary_new() : ret;
} /* }}} */
开发者ID:guns,项目名称:subtle,代码行数:66,代码来源:gravity.c


示例12: rb_hash_delete

static VALUE
rb_hash_delete(VALUE hash, VALUE key)
{
  return rb_funcall(hash, rb_intern("delete"), 1, key);
}
开发者ID:Winstonwzl,项目名称:rubinius,代码行数:5,代码来源:ptr.c


示例13: exit_status

static VALUE
exit_status(VALUE exc, SEL sel)
{
    return rb_attr_get(exc, rb_intern("status"));
}
开发者ID:ferrous26,项目名称:MacRuby,代码行数:5,代码来源:error.c


示例14: dtracebufdata_record

/* 
 * Returns the record in this DtraceBufdata. Records are returned as
 * either DtraceRecords or DtraceStackRecords as appropriate for the
 * type of action.
 */
VALUE dtracebufdata_record(VALUE self)
{
  dtrace_bufdata_t *bufdata;
  const dtrace_recdesc_t *rec;
  dtrace_actkind_t act = DTRACEACT_NONE;
  const char *s;
  VALUE v = Qnil;
  VALUE dtracerecord;
  VALUE dtraceaggdata;
  VALUE dtracerecdesc;

  Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
  
  if (bufdata->dtbda_aggdata) {
    dtraceaggdata = Data_Wrap_Struct(cDtraceAggData, 0, NULL, (dtrace_bufdata_t *)bufdata);
    return dtraceaggdata;
  }

  s = bufdata->dtbda_buffered;
  if (s == NULL) {
    return Qnil;
  }
  
  rec = bufdata->dtbda_recdesc;
  if (rec) {
    act = rec->dtrd_action;
  }
  
  switch (act) {
  case DTRACEACT_DIFEXPR:
    /* trace() action */
    break;
  case DTRACEACT_PRINTF:
    /* printf action, not available in probedata */
    v = rb_str_new2(s);
    dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::PrintfRecord"));
    rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
    rb_iv_set(dtracerecord, "@value", v);
    return (dtracerecord);
    break;
  case DTRACEACT_STACK:
  case DTRACEACT_USTACK:
  case DTRACEACT_JSTACK:
    /* stand-alone stack(), ustack(), or jstack() action */
    v = rb_str_new2(s);
    dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::StackRecord"));
    rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
    rb_funcall(dtracerecord, rb_intern("parse"), 1, v);
    return (dtracerecord);
    break;
  case DTRACEACT_USYM:
  case DTRACEACT_UADDR:
  case DTRACEACT_UMOD:
  case DTRACEACT_SYM:
  case DTRACEACT_MOD:
    v = rb_str_new2(s);
    break;
  case DTRACEACT_PRINTA:
    v = rb_str_new2(s);
    break;
  default:
    /*
     * The record handle defers nothing else to this
     * bufhandler.
     */
    break;
  }

  if (!NIL_P(v)) {
    dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::Record"));
    rb_iv_set(dtracerecord, "@value", v);
    rb_iv_set(dtracerecord, "@action", INT2FIX(act));
    rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
    return (dtracerecord);
  }
  else {
    return Qnil;
  }
}
开发者ID:GunioRobot,项目名称:ruby-dtrace,代码行数:84,代码来源:dtrace_bufdata.c


示例15: dict_each_key

static void
dict_each_key (const char *key, xmmsv_t *value, void *udata)
{
	rb_yield (ID2SYM (rb_intern (key)));
}
开发者ID:dsheeler,项目名称:xmms2,代码行数:5,代码来源:rb_result.c


示例16: r_get_default_mpc_rounding_mode

mpc_rnd_t r_get_default_mpc_rounding_mode()
{
  return r_get_mpc_rounding_mode (rb_const_get (cMPC, rb_intern ("MPC_RNDNN")));
}
开发者ID:srawlins,项目名称:gnu_mpc,代码行数:4,代码来源:mpcrnd.c


示例17: Init_boardext

void Init_boardext() {

  /* Map Coord */

  Coord = rb_define_class( "Coord", rb_cObject );
  
  rb_define_singleton_method( Coord, "[]", coord_class_subscript, -1 );
                                                              /* in coord.c */
  rb_define_method( Coord, "+", coord_addition, 1 );          /* in coord.c */
  rb_define_method( Coord, "direction_to", coord_direction_to, 1 ); 
                                                              /* in coord.c */

  /* Map Coords */

  Coords = rb_define_class( "Coords", rb_cObject );

  rb_define_method( Coords, "include?", coords_include, 1 ); /* in coords.c */
  rb_define_method( Coords, "next", coords_next, 2 );        /* in coords.c */


  /* Map Board */

  Board = rb_define_class( "Board", rb_cObject );

  rb_define_method( Board, "in_bounds?", board_in_bounds, 2 );
                                                              /* in board.c */
  rb_define_method( Board, "[]", board_subscript, -1 );       /* in board.c */
  rb_define_method( Board, "[]=", board_subscript_assign, -1 );
                                                              /* in board.c */
  rb_define_method( Board, "get", board_get, 2 );             /* in board.c */
  rb_define_method( Board, "set", board_set, 3 );             /* in board.c */

  rb_define_method( Board, "ci", board_ci, 2 );               /* in board.c */


  /* Plugins namespace. */

  Plugins  = rb_define_module_under( Board, "Plugins" );


  /* Map Board::Plugins::Frontier */

  Frontier = rb_define_module_under( Plugins, "Frontier" );

  rb_define_method( Frontier, "update_frontier", frontier_update, 2 );
                                                           /* in frontier.c */

  /* Map Board::Plugins::CustodialFlip */

  CustodialFlip = rb_define_module_under( Plugins, "CustodialFlip" );

  rb_define_method( CustodialFlip, "will_flip?", custodial_flip_valid, 2 );
                                                     /* in custodial_flip.c */
  rb_define_method( CustodialFlip, "custodial_flip", custodial_flip, 2 );
                                                     /* in custodial_flip.c */

  /* Look up all our ids */

  id_dup = rb_intern("dup");
  id_x = rb_intern("x");
  id_y = rb_intern("y");
  id_subscript = rb_intern("[]");
  id_subscript_assign = rb_intern("[]=");
  id_new = rb_intern("new");
  id_hash = rb_intern("hash");
  id_include = rb_intern("include?");
  id_n = rb_intern("n");
  id_s = rb_intern("s");
  id_w = rb_intern("w");
  id_e = rb_intern("e");
  id_se = rb_intern("se");
  id_nw = rb_intern("nw");
  id_sw = rb_intern("sw");
  id_ne = rb_intern("ne");
  id_DIRECTIONS = rb_intern("DIRECTIONS");
  id_white = rb_intern("white");
  id_black = rb_intern("black");
  id_delete = rb_intern("delete");
  id_uniq_ex = rb_intern("uniq!");
  id_to_s = rb_intern( "to_s" );
  id_before_set = rb_intern( "before_set" );
  id_after_set = rb_intern( "after_set" );

  /* Look up all our symbols */

  sym_white = ID2SYM(id_white);
  sym_black = ID2SYM(id_black);
  sym_n = ID2SYM(id_n);
  sym_s = ID2SYM(id_s);
  sym_w = ID2SYM(id_w);
  sym_e = ID2SYM(id_e);
  sym_se = ID2SYM(id_se);
  sym_nw = ID2SYM(id_nw);
  sym_sw = ID2SYM(id_sw);
  sym_ne = ID2SYM(id_ne);

}
开发者ID:Carroll,项目名称:vying,代码行数:97,代码来源:init.c


示例18: ossl_asn1_get_asn1type

ASN1_TYPE*
ossl_asn1_get_asn1type(VALUE obj)
{
    ASN1_TYPE *ret;
    VALUE value, rflag;
    void *ptr;
    void (*free_func)();
    long tag, flag;

    tag = ossl_asn1_default_tag(obj);
    value = ossl_asn1_get_value(obj);
    switch(tag){
    case V_ASN1_BOOLEAN:
	ptr = (void*)obj_to_asn1bool(value);
	free_func = NULL;
	break;
    case V_ASN1_INTEGER:         /* FALLTHROUGH */
    case V_ASN1_ENUMERATED:
	ptr = obj_to_asn1int(value);
	free_func = ASN1_INTEGER_free;
	break;
    case V_ASN1_BIT_STRING:
        rflag = rb_attr_get(obj, rb_intern("@unused_bits"));
        flag = NIL_P(rflag) ? -1 : NUM2INT(rflag);
	ptr = obj_to_asn1bstr(value, flag);
	free_func = ASN1_BIT_STRING_free;
	break;
    case V_ASN1_NULL:
	ptr = obj_to_asn1null(value);
	free_func = ASN1_NULL_free;
	break;
    case V_ASN1_OCTET_STRING:    /* FALLTHROUGH */
    case V_ASN1_UTF8STRING:      /* FALLTHROUGH */
    case V_ASN1_NUMERICSTRING:   /* FALLTHROUGH */
    case V_ASN1_PRINTABLESTRING: /* FALLTHROUGH */
    case V_ASN1_T61STRING:       /* FALLTHROUGH */
    case V_ASN1_VIDEOTEXSTRING:  /* FALLTHROUGH */
    case V_ASN1_IA5STRING:       /* FALLTHROUGH */
    case V_ASN1_GRAPHICSTRING:   /* FALLTHROUGH */
    case V_ASN1_ISO64STRING:     /* FALLTHROUGH */
    case V_ASN1_GENERALSTRING:   /* FALLTHROUGH */
    case V_ASN1_UNIVERSALSTRING: /* FALLTHROUGH */
    case V_ASN1_BMPSTRING:   
	ptr = obj_to_asn1str(value);
	free_func = ASN1_STRING_free;
	break;
    case V_ASN1_OBJECT:
	ptr = obj_to_asn1obj(value);
	free_func = ASN1_OBJECT_free;
	break;
    case V_ASN1_UTCTIME:
	ptr = obj_to_asn1utime(value);
	free_func = ASN1_TIME_free;
	break;
    case V_ASN1_GENERALIZEDTIME:
	ptr = obj_to_asn1gtime(value);
	free_func = ASN1_TIME_free;
	break;
    case V_ASN1_SET:             /* FALLTHROUGH */
    case V_ASN1_SEQUENCE:
	ptr = obj_to_asn1derstr(obj);
	free_func = ASN1_STRING_free;
	break;
    default:
	ossl_raise(eASN1Error, "unsupported ASN.1 type");
    }
    if(!(ret = OPENSSL_malloc(sizeof(ASN1_TYPE)))){
	if(free_func) free_func(ptr);
	ossl_raise(eASN1Error, "ASN1_TYPE alloc failure");
    }
    memset(ret, 0, sizeof(ASN1_TYPE));
    ASN1_TYPE_set(ret, tag, ptr);

    return ret;
}
开发者ID:genki,项目名称:ruby,代码行数:75,代码来源:ossl_asn1.c


示例19: ossl_ec_key_initialize

/*  call-seq:
 *     OpenSSL::PKey::EC.new()
 *     OpenSSL::PKey::EC.new(ec_key)
 *     OpenSSL::PKey::EC.new(ec_group)
 *     OpenSSL::PKey::EC.new("secp112r1")
 *     OpenSSL::PKey::EC.new(pem_string)
 *     OpenSSL::PKey::EC.new(pem_string [, pwd])
 *     OpenSSL::PKey::EC.new(der_string)
 *
 *  See the OpenSSL documentation for:
 *     EC_KEY_*
 */
static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
{
    EVP_PKEY *pkey;
    EC_KEY *ec = NULL;
    VALUE arg, pass;
    VALUE group = Qnil;
    char *passwd = NULL;

    GetPKey(self, pkey);
    if (pkey->pkey.ec)
        ossl_raise(eECError, "EC_KEY already initialized");

    rb_scan_args(argc, argv, "02", &arg, &pass);

    if (NIL_P(arg)) {
        ec = EC_KEY_new();
    } else {
        if (rb_obj_is_kind_of(arg, cEC)) {
            EC_KEY *other_ec = NULL;

            SafeRequire_EC_KEY(arg, other_ec);
            ec = EC_KEY_dup(other_ec);
        } else if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
        	ec = EC_KEY_new();
        	group = arg;
        } else {
            BIO *in = ossl_obj2bio(arg);

            if (!NIL_P(pass)) {
		passwd = StringValuePtr(pass);
	    }
	    ec = PEM_read_bio_ECPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
            if (!ec) {
		OSSL_BIO_reset(in);
		ec = PEM_read_bio_EC_PUBKEY(in, NULL, ossl_pem_passwd_cb, passwd);
            }
            if (!ec) {
		OSSL_BIO_reset(in);
                ec = d2i_ECPrivateKey_bio(in, NULL);
            }
            if (!ec) {
		OSSL_BIO_reset(in);
                ec = d2i_EC_PUBKEY_bio(in, NULL);
            }

            BIO_free(in);

            if (ec == NULL) {
                const char *name = StringValueCStr(arg);
                int nid = OBJ_sn2nid(name);

                (void)ERR_get_error();
                if (nid == NID_undef)
                    ossl_raise(eECError, "unknown curve name (%s)\n", name);

                if ((ec = EC_KEY_new_by_curve_name(nid)) == NULL)
                    ossl_raise(eECError, "unable to create curve (%s)\n", name);

                EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
                EC_KEY_set_conv_form(ec, POINT_CONVERSION_UNCOMPRESSED);
            }
        }
    }

    if (ec == NULL)
        ossl_raise(eECError, NULL);

    if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) {
	EC_KEY_free(ec);
	ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY");
    }

    rb_iv_set(self, "@group", Qnil);

    if (!NIL_P(group))
        rb_funcall(self, rb_intern("group="), 1, arg);

    return self;
}
开发者ID:jruby,项目名称:openssl,代码行数:91,代码来源:ossl_pkey_ec.c


示例20: ossl_asn1_decode0

static VALUE
ossl_asn1_decode0(unsigned char **pp, long length, long *offset, long depth,
		  int once, int yield)
{
    unsigned char *start, *p;
    const unsigned char *p0;
    long len, off = *offset;
    int hlen, tag, tc, j;
    VALUE ary, asn1data, value, tag_class;

    ary = rb_ary_new();
    p = *pp;
    while(length > 0){
	start = p;
	p0 = p;
	j = ASN1_get_object(&p0, &len, &tag, &tc, length);
	p = (unsigned char *)p0;
	if(j & 0x80) ossl_raise(eASN1Error, NULL);
	hlen = p - start;
	if(yield){
	    VALUE arg = rb_ary_new();
	    rb_ary_push(arg, LONG2NUM(depth));
	    rb_ary_push(arg, LONG2NUM(off));
	    rb_ary_push(arg, LONG2NUM(hlen));
	    rb_ary_push(arg, LONG2NUM(len));
	    rb_ary_push(arg, (j & V_ASN1_CONSTRUCTED) ? Qtrue : Qfalse);
	    rb_ary_push(arg, ossl_asn1_class2sym(tc));
	    rb_ary_push(arg, INT2NUM(tag));
	    rb_yield(arg);
	}
	length -= hlen;
	off += hlen; 
	if(len > length) ossl_raise(eASN1Error, "value is too short");
	if((tc & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
	    tag_class = sPRIVATE;
	else if((tc & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
	    tag_class = sCONTEXT_SPECIFIC;
	else if((tc & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
	    tag_class = sAPPLICATION;
	else
	    tag_class = sUNIVERSAL;
	if(j & V_ASN1_CONSTRUCTED){
	    /* TODO: if j == 0x21 it is indefinite length object. */
	    if((j == 0x21) && (len == 0)){
		long lastoff = off;
		value = ossl_asn1_decode0(&p, length, &off, depth+1, 0, yield);
		len = off - lastoff;
	    }
	    else value = ossl_asn1_decode0(&p, len, &off, depth+1, 0, yield);
	}
	else{
	    value = rb_str_new((const char *)p, len);
	    p += len;
	    off += len;
	}
	if(tag_class == sUNIVERSAL &&
	   tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass){
	    VALUE klass = *ossl_asn1_info[tag].klass;
	    long flag = 0;
	    if(!rb_obj_is_kind_of(value, rb_cArray)){
		switch(tag){
		case V_ASN1_BOOLEAN:
		    value = decode_bool(start, hlen+len);
		    break;
		case V_ASN1_INTEGER:
		    value = decode_int(start, hlen+len);
		    break;
		case V_ASN1_BIT_STRING:
		    value = decode_bstr(start, hlen+len, &flag);
		    break;
		case V_ASN1_NULL:
		    value = decode_null(start, hlen+len);
		    break;
		case V_ASN1_ENUMERATED:
		    value = decode_enum(start, hlen+len);
		    break;
		case V_ASN1_OBJECT:
		    value = decode_obj(start, hlen+len);
		    break;
		case V_ASN1_UTCTIME:           /* FALLTHROUGH */
		case V_ASN1_GENERALIZEDTIME:
		    value = decode_time(start, hlen+len);
		    break;
		default:
		    /* use original value */
		    break;
		}
	    }
	    asn1data = rb_funcall(klass, rb_intern("new"), 1, value);
	    if(tag == V_ASN1_BIT_STRING){
		rb_iv_set(asn1data, "@unused_bits", LONG2NUM(flag));
	    }
	}
	else{
	    asn1data = rb_funcall(cASN1Data, rb_intern("new"), 3,
				  value, INT2NUM(tag), ID2SYM(tag_class));
	}
	rb_ary_push(ary, asn1data);
	length -= len;
        if(once) break;
//.........这里部分代码省略.........
开发者ID:genki,项目名称:ruby,代码行数:101,代码来源:ossl_asn1.c



注:本文中的rb_intern函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_is_red函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_inspect函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap