示例#1
0
static VALUE
lazy_take_size(VALUE generator, VALUE args, VALUE lazy)
{
    VALUE receiver = lazy_size(lazy);
    long len = NUM2LONG(RARRAY_PTR(rb_ivar_get(lazy, id_arguments))[0]);
    if (NIL_P(receiver) || (FIXNUM_P(receiver) && FIX2LONG(receiver) < len))
	return receiver;
    return LONG2NUM(len);
}
示例#2
0
static void
activate_action(GtkAction *action, VALUE self)
{
    VALUE proc = rb_hash_aref(rb_ivar_get(self, id_action_procs),
                              CSTR2RVAL(gtk_action_get_name(action)));

    if (!NIL_P(proc))
        rb_funcall(proc, id_call, 2, self, GOBJ2RVAL(action));
}
示例#3
0
static void copy_server_handle(oci8_svcctx_t *svcctx)
{
    VALUE obj = rb_ivar_get(svcctx->base.self, id_at_server_handle);
    oci8_base_t *base;

    Check_Handle(obj, cServer, base);
    base->type = OCI_HTYPE_SERVER;
    base->hp.srvhp = svcctx->srvhp;
}
示例#4
0
文件: db.c 项目: basecamp/ruby-rpm
/*
 * Add a delete operation to the transaction
 * @param [String, Package, Dependency] pkg Package to delete
 */
