当前位置: 首页>>代码示例>>C++>>正文


C++ rb_obj_alloc函数代码示例

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


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

示例1: CheckOSStatusOrRaise

static void CheckOSStatusOrRaise(OSStatus err){
  if(err != 0){
    CFStringRef description = SecCopyErrorMessageString(err, NULL);

    CFIndex bufferSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(description), kCFStringEncodingUTF8);
    char *buffer = malloc(bufferSize + 1);
    CFStringGetCString(description, buffer, bufferSize + 1, kCFStringEncodingUTF8);
    CFRelease(description);

    VALUE exceptionString = rb_enc_str_new(buffer, strlen(buffer), rb_utf8_encoding());
    free(buffer);
    VALUE exception = Qnil;

    switch(err){
      case errSecAuthFailed:
        exception = rb_obj_alloc(rb_eKeychainAuthFailedError);
        break;
      case errSecNoSuchKeychain:
        exception = rb_obj_alloc(rb_eKeychainNoSuchKeychainError);
        break;
      case errSecDuplicateItem:
        exception = rb_obj_alloc(rb_eKeychainDuplicateItemError);
        break;
      default:
        exception = rb_obj_alloc(rb_eKeychainError);
    }
    rb_funcall(exception, rb_intern("initialize"), 2,exceptionString, INT2FIX(err));
    rb_exc_raise(exception);
  }
}
开发者ID:fcheung,项目名称:keychain_c,代码行数:30,代码来源:keychain.c

示例2: define_method_with_data

// Define a method and attach data to it.
// The method looks to ruby like a normal aliased CFUNC, with a modified
// origin class.
//
// How this works:
//
// To store method data and have it registered with the GC, we need a
// "slot" to put it in.  This "slot" must be recognized and marked by
// the garbage collector.  There happens to be such a place we can put
// data, and it has to do with aliased methods.  When Ruby creates an
// alias for a method, it stores a reference to the original class in
// the method entry.  The form of the method entry differs from ruby
// version to ruby version, but the concept is the same across all of
// them.
// 
// In Rice, we make use of this by attach the data to a dummy object 
// (store) in the class variables table.
// 
// When Ruby makes a method call, it stores the class Object and method
// ID in the current stack frame.  When Ruby calls into Rice, we grab
// the class and method ID from the stack frame, then pull the data out
// of the class. The data item is then used to determine how to convert
// arguments and return type, how to handle exceptions, etc.
//
VALUE
Rice::detail::
define_method_with_data(
    VALUE klass, ID id, VALUE (*cfunc)(ANYARGS), int arity, VALUE data)
{
  VALUE store = rb_attr_get(klass, RICE_ID);

  if (store == Qnil) {
    store = rb_obj_alloc(rb_cObject);
    // store is stored in the instance variables table with
    // name "__rice__".
    // since "__rice__" does not have the @ prefix,
    // so it can never be read at the Ruby level.
    rb_ivar_set(klass, RICE_ID, store);
  }

  rb_ivar_set(store, id, data);

  // Create the aliased method on the origin class
  rb_define_method(
      klass,
      rb_id2name(id),
      cfunc,
      arity);

  return Qnil;
}
开发者ID:Kagetsuki,项目名称:rice,代码行数:51,代码来源:method_data.cpp

示例3: dnssd_tr_new

VALUE
dnssd_tr_new(long len, const char *buf)
{
	VALUE self = rb_obj_alloc(cDNSSDTextRecord);
	dnssd_tr_decode_buffer(self, len, buf);
	return self;
}
开发者ID:lachie,项目名称:zeroconf,代码行数:7,代码来源:rdnssd_tr.c

示例4: oci8_svcctx_init

static void oci8_svcctx_init(oci8_base_t *base)
{
    oci8_svcctx_t *svcctx = (oci8_svcctx_t *)base;

    svcctx->executing_thread = Qnil;
    svcctx->session = DATA_PTR(rb_obj_alloc(cSession));
    svcctx->server = DATA_PTR(rb_obj_alloc(cServer));
    ((oci8_svcctx_associate_t *)svcctx->session)->svcctx = svcctx;
    ((oci8_svcctx_associate_t *)svcctx->server)->svcctx = svcctx;
    svcctx->pid = getpid();
    svcctx->is_autocommit = 0;
#ifdef HAVE_TYPE_RB_BLOCKING_FUNCTION_T
    svcctx->non_blocking = 1;
#endif
    svcctx->long_read_len = INT2FIX(65535);
}
开发者ID:adanmayer,项目名称:ruby-oci8,代码行数:16,代码来源:oci8.c

示例5: ossl_sslctx_session_remove_cb

