コード例 #1
0
ファイル: enumerator.c プロジェクト: Danylyuk/first_app
static VALUE
lazy_take_func(VALUE val, VALUE args, int argc, VALUE *argv)
{
    long remain;
    VALUE memo = rb_attr_get(argv[0], id_memo);
    if (NIL_P(memo)) {
	memo = args;
    }

    rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
    if ((remain = NUM2LONG(memo)-1) == 0) {
	return Qundef;
    }
    else {
	rb_ivar_set(argv[0], id_memo, LONG2NUM(remain));
	return Qnil;
    }
}
コード例 #2
0
ファイル: sha1init.c プロジェクト: brightbox/deb-ruby2.1
/*
 * A class for calculating message digests using the SHA-1 Secure Hash
 * Algorithm by NIST (the US' National Institute of Standards and
 * Technology), described in FIPS PUB 180-1.
 */
void
Init_sha1()
{
    VALUE mDigest, cDigest_Base, cDigest_SHA1;

    rb_require("digest");

#if 0
    mDigest = rb_define_module("Digest"); /* let rdoc know */
#endif
    mDigest = rb_path2class("Digest");
    cDigest_Base = rb_path2class("Digest::Base");

    cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);

    rb_ivar_set(cDigest_SHA1, rb_intern("metadata"),
      Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&sha1));
}
コード例 #3
0
ファイル: rb_cairo_context.c プロジェクト: cosmo0920/rcairo
static VALUE
cr_s_wrap (VALUE self, VALUE pointer)
{
  VALUE result;
  VALUE rb_cr;
  cairo_t *cr;

  if (NIL_P (rb_cairo__cFFIPointer))
    {
      rb_raise (rb_eNotImpError,
                "%s: FFI::Pointer is required",
                rb_id2name (rb_frame_this_func ()));
    }

  if (!RTEST (rb_obj_is_kind_of (pointer, rb_cairo__cFFIPointer)))
    {
      rb_raise (rb_eArgError,
                "must be FFI::Pointer: %s",
                rb_cairo__inspect (pointer));
    }

  {
    VALUE rb_cr_address;
    rb_cr_address = rb_funcall (pointer, rb_intern ("address"), 0);
    cr = NUM2PTR (rb_cr_address);
    cr_check_status (cr);
  }

  rb_cr = rb_obj_alloc (self);
  cairo_reference (cr);
  DATA_PTR (rb_cr) = cr;
  rb_ivar_set (rb_cr, cr_id_surface, Qnil);

  if (rb_block_given_p ())
    {
      result = rb_ensure (rb_yield, rb_cr, cr_destroy_with_destroy_check, rb_cr);
    }
  else
    {
      result = rb_cr;
    }

  return result;
}
コード例 #4
0
ファイル: ruby_xml_reader.c プロジェクト: GREENMASK/mgr
/* call-seq:
 *    XML::Reader.io(io) -> XML::Reader
 *    XML::Reader.io(io, :encoding => XML::Encoding::UTF_8,
 *                       :options => XML::Parser::Options::NOENT) -> XML::Parser
 *
 * Creates a new reader by parsing the specified io object.
 *
 * You may provide an optional hash table to control how the
 * parsing is performed.  Valid options are:
 *
 *  base_uri - The base url for the parsed document.
 *  encoding - The document encoding, defaults to nil. Valid values
 *             are the encoding constants defined on XML::Encoding.
 *  options - Controls the execution of the parser, defaults to 0.
 *            Valid values are the constants defined on
 *            XML::Parser::Options.  Mutliple options can be combined
 *            by using Bitwise OR (|). 
 */
