Exemple #1
0
void
rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
{
    VALUE exc = rb_syserr_new_str(e, mesg);
    rb_extend_object(exc, mod);
    rb_exc_raise(exc);
}
Exemple #2
0
VALUE
rb_eval_string_wrap(const char *str, int *state)
{
    int status;
    rb_thread_t *th = GET_THREAD();
    VALUE self = th->top_self;
    VALUE wrapper = th->top_wrapper;
    VALUE val;

    th->top_wrapper = rb_module_new();
    th->top_self = rb_obj_clone(rb_vm_top_self());
    rb_extend_object(th->top_self, th->top_wrapper);

    val = rb_eval_string_protect(str, &status);

    th->top_self = self;
    th->top_wrapper = wrapper;

    if (state) {
	*state = status;
    }
    else if (status) {
	JUMP_TAG(status);
    }
    return val;
}
void
rb_mod_sys_fail(VALUE mod, const char *mesg)
{
    VALUE exc = make_errno_exc(mesg);
    rb_extend_object(exc, mod);
    rb_exc_raise(exc);
}
void
rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
{
    VALUE exc = make_errno_exc_str(mesg);
    rb_extend_object(exc, mod);
    rb_exc_raise(exc);
}
void
rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
{
    VALUE exc = rb_syserr_new(e, mesg);
    rb_extend_object(exc, mod);
    rb_exc_raise(exc);
}
Exemple #6
0
void
rb_extend_object(VALUE obj, VALUE module)
{
    VALUE klass;
    if (TYPE(obj) == T_CLASS && RCLASS_RUBY(obj)) {
	VALUE sklass = rb_make_singleton_class(RCLASS_SUPER(obj));
	RCLASS_SET_SUPER(obj, sklass);
	klass = *(VALUE *)sklass;
    }
    else {
	klass = rb_singleton_class(obj);
    }

    rb_include_module(klass, module);

    VALUE m = module;
    do {
	VALUE ary = rb_attr_get(m, idIncludedModules);
	if (ary != Qnil) {
	    for (int i = 0, count = RARRAY_LEN(ary); i < count; i++) {
		VALUE mod = RARRAY_AT(ary, i);
		rb_extend_object(obj, mod);
	    }
	}
	m = RCLASS_SUPER(m);
    }
    while (m == 0 || RCLASS_SINGLETON(m));
}
Exemple #7
0
static void
read_would_block(int nonblock)
{
    if (nonblock) {
        VALUE exc = ossl_exc_new(eSSLError, "read would block");
        rb_extend_object(exc, rb_mWaitReadable);
        rb_exc_raise(exc);
    }
}
Exemple #8
0
void
Init_native_sumbur()
{
    VALUE mod_sumbur = rb_define_module("Sumbur");
    VALUE mod_native = rb_define_module_under(mod_sumbur, "NativeSumbur");

    rb_define_method(mod_native, "sumbur", rb_sumbur, 2);
    rb_extend_object(mod_native, mod_native);
}
Exemple #9
0
VALUE
auto_extend(VALUE object)
{
  CvSeq *seq = CVSEQ(object);
  if(CV_IS_SEQ_POINT_SET(seq)){
    rb_extend_object(object, mPointSet::rb_module());
  }
  return object;
}
Exemple #10
0
static void
write_would_block(int nonblock)
{
    if (nonblock) {
        VALUE exc = ossl_exc_new(eSSLError, "write would block");
        rb_extend_object(exc, rb_mWaitWritable);
        rb_exc_raise(exc);
    }
}
Exemple #11
0
/*
 * :nodoc:
 */
