示例#1
0
文件: array.cpp 项目: Epictetus/jruby
extern "C" int
rb_ary_size(VALUE ary)
{
    JLocalEnv env;
    int length = (int)(env->GetIntField(valueToObject(env, ary), RubyArray_length_field));
    checkExceptions(env);
    return length;
}
示例#2
0
文件: string.cpp 项目: brasten/jruby
int
RubyString::length()
{
    // If already synced with java, just return the cached length value
    if (rwdata.rstring != NULL) {
        return rwdata.rstring->len;
    }

    JLocalEnv env;

    jobject byteList = env->GetObjectField(obj, RubyString_value_field);

    return env->GetIntField(byteList, ByteList_length_field);
}
示例#3
0
extern "C" ID
rb_intern2(const char* name, long len)
{
    std::map<StringKey, ID>::iterator it = nonConstSymbolMap.find(StringKey(name, len));
    if (it != nonConstSymbolMap.end()) {
        return it->second;
    }

    JLocalEnv env;
    jobject result = env->CallObjectMethod(getRuntime(), Ruby_newSymbol_method, env->NewStringUTF(name));
    checkExceptions(env);

    Symbol* sym = addSymbol(env, env->GetIntField(result, RubySymbol_id_field), result);
    nonConstSymbolMap.insert(std::map<StringKey, ID>::value_type(StringKey(sym->cstr, (long) len), sym->id));

    return sym->id;
}