static VALUE rxml_reader_io(int argc, VALUE *argv, VALUE klass)
{
  xmlTextReaderPtr xreader;
  VALUE result;
  VALUE io;
  VALUE options;
  char *xbaseurl = NULL;
  const char *xencoding = NULL;
  int xoptions = 0;

  rb_scan_args(argc, argv, "11", &io, &options);

  if (!NIL_P(options))
  {
    VALUE baseurl = Qnil;
    VALUE encoding = Qnil;
    VALUE parserOptions = Qnil;

    Check_Type(options, T_HASH);

    baseurl = rb_hash_aref(options, BASE_URI_SYMBOL);
    xbaseurl = NIL_P(baseurl) ? NULL : StringValueCStr(baseurl);

    encoding = rb_hash_aref(options, ENCODING_SYMBOL);
    xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding));

    parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
    xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions);
  }
  
  xreader = xmlReaderForIO((xmlInputReadCallback) rxml_read_callback, NULL,
                           (void *) io, 
                           xbaseurl, xencoding, xoptions);

  if (xreader == NULL)
    rxml_raise(&xmlLastError);

  result = rxml_reader_wrap(xreader);

  /* Attach io object to parser so it won't get freed.*/
  rb_ivar_set(result, IO_ATTR, io);

  return result;
}
コード例 #5
0
ファイル: rbosa.c プロジェクト: bmorton/rubyosa
static VALUE
rbosa_element_make (VALUE klass, AEDesc *desc, VALUE app)
{
    AEDesc *    newDesc;
    VALUE       new_klass, obj;

    newDesc = (AEDesc *)malloc (sizeof (AEDesc));
    if (newDesc == NULL)
        rb_fatal ("cannot allocate memory");
    memcpy (newDesc, desc, sizeof (AEDesc));
    new_klass = Qnil;

    /* Let's replace the klass here according to the type of the descriptor,
     * if the basic class OSA::Element was given.
     */
    if (klass == cOSAElement) {
        if (newDesc->descriptorType == 'list') {
            klass = cOSAElementList;
        }
        else if (newDesc->descriptorType == 'reco') {
            klass = cOSAElementRecord;
        }
        else if (newDesc->descriptorType == 'type') {
            new_klass = __rbosa_class_from_desc_data (app, *newDesc);
        }
        else if (newDesc->descriptorType == 'obj ' && !NIL_P (app)) {
            AEDesc  res;
            OSErr   err;

            if ((err = AEGetParamDesc ((AppleEvent *)newDesc, 'want', '****', &res)) == noErr)
                new_klass = __rbosa_class_from_desc_data (app, res);
        }
    }

    if (!NIL_P (new_klass))
        klass = new_klass; 
    
    obj = Data_Wrap_Struct (klass, NULL, rbosa_element_free, newDesc);

    rb_ivar_set (obj, sApp, NIL_P (app) ? obj : app);

    return obj;
}
コード例 #6
0
ファイル: rbvlcmedialist.c プロジェクト: Vasfed/ruby-gnome2
/*
 * Create an empty media list.
 *
 * @param [VLC::Core] core the core instance
 * @raise [ArgumentError] Invalid or unsupported arguments
 * @todo fixme
 */
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE core;
    libvlc_media_list_t *instance;

    rb_scan_args(argc, argv, "01", &core);
    if (NIL_P(core))
        core = rb_funcall(GTYPE2CLASS(VLC_TYPE_CORE), rb_intern("new"), 0);

    instance = libvlc_media_list_new(RVAL2VLCCORE(core));
    if (!instance)
        rb_raise(rb_eArgError, "Invalid arguments.");
    rb_ivar_set(self, id_core, core);

    G_INITIALIZE(self, instance);
    vlc_media_list_free(instance);
    return Qnil;
}
コード例 #7
0
ファイル: message.c プロジェクト: 1nf1corp/protobuf
VALUE Message_alloc(VALUE klass) {
  VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
  Descriptor* desc = ruby_to_Descriptor(descriptor);
  MessageHeader* msg = (MessageHeader*)ALLOC_N(
      uint8_t, sizeof(MessageHeader) + desc->layout->size);
  VALUE ret;

  memset(Message_data(msg), 0, desc->layout->size);

  // We wrap first so that everything in the message object is GC-rooted in case
  // a collection happens during object creation in layout_init().
  ret = TypedData_Wrap_Struct(klass, &Message_type, msg);
  msg->descriptor = desc;
  rb_ivar_set(ret, descriptor_instancevar_interned, descriptor);

  layout_init(desc->layout, Message_data(msg));

  return ret;
}
コード例 #8
0
static VALUE
cr_get_target (VALUE self)
{
  cairo_surface_t *surface;
  VALUE rb_surface = Qnil;

  surface = cairo_get_target (_SELF);
  rb_cairo_check_status (cairo_surface_status (surface));

  if (RTEST (rb_ivar_defined (self, cr_id_surface)))
      rb_surface = rb_ivar_get (self, cr_id_surface);
  if (NIL_P (rb_surface) || RVAL2CRSURFACE (rb_surface) != surface)
    {
      rb_surface = CRSURFACE2RVAL (surface);
      rb_ivar_set (self, cr_id_surface, rb_surface);
    }

  return rb_surface;
}
コード例 #9
0
ファイル: rbgtk.c プロジェクト: benolee/ruby-gnome2
void
rbgtk_initialize_gtkobject(VALUE obj, GtkObject *gtkobj)
{
    gtkobj = g_object_ref(gtkobj);
    gtk_object_sink(gtkobj);
    G_INITIALIZE(obj, gtkobj);

    if (GTK_IS_WINDOW(gtkobj) || GTK_IS_MENU_SHELL(gtkobj)) {
        VALUE klass;
        klass = rb_obj_class(obj);
        if (rb_ivar_defined(klass, id__windows__) == Qfalse) {
            rb_ivar_set(klass, id__windows__, rb_hash_new());
        }
        rb_hash_aset(rb_ivar_get(klass, id__windows__), obj, Qnil);
        g_signal_connect_after(gtkobj, "destroy",
                               G_CALLBACK(remove_from_windows),
                               (gpointer)obj);
    }
}
コード例 #10
0
ファイル: selector.c プロジェクト: emosei/chef
/* Synchronize around a reentrant selector lock */
static VALUE NIO_Selector_synchronize(VALUE self, VALUE (*func)(VALUE *args), VALUE *args)
{
    VALUE current_thread, lock_holder, lock;

    current_thread = rb_thread_current();
    lock_holder = rb_ivar_get(self, rb_intern("lock_holder"));

    if(lock_holder != current_thread) {
        lock = rb_ivar_get(self, rb_intern("lock"));
        rb_funcall(lock, rb_intern("lock"), 0, 0);
        rb_ivar_set(self, rb_intern("lock_holder"), current_thread);

        /* We've acquired the lock, so ensure we unlock it */
        return rb_ensure(func, (VALUE)args, NIO_Selector_unlock, self);
    } else {
        /* We already hold the selector lock, so no need to unlock it */
        return func(args);
    }
}
コード例 #11
0
static VALUE
cr_initialize (VALUE self, VALUE target)
{
  cairo_t *cr;
  VALUE result = Qnil;

  cr = cairo_create (RVAL2CRSURFACE (target));
  cr_check_status (cr);
  rb_ivar_set (self, cr_id_surface, target);
  if (rb_ivar_defined (target, rb_cairo__io_id_output))
    cr_set_user_data (cr,
                      &cr_object_holder_key,
                      cr_object_holder_new (self),
                      cr_object_holder_free);
  DATA_PTR (self) = cr;
  if (rb_block_given_p ())
    result = rb_ensure (rb_yield, self, cr_destroy_with_destroy_check, self);
  return result;
}
コード例 #12
0
ファイル: enumerator.c プロジェクト: takuto-h/ruby
static VALUE
lazy_zip_arrays_func(VALUE val, VALUE arrays, int argc, VALUE *argv)
{
    VALUE yielder, ary, memo;
    long i, count;

    yielder = argv[0];
    memo = rb_attr_get(yielder, id_memo);
    count = NIL_P(memo) ? 0 : NUM2LONG(memo);

    ary = rb_ary_new2(RARRAY_LEN(arrays) + 1);
    rb_ary_push(ary, argv[1]);
    for (i = 0; i < RARRAY_LEN(arrays); i++) {
	rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
    }
    rb_funcall(yielder, id_yield, 1, ary);
    rb_ivar_set(yielder, id_memo, LONG2NUM(++count));
    return Qnil;
}
コード例 #13
0
ファイル: rb_cairo_font_face.c プロジェクト: rcairo/rcairo
static VALUE
cr_text_to_glyphs_data_initialize (VALUE self,
                                   VALUE need_glyphs, VALUE need_clusters,
                                   VALUE need_cluster_flags)
{
  rb_ivar_set (self, cr_id_at_glyphs, Qnil);
  rb_ivar_set (self, cr_id_at_clusters, Qnil);
  rb_ivar_set (self, cr_id_at_cluster_flags, INT2NUM (0));
  rb_ivar_set (self, cr_id_at_need_glyphs, need_glyphs);
  rb_ivar_set (self, cr_id_at_need_clusters, need_clusters);
  rb_ivar_set (self, cr_id_at_need_cluster_flags, need_cluster_flags);

  return Qnil;
}
コード例 #14
0
ファイル: spec.c プロジェクト: daviddavis/rpm.rb
/*
 * @return [Array<RPM::Package>] Packages defined in the spec file
 */
