Esempio n. 1
0
static VALUE
range_max(VALUE range, SEL sel)
{
    VALUE e = RANGE_END(range);
    int nm = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric);

    if (rb_block_given_p() || (EXCL(range) && !nm)) {
	if (sel == NULL) {
	    sel = sel_registerName("max");
	}
	return rb_vm_call_super(range, sel, 0, NULL);
    }
    else {
	VALUE b = RANGE_BEG(range);
	int c = rb_cmpint(rb_objs_cmp(b, e), b, e);

	if (c > 0)
	    return Qnil;
	if (EXCL(range)) {
	    if (!FIXNUM_P(e) && !rb_obj_is_kind_of(e, rb_cInteger)) {
		rb_raise(rb_eTypeError, "cannot exclude non Integer end value");
	    }
	    if (c == 0) {
		return Qnil;
	    }
	    if (FIXNUM_P(e)) {
		return LONG2NUM(FIX2LONG(e) - 1);
	    }
	    VALUE one = INT2FIX(1);
	    return rb_vm_call(e, selMINUS, 1, &one);
	}
	return e;
    }
}
Esempio n. 2
0
static VALUE
interrupt_init(VALUE self, SEL sel, int argc, VALUE *argv)
{
    VALUE args[2];

    args[0] = INT2FIX(SIGINT);
    rb_scan_args(argc, argv, "01", &args[1]);
    return rb_vm_call_super(self, selInitialize2, 2, args);
}
Esempio n. 3
0
VALUE
rb_call_super(int argc, const VALUE *argv)
{
    RoxorVM *vm = GET_VM();
    VALUE self = vm->get_current_mri_method_self();
    SEL sel = vm->get_current_mri_method_sel();
    assert(self != 0 && sel != 0);

    return rb_vm_call_super(self, sel, argc, argv);
}
Esempio n. 4
0
static VALUE
nometh_err_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
{
    VALUE args = (argc > 2) ? argv[--argc] : Qnil;
    //name_err_initialize(self, sel, argc, argv);
    if (sel == 0) {
	sel = argc == 0 ? selInitialize : selInitialize2;
    }
    rb_vm_call_super(self, sel, argc, argv);
    rb_iv_set(self, "args", args);
    return self;
}
Esempio n. 5
0
static VALUE
name_err_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
{
    VALUE name;

    name = (argc > 1) ? argv[--argc] : Qnil;
    if (sel == 0) {
	sel = argc == 0 ? selInitialize : selInitialize2;
    }
    rb_vm_call_super(self, sel, argc, argv);
    rb_iv_set(self, "name", name);
    return self;
}
Esempio n. 6
0
static VALUE
esignal_init(VALUE self, SEL sel, int argc, VALUE *argv)
{
    int argnum = 1;
    VALUE sig = Qnil;
    int signo;
    const char *signm;

    if (argc > 0) {
	sig = rb_check_to_integer(argv[0], "to_int");
	if (!NIL_P(sig)) argnum = 2;
	else sig = argv[0];
    }
    if (argc < 1 || argnum < argc) {
	rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
		 argc, argnum);
    }
    if (argnum == 2) {
	signo = NUM2INT(sig);
	if (signo < 0 || signo > NSIG) {
	    rb_raise(rb_eArgError, "invalid signal number (%d)", signo);
	}
	if (argc > 1) {
	    sig = argv[1];
	}
	else {
	    signm = signo2signm(signo);
	    if (signm) {
		sig = rb_sprintf("SIG%s", signm);
	    }
	    else {
		sig = rb_sprintf("SIG%u", signo);
	    }
	}
    }
    else {
	signm = SYMBOL_P(sig) ? rb_sym2name(sig) : StringValuePtr(sig);
	if (strncmp(signm, "SIG", 3) == 0) signm += 3;
	signo = signm2signo(signm);
	if (!signo) {
	    rb_raise(rb_eArgError, "unsupported name `SIG%s'", signm);
	}
	sig = rb_sprintf("SIG%s", signm);
    }
    rb_vm_call_super(self, selInitialize2, 1, &sig);
    rb_iv_set(self, "signo", INT2NUM(signo));

    return self;
}
Esempio n. 7
0
static VALUE
exit_initialize(VALUE exc, SEL sel, int argc, VALUE *argv)
{
    VALUE status = INT2FIX(EXIT_SUCCESS);
    if (argc > 0 && FIXNUM_P(argv[0])) {
	status = *argv++;
	--argc;
    }
    if (sel == 0) {
	sel = argc == 0 ? selInitialize : selInitialize2;
    }
    rb_vm_call_super(exc, sel, argc, argv);
    rb_iv_set(exc, "status", status);
    return exc;
}
Esempio n. 8
0
static VALUE
range_include(VALUE range, SEL sel, VALUE val)
{
    VALUE beg = RANGE_BEG(range);
    VALUE end = RANGE_END(range);
    int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
	     rb_obj_is_kind_of(beg, rb_cNumeric) ||
	     rb_obj_is_kind_of(end, rb_cNumeric);

    if (nv ||
	!NIL_P(rb_check_to_integer(beg, "to_int")) ||
	!NIL_P(rb_check_to_integer(end, "to_int"))) {
	if (r_le(beg, val)) {
	    if (EXCL(range)) {
		if (r_lt(val, end))
		    return Qtrue;
	    }
	    else {
		if (r_le(val, end))
		    return Qtrue;
	    }
	}
	return Qfalse;
    }
    else if (TYPE(beg) == T_STRING && TYPE(end) == T_STRING &&
	     RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1) {
	if (NIL_P(val)) return Qfalse;
	if (TYPE(val) == T_STRING) {
	    if (RSTRING_LEN(val) == 0 || RSTRING_LEN(val) > 1)
		return Qfalse;
	    else {
		char b = RSTRING_PTR(beg)[0];
		char e = RSTRING_PTR(end)[0];
		char v = RSTRING_PTR(val)[0];

		if (ISASCII(b) && ISASCII(e) && ISASCII(v)) {
		    if (b <= v && v < e) return Qtrue;
		    if (!EXCL(range) && v == e) return Qtrue;
		    return Qfalse;
		}
	    }
	}
    }
    if (sel == NULL) {
	sel = sel_registerName("include?:");
    }
    return rb_vm_call_super(range, sel, 1, &val);
}
Esempio n. 9
0
static VALUE
syserr_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
{
#if !defined(_WIN32) && !defined(__VMS)
    char *strerror();
#endif
    const char *err;
    VALUE mesg, error;
    VALUE klass = rb_obj_class(self);

    if (klass == rb_eSystemCallError) {
	rb_scan_args(argc, argv, "11", &mesg, &error);
	if (argc == 1 && FIXNUM_P(mesg)) {
	    error = mesg; mesg = Qnil;
	}
	if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &klass)) {
	    /* change class */
	    if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
		rb_raise(rb_eTypeError, "invalid instance type");
	    }
	    RBASIC(self)->klass = klass;
	}
    }
    else {
	rb_scan_args(argc, argv, "01", &mesg);
	error = rb_const_get(klass, rb_intern("Errno"));
    }
    if (!NIL_P(error)) err = strerror(NUM2INT(error));
    else err = "unknown error";
    if (!NIL_P(mesg)) {
	VALUE str = mesg;

	StringValue(str);
	mesg = rb_sprintf("%s - %.*s", err,
			  (int)RSTRING_LEN(str), RSTRING_PTR(str));
    }
    else {
	mesg = rb_str_new2(err);
    }
    rb_vm_call_super(self, selInitialize2, 1, &mesg);
    rb_iv_set(self, "errno", error);
    return self;
}
Esempio n. 10
0
static VALUE
range_min(VALUE range, SEL sel)
{
    if (rb_block_given_p()) {
	if (sel == NULL) {
	    sel = sel_registerName("min");
	}
	return rb_vm_call_super(range, sel, 0, NULL);
    }
    else {
	VALUE b = RANGE_BEG(range);
	VALUE e = RANGE_END(range);
	int c = rb_cmpint(rb_objs_cmp(b, e), b, e);

	if (c > 0 || (c == 0 && EXCL(range)))
	    return Qnil;
	return b;
    }
}
Esempio n. 11
0
/*
 * call-seq:
 *    SSLSocket.new(io) => aSSLSocket
 *    SSLSocket.new(io, ctx) => aSSLSocket
 *
 * === Parameters
 * * +io+ is a real ruby IO object.  Not an IO like object that responds to read/write.
 * * +ctx+ is an OpenSSLSSL::SSLContext.
 *
 * The OpenSSL::Buffering module provides additional IO methods.
 *
 * This method will freeze the SSLContext if one is provided;
 * however, session management is still allowed in the frozen SSLContext.
 */
static VALUE
ossl_ssl_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
{
    VALUE io, ctx;

    if (rb_scan_args(argc, argv, "11", &io, &ctx) == 1) {
        ctx = rb_funcall(cSSLContext, rb_intern("new"), 0);
    }
    OSSL_Check_Kind(ctx, cSSLContext);
    Check_Type(io, T_FILE);
    ossl_ssl_set_io(self, io);
    ossl_ssl_set_ctx(self, ctx);
    ossl_ssl_set_sync_close(self, Qfalse);
    ossl_sslctx_setup(ctx);

    rb_vm_call_super(self, sel, 0, NULL);

    return self;
}