static void
ossl_sslctx_session_remove_cb(SSL_CTX *ctx, SSL_SESSION *sess)
{
    VALUE ary, sslctx_obj, sess_obj, ret_obj;
    void *ptr;
    int state = 0;

    OSSL_Debug("SSL SESSION remove callback entered");

    if ((ptr = SSL_CTX_get_ex_data(ctx, ossl_ssl_ex_ptr_idx)) == NULL)
    	return;
    sslctx_obj = (VALUE)ptr;
    sess_obj = rb_obj_alloc(cSSLSession);
    CRYPTO_add(&sess->references, 1, CRYPTO_LOCK_SSL_SESSION);
    DATA_PTR(sess_obj) = sess;

    ary = rb_ary_new2(2);
    rb_ary_push(ary, sslctx_obj);
    rb_ary_push(ary, sess_obj);

    ret_obj = rb_protect((VALUE(*)_((VALUE)))ossl_call_session_new_cb, ary, &state);
    if (state) {
/*
  the SSL_CTX is frozen, nowhere to save state.
  there is no common accessor method to check it either.
        rb_ivar_set(sslctx_obj, ID_callback_state, INT2NUM(state));
*/
    }
}
开发者ID:2220142,项目名称:ruby,代码行数:29,代码来源:ossl_ssl.c

示例6: t_get_subprocess_status

static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
{
    VALUE proc_status = Qnil;

    int status;
    pid_t pid;

    if (evma_get_subprocess_status (NUM2ULONG (signature), &status)) {
        if (evma_get_subprocess_pid (NUM2ULONG (signature), &pid)) {
            proc_status = rb_obj_alloc(rb_cProcStatus);

            /* MRI Ruby uses hidden instance vars */
            rb_iv_set(proc_status, "status", INT2FIX(status));
            rb_iv_set(proc_status, "pid", INT2FIX(pid));

#ifdef RUBINIUS
            /* Rubinius uses standard instance vars */
            rb_iv_set(proc_status, "@pid", INT2FIX(pid));
            if (WIFEXITED(status)) {
                rb_iv_set(proc_status, "@status", INT2FIX(WEXITSTATUS(status)));
            } else if(WIFSIGNALED(status)) {
                rb_iv_set(proc_status, "@termsig", INT2FIX(WTERMSIG(status)));
            } else if(WIFSTOPPED(status)) {
                rb_iv_set(proc_status, "@stopsig", INT2FIX(WSTOPSIG(status)));
            }
#endif
        }
    }

    return proc_status;
}
开发者ID:MitulMistry,项目名称:sinatra-sessions-v-000,代码行数:31,代码来源:rubymain.cpp

示例7: fileIntForPath

static VALUE
fileIntForPath(const char *path, bool rubyExc)
{
	SDL_RWops *ops = SDL_AllocRW();

	try
	{
		shState->fileSystem().openRead(*ops, path);
	}
	catch (const Exception &e)
	{
		SDL_FreeRW(ops);

		if (rubyExc)
			raiseRbExc(e);
		else
			throw e;
	}

	VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt"));

	VALUE obj = rb_obj_alloc(klass);

	setPrivateData(obj, ops);

	return obj;
}
开发者ID:AlexandreSousa,项目名称:mkxp,代码行数:27,代码来源:filesystem-binding.cpp

示例8: rb_f_catch

static VALUE
rb_f_catch(int argc, VALUE *argv)
{
    VALUE tag;
    int state;
    VALUE val = Qnil;		/* OK */
    rb_thread_t *th = GET_THREAD();
    rb_control_frame_t *saved_cfp = th->cfp;

    if (argc == 0) {
	tag = rb_obj_alloc(rb_cObject);
    }
    else {
	rb_scan_args(argc, argv, "01", &tag);
    }
    PUSH_TAG();

    th->tag->tag = tag;

    if ((state = EXEC_TAG()) == 0) {
	val = rb_yield_0(1, &tag);
    }
    else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
	th->cfp = saved_cfp;
	val = th->tag->retval;
	th->errinfo = Qnil;
	state = 0;
    }
    POP_TAG();
    if (state)
	JUMP_TAG(state);

    return val;
}
开发者ID:3runo5ouza,项目名称:rhodes,代码行数:34,代码来源:vm_eval.c

示例9: ossl_ec_key_get_group

/*
 *  call-seq:
 *     key.group   => group
 *
 *  Returns a constant <code>OpenSSL::EC::Group</code> that is tied to the key.
 *  Modifying the returned group can make the key invalid.
 */
static VALUE ossl_ec_key_get_group(VALUE self)
{
    VALUE group_v;
    EC_KEY *ec;
    ossl_ec_group *ec_group;
    EC_GROUP *group;

    Require_EC_KEY(self, ec);

    group_v = rb_iv_get(self, "@group");
    if (!NIL_P(group_v))
        return group_v;

    if ((group = (EC_GROUP *)EC_KEY_get0_group(ec)) != NULL) {
        group_v = rb_obj_alloc(cEC_GROUP);
        SafeGet_ec_group(group_v, ec_group);
        ec_group->group = group;
        ec_group->dont_free = 1;
        rb_iv_set(group_v, "@key", self);
        rb_iv_set(self, "@group", group_v);
        return group_v;
    }

    return Qnil;
}
开发者ID:fi8on,项目名称:ruby,代码行数:32,代码来源:ossl_pkey_ec.c