static VALUE rbpod_collection_included(VALUE self, VALUE other)
{
    /* Collections should be Enumerable and Comparable. */
    rb_include_module(other, rb_mEnumerable);
    rb_include_module(other, rb_mComparable);

    /* Override Enumerable with our methods. */
    rb_extend_object(other, self);

    return self;
}
void
Init_gobject_typeinstance(void)
{
    /* should be renamed to GLib::Instance? */
    cInstantiatable = rb_define_class_under(mGLib, "Instantiatable", rb_cObject);
    rb_extend_object(cInstantiatable, mMetaInterface);

    rb_define_alloc_func(cInstantiatable, (VALUE(*)_((VALUE)))instantiatable_s_allocate);
    rb_define_method(cInstantiatable, "gtype", instantiatable_get_gtype, 0);
    rb_define_method(cInstantiatable, "clone", instantiatable_clone, 0);
}
Exemple #13
0
VALUE build_class_from_descriptor(Descriptor* desc) {
  const char *name;
  VALUE klass;

  if (desc->layout == NULL) {
    desc->layout = create_layout(desc->msgdef);
  }
  if (desc->fill_method == NULL) {
    desc->fill_method = new_fillmsg_decodermethod(desc, &desc->fill_method);
  }

  name = upb_msgdef_fullname(desc->msgdef);
  if (name == NULL) {
    rb_raise(rb_eRuntimeError, "Descriptor does not have assigned name.");
  }

  klass = rb_define_class_id(
      // Docs say this parameter is ignored. User will assign return value to
      // their own toplevel constant class name.
      rb_intern("Message"),
      rb_cObject);
  rb_ivar_set(klass, descriptor_instancevar_interned,
              get_def_obj(desc->msgdef));
  rb_define_alloc_func(klass, Message_alloc);
  rb_require("google/protobuf/message_exts");
  rb_include_module(klass, rb_eval_string("::Google::Protobuf::MessageExts"));
  rb_extend_object(
      klass, rb_eval_string("::Google::Protobuf::MessageExts::ClassMethods"));

  rb_define_method(klass, "method_missing",
                   Message_method_missing, -1);
  rb_define_method(klass, "respond_to_missing?",
                   Message_respond_to_missing, -1);
  rb_define_method(klass, "initialize", Message_initialize, -1);
  rb_define_method(klass, "dup", Message_dup, 0);
  // Also define #clone so that we don't inherit Object#clone.
  rb_define_method(klass, "clone", Message_dup, 0);
  rb_define_method(klass, "==", Message_eq, 1);
  rb_define_method(klass, "hash", Message_hash, 0);
  rb_define_method(klass, "to_h", Message_to_h, 0);
  rb_define_method(klass, "to_hash", Message_to_h, 0);
  rb_define_method(klass, "inspect", Message_inspect, 0);
  rb_define_method(klass, "[]", Message_index, 1);
  rb_define_method(klass, "[]=", Message_index_set, 2);
  rb_define_singleton_method(klass, "decode", Message_decode, 1);
  rb_define_singleton_method(klass, "encode", Message_encode, 1);
  rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
  rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
  rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);

  return klass;
}
Exemple #14
0
void
Init_escape(void)
{
    rb_cCGI    = rb_define_class("CGI", rb_cObject);
    rb_mEscape = rb_define_module_under(rb_cCGI, "Escape");
    rb_mUtil   = rb_define_module_under(rb_cCGI, "Util");
    rb_define_method(rb_mEscape, "escapeHTML", cgiesc_escape_html, 1);
    rb_define_method(rb_mEscape, "unescapeHTML", cgiesc_unescape_html, 1);
    rb_define_method(rb_mEscape, "escape", cgiesc_escape, 1);
    rb_define_private_method(rb_mEscape, "_unescape", cgiesc_unescape, 2);
    rb_prepend_module(rb_mUtil, rb_mEscape);
    rb_extend_object(rb_cCGI, rb_mEscape);
}
Exemple #15
0
void
Init_ENV(void)
{
    origenviron = GET_ENVIRON();
    envtbl = rb_obj_alloc(rb_cObject);
    rb_extend_object(envtbl, rb_mEnumerable);

    VALUE klass = rb_singleton_class(envtbl);

    rb_objc_define_method(klass, "[]", rb_f_getenv, 1);
    rb_objc_define_method(klass, "fetch", env_fetch, -1);
    rb_objc_define_method(klass, "[]=", env_aset, 2);
    rb_objc_define_method(klass, "store", env_aset, 2);
    rb_objc_define_method(klass, "each", env_each_pair, 0);
    rb_objc_define_method(klass, "each_pair", env_each_pair, 0);
    rb_objc_define_method(klass, "each_key", env_each_key, 0);
    rb_objc_define_method(klass, "each_value", env_each_value, 0);
    rb_objc_define_method(klass, "delete", env_delete_m, 1);
    rb_objc_define_method(klass, "delete_if", env_delete_if, 0);
    rb_objc_define_method(klass, "clear", rb_env_clear_imp, 0);
    rb_objc_define_method(klass, "reject", env_reject, 0);
    rb_objc_define_method(klass, "reject!", env_reject_bang, 0);
    rb_objc_define_method(klass, "select", env_select, 0);
    rb_objc_define_method(klass, "shift", env_shift, 0);
    rb_objc_define_method(klass, "invert", env_invert, 0);
    rb_objc_define_method(klass, "replace", env_replace, 1);
    rb_objc_define_method(klass, "update", env_update, 1);
    rb_objc_define_method(klass, "inspect", env_inspect, 0);
    rb_objc_define_method(klass, "rehash", env_none, 0);
    rb_objc_define_method(klass, "to_a", env_to_a, 0);
    rb_objc_define_method(klass, "to_s", env_to_s, 0);
    rb_objc_define_method(klass, "key", env_key, 1);
    rb_objc_define_method(klass, "index", env_index, 1);
    rb_objc_define_method(klass, "size", env_size, 0);
    rb_objc_define_method(klass, "length", env_size, 0);
    rb_objc_define_method(klass, "empty?", env_empty_p, 0);
    rb_objc_define_method(klass, "keys", env_keys, 0);
    rb_objc_define_method(klass, "values", env_values, 0);
    rb_objc_define_method(klass, "values_at", env_values_at, -1);
    rb_objc_define_method(klass, "include?", env_has_key, 1);
    rb_objc_define_method(klass, "member?", env_has_key, 1);
    rb_objc_define_method(klass, "has_key?", env_has_key, 1);
    rb_objc_define_method(klass, "has_value?", env_has_value, 1);
    rb_objc_define_method(klass, "key?", env_has_key, 1);
    rb_objc_define_method(klass, "value?", env_has_value, 1);
    rb_objc_define_method(klass, "to_hash", env_to_hash, 0);
    rb_objc_define_method(klass, "assoc", env_assoc, 1);
    rb_objc_define_method(klass, "rassoc", env_rassoc, 1);

    rb_define_global_const("ENV", envtbl);
}
Exemple #16
0
static void
setup_obj_common(VALUE obj)
{
  rb_extend_object(obj, rb_mEnumerable);
  rb_include_module(obj, rb_mComparable);
  rb_define_method(obj, "del", ngraph_inst_method_del, 0);
  rb_define_method(obj, "===", ngraph_inst_method_equal, 1);
  rb_define_method(obj, "<=>", ngraph_inst_method_compare, 1);
  rb_define_method(obj, "move_up", ngraph_inst_method_move_up, 0);
  rb_define_method(obj, "move_down", ngraph_inst_method_move_down, 0);
  rb_define_method(obj, "move_top", ngraph_inst_method_move_top, 0);
  rb_define_method(obj, "move_last", ngraph_inst_method_move_last, 0);
  rb_define_method(obj, "exchange", ngraph_inst_method_exchange, 1);
  rb_define_method(obj, "to_s", ngraph_inst_method_to_str, 0);
  rb_define_method(obj, "rcode", ngraph_inst_method_rcode, 0);
  rb_define_method(obj, "copy", ngraph_inst_method_copy, 1);
}
Exemple #17
0
/* call-seq:
 *   extend_between(mod){|p, c| } -> mod || nil
 *
 * Walks the receiver's singleton class's super chain until it reaches the receiver's
 * class, yielding the previous and current entries in the super chain at every step.
 * The first time the block returns +true+, +mod+ is inserted into the super chain
 * between the two values and the method returns immediately.  Raises +TypeError+ if
 * +mod+ is not a Module or if the receiver is an immediate.
 * If the block ever returns +true+, the return value is
 * +mod+.  If the block never returns +true+, the return value is +nil+.  On the first block call,
 * the first block argument is the receiver's singleton class, and on the last block call,
 * the last block argument is the receiver's class. */
