makeIntArray takes array of initial values

This commit is contained in:
ehouse 2010-01-07 14:24:53 +00:00
parent df7a445a9e
commit ecd5667cf0
2 changed files with 9 additions and 7 deletions

View file

@ -168,14 +168,16 @@ getBool( JNIEnv* env, jobject obj, const char* name, XP_Bool* result )
} }
jintArray jintArray
makeIntArray( JNIEnv *env, int val ) makeIntArray( JNIEnv *env, int siz, const jint* vals )
{ {
jintArray array = (*env)->NewIntArray( env, 1 ); jintArray array = (*env)->NewIntArray( env, siz );
XP_ASSERT( !!array ); XP_ASSERT( !!array );
jint* elems = (*env)->GetIntArrayElements( env, array, NULL ); if ( !!vals ) {
XP_ASSERT( !!elems ); jint* elems = (*env)->GetIntArrayElements( env, array, NULL );
*elems = val; XP_ASSERT( !!elems );
(*env)->ReleaseIntArrayElements( env, array, elems, 0 ); XP_MEMCPY( elems, vals, siz * sizeof(*elems) );
(*env)->ReleaseIntArrayElements( env, array, elems, 0 );
}
return array; return array;
} }

View file

@ -22,7 +22,7 @@ bool getString( JNIEnv* env, jobject jlp, const char* name, XP_UCHAR* buf,
bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig, bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
jobject* ret ); jobject* ret );
jintArray makeIntArray( JNIEnv *env, int val ); jintArray makeIntArray( JNIEnv *env, int size, const jint* vals );
int getIntFromArray( JNIEnv* env, jintArray arr, bool del ); int getIntFromArray( JNIEnv* env, jintArray arr, bool del );
/* Note: jmethodID can be cached. Should not look up more than once. */ /* Note: jmethodID can be cached. Should not look up more than once. */