VALUE
rpm_spec_get_packages(VALUE spec)
{
	VALUE pkg = rb_ivar_get(spec, id_pkg);

	if (NIL_P(pkg)) {
		Package p = RPM_SPEC(spec)->packages;

		pkg = rb_ary_new();
		while (p != NULL) {
			if (p->fileList)
				rb_ary_push(pkg, rpm_package_new_from_header(p->header));
			p = p->next;
		}

		rb_ivar_set(spec, id_pkg, pkg);
	}

	return pkg;
}
コード例 #15
0
ファイル: rbgobj_type.c プロジェクト: aurelj/ruby-gnome2
static VALUE
rg_initialize(VALUE self, VALUE type)
{
    GType gtype;

    if (RVAL2CBOOL(rb_obj_is_kind_of(type, rb_cInteger))) {
        gtype = NUM2ULONG(type);
        if (!g_type_name(gtype))
            gtype = G_TYPE_INVALID;
    } else {
        gtype = g_type_from_name(StringValuePtr(type));
    }

    if (G_TYPE_INVALID == gtype)
        rb_raise(rb_eArgError, "invalid GType");

    rb_ivar_set(self, id_gtype, ULONG2NUM(gtype));

    return Qnil;
}
コード例 #16
0
ファイル: Function.c プロジェクト: shafferj/ffi
VALUE
rbffi_Function_ForProc(VALUE rbFunctionInfo, VALUE proc)
{
    VALUE callback;
    VALUE cbTable = RTEST(rb_ivar_defined(proc, id_cbtable)) ? rb_ivar_get(proc, id_cbtable) : Qnil;

    if (cbTable == Qnil) {
        cbTable = rb_hash_new();
        rb_ivar_set(proc, id_cbtable, cbTable);
    }

    callback = rb_hash_aref(cbTable, rbFunctionInfo);
    if (callback != Qnil) {
        return callback;
    }

    callback = rbffi_Function_NewInstance(rbFunctionInfo, proc);
    rb_hash_aset(cbTable, rbFunctionInfo, callback);
    return callback;
}
コード例 #17
0
ファイル: rbrsvg.c プロジェクト: benolee/ruby-gnome2
static VALUE
rb_rsvg_handle_close(VALUE self)
{
    gboolean result;
    GError *error = NULL;

    if (RVAL2CBOOL(rb_ivar_get(self, id_closed))) {
        return Qnil;
    }

    result = rsvg_handle_close(_SELF(self), &error);

    if (result) {
        rb_ivar_set(self, id_closed, Qtrue);
    } else {
        RAISE_GERROR(error);
    }

    return CBOOL2RVAL(result);
}
コード例 #18
0
ファイル: vm_args.c プロジェクト: hayaken8112/.emacs.d
static void
raise_argument_error(rb_thread_t *th, const rb_iseq_t *iseq, const VALUE exc)
{
    VALUE at;

    if (iseq) {
	vm_push_frame(th, iseq, VM_FRAME_MAGIC_DUMMY, Qnil /* self */,
		      VM_ENVVAL_BLOCK_PTR(0) /* specval*/, Qfalse /* me or cref */,
		      iseq->body->iseq_encoded, th->cfp->sp, 1 /* local_size (cref/me) */, 0 /* stack_max */);
	at = rb_vm_backtrace_object();
	vm_pop_frame(th);
    }
    else {
	at = rb_vm_backtrace_object();
    }

    rb_ivar_set(exc, idBt_locations, at);
    rb_exc_set_backtrace(exc, at);
    rb_exc_raise(exc);
}
コード例 #19
0
ファイル: sprite.c プロジェクト: wanabe/ExtRgss
static VALUE Sprite_initialize(int argc, VALUE *argv, VALUE self) {
  VALUE sprites = rb_ivar_get(mGraphics, rb_intern("@sprites"));
  VALUE src_rect = rb_class_new_instance(0, NULL, cRect);
  Sprite *sprite = EXT_SPRITE(self);

  rb_ary_push(sprites, self);
  old_call(self, rb_intern("initialize"), argc, argv);

  src_rect = old_call(self, rb_intern("src_rect"), 0, NULL); /* TODO */
  rb_ivar_set(self, rb_intern("@src_rect"), src_rect);
  Rect__add_ref(src_rect, self);
  sprite->src_rect = src_rect;

  sprite->x = sprite->y = 0;
  sprite->ox = sprite->oy = 0;
  sprite->disposed = 0;
  sprite->visible = 1;

  return self;
}
コード例 #20
0
static VALUE rb_eu_escape_html_as_html_safe(VALUE self, VALUE str)
{
	VALUE result;
	int secure = g_html_secure;
	gh_buf buf = GH_BUF_INIT;

	Check_Type(str, T_STRING);
	check_utf8_encoding(str);

	if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(str), RSTRING_LEN(str), secure)) {
		result = new_html_safe_string(buf.ptr, buf.size);
		gh_buf_free(&buf);
	} else {
		result = new_html_safe_string(RSTRING_PTR(str), RSTRING_LEN(str));
	}

	rb_ivar_set(result, ID_at_html_safe, Qtrue);

	return result;
}
コード例 #21
0
ファイル: rmd160init.c プロジェクト: markkkkkkk/demo_apps
/*
 * A class for calculating message digests using RIPEMD-160
 * cryptographic hash function, designed by Hans Dobbertin, Antoon
 * Bosselaers, and Bart Preneel.
 */