static VALUE evilr_extend_between(VALUE self, VALUE mod) {
  VALUE sc, iclass, klass, prev, cur;

  evilr__check_immediates(self, mod);
  evilr__check_type(T_MODULE, mod);

  sc = rb_singleton_class(self);
  klass = rb_obj_class(self);
  rb_extend_object(self, mod);
  iclass = evilr__iclass_matching_before(sc, mod, klass);
  if (iclass == NULL) {
    rb_raise(rb_eArgError, "module already included in object's class");
  }
  evilr_unextend(self, mod);

  for (prev = sc, cur = RCLASS_SUPER(sc); prev && prev != klass; prev = cur, cur = cur ? RCLASS_SUPER(cur) : cur) {
    if (rb_yield_values(2, INCLUDE_BETWEEN_VAL(prev), INCLUDE_BETWEEN_VAL(cur)) == Qtrue) {
      RCLASS_SET_SUPER(prev, iclass);
      RCLASS_SET_SUPER(iclass, cur);
      return mod;
    }
  }
  return Qnil;
}
Exemple #18
0
static int
rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap)
{
    int state;
    volatile VALUE wrapper = th->top_wrapper;
    volatile VALUE self = th->top_self;
    volatile int loaded = FALSE;
    volatile int mild_compile_error;
#if !defined __GNUC__
    rb_thread_t *volatile th0 = th;
#endif

    th->errinfo = Qnil; /* ensure */

    if (!wrap) {
	th->top_wrapper = 0;
    }
    else {
	/* load in anonymous module as toplevel */
	th->top_self = rb_obj_clone(rb_vm_top_self());
	th->top_wrapper = rb_module_new();
	rb_extend_object(th->top_self, th->top_wrapper);
    }

    mild_compile_error = th->mild_compile_error;
    TH_PUSH_TAG(th);
    state = EXEC_TAG();
    if (state == 0) {
	NODE *node;
	rb_iseq_t *iseq;

	th->mild_compile_error++;
	node = (NODE *)rb_load_file_str(fname);
	loaded = TRUE;
	iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), NULL);
	th->mild_compile_error--;
	rb_iseq_eval(iseq);
    }
    TH_POP_TAG();

