turn on sanity checking of dicts in download directory, but from

DictLangCache rather than when the directory's walked initially.  Need
to test still with bogus dict and make sure it's never shown.
This commit is contained in:
Andy2 2011-11-10 19:02:18 -08:00
parent 9f22b11f81
commit 284bd2d0c4
6 changed files with 23 additions and 16 deletions

View file

@ -25,6 +25,7 @@ local_DEFINES += \
-DDISABLE_TILE_SEL \
-DXWFEATURE_BOARDWORDS \
-DXWFEATURE_WALKDICT \
-DXWFEATURE_DICTSANITY \
-DFEATURE_TRAY_EDIT \
-DNODE_CAN_4 \
-DRELAY_ROOM_DEFAULT=\"\"\

View file

@ -266,7 +266,8 @@ splitFaces_via_java( JNIEnv* env, AndDictionaryCtxt* ctxt, const XP_U8* ptr,
} /* splitFaces_via_java */
static XP_Bool
parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength )
parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength,
XP_U32* numEdges )
{
XP_Bool success = XP_TRUE;
XP_ASSERT( !!ptr );
@ -377,14 +378,13 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength )
dictLength -= sizeof(offset);
#ifdef NODE_CAN_4
XP_ASSERT( dictLength % ctxt->super.nodeSize == 0 );
# ifdef DEBUG
ctxt->super.numEdges = dictLength / ctxt->super.nodeSize;
# endif
*numEdges = dictLength / ctxt->super.nodeSize;
#else
XP_ASSERT( dictLength % 3 == 0 );
# ifdef DEBUG
ctxt->super.numEdges = dictLength / 3;
# endif
*numEdges = dictLength / 3;
#endif
#ifdef DEBUG
ctxt->super.numEdges = *numEdges;
#endif
} else {
offset = 0;
@ -502,7 +502,7 @@ makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
if ( NULL != jdict || NULL != jpath ) {
jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii );
dict = makeDict( MPPARM(mpool) env, jniutil, jname, jdict,
jpath, jlang );
jpath, jlang, false );
XP_ASSERT( !!dict );
(*env)->DeleteLocalRef( env, jdict );
(*env)->DeleteLocalRef( env, jname );
@ -522,7 +522,7 @@ makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
DictionaryCtxt*
makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jstring jname,
jbyteArray jbytes, jstring jpath, jstring jlangname )
jbyteArray jbytes, jstring jpath, jstring jlangname, jboolean check )
{
AndDictionaryCtxt* anddict = (AndDictionaryCtxt*)
and_dictionary_make_empty( MPPARM(mpool) env, jniutil );
@ -561,7 +561,10 @@ makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jstring jname,
anddict->super.name = getStringCopy( MPPARM(mpool) env, jname );
anddict->super.langName = getStringCopy( MPPARM(mpool) env, jlangname );
if ( !parseDict( anddict, (XP_U8*)anddict->bytes, len ) ) {
XP_U32 numEdges;
XP_Bool parses = parseDict( anddict, (XP_U8*)anddict->bytes,
len, &numEdges );
if ( !parses || (check && !checkSanity( anddict, numEdges ) ) ) {
and_dictionary_destroy( (DictionaryCtxt*)anddict );
anddict = NULL;
}

View file

@ -31,7 +31,7 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* bytes,
DictionaryCtxt* makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
jstring jname, jbyteArray bytes, jstring path,
jstring jlang );
jstring jlang, jboolean check );
void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil,
DictionaryCtxt** dict, PlayerDicts* dicts, jobjectArray jnames,

View file

@ -270,7 +270,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getInitialAddr
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
( JNIEnv* env, jclass C, jbyteArray jDictBytes, jstring jpath,
jobject jniu, jobject jinfo )
jobject jniu, jboolean check, jobject jinfo )
{
jboolean result = false;
#ifdef MEM_DEBUG
@ -278,7 +278,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
#endif
JNIUtilCtxt* jniutil = makeJNIUtil( MPPARM(mpool) &env, jniu );
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, jniutil, NULL,
jDictBytes, jpath, NULL );
jDictBytes, jpath, NULL, check );
if ( NULL != dict ) {
setInt( env, jinfo, "langCode", dict_getLangCode( dict ) );
setInt( env, jinfo, "wordCount", dict_getWordCount( dict ) );
@ -1289,7 +1289,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init
data->env = env;
JNIUtilCtxt* jniutil = makeJNIUtil( MPPARM(mpool) &data->env, jniu );
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, jniutil, NULL,
jDictBytes, jpath, NULL );
jDictBytes, jpath, NULL, false );
if ( !!dict ) {
data->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
data->jniutil = jniutil;

View file

@ -374,7 +374,9 @@ public class DictLangCache {
info = new DictInfo();
if ( XwJNI.dict_getInfo( pairs.m_bytes[0], pairs.m_paths[0],
JNIUtilsImpl.get(), info ) ) {
JNIUtilsImpl.get(),
DictUtils.DictLoc.DOWNLOAD == dal.loc,
info ) ) {
info.name = dal.name;
s_nameToLang.put( dal, info );

View file

@ -232,7 +232,8 @@ public class XwJNI {
public static native boolean dict_tilesAreSame( int dictPtr1, int dictPtr2 );
public static native String[] dict_getChars( int dictPtr );
public static native boolean dict_getInfo( byte[] dict, String path,
JNIUtils jniu, DictInfo info );
JNIUtils jniu, boolean check,
DictInfo info );
public static native int dict_getTileValue( int dictPtr, int tile );
// Dict iterator