Fix for bug 55140, r=brade, sr=ftang. Fix a stale pointer bug in unicode font mapping routines, by not using a global (which got stale), but using an inline getter instead.

git-svn-id: svn://10.0.0.236/branches/Netscape_20000922_BRANCH@80421 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sfraser%netscape.com
2000-10-05 04:06:53 +00:00
parent a0002de063
commit f234564c68
4 changed files with 15 additions and 12 deletions

View File

@@ -125,7 +125,6 @@ static PRBool FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *a
}
//--------------------------------------------------------------------------
nsUnicodeMappingUtil *nsUnicodeFontMappingMac::gUtil = nsnull;
nsUnicodeFontMappingCache *nsUnicodeFontMappingMac::gCache = nsnull;
//--------------------------------------------------------------------------
@@ -308,19 +307,21 @@ nsUnicodeFontMappingMac* nsUnicodeFontMappingMac::GetCachedInstance(
{
if(! gUtil)
gUtil = nsUnicodeMappingUtil::GetSingleton();
if(! gCache)
gCache = gUtil->GetFontMappingCache();
nsUnicodeFontMappingCache* fontMappingCache = gUtil->GetFontMappingCache();
NS_ASSERTION(fontMappingCache, "Should have a fontMappingCache here");
if (!fontMappingCache) return nsnull;
nsUnicodeFontMappingMac* obj = nsnull;
nsAutoString key(aFont->name);
key.AppendWithConversion(":");
key.Append(aLangGroup);
key.AppendWithConversion(":");
key.Append(aLANG);
if(! gCache->Get ( key, &obj )){
if(! fontMappingCache->Get ( key, &obj )){
obj = new nsUnicodeFontMappingMac(aFont, aDeviceContext, aLangGroup, aLANG);
if( obj )
gCache->Set ( key, obj);
fontMappingCache->Set ( key, obj);
}
NS_PRECONDITION(nsnull != obj, "out of memory");
return obj;

View File

@@ -57,7 +57,6 @@ private:
PRInt8 mPrivBlockToScript [kUnicodeBlockVarScriptMax] ;
short mScriptFallbackFontIDs [smPseudoTotalScripts] ;
static nsUnicodeMappingUtil* gUtil;
static nsUnicodeFontMappingCache* gCache;
};
#endif /* nsUnicodeFontMappingMac_h__ */

View File

@@ -59,7 +59,7 @@ void nsUnicodeMappingUtil::Init()
InitFromPref();
InitScriptFontMapping();
InitBlockToScriptMapping(); // this must be called after InitScriptEnabled()
gCache = new nsUnicodeFontMappingCache();
mCache = new nsUnicodeFontMappingCache();
++gUnicodeMappingUtilCount;
}
void nsUnicodeMappingUtil::CleanUp()
@@ -70,8 +70,11 @@ void nsUnicodeMappingUtil::CleanUp()
nsString::Recycle(mGenericFontMapping[i][j]);
}
}
if(gCache)
delete gCache;
if (mCache)
{
delete mCache;
mCache = nsnull;
}
}
//--------------------------------------------------------------------------

View File

@@ -69,7 +69,7 @@ public:
else
return mGenericFontMapping[aScript][aType];
}
inline nsUnicodeFontMappingCache* GetFontMappingCache() { return gCache; };
inline nsUnicodeFontMappingCache* GetFontMappingCache() { return mCache; };
ScriptCode MapLangGroupToScriptCode(const char* aLangGroup);
static nsUnicodeMappingUtil* GetSingleton();
@@ -86,7 +86,7 @@ private:
PRUint32 mScriptEnabled;
short mScriptFontMapping[smPseudoTotalScripts];
PRInt8 mBlockToScriptMapping[kUnicodeBlockSize];
nsUnicodeFontMappingCache* gCache;
nsUnicodeFontMappingCache* mCache;
static nsUnicodeMappingUtil* gSingleton;