#if !defined __GNUC__
    th = th0;
    fname = RB_GC_GUARD(fname);
#endif
    th->mild_compile_error = mild_compile_error;
    th->top_self = self;
    th->top_wrapper = wrapper;

    if (!loaded && !FIXNUM_P(th->errinfo)) {
	/* an error on loading don't include INT2FIX(TAG_FATAL) see r35625 */
	return TAG_RAISE;
    }
    if (state) {
	VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef);
	if (NIL_P(exc)) return state;
	th->errinfo = exc;
	return TAG_RAISE;
    }

    if (!NIL_P(th->errinfo)) {
	/* exception during load */
	return TAG_RAISE;
    }
    return state;
}
Exemple #19
0
/*
 * The Etc module provides access to information typically stored in
 * files in the /etc directory on Unix systems.
 *
 * The information accessible consists of the information found in the
 * /etc/passwd and /etc/group files, plus information about the system's
 * temporary directory (/tmp) and configuration directory (/etc).
 *
 * The Etc module provides a more reliable way to access information about
 * the logged in user than environment variables such as +$USER+.
 *
 * == Example:
 *
 *     require 'etc'
 *
 *     login = Etc.getlogin
 *     info = Etc.getpwnam(login)
 *     username = info.gecos.split(/,/).first
 *     puts "Hello #{username}, I see your login name is #{login}"
 *
 * Note that the methods provided by this module are not always secure.
 * It should be used for informational purposes, and not for security.
 *
 * All operations defined in this module are class methods, so that you can
 * include the Etc module into your class.
 */
void
Init_etc(void)
{
    VALUE mEtc;

    mEtc = rb_define_module("Etc");
    rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);

    rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1);
    rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1);
    rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0);
    rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0);
    rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0);
    rb_define_module_function(mEtc, "passwd", etc_passwd, 0);

    rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1);
    rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
    rb_define_module_function(mEtc, "group", etc_group, 0);
    rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0);
    rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0);
    rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0);
    rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
    rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);

    sPasswd =  rb_struct_define_under(mEtc, "Passwd",
				      "name",
#ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
				      "passwd",
#endif
				      "uid",
				      "gid",
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
				      "gecos",
#endif
				      "dir",
				      "shell",
#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
				      "change",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
				      "quota",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_AGE
				      "age",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
				      "uclass",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
				      "comment",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
				      "expire",
#endif
				      NULL);
#if 0
    /* Define-const: Passwd
     *
     * Passwd is a Struct that contains the following members:
     *
     * name::
     *	    contains the short login name of the user as a String.
     * passwd::
     *	    contains the encrypted password of the user as a String.
     *	    an 'x' is returned if shadow passwords are in use. An '*' is returned
     *      if the user cannot log in using a password.
     * uid::
     *	    contains the integer user ID (uid) of the user.
     * gid::
     *	    contains the integer group ID (gid) of the user's primary group.
     * dir::
     *	    contains the path to the home directory of the user as a String.
     * shell::
     *	    contains the path to the login shell of the user as a String.
     *
     * === The following members below are optional, and must be compiled with special flags:
     *
     * gecos::
     *     contains a longer String description of the user, such as
     *	   a full name. Some Unix systems provide structured information in the
     *     gecos field, but this is system-dependent.
     *     must be compiled with +HAVE_STRUCT_PASSWD_PW_GECOS+
     * change::
     *     password change time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_CHANGE+
     * quota::
     *     quota value(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_QUOTA+
     * age::
     *     password age(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_AGE+
     * class::
     *     user access class(string) must be compiled with +HAVE_STRUCT_PASSWD_PW_CLASS+
     * comment::
     *     comment(string) must be compiled with +HAVE_STRUCT_PASSWD_PW_COMMENT+
     * expire::
     *	    account expiration time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_EXPIRE+
     */
    rb_define_const(mEtc, "Passwd", sPasswd);
#endif
    rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */
    rb_extend_object(sPasswd, rb_mEnumerable);
    rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0);

#ifdef HAVE_GETGRENT
    sGroup = rb_struct_define_under(mEtc, "Group", "name",
#ifdef HAVE_STRUCT_GROUP_GR_PASSWD
				    "passwd",
#endif
				    "gid", "mem", NULL);

#if 0
    /* Define-const: Group
     *
     * Group is a Struct that is only available when compiled with +HAVE_GETGRENT+.
     *
     * The struct contains the following members:
     *
     * name::
     *	    contains the name of the group as a String.
     * passwd::
     *	    contains the encrypted password as a String. An 'x' is
     *	    returned if password access to the group is not available; an empty
     *	    string is returned if no password is needed to obtain membership of
     *	    the group.
     *
     *	    Must be compiled with +HAVE_STRUCT_GROUP_GR_PASSWD+.
     * gid::
     *	    contains the group's numeric ID as an integer.
     * mem::
     *	    is an Array of Strings containing the short login names of the
     *	    members of the group.
     */
    rb_define_const(mEtc, "Group", sGroup);
