VirtualBox

Changeset 92115 in vbox for trunk/src


Ignore:
Timestamp:
Oct 27, 2021 8:21:30 PM (3 years ago)
Author:
vboxsync
Message:

Main/NLS: Must check that pszSourceTls and pszTranslationTls aren't NULL. Use the simple RTTls functions. bugref:1909

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/VirtualBoxTranslator.cpp

    r92102 r92115  
    3737RTCRITSECTRW                VirtualBoxTranslator::s_instanceRwLock;
    3838VirtualBoxTranslator       *VirtualBoxTranslator::s_pInstance = NULL;
     39/** TLS index that points to the translated text. */
    3940static RTTLS                g_idxTlsTr = NIL_RTTLS;
     41/** TLS index that points to the original text. */
    4042static RTTLS                g_idxTlsSrc = NIL_RTTLS;
    4143
     
    5759    , m_hStrCache(NIL_RTSTRCACHE)
    5860{
    59     RTTlsAllocEx(&g_idxTlsTr, NULL);
    60     RTTlsAllocEx(&g_idxTlsSrc, NULL);
     61    g_idxTlsTr  = RTTlsAlloc();
     62    g_idxTlsSrc = RTTlsAlloc();
    6163    int rc = RTStrCacheCreate(&m_hStrCache, "API Translation");
    6264    m_rcCache = rc;
     
    6870VirtualBoxTranslator::~VirtualBoxTranslator()
    6971{
    70     if (g_idxTlsTr != NIL_RTTLS)
    71     {
    72         RTTlsFree(g_idxTlsTr);
    73         g_idxTlsTr = NIL_RTTLS;
    74     }
    75     if (g_idxTlsSrc != NIL_RTTLS)
    76     {
    77         RTTlsFree(g_idxTlsSrc);
    78         g_idxTlsSrc = NIL_RTTLS;
    79     }
     72    RTTlsFree(g_idxTlsTr);
     73    g_idxTlsTr = NIL_RTTLS;
     74    RTTlsFree(g_idxTlsSrc);
     75    g_idxTlsSrc = NIL_RTTLS;
    8076
    8177    m_pDefaultComponent = NULL;
     
    446442    const char *pszSafeSource  = NULL;
    447443    const char *pszTranslation = aComponent->pTranslator->translate(aContext, aSourceText, &pszSafeSource, aComment, aNum);
    448     if (pszSafeSource)
    449     {
    450         if (g_idxTlsSrc != NIL_RTTLS && g_idxTlsTr != NIL_RTTLS)
    451         {
    452             int vrc = RTTlsSet(g_idxTlsTr, (void*)pszTranslation);
    453             if (RT_SUCCESS(vrc))
    454                 vrc = RTTlsSet(g_idxTlsSrc, (void*)pszSafeSource);
    455             if (RT_FAILURE(vrc))
    456                 RTTlsSet(g_idxTlsTr, NULL);
    457         }
     444    if (pszSafeSource && g_idxTlsSrc != NIL_RTTLS && g_idxTlsTr != NIL_RTTLS)
     445    {
     446        RTTlsSet(g_idxTlsTr, (void *)pszTranslation);
     447        RTTlsSet(g_idxTlsSrc, (void *)pszSafeSource);
    458448    }
    459449
     
    470460        if (g_idxTlsSrc != NIL_RTTLS && g_idxTlsTr != NIL_RTTLS)
    471461        {
    472             const char *pszTranslationTls = NULL;
    473             const char *pszSourceTls = NULL;
    474             int vrc =RTTlsGetEx(g_idxTlsTr, (void**)&pszTranslationTls);
    475             if (   RT_SUCCESS(vrc)
     462            const char * const pszTranslationTls = (const char *)RTTlsGet(g_idxTlsTr);
     463            const char * const pszSourceTls      = (const char *)RTTlsGet(g_idxTlsSrc);
     464            if (   pszSourceTls      != NULL
     465                && pszTranslationTls != NULL
    476466                && (   pszTranslationTls == aTranslation
    477467                    || strcmp(pszTranslationTls, aTranslation) == 0))
    478             {
    479                 vrc = RTTlsGetEx(g_idxTlsSrc, (void**)&pszSourceTls);
    480                 if (RT_SUCCESS(vrc))
    481                     pszSource = pszSourceTls;
    482             }
     468                pszSource = pszSourceTls;
    483469        }
    484470        pCurInstance->release();
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette