示例#1
0
static VALUE
rg_describe(int argc, VALUE *argv, VALUE self)
{
    VALUE desc, absolute_size;
    rb_scan_args(argc, argv, "01", &absolute_size);

    if (NIL_P(absolute_size) || ! RVAL2CBOOL(absolute_size)) {
        desc = PANGOFONTDESCRIPTION2RVAL(pango_font_describe(_SELF(self)));
    } else {
#if PANGO_CHECK_VERSION(1,14,0)
        desc = PANGOFONTDESCRIPTION2RVAL(pango_font_describe_with_absolute_size(_SELF(self)));
#else
        rb_warning("Pango::Font#describe(absolute) has been supported since GTK+-2.10.x. Use Pango::Font#describe() instead.");
        desc = PANGOFONTDESCRIPTION2RVAL(pango_font_describe(_SELF(self)));
#endif
    }
    return desc;
}
/* PopplerCalloutLine */
static VALUE
annot_callout_line_initialize(VALUE self, VALUE multiline, VALUE x1, VALUE y1,
                              VALUE x2, VALUE y2, VALUE x3, VALUE y3)
{
    PopplerAnnotCalloutLine *line;

    line = poppler_annot_callout_line_new();
    line->multiline = RVAL2CBOOL(multiline);
    line->x1 = NUM2DBL(x1);
    line->y1 = NUM2DBL(y1);
    line->x2 = NUM2DBL(x2);
    line->y2 = NUM2DBL(y2);
    line->x3 = NUM2DBL(x3);
    line->y3 = NUM2DBL(y3);

    G_INITIALIZE(self, line);
    return Qnil;
}
示例#3
0
static VALUE
gdkregion_spans_intersect_foreach(VALUE self, VALUE spans, VALUE sorted)
{
    int i;
    GdkSpan* gspans = ALLOCA_N(GdkSpan, RARRAY_LEN(spans));
    volatile VALUE func = rb_block_proc();

    G_RELATIVE(self, func);
    for (i = 0; i < RARRAY_LEN(spans); i++) {
        gspans[i].x = NUM2INT(RARRAY_PTR(RARRAY_PTR(spans)[i])[0]);
        gspans[i].y = NUM2INT(RARRAY_PTR(RARRAY_PTR(spans)[i])[1]);
        gspans[i].width = NUM2INT(RARRAY_PTR(RARRAY_PTR(spans)[i])[2]);
    }
    gdk_region_spans_intersect_foreach(_SELF(self),
                                       gspans, RARRAY_LEN(spans), RVAL2CBOOL(sorted),
                                       (GdkSpanFunc)gdkregion_span_func, (gpointer)func);
    return self;
}
示例#4
0
gpointer
rbgobj_boxed_get(VALUE obj, GType gtype)
{
    boxed_holder* holder;

    if (NIL_P(obj))
        return NULL;

    if (!RVAL2CBOOL(rb_obj_is_kind_of(obj, GTYPE2CLASS(gtype))))
        rb_raise(rb_eArgError, "invalid argument %s (expect %s)",
                 rb_class2name(CLASS_OF(obj)), 
                 rb_class2name(GTYPE2CLASS(gtype)));

    Data_Get_Struct(obj, boxed_holder, holder);
    if (!holder->boxed)
        rb_raise(rb_eArgError, "uninitialize %s", rb_class2name(CLASS_OF(obj)));

    return holder->boxed;
}
示例#5
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE options, entry;
    GtkWidget *widget = NULL;

    rb_scan_args(argc, argv, "01", &options);
    rbg_scan_options(options,
                     "entry", &entry,
                     NULL);

    if (RVAL2CBOOL(entry))
        widget = gtk_combo_box_text_new_with_entry();
    else
        widget = gtk_combo_box_text_new();
    RBGTK_INITIALIZE(self, widget);

    return Qnil;
}
示例#6
0
static VALUE
rg_operator_type_compare(VALUE self, VALUE other)
{
    if (!RVAL2CBOOL(rb_obj_is_kind_of(other, RG_TARGET_NAMESPACE)))
        return Qnil;
    else {
        GType a = rbgobj_gtype_get(self);
        GType b = rbgobj_gtype_get(other);

        if (a==b)
            return INT2FIX(0);
        else if (g_type_is_a(a,b))
            return INT2FIX(-1);
        else if (g_type_is_a(b,a))
            return INT2FIX(1);
        else
            return Qnil;
    }
}
示例#7
0
static VALUE
rbg_rval2gtktoggleactionentries_body(VALUE value)
{
    long i;
    struct rbg_rval2gtktoggleactionentries_args *args = (struct rbg_rval2gtktoggleactionentries_args *)value;

    for (i = 0; i < args->n; i++) {
        VALUE entry;
        long n;

        RARRAY_PTR(args->ary)[i] = rb_ary_dup(rb_ary_to_ary(RARRAY_PTR(args->ary)[i]));
        entry = RARRAY_PTR(args->ary)[i];
        n = RARRAY_LEN(entry);

        args->result[i].callback = G_CALLBACK(activate_toggle_action);

        if (n < 1 || n > 7)
            rb_raise(rb_eArgError, "entry does not contain right number of entries %ld (1..7)", n);

        args->result[i].name = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[0]);

        switch (n) {
        case 7:
            args->result[i].is_active = RVAL2CBOOL(RARRAY_PTR(entry)[6]);
        case 6:
            /* TODO: Call #to_proc on entry 5? */
            rb_hash_aset(args->procs, RARRAY_PTR(entry)[0], RARRAY_PTR(entry)[5]);
        case 5:
            args->result[i].tooltip = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[4]);
        case 4:
            args->result[i].accelerator = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[3]);
        case 3:
            args->result[i].label = RVAL2CSTR_ACCEPT_NIL(RARRAY_PTR(entry)[2]);
        case 2:
            args->result[i].stock_id = RVAL2CSTR_ACCEPT_SYMBOL_ACCEPT_NIL(RARRAY_PTR(entry)[1]);
            break;
        default:
            break;
        }
    }

    return Qnil;
}
示例#8
0
static VALUE
rg_guess_content_type(int argc, VALUE *argv, VALUE self)
{
        VALUE rbforce_rescan, rbcancellable, block;
        gboolean force_rescan;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "02&", &rbforce_rescan, &rbcancellable, &block);
        force_rescan = RVAL2CBOOL(rbforce_rescan);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_mount_guess_content_type(_SELF(self),
                                   force_rescan,
                                   cancellable,
                                   rbgio_async_ready_callback,
                                   (gpointer)block);

        return self;
}
示例#9
0
static VALUE
rg_close(gint argc, VALUE *argv, VALUE self)
{
    VALUE flush;
    GError* err = NULL;
    gboolean gflush = TRUE;
    GIOStatus status;

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

    if (!NIL_P(flush)){
        gflush = RVAL2CBOOL(flush);
    }

    status = g_io_channel_shutdown(_SELF(self), gflush, &err);
    ioc_error(status, err);

    return self;
}
示例#10
0
static VALUE
type_compare(VALUE self, VALUE other)
{
    if (!RVAL2CBOOL(rb_obj_is_kind_of(other, rbgobj_cType)))
        return Qnil;
    else {
        GType a = rbgobj_gtype_get(self);
        GType b = rbgobj_gtype_get(other);

        if (a==b)
            return INT2FIX(0);
        else if (g_type_is_a(a,b))
            return INT2FIX(-1);
        else if (g_type_is_a(b,a))
            return INT2FIX(1);
        else
            return Qnil;
    }
}
示例#11
0
grn_obj *
rb_grn_uvector_from_ruby_object (VALUE object, grn_ctx *context,
				 grn_obj *uvector, VALUE related_object)
{
    VALUE *values;
    int i, n;

    if (NIL_P(object))
	return NULL;

    n = RARRAY_LEN(object);
    values = RARRAY_PTR(object);
    for (i = 0; i < n; i++) {
	VALUE value;
	grn_id id;
	void *grn_value;

	value = values[i];
	switch (TYPE(value)) {
	  case T_FIXNUM:
	    id = NUM2UINT(value);
	    break;
	  default:
	    if (RVAL2CBOOL(rb_obj_is_kind_of(value, rb_cGrnRecord))) {
		id = NUM2UINT(rb_funcall(value, rb_intern("id"), 0));
	    } else {
		grn_obj_unlink(context, uvector);
		rb_raise(rb_eArgError,
			 "uvector value should be one of "
			 "[Fixnum, Groonga::Record]: %s (%s): %s",
			 rb_grn_inspect(value),
			 rb_grn_inspect(object),
			 rb_grn_inspect(related_object));
	    }
	    break;
	}
	grn_value = &id;
	grn_bulk_write(context, uvector, grn_value, sizeof(grn_id));
    }

    return uvector;
}
示例#12
0
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);
}
static VALUE
encode_replace_body (VALUE self, VALUE chunk)
{
    const gchar *packet;
    gsize packet_size, packed_size;

    if (!RVAL2CBOOL(rb_obj_is_kind_of(chunk, rb_cString)))
	rb_raise(rb_eArgError,
		 "chunk should be a String: %s",
		 RBG_INSPECT(chunk));
    milter_reply_encoder_encode_replace_body(SELF(self),
					     &packet, &packet_size,
					     RSTRING_PTR(chunk),
					     RSTRING_LEN(chunk),
					     &packed_size);

    return rb_ary_new3(2,
		       CSTR2RVAL_SIZE(packet, packet_size),
		       UINT2NUM(packed_size));
}
示例#14
0
static VALUE
rg_set_font_description(VALUE self, VALUE rb_desc)
{
    PangoFontDescription *desc;
    gboolean desc_created = FALSE;

    if (RVAL2CBOOL(rb_obj_is_kind_of(rb_desc, rb_cString))) {
        desc = pango_font_description_from_string(RVAL2CSTR(rb_desc));
        desc_created = TRUE;
    } else {
        desc = RVAL2BOXED(rb_desc, PANGO_TYPE_FONT_DESCRIPTION);
    }

    pango_layout_set_font_description(_SELF(self), desc);

    if (desc_created)
        pango_font_description_free(desc);

    return self;
}
/*
 * @overload delete(id, :id=>true)
 *   Delete a record that has ID @id@.
 *
 *   @param id [Integer] The ID of delete target record.
 *
 *   @return void
 *
 * @overload delete(key)
 *   Delete a record that has key @key@.
 *
 *   @param key [Object] The key of delete target record.
 *
 *   @return void
 *
 * @overload delete
 *   @yield [record]
 *     TODO: See #select.
 *   @yieldparam [Groonga::RecodExpressionBuilder] record
 *     TODO: See #select.
 *   @yieldreturn [Groonga::ExpressionBuilder]
 *     TODO: See #select.
 *
 *   @return void
 */