#endif
    rb_define_const(rb_cStruct, "Group", sGroup); /* deprecated name */
    rb_extend_object(sGroup, rb_mEnumerable);
    rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
#endif
}
Exemple #20
0
static VALUE
rb_mod_extend_object(VALUE mod, SEL sel, VALUE obj)
{
    rb_extend_object(obj, mod);
    return obj;
}
Exemple #21
0
void
Init_mouse()
{
    // on either supported Ruby, this should be defined by now
    rb_cCGPoint = rb_const_get(rb_cObject, rb_intern("CGPoint"));

    sel_x        = rb_intern("x");
    sel_y        = rb_intern("y");
    sel_to_point = rb_intern("to_point");
    sel_new      = rb_intern("new");

    sym_pixel    = ID2SYM(rb_intern("pixel"));
    sym_line     = ID2SYM(rb_intern("line"));

    sym_up       = ID2SYM(rb_intern("up"));
    sym_down     = ID2SYM(rb_intern("down"));
    sym_left     = ID2SYM(rb_intern("left"));
    sym_right    = ID2SYM(rb_intern("right"));

    sym_zoom     = ID2SYM(rb_intern("zoom"));
    sym_unzoom   = ID2SYM(rb_intern("unzoom"));
    sym_expand   = ID2SYM(rb_intern("expand"));
    sym_contract = ID2SYM(rb_intern("contract"));

    sym_cw                 = ID2SYM(rb_intern("cw"));
    sym_clockwise          = ID2SYM(rb_intern("clockwise"));
    sym_clock_wise         = ID2SYM(rb_intern("clock_wise"));
    sym_ccw                = ID2SYM(rb_intern("ccw"));
    sym_counter_clockwise  = ID2SYM(rb_intern("counter_clockwise"));
    sym_counter_clock_wise = ID2SYM(rb_intern("counter_clock_wise"));

    /*
     * Document-module: Mouse
     *
     * A module with methods that "tap" into the system input methods.
     * This is done by wrapping wrapping around the CoreGraphics event
     * taps API provided by OS X.
     *
     * The module provides a simple Ruby interface to performing mouse
     * interactions such as moving and clicking.
     *
     * This module can be used in a stand alone fashion or you can mix
     * it into another class.
     *
     * [Reference](http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html)
     */
    rb_mMouse = rb_define_module("Mouse");

    rb_extend_object(rb_mMouse, rb_mMouse);

    rb_define_method(rb_mMouse, "current_position",     rb_mouse_current_position,      0);
    rb_define_method(rb_mMouse, "move_to",              rb_mouse_move_to,              -1);
    rb_define_method(rb_mMouse, "drag_to",              rb_mouse_drag_to,              -1);
    rb_define_method(rb_mMouse, "scroll",               rb_mouse_scroll,               -1);
    rb_define_method(rb_mMouse, "horizontal_scroll",    rb_mouse_horizontal_scroll,    -1);
    rb_define_method(rb_mMouse, "click_down",           rb_mouse_click_down,           -1);
    rb_define_method(rb_mMouse, "click_up",             rb_mouse_click_up,             -1);
    rb_define_method(rb_mMouse, "click",                rb_mouse_click,                -1);
    rb_define_method(rb_mMouse, "secondary_click_down", rb_mouse_secondary_click_down, -1);
    rb_define_method(rb_mMouse, "secondary_click_up",   rb_mouse_secondary_click_up,   -1);
    rb_define_method(rb_mMouse, "secondary_click",      rb_mouse_secondary_click,      -1);
    rb_define_method(rb_mMouse, "middle_click",         rb_mouse_middle_click,         -1);
    rb_define_method(rb_mMouse, "arbitrary_click_down", rb_mouse_arbitrary_click_down, -1);
    rb_define_method(rb_mMouse, "arbitrary_click_up",   rb_mouse_arbitrary_click_up,   -1);
    rb_define_method(rb_mMouse, "arbitrary_click",      rb_mouse_arbitrary_click,      -1);
    rb_define_method(rb_mMouse, "multi_click",          rb_mouse_multi_click,          -1);
    rb_define_method(rb_mMouse, "double_click",         rb_mouse_double_click,         -1);
    rb_define_method(rb_mMouse, "triple_click",         rb_mouse_triple_click,         -1);

    rb_define_method(rb_mMouse, "smart_magnify",        rb_mouse_smart_magnify,        -1);
    rb_define_method(rb_mMouse, "swipe",                rb_mouse_swipe,                -1);
    rb_define_method(rb_mMouse, "pinch",                rb_mouse_pinch,                -1);
    rb_define_method(rb_mMouse, "rotate",               rb_mouse_rotate,               -1);

    rb_define_alias(rb_mMouse, "hscroll",               "horizontal_scroll");
    rb_define_alias(rb_mMouse, "right_click_down",      "secondary_click_down");
    rb_define_alias(rb_mMouse, "right_click_up",        "secondary_click_up");
    rb_define_alias(rb_mMouse, "right_click",           "secondary_click");
    rb_define_alias(rb_mMouse, "two_finger_double_tap", "smart_magnify");
}
Exemple #22
0
static void
rb_load_internal(VALUE fname, int wrap)
{
    int state;
    rb_thread_t *th = GET_THREAD();
    volatile VALUE wrapper = th->top_wrapper;
    volatile VALUE self = th->top_self;
    volatile int loaded = FALSE;
    volatile int mild_compile_error;
#ifndef __GNUC__
    rb_thread_t *volatile th0 = th;
#endif

    th->errinfo = Qnil; /* ensure */

    if (!wrap) {
	rb_secure(4);		/* should alter global state */
	th->top_wrapper = 0;
    }
    else {
	/* load in anonymous module as toplevel */
	th->top_self = rb_obj_clone(rb_vm_top_self());
	th->top_wrapper = rb_module_new();
	rb_extend_object(th->top_self, th->top_wrapper);
    }

    mild_compile_error = th->mild_compile_error;
    PUSH_TAG();
    state = EXEC_TAG();
    if (state == 0) {
	NODE *node;
	VALUE iseq;

	th->mild_compile_error++;
	node = (NODE *)rb_load_file(RSTRING_PTR(fname));
	loaded = TRUE;
	iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse);
	th->mild_compile_error--;
	rb_iseq_eval(iseq);
    }
    POP_TAG();