VALUE
rpm_transaction_delete(VALUE trans, VALUE pkg)
{
	VALUE db;
	VALUE mi;

#if RPM_VERSION_CODE < RPM_VERSION(4,9,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
	db = rb_ivar_get(trans, id_db);

	if (TYPE(pkg) == T_STRING)
		mi = rpm_db_init_iterator(db, INT2NUM(RPMDBI_LABEL), pkg);
	else if (rb_obj_is_kind_of(pkg, rpm_cPackage) != Qfalse) {
		VALUE sigmd5 = rpm_package_aref(pkg,INT2NUM(RPMTAG_SIGMD5));
		if (sigmd5 != Qnil){
			mi = rpm_db_init_iterator(db, INT2NUM(RPMTAG_SIGMD5), sigmd5);
		}else{
			VALUE name = rpm_package_aref(pkg,INT2NUM(RPMDBI_LABEL));
			mi = rpm_db_init_iterator(db, INT2NUM(RPMDBI_LABEL), name);
		}
	} else if ( rb_obj_is_kind_of(pkg, rpm_cDependency) ==Qfalse &&
                    rb_respond_to(pkg,rb_intern("name")) && rb_respond_to(pkg,rb_intern("version"))){
		mi = rpm_db_init_iterator(db, INT2NUM(RPMDBI_LABEL),rb_funcall(pkg,rb_intern("name"),0));
		rpm_mi_set_iterator_version(mi,rb_funcall(pkg,rb_intern("version"),0));
	} else
		rb_raise(rb_eTypeError, "illegal argument type");
#else
	if (TYPE(pkg) == T_STRING)
		mi = rpm_transaction_init_iterator(trans, INT2NUM(RPMDBI_LABEL), pkg);
	else if (rb_obj_is_kind_of(pkg, rpm_cPackage) != Qfalse) {
		VALUE sigmd5 = rpm_package_aref(pkg,INT2NUM(RPMTAG_SIGMD5));
		if (sigmd5 != Qnil){
			mi = rpm_transaction_init_iterator(trans, INT2NUM(RPMTAG_SIGMD5), sigmd5);
		}else{
			VALUE name = rpm_package_aref(pkg,INT2NUM(RPMDBI_LABEL));
			mi = rpm_transaction_init_iterator(trans, INT2NUM(RPMDBI_LABEL), name);
		}
	} else if ( rb_obj_is_kind_of(pkg, rpm_cDependency) ==Qfalse &&
                    rb_respond_to(pkg,rb_intern("name")) && rb_respond_to(pkg,rb_intern("version"))){
		mi = rpm_transaction_init_iterator(trans, INT2NUM(RPMDBI_LABEL),rb_funcall(pkg,rb_intern("name"),0));
		rpm_mi_set_iterator_version(mi,rb_funcall(pkg,rb_intern("version"),0));
	} else
		rb_raise(rb_eTypeError, "illegal argument type");
#endif

	VALUE p;
	while (!NIL_P(p = rpm_mi_next_iterator(mi))) {
		VALUE off = rpm_mi_get_iterator_offset(mi);
		if (!NIL_P(off)){
#if RPM_VERSION_CODE < RPM_VERSION(4,1,0)
			rpmtransRemovePackage(RPM_TRANSACTION(trans), NUM2INT(off));
#else
			rpmtsAddEraseElement(RPM_TRANSACTION(trans), RPM_HEADER(p), NUM2INT(off));
#endif
		}
	}
	return Qnil;
}
示例#5
0
文件: cparse.c 项目: vasco/racc
static int
reduce(struct cparse_params *v, long act)
{
    VALUE code;
    v->ruleno = -act * 3;
    code = rb_catch("racc_jump", reduce0, v->value_v);
    v->errstatus = num_to_long(rb_ivar_get(v->parser, id_errstatus));
    return NUM2INT(code);
}
示例#6
0
文件: generator.c 项目: 0x00xw/json-2
/*
* call-seq: [](name)
*
* Returns the value returned by method +name+.
*/
static VALUE cState_aref(VALUE self, VALUE name)
{
    name = rb_funcall(name, i_to_s, 0);
    if (RTEST(rb_funcall(self, i_respond_to_p, 1, name))) {
        return rb_funcall(self, i_send, 1, name);
    } else {
        return rb_ivar_get(self, rb_intern_str(rb_str_concat(rb_str_new2("@"), name)));
    }
}
示例#7
0
static void copy_session_handle(oci8_svcctx_t *svcctx)
{
    VALUE obj = rb_ivar_get(svcctx->base.self, id_at_session_handle);
    oci8_base_t *base;

    Check_Handle(obj, cSession, base);
    base->type = OCI_HTYPE_SESSION;
    base->hp.usrhp = svcctx->usrhp;
}
示例#8
0
文件: pathname.c 项目: takuto-h/ruby
static VALUE
get_strpath(VALUE obj)
{
    VALUE strpath;
    strpath = rb_ivar_get(obj, id_at_path);
    if (!RB_TYPE_P(strpath, T_STRING))
        rb_raise(rb_eTypeError, "unexpected @path");
    return strpath;
}
示例#9
0
/*
=begin
--- OCIStmt#prepare(stmt [, language [, mode]])
     set and prepare SQL statement.

     :stmt
        SQL or PL/SQL statement
     :language
        ((|OCI_NTV_SYNTAX|)), ((|OCI_V7_SYNTAX|)), or ((|OCI_V8_SYNTAX|)).
        Default value is ((|OCI_NTV_SYNTAX|))
     :mode
        ((|OCI_DEFAULT|)) or ((|OCI_NO_SHARING|)). Default value is ((|OCI_DEFAULT|)).

        ((|OCI_NO_SHARING|)) disables ((<Shared Data Mode>)) for this statement.

     correspond native OCI function: ((|OCIStmtPrepare|))
=end
 */