static VALUE
rb_grn_table_key_support_delete (int argc, VALUE *argv, VALUE self)
{
    VALUE rb_id_or_key, rb_options;
    VALUE rb_option_id;

    if (rb_block_given_p()) {
        return rb_grn_table_delete_by_expression(self);
    }

    rb_scan_args(argc, argv, "11", &rb_id_or_key, &rb_options);
    rb_grn_scan_options(rb_options,
                        "id", &rb_option_id,
                        NULL);
    if (RVAL2CBOOL(rb_option_id)) {
        return rb_grn_table_delete_by_id(self, rb_id_or_key);
    } else {
        return rb_grn_table_key_support_delete_by_key(self, rb_id_or_key);
    }
}
示例#16
0
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;
}
示例#17
0
/*
 * Tokenize a string using the table as lexicon.
 *
 * @overload tokenize(string, options={})
 *   @param [String] string The string to be tokenized.
 *   @param [::Hash] options
 *   @option options [Bool] :add (true) Adds a new token to the table if true.
 *      Returned tokens include the new token. Otherwise, a new token is
 *      just ignored.
 *   @return [::Array<Groonga::Record>] Tokenized tokens.
 */
static VALUE
rb_grn_table_key_support_tokenize (int argc, VALUE *argv, VALUE self)
{
    VALUE rb_string, rb_add_p;
    VALUE rb_options;
    VALUE rb_tokens = Qnil;
    grn_ctx *context;
    grn_obj *table;
    char *string;
    int string_size;
    grn_bool add_p;
    grn_obj tokens;

    rb_scan_args(argc, argv, "11", &rb_string, &rb_options);
    rb_grn_scan_options(rb_options,
                        "add", &rb_add_p,
                        NULL);
    if (NIL_P(rb_add_p)) {
        rb_add_p = Qtrue;
    }

    rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
                                         NULL, NULL, NULL,
                                         NULL, NULL, NULL,
                                         NULL);

    string = StringValueCStr(rb_string);
    string_size = RSTRING_LEN(rb_string);

    add_p = RVAL2CBOOL(rb_add_p);

    GRN_RECORD_INIT(&tokens, GRN_OBJ_VECTOR, grn_obj_id(context, table));
    grn_table_tokenize(context, table, string, string_size, &tokens, add_p);
    if (context->rc == GRN_SUCCESS) {
        rb_tokens = GRNUVECTOR2RVAL(context, &tokens, table, self);
    }
    grn_obj_unlink(context, &tokens);
    rb_grn_context_check(context, self);

    return rb_tokens;
}
示例#18
0
static VALUE
cr_fill (int argc, VALUE *argv, VALUE self)
{
  VALUE preserve;

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

  if (rb_block_given_p ())
    {
      cr_new_path (self);
      rb_yield (self);
    }

  if (RVAL2CBOOL (preserve))
    cairo_fill_preserve (_SELF);
  else
    cairo_fill (_SELF);

  cr_check_status (_SELF);
  return self;
}
示例#19
0
void
rb_grn_scan_options (VALUE options, ...)
{
    VALUE original_options = options;
    VALUE available_keys;
    const char *key;
    VALUE *value;
    va_list args;

    options = rb_check_convert_type(options, T_HASH, "Hash", "to_hash");
    if (NIL_P(options)) {
        options = rb_hash_new();
    } else if (options == original_options) {
        options = rb_funcall(options, rb_intern("dup"), 0);
    }

    available_keys = rb_ary_new();
    va_start(args, options);
    key = va_arg(args, const char *);
    while (key) {
        VALUE rb_key;
        value = va_arg(args, VALUE *);

        rb_key = RB_GRN_INTERN(key);
        rb_ary_push(available_keys, rb_key);
        *value = rb_funcall(options, rb_intern("delete"), 1, rb_key);

        key = va_arg(args, const char *);
    }
    va_end(args);

    if (RVAL2CBOOL(rb_funcall(options, rb_intern("empty?"), 0)))
        return;

    rb_raise(rb_eArgError,
             "unexpected key(s) exist: %s: available keys: %s",
             rb_grn_inspect(rb_funcall(options, rb_intern("keys"), 0)),
             rb_grn_inspect(available_keys));
}
示例#20
0
static GtkWidget*
create_button(VALUE group, VALUE label, VALUE use_underline)
{
    GtkWidget* widget = NULL;

    if (TYPE(label) == T_STRING){
        if (NIL_P(use_underline) || RVAL2CBOOL(use_underline)){
            widget = gtk_radio_button_new_with_mnemonic_from_widget(_GROUP(group), RVAL2CSTR(label));
        } else {
            widget = gtk_radio_button_new_with_label_from_widget(_GROUP(group), RVAL2CSTR(label));
        }
    } else if (TYPE(label) == T_SYMBOL){
        widget = gtk_radio_button_new_with_label_from_widget(_GROUP(group), rb_id2name(SYM2ID(label)));
        gtk_button_set_use_stock(GTK_BUTTON(widget), TRUE);
    } else if (NIL_P(label)){
        widget = gtk_radio_button_new_from_widget(_GROUP(group));
    } else {
        rb_raise(rb_eArgError, "invalid argument %s (expect Symbol(Gtk::Stock constants) or String)", 
                         rb_class2name(CLASS_OF(label)));
    }
    return widget;
}
示例#21
0
/*
 * Pulls a record from the array. The required values should be
 * retrieved in the given block.
 *
 * If {Groonga::Array#push} failes to fill values of the pushed
 * record, the pulled record may be uncompleted. It should be handled
 * by your application.
 *
 * If you passes @:block? => true@ option, the pull operation blocks
 * until a pushed record is pushed. It is the default behavior.
 *
 * If you passes @:block? => false@ option, the pull operation returns
 * immediately, the given block isn't called and returns nil when no
 * record exist in the array.
 *
 * @example A program that pulls with non-block mode
 *   queue = Groonga::Array.open(:name => "CrawlURLQueue")
 *   loop do
 *     url = nil
 *     # The case for no pushed records in the array.
 *     pulled_record = queue.pull(:block? => false) do |record|
 *       # This block isn't called
 *       url = record.url
 *       record.delete
 *     end
 *     p pulled_record.nil? # => true
 *   end
 *
 * Note that your signal handlers can't be ran while a pull
 * operation. You need to use {Groonga::Array#unblock} from
 * another process to unblock the pull operation. If you call
 * {Groonga::Array#unblock}, signal handler can be ran.
 *
 * @example Signal handler isn't called
 *   queue = Groonga::Array.open(:name => "CrawlURLQueue")
 *   trap(:INT) do
 *     p :not_called!
 *   end
 *   queue.pull do |record|
 *     # Send SIGINT while blocking the pull operation.
 *     # The signal handler isn't called.
 *   end
 *
 * @see Groonga::Array#push Examples exist in the push documentation.
 *
 * @overload pull(options={})
 *   @param [::Hash] options The option parameters.
 *   @option options [Boolean] :block? (true)
 *     Whether the pull operation is blocked or not when no record exist
 *     in the array.
 *   @yield [record] Gets required values for a pull record in the given block.
 *   @yieldparam record [Groonga::Record or nil]
 *     A pulled record. It is nil when no records exist in the array
 *     and @block?@ parameter is not @true@.
 *   @return [Groonga::Record or nil] A pulled record that is yielded.
 *
 */
