cleanup around jni wrapping and checking

Separated the refcounting and ptr-as-long wrapping aspects of GamePtr
into a superclass that others might later inherit from. Cleaned up
dict_iter entrypoints, and added sanity checks to both structs so I'll
quickly notice if I get the ptr management wrong.
This commit is contained in:
Eric House 2020-04-28 20:13:59 -07:00
parent 9aaeee19b1
commit 0078e58535
2 changed files with 214 additions and 154 deletions

View file

@ -36,45 +36,82 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
public class XwJNI { public class XwJNI {
private static final String TAG = XwJNI.class.getSimpleName(); private static final String TAG = XwJNI.class.getSimpleName();
public static class GamePtr implements AutoCloseable { abstract static class PtrWrapper {
private long m_ptrGame = 0; // This class provides ref counting and wrapping of a long that's
// really a pointer returned by jni code. In addition to the
// refcounting, which doesn't have to be used in a meaningful way, it
// provides type safety (avoids a long representing every jni
// datatype. BUT there's cost to the jni code calling back into java
// (the ptr() method) to get the long. I originally did this to wrap
// the long that represents DictIter state, then pulled that on
// noticing a slowdown in wordlist browsing. Still, I like having two
// classes here so I'm keeping that.
private long m_ptr;
private int m_refCount = 0; private int m_refCount = 0;
private long m_rowid;
private String mStack; private String mStack;
private GamePtr( long ptr, long rowid ) PtrWrapper( long ptr )
{ {
m_ptrGame = ptr; m_ptr = ptr;
m_rowid = rowid; if ( BuildConfig.DEBUG ) {
mStack = android.util.Log.getStackTraceString(new Exception()); mStack = android.util.Log.getStackTraceString(new Exception());
Quarantine.recordOpened( rowid ); }
} }
public synchronized long ptr() public long ptr()
{ {
Assert.assertTrue( 0 != m_ptrGame ); Assert.assertTrueNR( 0 != m_ptr );
return m_ptrGame; return m_ptr;
} }
public synchronized GamePtr retain() public synchronized PtrWrapper retain()
{ {
++m_refCount; ++m_refCount;
Log.d( TAG, "retain(this=%H, rowid=%d): refCount now %d",
this, m_rowid, m_refCount );
return this; return this;
} }
public long getRowid() { return m_rowid; } abstract void onFinalRelease( long ptr );
// Force (via an assert in finalize() below) that this is called. It's // Force (via an assert in finalize() below) that this is called. It's
// better if jni stuff isn't being done on the finalizer thread // better if jni stuff isn't being done on the finalizer thread
public synchronized void release() public synchronized void release()
{ {
--m_refCount; --m_refCount;
// Log.d( TAG, "%s.release(this=%H, rowid=%d): refCount now %d",
// getClass().getName(), this, m_rowid, m_refCount );
if ( 0 == m_refCount ) { if ( 0 == m_refCount ) {
if ( 0 != m_ptrGame ) { onFinalRelease( m_ptr );
m_ptr = 0;
} else {
Assert.assertTrue( m_refCount > 0 || !BuildConfig.DEBUG );
}
}
// @Override
public void finalize() throws java.lang.Throwable
{
if ( BuildConfig.DEBUG && (0 != m_refCount || 0 != m_ptr) ) {
Log.e( TAG, "finalize(): called prematurely: refCount: %d"
+ "; ptr: %d; creator: %s", m_refCount, m_ptr, mStack );
}
super.finalize();
}
}
public static class GamePtr extends PtrWrapper implements AutoCloseable {
private long m_rowid;
private GamePtr( long ptr, long rowid )
{
super( ptr );
m_rowid = rowid;
Quarantine.recordOpened( rowid );
}
public long getRowid() { return m_rowid; }
@Override
void onFinalRelease( long ptr )
{
if ( 0 != ptr ) {
Quarantine.recordClosed( m_rowid ); Quarantine.recordClosed( m_rowid );
if ( haveEnv( getJNI().m_ptrGlobals ) ) { if ( haveEnv( getJNI().m_ptrGlobals ) ) {
game_dispose( this ); // will crash if haveEnv fails game_dispose( this ); // will crash if haveEnv fails
@ -83,11 +120,15 @@ public class XwJNI {
this, m_rowid ); this, m_rowid );
Assert.failDbg(); // seen on Play Store console Assert.failDbg(); // seen on Play Store console
} }
m_ptrGame = 0;
} }
} else {
Assert.assertTrue( m_refCount > 0 || !BuildConfig.DEBUG );
} }
public GamePtr retain()
{
super.retain();
// Log.d( TAG, "retain(this=%H, rowid=%d): refCount now %d",
// this, m_rowid, m_refCount );
return this;
} }
@Override @Override
@ -95,17 +136,7 @@ public class XwJNI {
{ {
release(); release();
} }
} // GamePtr
// @Override
public void finalize() throws java.lang.Throwable
{
if ( BuildConfig.DEBUG && (0 != m_refCount || 0 != m_ptrGame) ) {
Log.e( TAG, "finalize(): called prematurely: refCount: %d"
+ "; ptr: %d; creator: %s", m_refCount, m_ptrGame, mStack );
}
super.finalize();
}
}
private static XwJNI s_JNI = null; private static XwJNI s_JNI = null;
private static synchronized XwJNI getJNI() private static synchronized XwJNI getJNI()
@ -559,5 +590,6 @@ public class XwJNI {
String fromPhone, String fromPhone,
int wantPort); int wantPort);
// This always returns true on release builds now.
private static native boolean haveEnv( long jniState ); private static native boolean haveEnv( long jniState );
} }

View file