static VALUE oci8_stmt_prepare(int argc, VALUE *argv, VALUE self)
{
  VALUE vsql, vlanguage, vmode;
  oci8_handle_t *h;
  oci8_string_t s;
  ub4 language;
  ub4 mode;
  sword rv;
  VALUE ary;
  VALUE hash;
  int i;

  rb_scan_args(argc, argv, "12", &vsql, &vlanguage, &vmode);
  Get_Handle(self, h); /* 0 */
  Get_String(vsql, s); /* 1 */
  Get_Int_With_Default(argc, 2, vlanguage, language, OCI_NTV_SYNTAX); /* 2 */
  Get_Int_With_Default(argc, 3, vmode, mode, OCI_DEFAULT); /* 3 */

  /* when a new statement is prepared, OCI implicitly free the previous 
   * statement's define and bind handles. 
   * But ruby's object don't know it. So free these handles in advance.
   */
  /* free define handles */
  ary = rb_ivar_get(self, oci8_id_define_array);
  if (ary != Qnil) {
    for (i = 0;i < RARRAY_LEN(ary);i++) {
      if (RARRAY_PTR(ary)[i] != Qnil)
	oci8_handle_free(RARRAY_PTR(ary)[i]);
    }
    rb_ivar_set(self, oci8_id_define_array, Qnil);
  }
  /* free bind handles */
  hash = rb_ivar_get(self, oci8_id_bind_hash);
  if (hash != Qnil) {
    rb_iterate(oci8_each_value, hash, oci8_handle_free, Qnil);
    rb_ivar_set(self, oci8_id_bind_hash, Qnil);
  }

  rv = OCIStmtPrepare(h->hp, h->errhp, s.ptr, s.len, language, mode);
  if (IS_OCI_ERROR(rv)) {
    oci8_raise(h->errhp, rv, h->hp);
  }
  return self;
}
示例#10
0
static VALUE
cr_user_font_face_text_to_glyphs_func_after (VALUE user_data)
{
  cr_user_font_face_invoke_data_t *data;
  cr_text_to_glyphs_after_hook_data_t *after_hook_data;
  VALUE text_to_glyphs_data;


  data = (cr_user_font_face_invoke_data_t *)user_data;
  after_hook_data = data->after_hook_data;
  text_to_glyphs_data = after_hook_data->text_to_glyphs_data;

  if (after_hook_data->glyphs)
    {
      VALUE rb_glyphs;

      rb_glyphs = rb_ivar_get (text_to_glyphs_data, cr_id_at_glyphs);
      rb_cairo__glyphs_from_ruby_object (rb_glyphs,
                                         after_hook_data->glyphs,
                                         after_hook_data->num_glyphs);
    }

  if (after_hook_data->clusters)
    {
      VALUE rb_clusters;

      rb_clusters = rb_ivar_get (text_to_glyphs_data, cr_id_at_clusters);
      rb_cairo__text_clusters_from_ruby_object (rb_clusters,
                                                after_hook_data->clusters,
                                                after_hook_data->num_clusters);
    }

  if (after_hook_data->cluster_flags)
    {
      VALUE rb_cluster_flags;

      rb_cluster_flags = rb_ivar_get (text_to_glyphs_data,
                                      cr_id_at_cluster_flags);
      *(after_hook_data->cluster_flags) =
        RVAL2CRTEXTCLUSTERFLAGS (rb_cluster_flags);
    }

  return data->result;
}
示例#11
0
static VALUE
actiongroup_add_actions(VALUE self, VALUE entries)
{
    guint i;
    VALUE action_procs;
    guint n_entries = (guint)RARRAY_LEN(entries);
    GtkActionEntry* gentries = g_new0(GtkActionEntry, n_entries);

    if (rb_ivar_defined(self, id_action_procs) == Qtrue){
        action_procs = rb_ivar_get(self, id_action_procs);
    } else {
        action_procs = rb_hash_new();
    }

    for (i = 0; i < n_entries; i++){
        VALUE entry;
        int size;

	entry = RARRAY_PTR(entries)[i];
	size = RARRAY_LEN(entry);
        if (size < 1)
            rb_raise(rb_eArgError, "wrong array parameter");

        gentries[i].name = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[0]);
        gentries[i].callback = G_CALLBACK(activate_action);

        if (size < 2) continue;

        if (NIL_P(RARRAY_PTR(entry)[1])){
            gentries[i].stock_id = NULL;
        } else if (SYMBOL_P(RARRAY_PTR(entry)[1])){
            gentries[i].stock_id = rb_id2name(SYM2ID(RARRAY_PTR(entry)[1]));
        } else if (TYPE(RARRAY_PTR(entry)[1]) == T_STRING){
            gentries[i].stock_id = RVAL2CSTR(RARRAY_PTR(entry)[1]);
        } else{
            rb_raise(rb_eArgError,
		     "invalid argument %s (expect Symbol or String)",
                     rb_class2name(CLASS_OF(RARRAY_PTR(entry)[1])));
        }

        if (size < 3) continue;
        gentries[i].label = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[2]);
        if (size < 4) continue;
        gentries[i].accelerator = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[3]);
        if (size < 4) continue;
        gentries[i].tooltip = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[4]);
        if (size < 5) continue;
        rb_hash_aset(action_procs, RARRAY_PTR(entry)[0], RARRAY_PTR(entry)[5]);
    }
    rb_ivar_set(self, id_action_procs, action_procs);
    gtk_action_group_add_actions(_SELF(self), gentries, n_entries,
				 (gpointer)self);
    g_free(gentries);

    return self;
}
示例#12
0
GType
rbgobj_gtype_get(VALUE self)
{
    if (RVAL2CBOOL(rb_obj_is_kind_of(self, RG_TARGET_NAMESPACE))) {
        return NUM2ULONG(rb_ivar_get(self, id_gtype));
    } else {
        return CLASS2GTYPE(self);
    }
    rb_raise(rb_eTypeError, "Not a GLib::Type");
}
示例#13
0
VALUE rb_Fonts_define_shadow_color(VALUE self, VALUE id, VALUE color)
{
    if(rb_obj_is_kind_of(color, rb_cColor) != Qtrue)
    {
        rb_raise(rb_eTypeError, "Expected Color got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(color))));
        return self;
    }
    rb_ary_store(rb_ivar_get(rb_mFonts, rb_Fonts_ivSColor), rb_num2long(id), color);
    return self;
}
示例#14
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);
    }
}
示例#15
0
static enum autopush_state state_get(VALUE io)
{
	VALUE val;