static VALUE
rb_grn_array_pull (int argc, VALUE *argv, VALUE self)
{
    grn_ctx *context = NULL;
    grn_obj *table;
    VALUE options;
    VALUE rb_block_p;
    YieldRecordCallbackData data;

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

    rb_grn_scan_options(options,
                        "block?", &rb_block_p,
                        NULL);

    if (!rb_block_given_p()) {
        rb_raise(rb_eArgError,
                 "tried to call Groonga::Array#pull without a block");
    }

    table = SELF(self, &context);

    if (NIL_P(rb_block_p)) {
        rb_block_p = Qtrue;
    }

    data.self = self;
    data.record = Qnil;
    data.status = 0;
    grn_array_pull(context, (grn_array *)table, RVAL2CBOOL(rb_block_p),
                   yield_record_callback, &data);
    if (data.status != 0) {
        rb_jump_tag(data.status);
    }
    rb_grn_context_check(context, self);

    return data.record;
}
示例#22
0
static VALUE
client_set_default_unix_socket_mode (VALUE self, VALUE rb_mode)
{
    guint mode;

    if (NIL_P(rb_mode)) {
        mode = 0;
    } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_mode, rb_cString))) {
        gchar *error_message = NULL;
        if (!milter_utils_parse_file_mode(RVAL2CSTR(rb_mode),
                                          &mode, &error_message)) {
            VALUE rb_error_message;
            rb_error_message = CSTR2RVAL(error_message);
            g_free(error_message);
            rb_raise(rb_eArgError, "%s", RSTRING_PTR(rb_error_message));
        }
    } else {
        mode = NUM2UINT(rb_mode);
    }

    milter_client_set_default_unix_socket_mode(SELF(self), mode);
    return self;
}
示例#23
0
void
rbgobj_add_relative(VALUE obj, VALUE relative)
{
    static VALUE mGLibObject = Qnil;
    if (NIL_P(mGLibObject)) {
        mGLibObject = rb_const_get(mGLib, rb_intern("Object"));
    }

    if (rb_obj_is_kind_of(obj, mGLibObject)) {
        rbgobj_object_add_relative(obj, relative);
    } else {
        VALUE rb_gc_marker = Qnil;

        if (RVAL2CBOOL(rb_ivar_defined(obj, id_relatives)))
            rb_gc_marker = rb_ivar_get(obj, id_relatives);

        if (NIL_P(rb_gc_marker)) {
            rb_gc_marker = rbg_gc_marker_new();
            rb_ivar_set(obj, id_relatives, rb_gc_marker);
        }
        rbg_gc_marker_guard(rb_gc_marker, relative);
    }
}
/*
 * Renames key of a record.
 *
 * @overload update(current_key, new_key)
 * @overload update(id, new_key, :id=>true)
 *
 * @since 4.0.5
 */
