2007-07-06 23:50:26 +00:00
|
|
|
#include "jnienv.h"
|
|
|
|
#include "machine.h"
|
2007-07-06 15:24:06 +00:00
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
namespace jni {
|
|
|
|
|
|
|
|
jsize
|
2007-07-06 23:18:40 +00:00
|
|
|
GetStringUTFLength(Thread* t, jstring s)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
|
|
|
ENTER(t, Thread::ActiveState);
|
|
|
|
|
2007-07-06 23:18:40 +00:00
|
|
|
return stringLength(t, *s);
|
2007-07-06 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
2007-07-06 23:18:40 +00:00
|
|
|
GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
|
|
|
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));
|
2007-07-06 15:24:06 +00:00
|
|
|
|
2007-07-06 23:18:40 +00:00
|
|
|
memcpy(chars,
|
|
|
|
&byteArrayBody(t, stringBytes(t, *s), stringOffset(t, *s)),
|
|
|
|
stringLength(t, *s));
|
2007-07-06 15:24:06 +00:00
|
|
|
|
2007-07-06 23:18:40 +00:00
|
|
|
chars[stringLength(t, *s)] = 0;
|
2007-07-06 15:24:06 +00:00
|
|
|
|
|
|
|
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 15:24:06 +00:00
|
|
|
{
|
2007-07-06 23:18:40 +00:00
|
|
|
t->vm->system->free(chars);
|
2007-07-06 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2007-07-06 15:24:06 +00:00
|
|
|
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;
|
2007-07-06 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace jni
|
|
|
|
} // namespace vm
|