corda/src/jnienv.cpp

55 lines
1.0 KiB
C++
Raw Normal View History

2007-07-06 23:50:26 +00:00
#include "jnienv.h"
#include "machine.h"
namespace vm {
namespace jni {
jsize
2007-07-06 23:18:40 +00:00
GetStringUTFLength(Thread* t, jstring s)
{
ENTER(t, Thread::ActiveState);
2007-07-06 23:18:40 +00:00
return stringLength(t, *s);
}
const char*
2007-07-06 23:18:40 +00:00
GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
{
ENTER(t, Thread::ActiveState);
2007-07-06 23:18:40 +00:00
char* chars = static_cast<char*>
(t->vm->system->allocate(stringLength(t, *s) + 1));
stringChars(t, *s, chars);
if (isCopy) *isCopy = true;
return chars;
}
void
2007-07-06 23:18:40 +00:00
ReleaseStringUTFChars(Thread* t, jstring, const char* chars)
{
2007-07-06 23:18:40 +00:00
t->vm->system->free(chars);
}
2007-07-07 23:47:35 +00:00
jstring
NewStringUTF(Thread* t, const char* chars)
{
ENTER(t, Thread::ActiveState);
return pushReference(t, makeString(t, "%s", chars));
}
void
populate(JNIEnvVTable* table)
{
memset(table, 0, sizeof(JNIEnvVTable));
2007-07-06 23:18:40 +00:00
table->GetStringUTFLength = GetStringUTFLength;
table->GetStringUTFChars = GetStringUTFChars;
table->ReleaseStringUTFChars = ReleaseStringUTFChars;
2007-07-07 23:47:35 +00:00
table->NewStringUTF = NewStringUTF;
}
} // namespace jni
} // namespace vm