static VALUE
rb_grn_double_array_trie_update (int argc, VALUE *argv, VALUE self)
{
    VALUE rb_current_key_or_id, rb_new_key, rb_options;
    VALUE rb_option_id;

    rb_scan_args(argc, argv, "21",
                 &rb_current_key_or_id, &rb_new_key, &rb_options);
    rb_grn_scan_options(rb_options,
                        "id", &rb_option_id,
                        NULL);
    if (RVAL2CBOOL(rb_option_id)) {
        VALUE rb_id;
        rb_id = rb_current_key_or_id;
        return rb_grn_double_array_trie_update_by_id(self, rb_id, rb_new_key);
    } else {
        VALUE rb_current_key;
        rb_current_key = rb_current_key_or_id;
        return rb_grn_double_array_trie_update_by_key(self,
                                                      rb_current_key,
                                                      rb_new_key);
    }
}
示例#25
0
static VALUE
rg_spans_intersect_each(VALUE self, VALUE rbspans, VALUE rbsorted)
{
    GdkRegion *region = _SELF(self);
    gboolean sorted = RVAL2CBOOL(rbsorted);
    VALUE func = rb_block_proc();
    long n;
    GdkSpan *spans;

    G_RELATIVE(self, func);

    spans = RVAL2GDKSPANS(rbspans, &n);

    gdk_region_spans_intersect_foreach(region,
                                       spans,
                                       n,
                                       sorted,
                                       (GdkSpanFunc)gdkregion_span_func,
                                       (gpointer)func);

    g_free(spans);

    return self;
}
示例#26
0
/*
 * call-seq:
 *   expression.define_variable(options={}) -> Groonga::Variable
 *
 * _expression_で使用可能な変数を作成する。
 *
 * _options_に指定可能な値は以下の通り。
 *
 * [+:name+]
 *   変数の名前。省略した場合は名前を付けない。
 *
 * [+:domain+]
 *   テーブルを指定すると、そのテーブル用のレコードとして初期化する。
 */
