Esempio n. 1
0
File: task.c Progetto: ko1/ptask
VALUE
rb_task_create(VALUE (*func)(VALUE *argv), int argc, ...)
{
    va_list args;

    if (worker_thread_num > 0) {
	rb_task_t *task;
	VALUE *argv = xmalloc(sizeof(VALUE) * argc);
	VALUE obj;
	int i;

	obj = TypedData_Make_Struct(rb_cTask, rb_task_t, &task_data_type, task);

	/* setup argv */
	va_init_list(args, argc);
	for (i=0; i<argc; i++) {
	    argv[i] = va_arg(args, VALUE);
	}
	va_end(args);

	task->func = func;
	task->argc = argc;
	task->argv = argv;
	task->result = Qundef;
	task->ptask = ptask_create(task_dispatch_callback, task);
	ptask_dispatch(task->ptask);
	return obj;
    }
    else {
	/* Do it immediately */
	int i;
	VALUE *argv = ALLOCA_N(VALUE, argc);

	va_init_list(args, argc);
	for (i=0; i<argc; i++) {
	    argv[i] = va_arg(args, VALUE);
	}
	va_end(args);

	return (VALUE)func(argv);
    }
}
Esempio n. 2
0
static void
warn_printf(const char *fmt, ...)
{
    VALUE str;
    va_list args;

    va_init_list(args, fmt);
    str = rb_vsprintf(fmt, args);
    va_end(args);
    rb_write_error_str(str);
}
Esempio n. 3
0
static void
warn_printf(const char *fmt, ...)
{
    char buf[BUFSIZ];
    va_list args;

    va_init_list(args, fmt);
    vsnprintf(buf, BUFSIZ, fmt, args);
    va_end(args);
    rb_write_error(buf);
}
Esempio n. 4
0
/* rb_warning() reports only in verbose mode */
void
rb_warning(const char *fmt, ...)
{
    char buf[BUFSIZ];
    va_list args;

    if (!RTEST(ruby_verbose)) return;

    snprintf(buf, BUFSIZ, "warning: %s", fmt);

    va_init_list(args, fmt);
    warn_print(buf, args);
    va_end(args);
}
Esempio n. 5
0
ropenldap_log( const char *level, const char *fmt, va_dcl )
#endif
{
	char buf[BUFSIZ];
	va_list	args;
	VALUE logger = Qnil;
	VALUE message = Qnil;

	va_init_list( args, fmt );
	vsnprintf( buf, BUFSIZ, fmt, args );
	message = rb_str_new2( buf );

	logger = rb_funcall( ropenldap_mOpenLDAP, rb_intern("logger"), 0, 0 );
	rb_funcall( logger, rb_intern(level), 1, message );

	va_end( args );
}
Esempio n. 6
0
ropenldap_check_result( int resultcode, const char *func, va_dcl )
#endif
{
	char buf[BUFSIZ];
	va_list args;
	VALUE exception_class = Qnil;

	if ( resultcode == LDAP_SUCCESS ) return;

	va_init_list( args, func );
	vsnprintf( buf, BUFSIZ, func, args );

	exception_class =
		rb_funcall( ropenldap_eOpenLDAPError, rb_intern("subclass_for"), 1, INT2FIX(resultcode) );

	rb_raise( exception_class, "%s", buf );
}
Esempio n. 7
0
rlink_log_obj( VALUE context, const char *level, const char *fmt, va_dcl )
#endif
{
	char buf[BUFSIZ];
	va_list	args;
	VALUE logger = Qnil;
	VALUE message = Qnil;

	va_init_list( args, fmt );
	vsnprintf( buf, BUFSIZ, fmt, args );
	message = rb_str_new2( buf );

	logger = rb_funcall( context, rb_intern("log"), 0, 0 );
	rb_funcall( logger, rb_intern(level), 1, message );

	va_end( args );
}
Esempio n. 8
0
VALUE
rb_yield_values(int n, ...)
{
    if (n == 0) {
	return rb_yield_0(0, 0);
    }
    else {
	int i;
	VALUE *argv;
	va_list args;
	argv = ALLOCA_N(VALUE, n);

	va_init_list(args, n);
	for (i=0; i<n; i++) {
	    argv[i] = va_arg(args, VALUE);
	}
	va_end(args);

	return rb_yield_0(n, argv);
    }
}
Esempio n. 9
0
VALUE
rb_funcall(VALUE recv, ID mid, int n, ...)
{
    VALUE *argv;
    va_list ar;
    va_init_list(ar, n);

    if (n > 0) {
	long i;

	argv = ALLOCA_N(VALUE, n);

	for (i = 0; i < n; i++) {
	    argv[i] = va_arg(ar, VALUE);
	}
	va_end(ar);
    }
    else {
	argv = 0;
    }
    return rb_call(CLASS_OF(recv), recv, mid, n, argv, CALL_FCALL);
}
Esempio n. 10
0
    VALUE
cb_proc_call(struct cb_bucket_st *bucket, VALUE recv, int argc, ...)
{
    VALUE *argv;
    va_list ar;
    int arity;
    int ii;
    struct proc_params_st params;

    arity = FIX2INT(rb_funcall(recv, cb_id_arity, 0));
    if (arity < 0) {
        arity = argc;
    }
    if (arity > 0) {
        va_init_list(ar, argc);
        argv = ALLOCA_N(VALUE, argc);
        for (ii = 0; ii < arity; ++ii) {
            if (ii < argc) {
                argv[ii] = va_arg(ar, VALUE);
            } else {
                argv[ii] = Qnil;
            }
        }
        va_end(ar);
    } else {
        argv = NULL;
    }
    params.bucket = bucket;
    params.recv = recv;
    params.mid = cb_id_call;
    params.argc = arity;
    params.argv = argv;
    return rb_rescue2(do_func_call, (VALUE)&params,
            func_call_failed, (VALUE)&params,
            rb_eException, (VALUE)0);
}