#ifndef __GNUC__
    th = th0;
    fname = RB_GC_GUARD(fname);
#endif
    th->mild_compile_error = mild_compile_error;
    th->top_self = self;
    th->top_wrapper = wrapper;

    if (!loaded) {
	rb_exc_raise(GET_THREAD()->errinfo);
    }
    if (state) {
	rb_vm_jump_tag_but_local_jump(state, Qundef);
    }

    if (!NIL_P(GET_THREAD()->errinfo)) {
	/* exception during load */
	rb_exc_raise(th->errinfo);
    }
}
Exemple #23
0
/*
 * The etc module provides access to information from the running OS.
 *
 * Documented by mathew <*****@*****.**>.
 */
void
Init_etc(void)
{
    VALUE mEtc;

    mEtc = rb_define_module("Etc");
    rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);

    rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1);
    rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1);
    rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0);
    rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0);
    rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0);
    rb_define_module_function(mEtc, "passwd", etc_passwd, 0);

    rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1);
    rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
    rb_define_module_function(mEtc, "group", etc_group, 0);
    rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0);
    rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0);
    rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0);
    rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
    rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);

    sPasswd =  rb_struct_define("Passwd",
                                "name", "passwd", "uid", "gid",
#ifdef HAVE_ST_PW_GECOS
                                "gecos",
#endif
                                "dir", "shell",
#ifdef HAVE_ST_PW_CHANGE
                                "change",
#endif
#ifdef HAVE_ST_PW_QUOTA
                                "quota",
#endif
#ifdef HAVE_ST_PW_AGE
                                "age",
#endif
#ifdef HAVE_ST_PW_CLASS
                                "uclass",
#endif
#ifdef HAVE_ST_PW_COMMENT
                                "comment",
#endif
#ifdef HAVE_ST_PW_EXPIRE
                                "expire",
#endif
                                NULL);
    rb_define_const(mEtc, "Passwd", sPasswd);
    rb_extend_object(sPasswd, rb_mEnumerable);
    rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0);