static VALUE
rb_grn_expression_define_variable (int argc, VALUE *argv, VALUE self)
{
    grn_ctx *context = NULL;
    grn_obj *expression, *variable;
    char *name = NULL;
    unsigned name_size = 0;
    VALUE options, rb_name, rb_domain, rb_variable;

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

    rb_grn_expression_deconstruct(SELF(self), &expression, &context,
                                  NULL, NULL,
                                  NULL, NULL, NULL);

    rb_grn_scan_options(options,
			"name", &rb_name,
			"domain", &rb_domain,
			NULL);

    if (!NIL_P(rb_name)) {
	name = StringValuePtr(rb_name);
	name_size = RSTRING_LEN(rb_name);
    }

    variable = grn_expr_add_var(context, expression, name, name_size);
    rb_variable = GRNVARIABLE2RVAL(context, variable);

    if (RVAL2CBOOL(rb_obj_is_kind_of(rb_domain, rb_cGrnTable))) {
	grn_id domain_id;
	domain_id = NUM2UINT(rb_funcall(rb_domain, rb_intern("id"), 0));
	GRN_RECORD_INIT(variable, 0, domain_id);
    }

    return rb_variable;
}
示例#27
0
void
rbgobj_add_relative_removable(VALUE obj, VALUE relative, ID obj_ivar_id, VALUE hash_key)
{
    static VALUE cGLibObject = Qnil;
    if (NIL_P(cGLibObject)) {
        cGLibObject = rb_const_get(mGLib, rb_intern("Object"));
    }

    if (obj_ivar_id == rbgobj_id_children &&
        rb_obj_is_kind_of(obj, cGLibObject)) {
        rbgobj_object_add_relative(obj, hash_key);
    } else {
        VALUE hash = Qnil;

        if (RVAL2CBOOL(rb_ivar_defined(obj, obj_ivar_id)))
            hash = rb_ivar_get(obj, obj_ivar_id);

        if (NIL_P(hash) || TYPE(hash) != RUBY_T_HASH) {
            hash = rb_hash_new();
            rb_ivar_set(obj, obj_ivar_id, hash);
        }
        rb_hash_aset(hash, hash_key, relative);
    }
}
示例#28
0
static VALUE
mitem_initialize(int argc, VALUE *argv, VALUE self)
{
    const gchar *label = NULL;
    VALUE rb_label, use_underline;
    GtkWidget *widget = NULL;

    rb_scan_args(argc, argv, "02", &rb_label, &use_underline);

    if (!NIL_P(rb_label))
        label = RVAL2CSTR(rb_label);
    if (label) {
        if (NIL_P(use_underline) || RVAL2CBOOL(use_underline)) {
            widget = gtk_menu_item_new_with_mnemonic(label);
        } else {
            widget = gtk_menu_item_new_with_label(label);
        }
    } else {
        widget = gtk_menu_item_new();
    }

    RBGTK_INITIALIZE(self, widget);
    return Qnil;
}
示例#29
0
VALUE
rb_gi_function_info_invoke_raw(GIFunctionInfo *info,
                               VALUE rb_info,
                               VALUE rb_receiver,
                               VALUE rb_arguments,
                               GIArgument *return_value,
                               VALUE *rb_return_value)
{
    GICallableInfo *callable_info;
    GIArgument receiver;
    GArray *in_args, *out_args;
    GPtrArray *args_metadata;
    VALUE rb_out_args = Qnil;
    gboolean succeeded;
    GError *error = NULL;
    gboolean unlock_gvl = FALSE;
    gboolean rb_receiver_is_class = FALSE;

    unlock_gvl = RVAL2CBOOL(rb_funcall(rb_info, rb_intern("unlock_gvl?"), 0));
    if (NIL_P(rb_receiver)) {
        receiver.v_pointer = NULL;
    } else {
        if (gobject_based_p((GIBaseInfo *)info)) {
            receiver.v_pointer = RVAL2GOBJ(rb_receiver);
        } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_receiver, rb_cClass)) &&
                   rb_respond_to(rb_receiver, rb_intern("gtype"))) {
            GObjectClass *object_class;
            rb_receiver_is_class = TRUE;
            object_class = g_type_class_ref(CLASS2GTYPE(rb_receiver));
            receiver.v_pointer = object_class;
        } else {
            receiver.v_pointer = DATA_PTR(rb_receiver);
        }
    }
    rb_arguments = rbg_to_array(rb_arguments);

    callable_info = (GICallableInfo *)info;
    arguments_init(&in_args, &out_args, &args_metadata);
    if (receiver.v_pointer) {
        g_array_append_val(in_args, receiver);
    }
    arguments_from_ruby(callable_info, rb_receiver, rb_arguments,
                        in_args, out_args, args_metadata);
    {
        InvokeData data;
        data.info = info;
        data.in_args = in_args;
        data.out_args = out_args;
        data.error = &error;
        if (unlock_gvl) {
            rb_thread_call_without_gvl(
                rb_gi_function_info_invoke_raw_call_without_gvl_body, &data,
                NULL, NULL);
        } else {
            rb_gi_function_info_invoke_raw_call(&data);
        }
        succeeded = data.succeeded;

        if (rb_receiver_is_class) {
            g_type_class_unref(receiver.v_pointer);
        }

        if (return_value) {
            *return_value = data.return_value;
        }
        if (rb_return_value) {
            if (succeeded) {
                *rb_return_value = GI_RETURN_ARGUMENT2RVAL(callable_info,
                                                           &(data.return_value),
                                                           in_args,
                                                           out_args,
                                                           args_metadata);
            } else {
                *rb_return_value = Qnil;
            }
        }
    }

    if (succeeded) {
        rb_out_args = out_arguments_to_ruby(callable_info,
                                            in_args, out_args,
                                            args_metadata);
    }
    arguments_free(rb_arguments, in_args, out_args, args_metadata);
    if (!succeeded) {
        RG_RAISE_ERROR(error);
    }

    if (!NIL_P(rb_out_args) && RARRAY_LEN(rb_out_args) == 1) {
        VALUE rb_out_arg;
        rb_out_arg = RARRAY_PTR(rb_out_args)[0];
        if (rb_obj_is_kind_of(rb_out_arg, rb_eException)) {
            rb_exc_raise(rb_out_arg);
        }
    }

    return rb_out_args;
}
示例#30
0
static VALUE
rg_set_page_complete(VALUE self, VALUE page, VALUE complete)
{
    gtk_assistant_set_page_complete(_SELF(self), GTK_WIDGET(RVAL2GOBJ(page)), RVAL2CBOOL(complete));
    return self;
}