mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-26 09:58:20 +01:00
add ability to delete a dict from a thread other than the one that
created it -- by making env something that can be set rather than always pulled out of the dict jni struct.
This commit is contained in:
parent
7c9519f80f
commit
07635ede37
6 changed files with 48 additions and 20 deletions
|
@ -592,3 +592,10 @@ destroyDicts( PlayerDicts* dicts )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
setDictEnv( DictionaryCtxt* dict, JNIEnv* env )
|
||||
{
|
||||
AndDictionaryCtxt* anddict = (AndDictionaryCtxt*)dict;
|
||||
anddict->env = env;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
|
|||
|
||||
void destroyDicts( PlayerDicts* dicts );
|
||||
|
||||
void setDictEnv( DictionaryCtxt* dict, JNIEnv* env );
|
||||
|
||||
DictionaryCtxt* and_dictionary_make_empty( MPFORMAL JNIEnv *env,
|
||||
JNIUtilCtxt* jniutil );
|
||||
|
||||
|
|
|
@ -41,11 +41,10 @@ makeJNIUtil( MPFORMAL JNIEnv** envp, jobject jniutls )
|
|||
}
|
||||
|
||||
void
|
||||
destroyJNIUtil( JNIUtilCtxt** ctxtp )
|
||||
destroyJNIUtil( JNIUtilCtxt** ctxtp, JNIEnv* env )
|
||||
{
|
||||
JNIUtilCtxt* ctxt = *ctxtp;
|
||||
if ( !!ctxt ) {
|
||||
JNIEnv* env = *ctxt->envp;
|
||||
(*env)->DeleteGlobalRef( env, ctxt->jjniutil );
|
||||
XP_FREE( ctxt->mpool, ctxt );
|
||||
*ctxtp = NULL;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*-mode: C; fill-column: 76; c-basic-offset: 4; -*- */
|
||||
/* -*-mode: C; compile-command: "../../scripts/ndkbuild.sh"; -*- */
|
||||
/*
|
||||
* Copyright 2001-2010 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
|
@ -29,7 +29,7 @@
|
|||
typedef struct JNIUtilCtxt JNIUtilCtxt;
|
||||
|
||||
JNIUtilCtxt* makeJNIUtil( MPFORMAL JNIEnv** env, jobject jniutls );
|
||||
void destroyJNIUtil( JNIUtilCtxt** jniu );
|
||||
void destroyJNIUtil( JNIUtilCtxt** jniu, JNIEnv* env );
|
||||
|
||||
jobject and_util_makeJBitmap( JNIUtilCtxt* jniu, int nCols, int nRows,
|
||||
const jboolean* colors );
|
||||
|
|
|
@ -290,7 +290,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
|
|||
dict_destroy( dict );
|
||||
result = true;
|
||||
}
|
||||
destroyJNIUtil( &jniutil );
|
||||
destroyJNIUtil( &jniutil, env );
|
||||
|
||||
#ifdef MEM_DEBUG
|
||||
mpool_destroy( mpool );
|
||||
|
@ -447,7 +447,7 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose
|
|||
destroyDraw( &globals->dctx );
|
||||
destroyXportProcs( &globals->xportProcs );
|
||||
destroyUtil( &globals->util );
|
||||
destroyJNIUtil( &globals->jniutil );
|
||||
destroyJNIUtil( &globals->jniutil, env );
|
||||
vtmgr_destroy( MPPARM(mpool) globals->vtMgr );
|
||||
|
||||
state->env = oldEnv;
|
||||
|
@ -498,7 +498,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
|
|||
destroyDicts( &dicts );
|
||||
dict_destroy( dict );
|
||||
destroyUtil( &globals->util );
|
||||
destroyJNIUtil( &globals->jniutil );
|
||||
destroyJNIUtil( &globals->jniutil, env );
|
||||
destroyGI( MPPARM(mpool) &globals->gi );
|
||||
}
|
||||
|
||||
|
@ -1305,7 +1305,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init
|
|||
#endif
|
||||
closure = (int)data;
|
||||
} else {
|
||||
destroyJNIUtil( &jniutil );
|
||||
destroyJNIUtil( &jniutil, env );
|
||||
XP_FREE( mpool, data );
|
||||
#ifdef MEM_DEBUG
|
||||
mpool_destroy( mpool );
|
||||
|
@ -1371,29 +1371,48 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1setMinMax
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_dict( JNIEnv* env, DictIterData* data )
|
||||
{
|
||||
#ifdef MEM_DEBUG
|
||||
MemPoolCtx* mpool = data->mpool;
|
||||
#endif
|
||||
dict_destroy( data->dict );
|
||||
destroyJNIUtil( &data->jniutil, env );
|
||||
freeIndices( data );
|
||||
vtmgr_destroy( MPPARM(mpool) data->vtMgr );
|
||||
XP_FREE( mpool, data );
|
||||
#ifdef MEM_DEBUG
|
||||
mpool_destroy( mpool );
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy
|
||||
( JNIEnv* env, jclass C, jint closure )
|
||||
{
|
||||
DictIterData* data = (DictIterData*)closure;
|
||||
if ( NULL != data ) {
|
||||
#ifdef MEM_DEBUG
|
||||
MemPoolCtx* mpool = data->mpool;
|
||||
#endif
|
||||
dict_destroy( data->dict );
|
||||
destroyJNIUtil( &data->jniutil );
|
||||
freeIndices( data );
|
||||
vtmgr_destroy( MPPARM(mpool) data->vtMgr );
|
||||
XP_FREE( mpool, data );
|
||||
#ifdef MEM_DEBUG
|
||||
mpool_destroy( mpool );
|
||||
#endif
|
||||
destroy_dict( env, data );
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1backDestroy
|
||||
( JNIEnv* env, jclass C, jint closure )
|
||||
{
|
||||
LOG_FUNC();
|
||||
DictIterData* data = (DictIterData*)closure;
|
||||
if ( NULL != data ) {
|
||||
setDictEnv( data->dict, env );
|
||||
destroy_dict( env, data );
|
||||
}
|
||||
LOG_RETURN_VOID();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount
|
||||
(JNIEnv* env, jclass C, jint closure )
|
||||
( JNIEnv* env, jclass C, jint closure )
|
||||
{
|
||||
jint result = 0;
|
||||
DictIterData* data = (DictIterData*)closure;
|
||||
|
|
|
@ -243,6 +243,7 @@ public class XwJNI {
|
|||
public static native void dict_iter_setMinMax( int closure,
|
||||
int min, int max );
|
||||
public static native void dict_iter_destroy( int closure );
|
||||
public static native void dict_iter_backDestroy( int closure );
|
||||
public static native int dict_iter_wordCount( int closure );
|
||||
public static native int[] dict_iter_getCounts( int closure );
|
||||
public static native String dict_iter_nthWord( int closure, int nn );
|
||||
|
|
Loading…
Reference in a new issue