	if (rb_ivar_defined(io, id_autopush_state) == Qfalse)
		return AUTOPUSH_STATE_IGNORE;
	val = rb_ivar_get(io, id_autopush_state);

	return (enum autopush_state)NUM2INT(val);
}
示例#16
0
/*
 * Get the index of encoding +val+.
 * :FIXME: Look into replacing this with rb_enc_get_index() since 1.9.1 isn't really
 * used anymore.
 */
int
pg_enc_get_index(VALUE val)
{
	int i = ENCODING_GET_INLINED(val);
	if (i == ENCODING_INLINE_MAX) {
		VALUE iv = rb_ivar_get(val, s_id_index);
		i = NUM2INT(iv);
	}
	return i;
}
示例#17
0
static 
ABSTRACT_ARGLIST* init_expr_arglist(ABSTRACT_CALLER* callback_state)
{
    VALUE self = (VALUE)callback_state;
    VALUE registory = rb_ivar_get(self, rb_intern("@internal_expr_args"));
    VALUE args = rb_ary_new();
    rb_ary_push(args, registory);
    rb_hash_aset(registory, rb_obj_id(args), args);
    return (ABSTRACT_ARGLIST*)args;
}
示例#18
0
static 
PSTRING get_string_from_value(VALUE self, char* key) {
  ID key_id = rb_intern(key);
  VALUE strval = rb_ivar_get(self, key_id);
  PSTRING retval={NULL,NULL};
  if (NIL_P(strval)) return retval;
  retval.begin = StringValuePtr(strval);
  retval.endnext = retval.begin + RSTRING_LEN(strval);
  return retval;
}
示例#19
0
static VALUE
data_type_get(VALUE self, ID type)
{
    VALUE value = rb_ivar_get(self, id_data_type);
    if (NIL_P(value)) {
        value = ID2SYM(type);
        data_type_set(self, value);
    }
    return value;
}
示例#20
0
文件: struct.c 项目: crnt/thrift-1
VALUE get_field_value(VALUE obj, VALUE field_name) {
  char name_buf[RSTRING_LEN(field_name) + 1];
  
  name_buf[0] = '@';
  strlcpy(&name_buf[1], RSTRING_PTR(field_name), sizeof(name_buf));

  VALUE value = rb_ivar_get(obj, rb_intern(name_buf));
  
  return value;
}
示例#21
0
static VALUE rbkit_status_as_hash(VALUE self) {
  VALUE status = rb_hash_new();
  VALUE pid = rb_funcall(rb_path2class("Process"), rb_intern("pid"), 0, 0);
  VALUE processName = rb_funcall(rb_path2class("Process"), rb_intern("argv0"), 0, 0);
  VALUE rbkitModule = rb_define_module("Rbkit");
  int object_trace_enabled = (logger && logger->enabled) ? 1 : 0;
  int cpu_profiling_enabled = (logger && logger->sampling_profiler_enabled) ? 1 : 0;

  rb_hash_aset(status, ID2SYM(rb_intern("rbkit_server_version")), rb_const_get(rbkitModule, rb_intern("VERSION")));
  rb_hash_aset(status, ID2SYM(rb_intern("rbkit_protocol_version")), rbkit_protocol_version());
  rb_hash_aset(status, ID2SYM(rb_intern("process_name")), processName);
  rb_hash_aset(status, ID2SYM(rb_intern("pwd")), rb_dir_getwd());
  rb_hash_aset(status, ID2SYM(rb_intern("pid")), pid);
  rb_hash_aset(status, ID2SYM(rb_intern("object_trace_enabled")), INT2FIX(object_trace_enabled));
  rb_hash_aset(status, ID2SYM(rb_intern("cpu_profiling_enabled")), INT2FIX(cpu_profiling_enabled));
  rb_hash_aset(status, ID2SYM(rb_intern("clock_type")), rb_ivar_get(self, rb_intern("@clock_type")));
  rb_hash_aset(status, ID2SYM(rb_intern("cpu_profiling_mode")), rb_ivar_get(self, rb_intern("@cpu_profiling_mode")));
  return status;
}
示例#22
0
static void
add_event_call_back(VALUE obj, VALUE event, VALUE data)
{
    VALUE events = rb_ivar_get(obj, id_events);
    if (NIL_P(events) || !RB_TYPE_P(events, T_ARRAY)) {
        events = rb_ary_new();
        rb_ivar_set(obj, id_events, events);
    }
    ole_delete_event(events, event);
    rb_ary_push(events, data);
}
示例#23
0
文件: packet.c 项目: WEST3357/COSMOS
/* Sets the received time of the packet
 *
 * @param received_time [Time] Time this packet was received */