示例10: ossl_sslctx_session_new_cb

/* return 1 normal.  return 0 removes the session */
static int
ossl_sslctx_session_new_cb(SSL *ssl, SSL_SESSION *sess)
{
    VALUE ary, ssl_obj, sess_obj, ret_obj;
    void *ptr;
    int state = 0;

    OSSL_Debug("SSL SESSION new callback entered");

    if ((ptr = SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)) == NULL)
    	return 1;
    ssl_obj = (VALUE)ptr;
    sess_obj = rb_obj_alloc(cSSLSession);
    CRYPTO_add(&sess->references, 1, CRYPTO_LOCK_SSL_SESSION);
    DATA_PTR(sess_obj) = sess;

    ary = rb_ary_new2(2);
    rb_ary_push(ary, ssl_obj);
    rb_ary_push(ary, sess_obj);

    ret_obj = rb_protect((VALUE(*)_((VALUE)))ossl_call_session_new_cb, ary, &state);
    if (state) {
        rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(state));
        return 0; /* what should be returned here??? */
    }

    return RTEST(ret_obj) ? 1 : 0;
}
开发者ID:2220142,项目名称:ruby,代码行数:29,代码来源:ossl_ssl.c

示例11: nary_s_step

static VALUE
nary_s_step( int argc, VALUE *argv, VALUE mod )
{
    VALUE self = rb_obj_alloc(na_cStep);
    step_initialize(argc, argv, self);
    return self;
}
开发者ID:biotrump,项目名称:narray-devel,代码行数:7,代码来源:step.c

示例12: rsock_s_accept

VALUE
rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
{
    int fd2;
    int retry = 0;
    struct accept_arg arg;

    rb_secure(3);
    arg.fd = fd;
    arg.sockaddr = sockaddr;
    arg.len = len;
  retry:
    rsock_maybe_wait_fd(fd);
    fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
    if (fd2 < 0) {
	switch (errno) {
	  case EMFILE:
	  case ENFILE:
	    if (retry) break;
	    rb_gc();
	    retry = 1;
	    goto retry;
	  default:
	    if (!rb_io_wait_readable(fd)) break;
	    retry = 0;
	    goto retry;
	}
	rb_sys_fail("accept(2)");
    }
    rb_update_max_fd(fd2);
    if (!klass) return INT2NUM(fd2);
    return rsock_init_sock(rb_obj_alloc(klass), fd2);
}
开发者ID:DashYang,项目名称:sim,代码行数:33,代码来源:init.c

示例13: rsock_s_accept_nonblock

VALUE
rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
{
    int fd2;

    rb_secure(3);
    rb_io_set_nonblock(fptr);
    fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len);
    if (fd2 < 0) {
	switch (errno) {
	  case EAGAIN:
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
	  case EWOULDBLOCK:
#endif
	  case ECONNABORTED:
#if defined EPROTO
	  case EPROTO:
#endif
            rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "accept(2) would block");
	}
        rb_sys_fail("accept(2)");
    }
    rb_update_max_fd(fd2);
    make_fd_nonblock(fd2);
    return rsock_init_sock(rb_obj_alloc(klass), fd2);
}
开发者ID:DashYang,项目名称:sim,代码行数:26,代码来源:init.c

示例14: create_prolog_doc

static void
create_prolog_doc(PInfo pi, const char *target, Attr attrs) {
    VALUE       doc;
    VALUE       ah;
    VALUE       nodes;

    if (0 != pi->h) { // top level object
        rb_raise(rb_eSyntaxError, "Prolog must be the first element in an XML document.\n");
    }
    pi->h = pi->helpers;
    doc = rb_obj_alloc(ox_document_clas);
    ah = rb_hash_new();
    for (; 0 != attrs->name; attrs++) {
        rb_hash_aset(ah, ID2SYM(rb_intern(attrs->name)), rb_str_new2(attrs->value));
#ifdef HAVE_RUBY_ENCODING_H
        if (0 == strcmp("encoding", attrs->name)) {
            pi->encoding = rb_enc_find(attrs->value);
        }
#endif
    }
    nodes = rb_ary_new();
    rb_ivar_set(doc, attributes_id, ah);
    rb_ivar_set(doc, nodes_id, nodes);
    pi->h->obj = nodes;
    pi->obj = doc;
}
开发者ID:artflakes,项目名称:ox,代码行数:26,代码来源:gen_load.c

示例15: rbgobj_gtype_new

VALUE
rbgobj_gtype_new(GType gtype)
{
    VALUE result = rb_obj_alloc(rbgobj_cType);
    VALUE arg = ULONG2NUM(gtype);
    rb_obj_call_init(result, 1, &arg);
    return result;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:8,代码来源:rbgobj_type.c


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