void
Init_rmd160(void)
{
    VALUE mDigest, cDigest_Base, cDigest_RMD160;

    rb_require("digest");

#if 0
    mDigest = rb_define_module("Digest"); /* let rdoc know */
#endif
    mDigest = rb_path2class("Digest");
    cDigest_Base = rb_path2class("Digest::Base");

    cDigest_RMD160 = rb_define_class_under(mDigest, "RMD160", cDigest_Base);

#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
    rb_ivar_set(cDigest_RMD160, rb_intern("metadata"),
                Data_Wrap_Struct(0, 0, 0, (void *)&rmd160));
}
コード例 #22
0
ファイル: rb_channel.c プロジェクト: FabioBatSilva/grpc
/*
  call-seq:
    insecure_channel = Channel:new("myhost:8080", {'arg1': 'value1'},
                                   :this_channel_is_insecure)
    creds = ...
    secure_channel = Channel:new("myhost:443", {'arg1': 'value1'}, creds)

  Creates channel instances. */
static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
  VALUE channel_args = Qnil;
  VALUE credentials = Qnil;
  VALUE target = Qnil;
  grpc_rb_channel *wrapper = NULL;
  grpc_channel *ch = NULL;
  grpc_channel_credentials *creds = NULL;
  char *target_chars = NULL;
  grpc_channel_args args;
  MEMZERO(&args, grpc_channel_args, 1);

  /* "3" == 3 mandatory args */
  rb_scan_args(argc, argv, "3", &target, &channel_args, &credentials);

  TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
  target_chars = StringValueCStr(target);
  grpc_rb_hash_convert_to_channel_args(channel_args, &args);
  if (TYPE(credentials) == T_SYMBOL) {
    if (id_insecure_channel != SYM2ID(credentials)) {
      rb_raise(rb_eTypeError,
               "bad creds symbol, want :this_channel_is_insecure");
      return Qnil;
    }
    ch = grpc_insecure_channel_create(target_chars, &args, NULL);
  } else {
    wrapper->credentials = credentials;
    creds = grpc_rb_get_wrapped_channel_credentials(credentials);
    ch = grpc_secure_channel_create(creds, target_chars, &args, NULL);
  }
  if (args.args != NULL) {
    xfree(args.args); /* Allocated by grpc_rb_hash_convert_to_channel_args */
  }
  if (ch == NULL) {
    rb_raise(rb_eRuntimeError, "could not create an rpc channel to target:%s",
             target_chars);
    return Qnil;
  }
  rb_ivar_set(self, id_target, target);
  wrapper->wrapped = ch;
  return self;
}
コード例 #23
0
ファイル: ossl_ssl.c プロジェクト: 2220142/ruby
static VALUE
ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, int nonblock)
{
    SSL *ssl;
    rb_io_t *fptr;
    int ret, ret2;
    VALUE cb_state;

    rb_ivar_set(self, ID_callback_state, Qnil);

    Data_Get_Struct(self, SSL, ssl);
    GetOpenFile(ossl_ssl_get_io(self), fptr);
    for(;;){
	ret = func(ssl);

        cb_state = rb_ivar_get(self, ID_callback_state);
        if (!NIL_P(cb_state))
            rb_jump_tag(NUM2INT(cb_state));

	if (ret > 0)
	    break;

	switch((ret2 = ssl_get_error(ssl, ret))){
	case SSL_ERROR_WANT_WRITE:
            write_would_block(nonblock);
            rb_io_wait_writable(FPTR_TO_FD(fptr));
            continue;
	case SSL_ERROR_WANT_READ:
            read_would_block(nonblock);
            rb_io_wait_readable(FPTR_TO_FD(fptr));
            continue;
	case SSL_ERROR_SYSCALL:
	    if (errno) rb_sys_fail(funcname);
	    ossl_raise(eSSLError, "%s SYSCALL returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
	default:
	    ossl_raise(eSSLError, "%s returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
	}
    }

    return self;
}
コード例 #24
0
ファイル: error.c プロジェクト: 0x00evil/ruby
static VALUE
exit_initialize(int argc, VALUE *argv, VALUE exc)
{
    VALUE status;
    if (argc > 0) {
	status = *argv;

	switch (status) {
	  case Qtrue:
	    status = INT2FIX(EXIT_SUCCESS);
	    ++argv;
	    --argc;
	    break;
	  case Qfalse:
	    status = INT2FIX(EXIT_FAILURE);
	    ++argv;
	    --argc;
	    break;
	  default:
	    status = rb_check_to_int(status);
	    if (NIL_P(status)) {
		status = INT2FIX(EXIT_SUCCESS);
	    }
	    else {
#if EXIT_SUCCESS != 0
		if (status == INT2FIX(0))
		    status = INT2FIX(EXIT_SUCCESS);
#endif
		++argv;
		--argc;
	    }
	    break;
	}
    }
    else {
	status = INT2FIX(EXIT_SUCCESS);
    }
    rb_call_super(argc, argv);
    rb_ivar_set(exc, id_status, status);
    return exc;
}
コード例 #25
0
ファイル: rb_call.c プロジェクト: makdharma/grpc
/*
  call-seq:
  call.set_credentials call_credentials

  Sets credentials on a call */
static VALUE grpc_rb_call_set_credentials(VALUE self, VALUE credentials) {
  grpc_rb_call *call = NULL;
  grpc_call_credentials *creds;
  grpc_call_error err;
  if (RTYPEDDATA_DATA(self) == NULL) {
    rb_raise(grpc_rb_eCallError, "Cannot set credentials of closed call");
    return Qnil;
  }
  TypedData_Get_Struct(self, grpc_rb_call, &grpc_call_data_type, call);
  creds = grpc_rb_get_wrapped_call_credentials(credentials);
  err = grpc_call_set_credentials(call->wrapped, creds);
  if (err != GRPC_CALL_OK) {
    rb_raise(grpc_rb_eCallError,
             "grpc_call_set_credentials failed with %s (code=%d)",
             grpc_call_error_detail_of(err), err);
  }
  /* We need the credentials to be alive for as long as the call is alive,
     but we don't care about destruction order. */
  rb_ivar_set(self, id_credentials, credentials);
  return Qnil;
}
コード例 #26
0
ファイル: carray_mask.c プロジェクト: himotoyoshi/carray
VALUE
rb_ca_mask_array (VALUE self)
{
  VALUE obj;
  CArray *ca;
  Data_Get_Struct(self, CArray, ca);

  ca_update_mask(ca);
  if ( ca->mask ) {
    obj = Data_Wrap_Struct(ca_class[ca->mask->obj_type],
            ca_mark, ca_free_nop, ca->mask);
    rb_ivar_set(obj, rb_intern("masked_array"), self);
    if ( OBJ_FROZEN(self) ) {
      rb_ca_freeze(obj);
    }
    return obj;
  }
  else {
    return INT2NUM(0);
  }
}
コード例 #27
0
ファイル: rb_cpShape.c プロジェクト: 0w/moai-dev
static VALUE
rb_cpPolyInitialize(VALUE self, VALUE body, VALUE arr, VALUE offset)
{
	cpPolyShape *poly = (cpPolyShape *)SHAPE(self);
	
	Check_Type(arr, T_ARRAY);
	int numVerts = RARRAY_LEN(arr);
	VALUE *ary_ptr = RARRAY_PTR(arr);
	cpVect verts[numVerts];
	
	for(int i=0; i<numVerts; i++)
		verts[i] = *VGET(ary_ptr[i]);
	
	cpPolyShapeInit(poly, BODY(body), numVerts, verts, *VGET(offset));
	poly->shape.data = (void *)self;
	poly->shape.collision_type = Qnil;

	rb_ivar_set(self, id_body, body);
	
	return self;
}
コード例 #28
0
ファイル: DataConverter.c プロジェクト: Atastor/ffi
static VALUE
conv_native_type(int argc, VALUE* argv, VALUE self)
{
    if (argc == 0) {
        if (!rb_ivar_defined(self, id_native_type_ivar)) {
            rb_raise(rb_eNotImpError, "native_type method not overridden and no native_type set");
        }

        return rb_ivar_get(self, id_native_type_ivar);

    } else if (argc == 1) {
        VALUE type = rbffi_Type_Find(argv[0]);

        rb_ivar_set(self, id_native_type_ivar, type);

        return type;

    } else {
        rb_raise(rb_eArgError, "incorrect arguments");
    }
}
コード例 #29
0
ファイル: enumerator.c プロジェクト: takuto-h/ruby
/*
 * call-seq:
 *   Lazy.new(obj, size=nil) { |yielder, *values| ... }
 *
 * Creates a new Lazy enumerator. When the enumerator is actually enumerated
 * (e.g. by calling #force), +obj+ will be enumerated and each value passed
 * to the given block. The block can yield values back using +yielder+.
 * For example, to create a method +filter_map+ in both lazy and
 * non-lazy fashions:
 *
 *   module Enumerable
 *     def filter_map(&block)
 *       map(&block).compact
 *     end
 *   end
 *
 *   class Enumerator::Lazy
 *     def filter_map
 *       Lazy.new(self) do |yielder, *values|
 *         result = yield *values
 *         yielder << result if result
 *       end
 *     end
 *   end
 *
 *   (1..Float::INFINITY).lazy.filter_map{|i| i*i if i.even?}.first(5)
 *       # => [4, 16, 36, 64, 100]
 */
static VALUE
lazy_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE obj, size = Qnil;
    VALUE generator;

    rb_check_arity(argc, 1, 2);
    if (!rb_block_given_p()) {
	rb_raise(rb_eArgError, "tried to call lazy new without a block");
    }
    obj = argv[0];
    if (argc > 1) {
	size = argv[1];
    }
    generator = generator_allocate(rb_cGenerator);
    rb_block_call(generator, id_initialize, 0, 0, lazy_init_block_i, obj);
    enumerator_init(self, generator, sym_each, 0, 0, 0, size);
    rb_ivar_set(self, id_receiver, obj);

    return self;
}
コード例 #30
0
ファイル: kernel.c プロジェクト: silicon/MacRuby
PRIMITIVE void
vm_ivar_set(VALUE obj, ID name, VALUE val, void *cache_p)
{
    struct icache *cache = (struct icache *)cache_p; 
    VALUE klass = 0;

    if (!SPECIAL_CONST_P(obj)) {
	klass = *(VALUE *)obj;
	if (klass == cache->klass) {
	    if ((unsigned int)cache->slot < ROBJECT(obj)->num_slots) {
		rb_object_ivar_slot_t *slot;
use_slot:
		slot = &ROBJECT(obj)->slots[cache->slot];
		if (slot->name == name) {
		    if ((ROBJECT(obj)->basic.flags & FL_FREEZE) == FL_FREEZE) {
			rb_error_frozen("object");
		    }
		    GC_WB(&slot->value, val);
		    return;
		}
	    }
	    goto find_slot;
	}
    }

    if (cache->slot == SLOT_CACHE_VIRGIN) {
	int slot;
find_slot:
	slot = rb_vm_get_ivar_slot(obj, name, true);
	if (slot >= 0) {
	    cache->klass = *(VALUE *)obj;
	    cache->slot = slot;
	    goto use_slot;
	}
	cache->slot = SLOT_CACHE_CANNOT;
    }

    rb_ivar_set(obj, name, val);
}