@ -116,9 +116,9 @@ releaseMPool( JNIGlobalState* globalState )
#define GAMEPTR_IS_OBJECT #define GAMEPTR_IS_OBJECT
#ifdef GAMEPTR_IS_OBJECT #ifdef GAMEPTR_IS_OBJECT
typedef jobject GamePtrType; typedef jobject PtrType;
#else #else
typedef long GamePtrType; typedef long PtrType;
#endif #endif
#ifdef LOG_MAPPING #ifdef LOG_MAPPING
@ -347,8 +347,8 @@ tilesArrayToTileSet( JNIEnv* env, jintArray jtiles, TrayTileSet* tset )
} }
#ifdef GAMEPTR_IS_OBJECT #ifdef GAMEPTR_IS_OBJECT
static JNIState* static void*
getState( JNIEnv* env, GamePtrType gamePtr, const char* func ) getState( JNIEnv* env, PtrType gamePtr, const char* func )
{ {
#ifdef DEBUG #ifdef DEBUG
if ( NULL == gamePtr ) { if ( NULL == gamePtr ) {
@ -359,7 +359,7 @@ getState( JNIEnv* env, GamePtrType gamePtr, const char* func )
XP_ASSERT( NULL != gamePtr ); /* fired */ XP_ASSERT( NULL != gamePtr ); /* fired */
jmethodID mid = getMethodID( env, gamePtr, "ptr", "()J" ); jmethodID mid = getMethodID( env, gamePtr, "ptr", "()J" );
XP_ASSERT( !!mid ); XP_ASSERT( !!mid );
return (JNIState*)(*env)->CallLongMethod( env, gamePtr, mid ); return (void*)(*env)->CallLongMethod( env, gamePtr, mid );
} }
#else #else
# define getState( env, gamePtr, func ) ((JNIState*)(gamePtr)) # define getState( env, gamePtr, func ) ((JNIState*)(gamePtr))
@ -977,12 +977,15 @@ struct _JNIState {
XP_U16 lastSavedSize; XP_U16 lastSavedSize;
#ifdef DEBUG #ifdef DEBUG
const char* envSetterFunc; const char* envSetterFunc;
XP_U32 guard;
#endif #endif
MPSLOT MPSLOT
}; };
#define GAME_GUARD 0x453627
#define XWJNI_START() { \ #define XWJNI_START() { \
JNIState* state = getState( env, gamePtr, __func__ ); \ JNIState* state = getState( env, gamePtr, __func__ ); \
XP_ASSERT( state->guard == GAME_GUARD ); \
MPSLOT; \ MPSLOT; \
MPASSIGN( mpool, state->mpool ); \ MPASSIGN( mpool, state->mpool ); \
XP_ASSERT( !!state->globalJNI ); \ XP_ASSERT( !!state->globalJNI ); \
@ -1003,6 +1006,9 @@ Java_org_eehouse_android_xw4_jni_XwJNI_initGameJNI
MemPoolCtx* mpool = ((JNIGlobalState*)jniGlobalPtr)->mpool; MemPoolCtx* mpool = ((JNIGlobalState*)jniGlobalPtr)->mpool;
#endif #endif
JNIState* state = (JNIState*)XP_CALLOC( mpool, sizeof(*state) ); JNIState* state = (JNIState*)XP_CALLOC( mpool, sizeof(*state) );
#ifdef DEBUG
state->guard = GAME_GUARD;
#endif
state->globalJNI = (JNIGlobalState*)jniGlobalPtr; state->globalJNI = (JNIGlobalState*)jniGlobalPtr;
MAP_THREAD( &state->globalJNI->ti, env ); MAP_THREAD( &state->globalJNI->ti, env );
AndGameGlobals* globals = &state->globals; AndGameGlobals* globals = &state->globals;
@ -1030,7 +1036,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_envDone
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject j_gi, ( JNIEnv* env, jclass C, PtrType gamePtr, jobject j_gi,
jobjectArray j_names, jobjectArray j_dicts, jobjectArray j_paths, jobjectArray j_names, jobjectArray j_dicts, jobjectArray j_paths,
jstring j_lang, jobject j_util, jobject j_draw, jobject j_cp, jstring j_lang, jobject j_util, jobject j_draw, jobject j_cp,
jobject j_procs ) jobject j_procs )
@ -1079,9 +1085,10 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
} /* makeNewGame */ } /* makeNewGame */
JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose
( JNIEnv* env, jclass claz, GamePtrType gamePtr ) ( JNIEnv* env, jclass claz, PtrType gamePtr )
{ {
JNIState* state = getState( env, gamePtr, __func__ ); JNIState* state = getState( env, gamePtr, __func__ );
XP_ASSERT( state->guard == GAME_GUARD );
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
MemPoolCtx* mpool = state->mpool; MemPoolCtx* mpool = state->mpool;
@ -1099,12 +1106,15 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose
MAP_REMOVE( &state->globalJNI->ti, env ); MAP_REMOVE( &state->globalJNI->ti, env );
#ifdef DEBUG
XP_MEMSET( state, -1, sizeof(*state) );
#endif
XP_FREE( mpool, state ); XP_FREE( mpool, state );
} /* game_dispose */ } /* game_dispose */
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
( JNIEnv* env, jclass C, GamePtrType gamePtr, jbyteArray jstream, jobject /*out*/jgi, ( JNIEnv* env, jclass C, PtrType gamePtr, jbyteArray jstream, jobject /*out*/jgi,
jobjectArray jdictNames, jobjectArray jdicts, jobjectArray jpaths, jobjectArray jdictNames, jobjectArray jdicts, jobjectArray jpaths,
jstring jlang, jobject jutil, jobject jdraw, jobject jcp, jobject jprocs ) jstring jlang, jobject jutil, jobject jdraw, jobject jcp, jobject jprocs )
{ {
@ -1161,7 +1171,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
JNIEXPORT jbyteArray JNICALL JNIEXPORT jbyteArray JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveToStream Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveToStream
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jgi ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jgi )
{ {
jbyteArray result; jbyteArray result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1191,7 +1201,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveToStream
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveSucceeded Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveSucceeded
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
game_saveSucceeded( &state->game, env, state->curSaveCount ); game_saveSucceeded( &state->game, env, state->curSaveCount );
@ -1200,7 +1210,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveSucceeded
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setDraw Java_org_eehouse_android_xw4_jni_XwJNI_board_1setDraw
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jdraw ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jdraw )
{ {
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1215,7 +1225,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setDraw
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1invalAll Java_org_eehouse_android_xw4_jni_XwJNI_board_1invalAll
( JNIEnv *env, jclass C, GamePtrType gamePtr ) ( JNIEnv *env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
board_invalAll( state->game.board ); board_invalAll( state->game.board );
@ -1224,7 +1234,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1invalAll
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1draw Java_org_eehouse_android_xw4_jni_XwJNI_board_1draw
( JNIEnv *env, jclass C, GamePtrType gamePtr ) ( JNIEnv *env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1235,7 +1245,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1draw
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1drawSnapshot Java_org_eehouse_android_xw4_jni_XwJNI_board_1drawSnapshot
( JNIEnv *env, jclass C, GamePtrType gamePtr, jobject jdraw, jint width, ( JNIEnv *env, jclass C, PtrType gamePtr, jobject jdraw, jint width,
jint height ) jint height )
{ {
XWJNI_START(); XWJNI_START();
@ -1248,7 +1258,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1drawSnapshot
#ifdef COMMON_LAYOUT #ifdef COMMON_LAYOUT
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1figureLayout Java_org_eehouse_android_xw4_jni_XwJNI_board_1figureLayout
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jgi, jint left, jint top, ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jgi, jint left, jint top,
jint width, jint height, jint scorePct, jint trayPct, jint scoreWidth, jint width, jint height, jint scorePct, jint trayPct, jint scoreWidth,
jint fontWidth, jint fontHt, jboolean squareTiles, jobject jdims ) jint fontWidth, jint fontHt, jboolean squareTiles, jobject jdims )
{ {
@ -1271,7 +1281,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1figureLayout
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1applyLayout Java_org_eehouse_android_xw4_jni_XwJNI_board_1applyLayout
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jdims ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jdims )
{ {
XWJNI_START(); XWJNI_START();
BoardDims dims; BoardDims dims;
@ -1284,7 +1294,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1applyLayout
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setPos Java_org_eehouse_android_xw4_jni_XwJNI_board_1setPos
(JNIEnv *env, jclass C, GamePtrType gamePtr, jint left, jint top, jint width, (JNIEnv *env, jclass C, PtrType gamePtr, jint left, jint top, jint width,
jint height, jint maxCellSize, jboolean lefty ) jint height, jint maxCellSize, jboolean lefty )
{ {
XWJNI_START(); XWJNI_START();
@ -1295,7 +1305,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setPos
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScoreboardLoc Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScoreboardLoc
( JNIEnv *env, jclass C, GamePtrType gamePtr, jint left, jint top, ( JNIEnv *env, jclass C, PtrType gamePtr, jint left, jint top,
jint width, jint height, jboolean divideHorizontally ) jint width, jint height, jboolean divideHorizontally )
{ {
XWJNI_START(); XWJNI_START();
@ -1306,7 +1316,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScoreboardLoc
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTrayLoc Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTrayLoc
( JNIEnv *env, jclass C, GamePtrType gamePtr, jint left, jint top, ( JNIEnv *env, jclass C, PtrType gamePtr, jint left, jint top,
jint width, jint height, jint minDividerWidth ) jint width, jint height, jint minDividerWidth )
{ {
XWJNI_START(); XWJNI_START();
@ -1318,7 +1328,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTrayLoc
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1zoom Java_org_eehouse_android_xw4_jni_XwJNI_board_1zoom
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint zoomBy, jbooleanArray jCanZoom ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint zoomBy, jbooleanArray jCanZoom )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1333,7 +1343,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1zoom
#ifdef XWFEATURE_ACTIVERECT #ifdef XWFEATURE_ACTIVERECT
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1getActiveRect Java_org_eehouse_android_xw4_jni_XwJNI_board_1getActiveRect
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jrect, jintArray dims ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jrect, jintArray dims )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1358,7 +1368,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1getActiveRect
#ifdef POINTER_SUPPORT #ifdef POINTER_SUPPORT
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenDown Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenDown
(JNIEnv *env, jclass C, GamePtrType gamePtr, jint xx, jint yy, jbooleanArray barray ) (JNIEnv *env, jclass C, PtrType gamePtr, jint xx, jint yy, jbooleanArray barray )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1370,7 +1380,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenDown
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenMove Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenMove
( JNIEnv *env, jclass C, GamePtrType gamePtr, jint xx, jint yy ) ( JNIEnv *env, jclass C, PtrType gamePtr, jint xx, jint yy )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1381,7 +1391,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenMove
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenUp Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenUp
( JNIEnv *env, jclass C, GamePtrType gamePtr, jint xx, jint yy ) ( JNIEnv *env, jclass C, PtrType gamePtr, jint xx, jint yy )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1392,7 +1402,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenUp
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1containsPt Java_org_eehouse_android_xw4_jni_XwJNI_board_1containsPt
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint xx, jint yy ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint xx, jint yy )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1404,7 +1414,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1containsPt
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1juggleTray Java_org_eehouse_android_xw4_jni_XwJNI_board_1juggleTray
(JNIEnv* env, jclass C, GamePtrType gamePtr ) (JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1415,7 +1425,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1juggleTray
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1getTrayVisState Java_org_eehouse_android_xw4_jni_XwJNI_board_1getTrayVisState
(JNIEnv* env, jclass C, GamePtrType gamePtr) (JNIEnv* env, jclass C, PtrType gamePtr)
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1426,7 +1436,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1getTrayVisState
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1getSelPlayer Java_org_eehouse_android_xw4_jni_XwJNI_board_1getSelPlayer
(JNIEnv* env, jclass C, GamePtrType gamePtr) (JNIEnv* env, jclass C, PtrType gamePtr)
{ {
jint result; jint result;
XWJNI_START(); XWJNI_START();
@ -1437,7 +1447,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1getSelPlayer
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1passwordProvided Java_org_eehouse_android_xw4_jni_XwJNI_board_1passwordProvided
(JNIEnv* env, jclass C, GamePtrType gamePtr, jint player, jstring jpasswd ) (JNIEnv* env, jclass C, PtrType gamePtr, jint player, jstring jpasswd )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1450,7 +1460,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1passwordProvided
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1hideTray Java_org_eehouse_android_xw4_jni_XwJNI_board_1hideTray
(JNIEnv* env, jclass C, GamePtrType gamePtr) (JNIEnv* env, jclass C, PtrType gamePtr)
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1461,7 +1471,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1hideTray
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1showTray Java_org_eehouse_android_xw4_jni_XwJNI_board_1showTray
(JNIEnv* env, jclass C, GamePtrType gamePtr) (JNIEnv* env, jclass C, PtrType gamePtr)
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1472,7 +1482,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1showTray
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1beginTrade Java_org_eehouse_android_xw4_jni_XwJNI_board_1beginTrade
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1483,7 +1493,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1beginTrade
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1endTrade Java_org_eehouse_android_xw4_jni_XwJNI_board_1endTrade
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1494,7 +1504,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1endTrade
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1setBlankValue Java_org_eehouse_android_xw4_jni_XwJNI_board_1setBlankValue
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint player, ( JNIEnv* env, jclass C, PtrType gamePtr, jint player,
jint col, jint row, jint tile ) jint col, jint row, jint tile )
{ {
jboolean result; jboolean result;
@ -1506,7 +1516,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setBlankValue
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1toggle_1showValues Java_org_eehouse_android_xw4_jni_XwJNI_board_1toggle_1showValues
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1517,7 +1527,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1toggle_1showValues
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1commitTurn Java_org_eehouse_android_xw4_jni_XwJNI_board_1commitTurn
( JNIEnv* env, jclass C, GamePtrType gamePtr, jboolean phoniesConfirmed, ( JNIEnv* env, jclass C, PtrType gamePtr, jboolean phoniesConfirmed,
jboolean turnConfirmed, jintArray jNewTiles ) jboolean turnConfirmed, jintArray jNewTiles )
{ {
jboolean result; jboolean result;
@ -1538,7 +1548,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1commitTurn
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1flip Java_org_eehouse_android_xw4_jni_XwJNI_board_1flip
(JNIEnv* env, jclass C, GamePtrType gamePtr) (JNIEnv* env, jclass C, PtrType gamePtr)
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1549,7 +1559,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1flip
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1replaceTiles Java_org_eehouse_android_xw4_jni_XwJNI_board_1replaceTiles
(JNIEnv* env, jclass C, GamePtrType gamePtr) (JNIEnv* env, jclass C, PtrType gamePtr)
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1560,7 +1570,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1replaceTiles
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1redoReplacedTiles Java_org_eehouse_android_xw4_jni_XwJNI_board_1redoReplacedTiles
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1571,7 +1581,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1redoReplacedTiles
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1reset Java_org_eehouse_android_xw4_jni_XwJNI_server_1reset
(JNIEnv* env, jclass C, GamePtrType gamePtr ) (JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
server_reset( state->game.server, env, state->game.comms ); server_reset( state->game.server, env, state->game.comms );
@ -1580,7 +1590,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1reset
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1handleUndo Java_org_eehouse_android_xw4_jni_XwJNI_server_1handleUndo
(JNIEnv* env, jclass C, GamePtrType gamePtr) (JNIEnv* env, jclass C, PtrType gamePtr)
{ {
XWJNI_START(); XWJNI_START();
server_handleUndo( state->game.server, env, 0 ); server_handleUndo( state->game.server, env, 0 );
@ -1589,7 +1599,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1handleUndo
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1do Java_org_eehouse_android_xw4_jni_XwJNI_server_1do
(JNIEnv* env, jclass C, GamePtrType gamePtr ) (JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1601,7 +1611,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1do
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1tilesPicked Java_org_eehouse_android_xw4_jni_XwJNI_server_1tilesPicked
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint player, jintArray jNewTiles ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint player, jintArray jNewTiles )
{ {
XWJNI_START(); XWJNI_START();
TrayTileSet newTiles; TrayTileSet newTiles;
@ -1612,7 +1622,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1tilesPicked
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1countTilesInPool Java_org_eehouse_android_xw4_jni_XwJNI_server_1countTilesInPool
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jint result; jint result;
XWJNI_START(); XWJNI_START();
@ -1623,7 +1633,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1countTilesInPool
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1resetEngine Java_org_eehouse_android_xw4_jni_XwJNI_board_1resetEngine
(JNIEnv* env, jclass C, GamePtrType gamePtr ) (JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
board_resetEngine( state->game.board ); board_resetEngine( state->game.board );
@ -1632,7 +1642,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1resetEngine
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1requestHint Java_org_eehouse_android_xw4_jni_XwJNI_board_1requestHint
( JNIEnv* env, jclass C, GamePtrType gamePtr, jboolean useLimits, ( JNIEnv* env, jclass C, PtrType gamePtr, jboolean useLimits,
jboolean goBack, jbooleanArray workRemains ) jboolean goBack, jbooleanArray workRemains )
{ {
jboolean result; jboolean result;
@ -1654,7 +1664,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1requestHint
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_timerFired Java_org_eehouse_android_xw4_jni_XwJNI_timerFired
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint why, jint when, jint handle ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint why, jint when, jint handle )
{ {
jboolean result; jboolean result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1666,7 +1676,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_timerFired
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1formatRemainingTiles Java_org_eehouse_android_xw4_jni_XwJNI_board_1formatRemainingTiles
(JNIEnv* env, jclass C, GamePtrType gamePtr ) (JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jstring result; jstring result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1682,7 +1692,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1formatRemainingTiles
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1formatDictCounts Java_org_eehouse_android_xw4_jni_XwJNI_server_1formatDictCounts
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint nCols ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint nCols )
{ {
jstring result; jstring result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1696,7 +1706,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1formatDictCounts
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1getGameIsOver Java_org_eehouse_android_xw4_jni_XwJNI_server_1getGameIsOver
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -1707,7 +1717,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1getGameIsOver
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_model_1writeGameHistory Java_org_eehouse_android_xw4_jni_XwJNI_model_1writeGameHistory
( JNIEnv* env, jclass C, GamePtrType gamePtr, jboolean gameOver ) ( JNIEnv* env, jclass C, PtrType gamePtr, jboolean gameOver )
{ {
jstring result; jstring result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1722,7 +1732,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_model_1writeGameHistory
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_model_1getNMoves Java_org_eehouse_android_xw4_jni_XwJNI_model_1getNMoves
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jint result; jint result;
XWJNI_START(); XWJNI_START();
@ -1735,7 +1745,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_model_1getNMoves
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_model_1getNumTilesInTray Java_org_eehouse_android_xw4_jni_XwJNI_model_1getNumTilesInTray
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint player ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint player )
{ {
jint result; jint result;
XWJNI_START(); XWJNI_START();
@ -1747,7 +1757,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_model_1getNumTilesInTray
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_model_1getPlayersLastScore Java_org_eehouse_android_xw4_jni_XwJNI_model_1getPlayersLastScore
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint player, jobject jlmi ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint player, jobject jlmi )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( !!state->game.model ); XP_ASSERT( !!state->game.model );
@ -1768,7 +1778,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_model_1getPlayersLastScore
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1writeFinalScores Java_org_eehouse_android_xw4_jni_XwJNI_server_1writeFinalScores
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jstring result; jstring result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1792,7 +1802,7 @@ and_send_on_close( XWStreamCtxt* stream, XWEnv xwe, void* closure )
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1initClientConnection Java_org_eehouse_android_xw4_jni_XwJNI_server_1initClientConnection
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
LOG_FUNC(); LOG_FUNC();
@ -1807,7 +1817,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1initClientConnection
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1start Java_org_eehouse_android_xw4_jni_XwJNI_comms_1start
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
CommsCtxt* comms = state->game.comms; CommsCtxt* comms = state->game.comms;
@ -1819,7 +1829,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1start
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1stop Java_org_eehouse_android_xw4_jni_XwJNI_comms_1stop
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
CommsCtxt* comms = state->game.comms; CommsCtxt* comms = state->game.comms;
@ -1831,7 +1841,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1stop
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resetSame Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resetSame
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
if ( !!state->game.comms ) { if ( !!state->game.comms ) {
@ -1842,7 +1852,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resetSame
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddr Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddr
(JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jaddr ) (JNIEnv* env, jclass C, PtrType gamePtr, jobject jaddr )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( state->game.comms ); XP_ASSERT( state->game.comms );
@ -1854,7 +1864,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddr
JNIEXPORT jobjectArray JNICALL JNIEXPORT jobjectArray JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jobjectArray result = NULL; jobjectArray result = NULL;
XWJNI_START(); XWJNI_START();
@ -1882,7 +1892,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1augmentHostAddr Java_org_eehouse_android_xw4_jni_XwJNI_comms_1augmentHostAddr
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jaddr ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jaddr )
{ {
XWJNI_START(); XWJNI_START();
if ( state->game.comms ) { if ( state->game.comms ) {
@ -1897,7 +1907,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1augmentHostAddr
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage
( JNIEnv* env, jclass C, GamePtrType gamePtr, jbyteArray jstream, jobject jaddr ) ( JNIEnv* env, jclass C, PtrType gamePtr, jbyteArray jstream, jobject jaddr )
{ {
jboolean result; jboolean result;
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -1922,7 +1932,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jsummary ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jsummary )
{ {
XWJNI_START(); XWJNI_START();
ModelCtxt* model = state->game.model; ModelCtxt* model = state->game.model;
@ -2016,7 +2026,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1server_1prefsChanged Java_org_eehouse_android_xw4_jni_XwJNI_board_1server_1prefsChanged
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jcp ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jcp )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -2034,7 +2044,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1server_1prefsChanged
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1getFocusOwner Java_org_eehouse_android_xw4_jni_XwJNI_board_1getFocusOwner
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jint result; jint result;
XWJNI_START(); XWJNI_START();
@ -2045,7 +2055,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1getFocusOwner
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1focusChanged Java_org_eehouse_android_xw4_jni_XwJNI_board_1focusChanged
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint typ ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint typ )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -2058,7 +2068,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1focusChanged
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handleKey Java_org_eehouse_android_xw4_jni_XwJNI_board_1handleKey
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jkey, jboolean jup, ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jkey, jboolean jup,
jbooleanArray jhandled ) jbooleanArray jhandled )
{ {
jboolean result; jboolean result;
@ -2080,7 +2090,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1handleKey
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1getGi Java_org_eehouse_android_xw4_jni_XwJNI_game_1getGi
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jgi ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jgi )
{ {
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
setJGI( env, jgi, globals->gi ); setJGI( env, jgi, globals->gi );
@ -2109,7 +2119,7 @@ static const SetInfo gsi_bools[] = {
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jgsi ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jgsi )
{ {
XWJNI_START(); XWJNI_START();
GameStateInfo info; GameStateInfo info;
@ -2123,7 +2133,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1hasComms Java_org_eehouse_android_xw4_jni_XwJNI_game_1hasComms
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -2135,7 +2145,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1hasComms
#ifdef XWFEATURE_CHANGEDICT #ifdef XWFEATURE_CHANGEDICT
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1changeDict Java_org_eehouse_android_xw4_jni_XwJNI_game_1changeDict
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jgi, jstring jname, ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jgi, jstring jname,
jbyteArray jDictBytes, jstring jpath ) jbyteArray jDictBytes, jstring jpath )
{ {
XWJNI_START_GLOBALS(); XWJNI_START_GLOBALS();
@ -2154,7 +2164,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1changeDict
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resendAll Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resendAll
( JNIEnv* env, jclass C, GamePtrType gamePtr, jboolean force, jobject jFilter, ( JNIEnv* env, jclass C, PtrType gamePtr, jboolean force, jobject jFilter,
jboolean thenAck ) jboolean thenAck )
{ {
jint result; jint result;
@ -2194,7 +2204,7 @@ onGotOne( void* closure, XWEnv xwe, XP_U8* msg, XP_U16 len, MsgID XP_UNUSED(msgI
JNIEXPORT jobjectArray JNICALL JNIEXPORT jobjectArray JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getPending Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getPending
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jobjectArray result = NULL; jobjectArray result = NULL;
XWJNI_START(); XWJNI_START();
@ -2215,7 +2225,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getPending
#ifdef XWFEATURE_COMMSACK #ifdef XWFEATURE_COMMSACK
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1ackAny Java_org_eehouse_android_xw4_jni_XwJNI_comms_1ackAny
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( !!state->game.comms ); XP_ASSERT( !!state->game.comms );
@ -2226,7 +2236,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1ackAny
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1transportFailed Java_org_eehouse_android_xw4_jni_XwJNI_comms_1transportFailed
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject failedTyp ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject failedTyp )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( !!state->game.comms ); XP_ASSERT( !!state->game.comms );
@ -2238,7 +2248,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1transportFailed
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1isConnected Java_org_eehouse_android_xw4_jni_XwJNI_comms_1isConnected
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jboolean result; jboolean result;
XWJNI_START(); XWJNI_START();
@ -2249,7 +2259,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1isConnected
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1formatRelayID Java_org_eehouse_android_xw4_jni_XwJNI_comms_1formatRelayID
( JNIEnv* env, jclass C, GamePtrType gamePtr, jint indx ) ( JNIEnv* env, jclass C, PtrType gamePtr, jint indx )
{ {
jstring result = NULL; jstring result = NULL;
XWJNI_START(); XWJNI_START();
@ -2268,7 +2278,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1formatRelayID
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getStats Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getStats
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
jstring result = NULL; jstring result = NULL;
#ifdef DEBUG #ifdef DEBUG
@ -2287,7 +2297,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getStats
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1dropHostAddr Java_org_eehouse_android_xw4_jni_XwJNI_comms_1dropHostAddr
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jConnTyp ) ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jConnTyp )
{ {
LOG_FUNC(); LOG_FUNC();
XWJNI_START(); XWJNI_START();
@ -2302,7 +2312,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1dropHostAddr
#ifdef DEBUG #ifdef DEBUG
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1setAddrDisabled Java_org_eehouse_android_xw4_jni_XwJNI_comms_1setAddrDisabled
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jConnTyp, ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jConnTyp,
jboolean forSend, jboolean val ) jboolean forSend, jboolean val )
{ {
XWJNI_START(); XWJNI_START();
@ -2316,7 +2326,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1setAddrDisabled
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrDisabled Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrDisabled
( JNIEnv* env, jclass C, GamePtrType gamePtr, jobject jConnTyp, ( JNIEnv* env, jclass C, PtrType gamePtr, jobject jConnTyp,
jboolean forSend ) jboolean forSend )
{ {
jboolean result = XP_FALSE; jboolean result = XP_FALSE;
@ -2345,7 +2355,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_haveEnv
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_server_1endGame Java_org_eehouse_android_xw4_jni_XwJNI_server_1endGame
( JNIEnv* env, jclass C, GamePtrType gamePtr ) ( JNIEnv* env, jclass C, PtrType gamePtr )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( !!state->game.server ); XP_ASSERT( !!state->game.server );
@ -2354,7 +2364,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1endGame
} }
JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_board_1pause JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_board_1pause
( JNIEnv* env, jclass C, GamePtrType gamePtr, jstring jmsg ) ( JNIEnv* env, jclass C, PtrType gamePtr, jstring jmsg )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( !!state->game.board ); XP_ASSERT( !!state->game.board );
@ -2367,7 +2377,7 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_board_1pause
} }
JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_board_1unpause JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_board_1unpause
( JNIEnv* env, jclass C, GamePtrType gamePtr, jstring jmsg ) ( JNIEnv* env, jclass C, PtrType gamePtr, jstring jmsg )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( !!state->game.board ); XP_ASSERT( !!state->game.board );
@ -2380,7 +2390,7 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_board_1unpause
#ifdef XWFEATURE_CHAT #ifdef XWFEATURE_CHAT
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1sendChat Java_org_eehouse_android_xw4_jni_XwJNI_board_1sendChat
( JNIEnv* env, jclass C, GamePtrType gamePtr, jstring jmsg ) ( JNIEnv* env, jclass C, PtrType gamePtr, jstring jmsg )
{ {
XWJNI_START(); XWJNI_START();
XP_ASSERT( !!state->game.server ); XP_ASSERT( !!state->game.server );
@ -2402,13 +2412,14 @@ typedef struct _DictIterData {
DictIter iter; DictIter iter;
IndexData idata; IndexData idata;
XP_U16 depth; XP_U16 depth;
#ifdef MEM_DEBUG #ifdef DEBUG
MemPoolCtx* mpool; XP_U32 guard;
#endif #endif
} DictIterData; } DictIterData;
static void makeIndex( DictIterData* data ); static void makeIndex( DictIterData* data );
static void freeIndices( DictIterData* data ); static void freeIndices( DictIterData* data );
#define GI_GUARD 0x89ab72
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_di_1init Java_org_eehouse_android_xw4_jni_XwJNI_di_1init
@ -2428,34 +2439,43 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1init
data->globalState = globalState; data->globalState = globalState;
data->dict = dict; data->dict = dict;
data->depth = 2; data->depth = 2;
#ifdef MEM_DEBUG #ifdef DEBUG
data->mpool = globalState->mpool; data->guard = GI_GUARD;
#endif #endif
closure = (jlong)data; closure = (jlong)data;
} }
return closure; return closure;
} }
#define DI_HEADER() { \
DictIterData* data = (DictIterData*)closure; \
XP_ASSERT( NULL == data || data->guard == GI_GUARD ); \
#define DI_HEADER_END() \
}
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_di_1setMinMax Java_org_eehouse_android_xw4_jni_XwJNI_di_1setMinMax
( JNIEnv* env, jclass C, jlong closure, jint min, jint max ) ( JNIEnv* env, jclass C, jlong closure, jint min, jint max )
{ {
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data ) { if ( NULL != data ) {
di_initIter( &data->iter, data->dict, min, max ); di_initIter( &data->iter, data->dict, min, max );
makeIndex( data ); makeIndex( data );
(void)di_firstWord( &data->iter ); (void)di_firstWord( &data->iter );
} }
DI_HEADER_END();
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_di_1destroy Java_org_eehouse_android_xw4_jni_XwJNI_di_1destroy
( JNIEnv* env, jclass C, jlong closure ) ( JNIEnv* env, jclass C, jlong closure )
{ {
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data ) { if ( NULL != data ) {
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
MemPoolCtx* mpool = data->mpool; MemPoolCtx* mpool = data->globalState->mpool;
#endif #endif
dict_unref( data->dict, env ); dict_unref( data->dict, env );
freeIndices( data ); freeIndices( data );
@ -2464,6 +2484,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1destroy
XP_FREE( mpool, data ); XP_FREE( mpool, data );
} }
DI_HEADER_END();
} }
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
@ -2471,10 +2492,11 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1wordCount
(JNIEnv* env, jclass C, jlong closure ) (JNIEnv* env, jclass C, jlong closure )
{ {
jint result = 0; jint result = 0;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data ) { if ( NULL != data ) {
result = data->iter.nWords; result = data->iter.nWords;
} }
DI_HEADER_END();
return result; return result;
} }
@ -2483,7 +2505,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getCounts
(JNIEnv* env, jclass C, jlong closure ) (JNIEnv* env, jclass C, jlong closure )
{ {
jintArray result = NULL; jintArray result = NULL;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data ) { if ( NULL != data ) {
DictIter iter; DictIter iter;
di_initIter( &iter, data->dict, 0, MAX_COLS_DICT ); di_initIter( &iter, data->dict, 0, MAX_COLS_DICT );
@ -2495,6 +2517,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getCounts
sizeof(lens.lens[0]) ); sizeof(lens.lens[0]) );
} }
} }
DI_HEADER_END();
return result; return result;
} }
@ -2503,7 +2526,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getPrefixes
( JNIEnv* env, jclass C, jlong closure ) ( JNIEnv* env, jclass C, jlong closure )
{ {
jobjectArray result = NULL; jobjectArray result = NULL;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data && NULL != data->idata.prefixes ) { if ( NULL != data && NULL != data->idata.prefixes ) {
result = makeStringArray( env, data->idata.count, NULL ); result = makeStringArray( env, data->idata.count, NULL );
@ -2518,6 +2541,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getPrefixes
deleteLocalRef( env, jstr ); deleteLocalRef( env, jstr );
} }
} }
DI_HEADER_END();
return result; return result;
} }
@ -2526,7 +2550,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getIndices
( JNIEnv* env, jclass C, jlong closure ) ( JNIEnv* env, jclass C, jlong closure )
{ {
jintArray jindices = NULL; jintArray jindices = NULL;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data ) { if ( NULL != data ) {
XP_ASSERT( !!data->idata.indices ); XP_ASSERT( !!data->idata.indices );
XP_ASSERT( sizeof(jint) == sizeof(data->idata.indices[0]) ); XP_ASSERT( sizeof(jint) == sizeof(data->idata.indices[0]) );
@ -2534,6 +2558,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getIndices
(jint*)data->idata.indices, (jint*)data->idata.indices,
sizeof(data->idata.indices[0]) ); sizeof(data->idata.indices[0]) );
} }
DI_HEADER_END();
return jindices; return jindices;
} }
@ -2542,7 +2567,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1nthWord
( JNIEnv* env, jclass C, jlong closure, jint nn, jstring jdelim ) ( JNIEnv* env, jclass C, jlong closure, jint nn, jstring jdelim )
{ {
jstring result = NULL; jstring result = NULL;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data ) { if ( NULL != data ) {
if ( di_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) { if ( di_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) {
XP_UCHAR buf[64]; XP_UCHAR buf[64];
@ -2555,6 +2580,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1nthWord
} }
} }
} }
DI_HEADER_END();
return result; return result;
} }
@ -2578,7 +2604,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1strToTiles
( JNIEnv* env, jclass C, jlong closure, jstring jstr ) ( JNIEnv* env, jclass C, jlong closure, jstring jstr )
{ {
jobjectArray result = NULL; jobjectArray result = NULL;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
const char* str = (*env)->GetStringUTFChars( env, jstr, NULL ); const char* str = (*env)->GetStringUTFChars( env, jstr, NULL );
FTData ftd = { .env = env, }; FTData ftd = { .env = env, };
@ -2593,7 +2619,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1strToTiles
} }
(*env)->ReleaseStringUTFChars( env, jstr, str ); (*env)->ReleaseStringUTFChars( env, jstr, str );
DI_HEADER_END();
return result; return result;
} }
@ -2602,7 +2628,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getStartsWith
( JNIEnv* env, jclass C, jlong closure, jbyteArray jtiles ) ( JNIEnv* env, jclass C, jlong closure, jbyteArray jtiles )
{ {
jint result = -1; jint result = -1;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
XP_U16 nTiles = (*env)->GetArrayLength( env, jtiles ); XP_U16 nTiles = (*env)->GetArrayLength( env, jtiles );
jbyte* tiles = (*env)->GetByteArrayElements( env, jtiles, NULL ); jbyte* tiles = (*env)->GetByteArrayElements( env, jtiles, NULL );
@ -2611,7 +2637,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getStartsWith
} }
(*env)->ReleaseByteArrayElements( env, jtiles, tiles, 0 ); (*env)->ReleaseByteArrayElements( env, jtiles, tiles, 0 );
DI_HEADER_END();
return result; return result;
} }
@ -2620,13 +2646,12 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1tilesToStr
( JNIEnv* env, jclass C, jlong closure, jbyteArray jtiles, jstring jdelim ) ( JNIEnv* env, jclass C, jlong closure, jbyteArray jtiles, jstring jdelim )
{ {
jstring result = NULL; jstring result = NULL;
DI_HEADER();
XP_UCHAR buf[64]; XP_UCHAR buf[64];
const XP_UCHAR* delim = NULL; const XP_UCHAR* delim = NULL;
if ( !!jdelim ) { if ( !!jdelim ) {
delim = (*env)->GetStringUTFChars( env, jdelim, NULL ); delim = (*env)->GetStringUTFChars( env, jdelim, NULL );
} }
DictIterData* data = (DictIterData*)closure;
XP_U16 nTiles = (*env)->GetArrayLength( env, jtiles ); XP_U16 nTiles = (*env)->GetArrayLength( env, jtiles );
jbyte* tiles = (*env)->GetByteArrayElements( env, jtiles, NULL ); jbyte* tiles = (*env)->GetByteArrayElements( env, jtiles, NULL );
@ -2642,7 +2667,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1tilesToStr
(*env)->ReleaseStringUTFChars( env, jdelim, delim ); (*env)->ReleaseStringUTFChars( env, jdelim, delim );
} }
(*env)->ReleaseByteArrayElements( env, jtiles, tiles, 0 ); (*env)->ReleaseByteArrayElements( env, jtiles, tiles, 0 );
DI_HEADER_END();
return result; return result;
} }
@ -2651,13 +2676,14 @@ Java_org_eehouse_android_xw4_jni_XwJNI_di_1getDesc
( JNIEnv* env, jclass C, jlong closure ) ( JNIEnv* env, jclass C, jlong closure )
{ {
jstring result = NULL; jstring result = NULL;
DictIterData* data = (DictIterData*)closure; DI_HEADER();
if ( NULL != data ) { if ( NULL != data ) {
const XP_UCHAR* disc = dict_getDesc( data->dict ); const XP_UCHAR* disc = dict_getDesc( data->dict );
if ( NULL != disc && '\0' != disc[0] ) { if ( NULL != disc && '\0' != disc[0] ) {
result = (*env)->NewStringUTF( env, disc ); result = (*env)->NewStringUTF( env, disc );
} }
} }
DI_HEADER_END();
return result; return result;
} }
@ -2666,11 +2692,11 @@ freeIndices( DictIterData* data )
{ {
IndexData* idata = &data->idata; IndexData* idata = &data->idata;
if ( !!idata->prefixes ) { if ( !!idata->prefixes ) {
XP_FREE( data->mpool, idata->prefixes ); XP_FREE( data->globalState->mpool, idata->prefixes );
idata->prefixes = NULL; idata->prefixes = NULL;
} }
if( !!idata->indices ) { if( !!idata->indices ) {
XP_FREE( data->mpool, idata->indices ); XP_FREE( data->globalState->mpool, idata->indices );
idata->indices = NULL; idata->indices = NULL;
} }
} }
@ -2688,18 +2714,20 @@ makeIndex( DictIterData* data )
freeIndices( data ); freeIndices( data );
IndexData* idata = &data->idata; IndexData* idata = &data->idata;
idata->prefixes = XP_MALLOC( data->mpool, count * data->depth #ifdef MEM_DEBUG
MemPoolCtx* mpool = data->globalState->mpool;
#endif
idata->prefixes = XP_MALLOC( mpool, count * data->depth
* sizeof(*idata->prefixes) ); * sizeof(*idata->prefixes) );
idata->indices = XP_MALLOC( data->mpool, idata->indices = XP_MALLOC( mpool, count * sizeof(*idata->indices) );
count * sizeof(*idata->indices) );
idata->count = count; idata->count = count;
di_makeIndex( &data->iter, data->depth, idata ); di_makeIndex( &data->iter, data->depth, idata );
if ( 0 < idata->count ) { if ( 0 < idata->count ) {
idata->prefixes = XP_REALLOC( data->mpool, idata->prefixes, idata->prefixes = XP_REALLOC( mpool, idata->prefixes,
idata->count * data->depth * idata->count * data->depth *
sizeof(*idata->prefixes) ); sizeof(*idata->prefixes) );
idata->indices = XP_REALLOC( data->mpool, idata->indices, idata->indices = XP_REALLOC( mpool, idata->indices,
idata->count * sizeof(*idata->indices) ); idata->count * sizeof(*idata->indices) );
} else { } else {
freeIndices( data ); freeIndices( data );