Exemple #1
0
extern "C" VALUE
rb_thread_blocking_region(rb_blocking_function_t func, void* data, rb_unblock_function_t ub_func, void* data2)
{
    JLocalEnv env;
    jlong jret = env->CallStaticLongMethod(JRuby_class, JRuby_nativeBlockingRegion, getRuntime(),
            p2j((void *)func), p2j(data),
            p2j((void *)ub_func), p2j(data2));
    checkExceptions(env);

    return (VALUE)(j2p(jret));
}
Exemple #2
0
extern "C" unsigned long
rb_big2ulong(VALUE obj)
{
    if (TYPE(obj) == T_BIGNUM) {
        JLocalEnv env;
        jlong result = env->CallStaticLongMethod(RubyBignum_class, RubyBignum_big2ulong_method, valueToObject(env, obj));
        checkExceptions(env);
        return (unsigned long) result;
    } else {
        return (unsigned long) rb_big2ll(obj);
    }
}
Exemple #3
0
static VALUE
newString(const char* ptr, int len, int capacity = 0, bool tainted = false)
{
    if (len < 0) {
        rb_raise(rb_eArgError, "negative string size (or size too big)");
    }

    JLocalEnv env;

    jbyteArray bytes = env->NewByteArray(capacity > len ? capacity : len);
    checkExceptions(env);

    if (len > 0 && ptr != NULL) {
        env->SetByteArrayRegion(bytes, 0, len, (jbyte *) ptr);
        checkExceptions(env);
    }

    jlong result = env->CallStaticLongMethod(JRuby_class, JRuby_newString, jruby::getRuntime(), bytes, (jint)len, (jboolean) tainted);
    checkExceptions(env);

    return (VALUE) result;
}
Exemple #4
0
RString*
RubyString::toRString(bool readonly)
{
    if (rwdata.rstring != NULL) {
        if (readonly || !rwdata.readonly) {
            return rwdata.rstring;
        }

        // Switch from readonly to read-write
        rwdata.readonly = false;
        TAILQ_INSERT_TAIL(&jruby::nsyncq, &rwdata.nsync, syncq);
        JLocalEnv env;
        nsync(env);

        return rwdata.rstring;
    }

    JLocalEnv env;
    rwdata.jsync.data = this;
    rwdata.jsync.sync = RubyString_jsync;
    rwdata.nsync.data = this;
    rwdata.nsync.sync = RubyString_nsync;
    rwdata.clean.data = this;
    rwdata.clean.sync = RubyString_clean;
    rwdata.rstring = (RString *) j2p(env->CallStaticLongMethod(JRuby_class, JRuby_getRString, obj));
    checkExceptions(env);
    rwdata.readonly = readonly;

    TAILQ_INSERT_TAIL(&jruby::cleanq, &rwdata.clean, syncq);
    TAILQ_INSERT_TAIL(&jruby::jsyncq, &rwdata.jsync, syncq);
    if (!readonly) {
        TAILQ_INSERT_TAIL(&jruby::nsyncq, &rwdata.nsync, syncq);
    }
    nsync(env);

    return rwdata.rstring;
}
Exemple #5
0
extern "C" VALUE
rb_class_of(VALUE obj)
{
    JLocalEnv env;
    return (VALUE) env->CallStaticLongMethod(JRuby_class, JRuby_getMetaClass, valueToObject(env, obj));
}