#ifdef HAVE_GETGRENT
    sGroup = rb_struct_define("Group", "name",
#ifdef HAVE_ST_GR_PASSWD
                              "passwd",
#endif
                              "gid", "mem", NULL);

    rb_define_const(mEtc, "Group", sGroup);
    rb_extend_object(sGroup, rb_mEnumerable);
    rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
#endif
}
Exemple #24
0
static VALUE mSyslogMacros_included(VALUE mod, VALUE target)
{
    rb_extend_object(target, mSyslogMacros);
    return mod;
}
Exemple #25
0
static VALUE object_spec_rb_extend_object(VALUE self, VALUE obj, VALUE mod) {
  rb_extend_object(obj, mod);
  return obj;
}
VALUE rb_ActsAsFoo_included(VALUE self, VALUE target) {
  rb_extend_object(target, ActsAsFoo_ClassMethods);
  return self;
}
Exemple #27
0
static int
rb_load_internal0(rb_execution_context_t *ec, VALUE fname, int wrap)
{
    enum ruby_tag_type state;
    rb_thread_t *th = rb_ec_thread_ptr(ec);
    volatile VALUE wrapper = th->top_wrapper;
    volatile VALUE self = th->top_self;
#if !defined __GNUC__
    rb_thread_t *volatile th0 = th;
#endif

    th->ec->errinfo = Qnil; /* ensure */

    if (!wrap) {
	th->top_wrapper = 0;
    }
    else {
	/* load in anonymous module as toplevel */
	th->top_self = rb_obj_clone(rb_vm_top_self());
	th->top_wrapper = rb_module_new();
	rb_extend_object(th->top_self, th->top_wrapper);
    }

    EC_PUSH_TAG(th->ec);
    state = EC_EXEC_TAG();
    if (state == TAG_NONE) {
	rb_ast_t *ast;
	const rb_iseq_t *iseq;

	if ((iseq = rb_iseq_load_iseq(fname)) != NULL) {
	    /* OK */
	}
	else {
	    VALUE parser = rb_parser_new();
	    rb_parser_set_context(parser, NULL, FALSE);
	    ast = (rb_ast_t *)rb_parser_load_file(parser, fname);
	    iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
			    fname, rb_realpath_internal(Qnil, fname, 1), NULL);
	    rb_ast_dispose(ast);
	}
        rb_exec_event_hook_script_compiled(ec, iseq, Qnil);
        rb_iseq_eval(iseq);
    }
    EC_POP_TAG();

#if !defined __GNUC__
    th = th0;
    fname = RB_GC_GUARD(fname);
#endif
    th->top_self = self;
    th->top_wrapper = wrapper;

    if (state) {
	/* usually state == TAG_RAISE only, except for
	 * rb_iseq_load_iseq case */
	VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef);
	if (NIL_P(exc)) return state;
	th->ec->errinfo = exc;
	return TAG_RAISE;
    }

    if (!NIL_P(th->ec->errinfo)) {
	/* exception during load */
	return TAG_RAISE;
    }
    return state;
}