static VALUE received_time_equals(VALUE self, VALUE received_time) {
  if (RTEST(received_time)) {
    if (rb_funcall(received_time, id_method_class, 0) != rb_cTime) {
      rb_raise(rb_eArgError, "received_time must be a Time but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(received_time, id_method_class, 0), id_method_to_s, 0)));
    }
    rb_ivar_set(self, id_ivar_received_time, rb_funcall(rb_funcall(received_time, id_method_clone, 0), id_method_freeze, 0));
  } else {
    rb_ivar_set(self, id_ivar_received_time, Qnil);
  }
  return rb_ivar_get(self, id_ivar_received_time);
}
示例#24
0
文件: packet.c 项目: WEST3357/COSMOS
/* Sets the description of the packet
 *
 * @param description [String] Description of the packet */
static VALUE description_equals(VALUE self, VALUE description) {
  if (RTEST(description)) {
    if (rb_funcall(description, id_method_class, 0) != rb_cString) {
      rb_raise(rb_eArgError, "description must be a String but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(description, id_method_class, 0), id_method_to_s, 0)));
    }
    rb_ivar_set(self, id_ivar_description, rb_funcall(rb_funcall(description, id_method_clone, 0), id_method_freeze, 0));
  } else {
    rb_ivar_set(self, id_ivar_description, Qnil);
  }
  return rb_ivar_get(self, id_ivar_description);
}
示例#25
0
文件: packet.c 项目: WEST3357/COSMOS
/* Sets the packet name. Unidentified packets will have packet name set to
 * nil.
 *
 * @param packet_name [String] Name of the packet */
static VALUE packet_name_equals(VALUE self, VALUE packet_name) {
  if (RTEST(packet_name)) {
    if (rb_funcall(packet_name, id_method_class, 0) != rb_cString) {
      rb_raise(rb_eArgError, "packet_name must be a String but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(packet_name, id_method_class, 0), id_method_to_s, 0)));
    }
    rb_ivar_set(self, id_ivar_packet_name, rb_funcall(rb_funcall(rb_funcall(packet_name, id_method_upcase, 0), id_method_clone, 0), id_method_freeze, 0));
  } else {
    rb_ivar_set(self, id_ivar_packet_name, Qnil);
  }
  return rb_ivar_get(self, id_ivar_packet_name);
}
示例#26
0
/*
 *  call-seq:
 *     WIN32OLE_METHOD#event?
 *
 *  Returns true if the method is event.
 *     tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbook')
 *     method = WIN32OLE_METHOD.new(tobj, 'SheetActivate')
 *     puts method.event? # => true
 *
 */
static VALUE
folemethod_event(VALUE self)
{
    struct olemethoddata *pmethod;
    TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod);
    if (!pmethod->pOwnerTypeInfo)
        return Qfalse;
    return ole_method_event(pmethod->pOwnerTypeInfo,
                            pmethod->index,
                            rb_ivar_get(self, rb_intern("name")));
}
示例#27
0
文件: struct.c 项目: 1nueve/MacRuby
static inline VALUE
struct_ivar_get(VALUE c, ID id)
{
    for (;;) {
	if (rb_ivar_defined(c, id))
	    return rb_ivar_get(c, id);
	c = RCLASS_SUPER(c);
	if (c == 0 || c == rb_cStruct)
	    return Qnil;
    }
}
示例#28
0
static void respond_with_message(char *buf, size_t size) {
  VALUE respond_callback;
  if(zmq_response_socket)
    zmq_send(zmq_response_socket, buf, size, 0);
  respond_callback = rb_ivar_get(server_instance, rb_intern("@respond_callback"));
  if (rb_obj_is_proc(respond_callback) == Qtrue) {
    VALUE message = rb_str_new(buf, size);
    VALUE argv[] = { message };
    rb_proc_call_with_block(respond_callback, 1, argv, Qnil);
  }
}
示例#29
0
static void publish_message(char *buf, size_t size) {
  VALUE publish_callback;
  if(zmq_publisher)
    zmq_send(zmq_publisher, buf, size, 0);
  publish_callback = rb_ivar_get(server_instance, rb_intern("@publish_callback"));
  if (rb_obj_is_proc(publish_callback) == Qtrue) {
    VALUE message = rb_str_new(buf, size);
    VALUE argv[] = { message };
    rb_proc_call_with_block(publish_callback, 1, argv, Qnil);
  }
}
示例#30
0
static void
remove_from_windows(GtkWidget *window, VALUE obj)
{
    VALUE klass, windows;

    klass = rb_obj_class(obj);
    windows = rb_ivar_get(klass, id__windows__);
    if (!NIL_P(windows)) {
        rb_hash_delete(windows, obj);
    }
}