/* * call-seq: * Signal.trap( signal, proc ) => obj * Signal.trap( signal ) {| | block } => obj * * Specifies the handling of signals. The first parameter is a signal * name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a * signal number. The characters ``SIG'' may be omitted from the * signal name. The command or block specifies code to be run when the * signal is raised. If the command is the string ``IGNORE'' or * ``SIG_IGN'', the signal will be ignored. If the command is * ``DEFAULT'' or ``SIG_DFL'', the operating system's default handler * will be invoked. If the command is ``EXIT'', the script will be * terminated by the signal. Otherwise, the given command or block * will be run. * The special signal name ``EXIT'' or signal number zero will be * invoked just prior to program termination. * trap returns the previous handler for the given signal. * * Signal.trap(0, proc { puts "Terminating: #{$$}" }) * Signal.trap("CLD") { puts "Child died" } * fork && Process.wait * * produces: * Terminating: 27461 * Child died * Terminating: 27460 */ static VALUE sig_trap(int argc, VALUE *argv) { struct trap_arg arg; rb_secure(2); if (argc == 0 || argc > 2) { rb_raise(rb_eArgError, "wrong number of arguments -- trap(sig, cmd)/trap(sig){...}"); } arg.sig = argv[0]; if (argc == 1) { arg.cmd = rb_block_proc(); } else if (argc == 2) { arg.cmd = argv[1]; } if (OBJ_TAINTED(arg.cmd)) { rb_raise(rb_eSecurityError, "Insecure: tainted signal trap"); } #ifndef _WIN32 /* disable interrupt */ # ifdef HAVE_SIGPROCMASK sigfillset(&arg.mask); sigprocmask(SIG_BLOCK, &arg.mask, &arg.mask); # else arg.mask = sigblock(~0); # endif return rb_ensure(trap, (VALUE)&arg, trap_ensure, (VALUE)&arg); #else return trap(&arg); #endif }
/* * call-seq: * Signal.trap( signal, command ) -> obj * Signal.trap( signal ) {| | block } -> obj * * Specifies the handling of signals. The first parameter is a signal * name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a * signal number. The characters ``SIG'' may be omitted from the * signal name. The command or block specifies code to be run when the * signal is raised. * If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal * will be ignored. * If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler * will be invoked. * If the command is ``EXIT'', the script will be terminated by the signal. * If the command is ``SYSTEM_DEFAULT'', the operating system's default * handler will be invoked. * Otherwise, the given command or block will be run. * The special signal name ``EXIT'' or signal number zero will be * invoked just prior to program termination. * trap returns the previous handler for the given signal. * * Signal.trap(0, proc { puts "Terminating: #{$$}" }) * Signal.trap("CLD") { puts "Child died" } * fork && Process.wait * * produces: * Terminating: 27461 * Child died * Terminating: 27460 */ static VALUE sig_trap(int argc, VALUE *argv) { int sig; sighandler_t func; VALUE cmd; rb_secure(2); rb_check_arity(argc, 1, 2); sig = trap_signm(argv[0]); if (reserved_signal_p(sig)) { const char *name = signo2signm(sig); if (name) rb_raise(rb_eArgError, "can't trap reserved signal: SIG%s", name); else rb_raise(rb_eArgError, "can't trap reserved signal: %d", sig); } if (argc == 1) { cmd = rb_block_proc(); func = sighandler; } else { cmd = argv[1]; func = trap_handler(&cmd, sig); } if (OBJ_TAINTED(cmd)) { rb_raise(rb_eSecurityError, "Insecure: tainted signal trap"); } return trap(sig, func, cmd); }
VALUE _appendNormalItem(int argc,VALUE *argv,VALUE self) { VALUE id,text,help,temp; rb_scan_args(argc, argv, "1*",&id,&temp); if(rb_obj_is_kind_of(id,rb_cString) && rb_block_given_p()){ rb_scan_args(argc, argv, "11",&text,&help); wxMenu *m = new wxMenu; rb_yield(wrap(m)); return wrap(_self->AppendSubMenu(m,wrap<wxString>(text),wrap<wxString>(help))); }else{ rb_scan_args(argc, argv, "12",&id,&text,&help); wxWindowID wid = unwrapID(id); if(!wxIsStockID(wid) && NIL_P(text)) rb_raise(rb_eArgError,"id %d needs an text",wid); wxMenuItem *item = _self->Append(wid,wrap<wxString>(text),wrap<wxString>(help)); if(rb_block_given_p()){ VALUE proc = rb_block_proc(); #ifdef wxHAS_EVENT_BIND _self->Bind(wxEVT_COMMAND_MENU_SELECTED,RubyFunctor(proc),item->GetId()); #else _self->Connect(item->GetId(),wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(RubyFunctor::operator()),NULL,new RubyFunctor(proc)); #endif } return wrap(item); } }
/* * Method: get_assoc_entry(id, method, flags, format, value) { ... } * id: the ID of the index writer. * method: the lookup method to use (see Gst::Index::LookupMethod). * flags: flags for the entry (see Gst::Index::AssocFlags). * format: a Gst::Format object. * value: the value to find. * * Finds the given format/value in the index. If a block is given, it will be * called as a compare function, passing references to 2 Gst::IndexEntry objects, * and waiting for a boolean as the return value. * * Returns: the entry associated with the value (as a Gst::IndexEntry object), or nil * if the value is not found. */ static VALUE rb_gst_index_get_assoc_entry (VALUE self, VALUE id, VALUE method, VALUE flags, VALUE format, VALUE value) { GstIndexEntry *index_entry; if (rb_block_given_p () == Qfalse) index_entry = gst_index_get_assoc_entry (RGST_INDEX (self), FIX2INT (id), RVAL2GENUM (method, GST_TYPE_INDEX_LOOKUP_METHOD), RVAL2GFLAGS (flags, GST_TYPE_ASSOC_FLAGS), *RGST_FORMAT (format), NUM2ULL (value)); else index_entry = gst_index_get_assoc_entry_full (RGST_INDEX (self), FIX2INT (id), RVAL2GENUM (method, GST_TYPE_INDEX_LOOKUP_METHOD), RVAL2GFLAGS (flags, GST_TYPE_ASSOC_FLAGS), *RGST_FORMAT (format), NUM2ULL (value), __compare, (gpointer) rb_block_proc ()); return index_entry != NULL ? RGST_INDEX_ENTRY_NEW (index_entry) : Qnil; }
static VALUE sig_trap(VALUE rcv, SEL sel, int argc, VALUE *argv) { struct trap_arg arg; rb_secure(2); if (argc == 0 || argc > 2) { rb_raise(rb_eArgError, "wrong number of arguments -- trap(sig, cmd)/trap(sig){...}"); } arg.sig = trap_signm(argv[0]); if (argc == 1) { arg.cmd = rb_block_proc(); arg.func = sighandler; } else { arg.cmd = argv[1]; arg.func = trap_handler(&arg.cmd, arg.sig); } if (OBJ_TAINTED(arg.cmd)) { rb_raise(rb_eSecurityError, "Insecure: tainted signal trap"); } return trap(&arg); }
static VALUE rb_gst_index_set_resolver (VALUE self) { gst_index_set_resolver (RGST_INDEX (self), __resolver, (gpointer) rb_block_proc ()); return self; }
/* * call-seq: * Signal.trap( signal, command ) -> obj * Signal.trap( signal ) {| | block } -> obj * * Specifies the handling of signals. The first parameter is a signal * name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a * signal number. The characters ``SIG'' may be omitted from the * signal name. The command or block specifies code to be run when the * signal is raised. * If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal * will be ignored. * If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler * will be invoked. * If the command is ``EXIT'', the script will be terminated by the signal. * If the command is ``SYSTEM_DEFAULT'', the operating system's default * handler will be invoked. * Otherwise, the given command or block will be run. * The special signal name ``EXIT'' or signal number zero will be * invoked just prior to program termination. * trap returns the previous handler for the given signal. * * Signal.trap(0, proc { puts "Terminating: #{$$}" }) * Signal.trap("CLD") { puts "Child died" } * fork && Process.wait * * produces: * Terminating: 27461 * Child died * Terminating: 27460 */ static VALUE sig_trap(int argc, VALUE *argv) { struct trap_arg arg; rb_secure(2); if (argc < 1 || argc > 2) { rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc); } arg.sig = trap_signm(argv[0]); if (argc == 1) { arg.cmd = rb_block_proc(); arg.func = sighandler; } else { arg.cmd = argv[1]; arg.func = trap_handler(&arg.cmd, arg.sig); } if (OBJ_TAINTED(arg.cmd)) { rb_raise(rb_eSecurityError, "Insecure: tainted signal trap"); } #if USE_TRAP_MASK /* disable interrupt */ sigfillset(&arg.mask); pthread_sigmask(SIG_BLOCK, &arg.mask, &arg.mask); return rb_ensure(trap, (VALUE)&arg, trap_ensure, (VALUE)&arg); #else return trap(&arg); #endif }
/* call-seq: define_function(name) { |args,...| } * * Define a function named +name+ with +args+. The arity of the block * will be used as the arity for the function defined. */ static VALUE define_function(VALUE self, VALUE name) { sqlite3RubyPtr ctx; VALUE block; int status; Data_Get_Struct(self, sqlite3Ruby, ctx); REQUIRE_OPEN_DB(ctx); block = rb_block_proc(); status = sqlite3_create_function( ctx->db, StringValuePtr(name), rb_proc_arity(block), SQLITE_UTF8, (void *)block, rb_sqlite3_func, NULL, NULL ); CHECK(ctx->db, status); return self; }
/* * call-seq: * Enumerator.new(size = nil) { |yielder| ... } * Enumerator.new(obj, method = :each, *args) * * Creates a new Enumerator object, which can be used as an * Enumerable. * * In the first form, iteration is defined by the given block, in * which a "yielder" object, given as block parameter, can be used to * yield a value by calling the +yield+ method (aliased as +<<+): * * fib = Enumerator.new do |y| * a = b = 1 * loop do * y << a * a, b = b, a + b * end * end * * p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] * * The optional parameter can be used to specify how to calculate the size * in a lazy fashion (see Enumerator#size). It can either be a value or * a callable object. * * In the second, deprecated, form, a generated Enumerator iterates over the * given object using the given method with the given arguments passed. * * Use of this form is discouraged. Use Kernel#enum_for or Kernel#to_enum * instead. * * e = Enumerator.new(ObjectSpace, :each_object) * #-> ObjectSpace.enum_for(:each_object) * * e.select { |obj| obj.is_a?(Class) } #=> array of all classes * */ static VALUE enumerator_initialize(int argc, VALUE *argv, VALUE obj) { VALUE recv, meth = sym_each; VALUE size = Qnil; if (rb_block_given_p()) { rb_check_arity(argc, 0, 1); recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc()); if (argc) { if (NIL_P(argv[0]) || rb_obj_is_proc(argv[0]) || (RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == INFINITY)) { size = argv[0]; } else { size = rb_to_int(argv[0]); } argc = 0; } } else { rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum"); recv = *argv++; if (--argc) { meth = *argv++; --argc; } } return enumerator_init(obj, recv, meth, argc, argv, 0, size); }
/* :nodoc: */ static VALUE generator_initialize(int argc, VALUE *argv, VALUE obj) { VALUE proc; if (argc == 0) { rb_need_block(); proc = rb_block_proc(); } else { rb_scan_args(argc, argv, "1", &proc); if (!rb_obj_is_proc(proc)) rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc)", rb_obj_classname(proc)); if (rb_block_given_p()) { rb_warn("given block not used"); } } return generator_init(obj, proc); }
/* :nodoc: */ static VALUE yielder_initialize(VALUE obj) { rb_need_block(); return yielder_init(obj, rb_block_proc()); }
static VALUE rbclt_script_connect_signals (int argc, VALUE *argv, VALUE self) { ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self)); AutoConnectData data; data.state = 0; if (rb_block_given_p ()) { data.args = rb_ary_new4 (argc, argv); data.proc = rb_block_proc (); data.obj = Qnil; } else { rb_scan_args (argc, argv, "1*", &data.obj, &data.args); data.proc = Qnil; } clutter_script_connect_signals_full (script, rbclt_script_connect_signal, &data); /* If an exception was thrown then continue throwing that now that we are safely out of the Clutter function call */ if (data.state) rb_jump_tag (data.state); return self; }
static VALUE rb_gsl_multimin_function_new(int argc, VALUE *argv, VALUE klass) { gsl_multimin_function *F = NULL; VALUE ary; size_t i; F = ALLOC(gsl_multimin_function); F->f = &rb_gsl_multimin_function_f; ary = rb_ary_new2(2); /* (VALUE) F->params = ary;*/ F->params = (void *) ary; if (rb_block_given_p()) rb_ary_store(ary, 0, rb_block_proc()); else rb_ary_store(ary, 0, Qnil); rb_ary_store(ary, 1, Qnil); switch (argc) { case 0: break; case 1: set_function(0, argv, F); break; case 2: case 3: for (i = 0; (int) i < argc; i++) set_function(i, argv, F); break; default: rb_raise(rb_eArgError, "wrong number of arguments"); } return Data_Wrap_Struct(klass, gsl_multimin_function_mark, gsl_multimin_function_free, F); }
static VALUE lb_set_uri_hook(VALUE self) { VALUE func = rb_block_proc(); G_RELATIVE(self, func); gtk_link_button_set_uri_hook((GtkLinkButtonUriFunc)link_func, (gpointer)func, (GDestroyNotify)NULL); return self; }
static VALUE rg_add_watch(VALUE self, VALUE condition) { VALUE func = rb_block_proc(); G_RELATIVE(self, func); return UINT2NUM(g_io_add_watch(_SELF(self), NUM2INT(condition), (GIOFunc)io_func, (gpointer)func)); }
static VALUE rg_set_forward_page_func(VALUE self) { VALUE func = rb_block_proc(); G_RELATIVE(self, func); gtk_assistant_set_forward_page_func(_SELF(self), (GtkAssistantPageFunc)ass_page_func, (gpointer)func, NULL); return self; }
static VALUE rb_rsvg_handle_set_size_callback(VALUE self) { rb_ivar_set(self, id_callback, rb_block_proc()); rsvg_handle_set_size_callback(_SELF(self), exec_callback, (gpointer)self, NULL); return self; }
static VALUE rg_initialize(VALUE self) { GClosure* closure = g_rclosure_new(rb_block_proc(), Qnil, NULL); G_INITIALIZE(self, closure); g_closure_sink(closure); return self; }
static VALUE rb_aio_s_error(VALUE aio, VALUE cb) { rb_aiocb_t *cbs = GetCBStruct(cb); if (rb_block_given_p()){ cbs->rcb = rb_block_proc(); } return rb_aio_err( &cbs->cb ); }
int rb_gsl_comparison_complex(const void *aa, const void *bb) { gsl_complex *a = NULL, *b = NULL; a = (gsl_complex *) aa; b = (gsl_complex *) bb; return FIX2INT(rb_funcall(rb_block_proc(), RBGSL_ID_call, 2, Data_Wrap_Struct(cgsl_complex, 0, NULL, a), Data_Wrap_Struct(cgsl_complex, 0, NULL, b))); }
static VALUE pj_send(VALUE self) { VALUE block = rb_block_proc(); G_CHILD_ADD(gPrintJob, block); gtk_print_job_send(_SELF(self), complete_func, (gpointer)block, remove_callback_reference); return self; }
static VALUE gdkevent_s_handler_set(VALUE self) { volatile VALUE func = rb_block_proc(); G_RELATIVE(self, func); gdk_event_handler_set((GdkEventFunc)handler_func, (gpointer)func, NULL); return self; }
static VALUE rg_s_set_window_creation_hook(VALUE self) { VALUE func = rb_block_proc(); G_RELATIVE(self, func); gtk_notebook_set_window_creation_hook((GtkNotebookWindowCreationFunc)creation_func, (gpointer)func, (GDestroyNotify)NULL); return self; }
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self) { VALUE index, flags, mtime; struct zipruby_archive *p_archive; struct zip_source *zsource; struct read_proc *z; int i_index, i_flags = 0; rb_scan_args(argc, argv, "12", &index, &mtime, &flags); rb_need_block(); if (TYPE(index) != T_STRING && !FIXNUM_P(index)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index))); } if (NIL_P(mtime)) { mtime = rb_funcall(rb_cTime, rb_intern("now"), 0); } else if (!rb_obj_is_instance_of(mtime, rb_cTime)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(mtime))); } if (!NIL_P(flags)) { i_flags = NUM2INT(flags); } Data_Get_Struct(self, struct zipruby_archive, p_archive); Check_Archive(p_archive); if (FIXNUM_P(index)) { i_index = NUM2INT(index); } else if ((i_index = zip_name_locate(p_archive->archive, RSTRING_PTR(index), i_flags)) == -1) { rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", RSTRING_PTR(index)); } if ((z = malloc(sizeof(struct read_proc))) == NULL) { zip_unchange_all(p_archive->archive); zip_unchange_archive(p_archive->archive); rb_raise(rb_eRuntimeError, "Replace failed at %d: Cannot allocate memory", i_index); } z->proc = rb_block_proc(); rb_ary_push(p_archive->sources, z->proc); z->mtime = TIME2LONG(mtime); if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) { free(z); rb_raise(Error, "Replace failed at %d: %s", i_index, zip_strerror(p_archive->archive)); } if (zip_replace(p_archive->archive, i_index, zsource) == -1) { zip_source_free(zsource); zip_unchange_all(p_archive->archive); zip_unchange_archive(p_archive->archive); rb_raise(Error, "Replace failed at %d: %s", i_index, zip_strerror(p_archive->archive)); } return Qnil; }
static VALUE rc_set_sort_func(VALUE self) { VALUE func = rb_block_proc(); G_CHILD_ADD(mGtk, func); gtk_recent_chooser_set_sort_func(_SELF(self), (GtkRecentSortFunc)sort_func, (gpointer)func, (GDestroyNotify)remove_callback_reference); return self; }
static VALUE ffil_add_custom(VALUE self, VALUE needed) { VALUE func = rb_block_proc(); G_RELATIVE(self, func); gtk_file_filter_add_custom(_SELF(self), RVAL2GFLAGS(needed, GTK_TYPE_FILE_FILTER_FLAGS), (GtkFileFilterFunc)filter_func, (gpointer)func, NULL); return self; }
static VALUE rbatk_add_key_event_listener(VALUE self) { guint ret; VALUE func = rb_block_proc(); G_RELATIVE(self, func); ret = atk_add_key_event_listener((AtkKeySnoopFunc)key_snoop_func, (gpointer)func); return UINT2NUM(ret); }
static VALUE gdkevent_s_add_client_message_filter(VALUE self, VALUE message_type) { volatile VALUE func = rb_block_proc(); G_RELATIVE(self, func); gdk_add_client_message_filter(RVAL2ATOM(message_type), (GdkFilterFunc)filter_func, (gpointer)func); return self; }
static VALUE rg_each(VALUE self) { volatile VALUE func = rb_block_proc(); gtk_text_tag_table_foreach(_SELF(self), (GtkTextTagTableForeach)txt_tt_foreach_func, (gpointer)func); return self; }
static VALUE rg_m_init_add(VALUE self) { volatile VALUE func = rb_block_proc(); gtk_init_add((GtkFunction)gtk_m_function2, (gpointer)func); G_RELATIVE(self, func); return Qnil; }