VirtualBox

Changeset 32718 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Sep 23, 2010 12:57:52 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
66148
Message:

com/string: Remove bool conversion operator and other convenience error operators. They are hiding programming errors (like incorrect empty string checks, and in one case a free of the wrong pointer).

Location:
trunk/src/VBox/Main/glue
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/ErrorInfo.cpp

    r30739 r32718  
    77
    88/*
    9  * Copyright (C) 2006-2007 Oracle Corporation
     9 * Copyright (C) 2006-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 */
    1919
    20 #if !defined (VBOX_WITH_XPCOM)
    21 #else
    22  #include <nsIServiceManager.h>
    23  #include <nsIExceptionService.h>
    24  #include <nsCOMPtr.h>
     20#if defined(VBOX_WITH_XPCOM)
     21# include <nsIServiceManager.h>
     22# include <nsIExceptionService.h>
     23# include <nsCOMPtr.h>
    2524#endif
    2625
     
    9291    HRESULT rc = E_FAIL;
    9392
    94 #if !defined (VBOX_WITH_XPCOM)
     93#if !defined(VBOX_WITH_XPCOM)
    9594
    9695    ComPtr<IErrorInfo> err;
    97     rc = ::GetErrorInfo (0, err.asOutParam());
     96    rc = ::GetErrorInfo(0, err.asOutParam());
    9897    if (rc == S_OK && err)
    9998    {
     
    104103        rc = err.queryInterfaceTo(info.asOutParam());
    105104        if (SUCCEEDED(rc) && info)
    106             init (info);
     105            init(info);
    107106
    108107        if (!mIsFullAvailable)
     
    110109            bool gotSomething = false;
    111110
    112             rc = err->GetGUID (mInterfaceID.asOutParam());
     111            rc = err->GetGUID(mInterfaceID.asOutParam());
    113112            gotSomething |= SUCCEEDED(rc);
    114113            if (SUCCEEDED(rc))
    115                 GetInterfaceNameByIID (mInterfaceID, mInterfaceName.asOutParam());
    116 
    117             rc = err->GetSource (mComponent.asOutParam());
     114                GetInterfaceNameByIID(mInterfaceID, mInterfaceName.asOutParam());
     115
     116            rc = err->GetSource(mComponent.asOutParam());
    118117            gotSomething |= SUCCEEDED(rc);
    119118
    120             rc = err->GetDescription (mText.asOutParam());
     119            rc = err->GetDescription(mText.asOutParam());
    121120            gotSomething |= SUCCEEDED(rc);
    122121
     
    124123                mIsBasicAvailable = true;
    125124
    126             AssertMsg (gotSomething, ("Nothing to fetch!\n"));
     125            AssertMsg(gotSomething, ("Nothing to fetch!\n"));
    127126        }
    128127    }
    129128
    130 #else // defined (VBOX_WITH_XPCOM)
     129#else // defined(VBOX_WITH_XPCOM)
    131130
    132131    nsCOMPtr<nsIExceptionService> es;
     
    135134    {
    136135        nsCOMPtr<nsIExceptionManager> em;
    137         rc = es->GetCurrentExceptionManager(getter_AddRefs (em));
     136        rc = es->GetCurrentExceptionManager(getter_AddRefs(em));
    138137        if (NS_SUCCEEDED(rc))
    139138        {
     
    148147                rc = ex.queryInterfaceTo(info.asOutParam());
    149148                if (NS_SUCCEEDED(rc) && info)
    150                     init (info);
     149                    init(info);
    151150
    152151                if (!mIsFullAvailable)
     
    163162                    {
    164163                        mText = Bstr(pszMsg);
    165                         nsMemory::Free(mText);
     164                        nsMemory::Free(pszMsg);
    166165                    }
    167166
     
    169168                        mIsBasicAvailable = true;
    170169
    171                     AssertMsg (gotSomething, ("Nothing to fetch!\n"));
     170                    AssertMsg(gotSomething, ("Nothing to fetch!\n"));
    172171                }
    173172
    174173                // set the exception to NULL (to emulate Win32 behavior)
    175                 em->SetCurrentException (NULL);
     174                em->SetCurrentException(NULL);
    176175
    177176                rc = NS_OK;
     
    183182        rc = NS_OK;
    184183
    185     AssertComRC (rc);
    186 
    187 #endif // defined (VBOX_WITH_XPCOM)
     184    AssertComRC(rc);
     185
     186#endif // defined(VBOX_WITH_XPCOM)
    188187}
    189188
     
    196195        return;
    197196
    198 #if !defined (VBOX_WITH_XPCOM)
     197#if !defined(VBOX_WITH_XPCOM)
    199198
    200199    ComPtr<IUnknown> iface = aI;
     
    203202    if (SUCCEEDED(rc))
    204203    {
    205         rc = serr->InterfaceSupportsErrorInfo (aIID);
     204        rc = serr->InterfaceSupportsErrorInfo(aIID);
    206205        if (SUCCEEDED(rc))
    207             init (aKeepObj);
     206            init(aKeepObj);
    208207    }
    209208
    210209#else
    211210
    212     init (aKeepObj);
     211    init(aKeepObj);
    213212
    214213#endif
     
    217216    {
    218217        mCalleeIID = aIID;
    219         GetInterfaceNameByIID (aIID, mCalleeName.asOutParam());
     218        GetInterfaceNameByIID(aIID, mCalleeName.asOutParam());
    220219    }
    221220}
     
    223222void ErrorInfo::init(IVirtualBoxErrorInfo *info)
    224223{
    225     AssertReturnVoid (info);
     224    AssertReturnVoid(info);
    226225
    227226    HRESULT rc = E_FAIL;
     
    230229    LONG lrc;
    231230
    232     rc = info->COMGETTER(ResultCode) (&lrc); mResultCode = lrc;
     231    rc = info->COMGETTER(ResultCode)(&lrc); mResultCode = lrc;
    233232    gotSomething |= SUCCEEDED(rc);
    234233    gotAll &= SUCCEEDED(rc);
    235234
    236235    Bstr iid;
    237     rc = info->COMGETTER(InterfaceID) (iid.asOutParam());
     236    rc = info->COMGETTER(InterfaceID)(iid.asOutParam());
    238237    gotSomething |= SUCCEEDED(rc);
    239238    gotAll &= SUCCEEDED(rc);
     
    241240    {
    242241        mInterfaceID = iid;
    243         GetInterfaceNameByIID (mInterfaceID, mInterfaceName.asOutParam());
    244     }
    245 
    246     rc = info->COMGETTER(Component) (mComponent.asOutParam());
    247     gotSomething |= SUCCEEDED(rc);
    248     gotAll &= SUCCEEDED(rc);
    249 
    250     rc = info->COMGETTER(Text) (mText.asOutParam());
     242        GetInterfaceNameByIID(mInterfaceID, mInterfaceName.asOutParam());
     243    }
     244
     245    rc = info->COMGETTER(Component)(mComponent.asOutParam());
     246    gotSomething |= SUCCEEDED(rc);
     247    gotAll &= SUCCEEDED(rc);
     248
     249    rc = info->COMGETTER(Text)(mText.asOutParam());
    251250    gotSomething |= SUCCEEDED(rc);
    252251    gotAll &= SUCCEEDED(rc);
     
    255254
    256255    ComPtr<IVirtualBoxErrorInfo> next;
    257     rc = info->COMGETTER(Next) (next.asOutParam());
     256    rc = info->COMGETTER(Next)(next.asOutParam());
    258257    if (SUCCEEDED(rc) && !next.isNull())
    259258    {
     
    270269    mIsFullAvailable = gotAll;
    271270
    272     AssertMsg (gotSomething, ("Nothing to fetch!\n"));
     271    AssertMsg(gotSomething, ("Nothing to fetch!\n"));
    273272}
    274273
     
    279278////////////////////////////////////////////////////////////////////////////////
    280279
    281 ProgressErrorInfo::ProgressErrorInfo (IProgress *progress) :
    282     ErrorInfo (false /* aDummy */)
     280ProgressErrorInfo::ProgressErrorInfo(IProgress *progress) :
     281    ErrorInfo(false /* aDummy */)
    283282{
    284283    Assert(progress);
     
    287286
    288287    ComPtr<IVirtualBoxErrorInfo> info;
    289     HRESULT rc = progress->COMGETTER(ErrorInfo) (info.asOutParam());
     288    HRESULT rc = progress->COMGETTER(ErrorInfo)(info.asOutParam());
    290289    if (SUCCEEDED(rc) && info)
    291         init (info);
     290        init(info);
    292291}
    293292
     
    305304    HRESULT rc = S_OK;
    306305
    307 #if !defined (VBOX_WITH_XPCOM)
     306#if !defined(VBOX_WITH_XPCOM)
    308307
    309308    ComPtr<IErrorInfo> err;
     
    311310    {
    312311        rc = mErrorInfo.queryInterfaceTo(err.asOutParam());
    313         AssertComRC (rc);
    314     }
    315     rc = ::SetErrorInfo (0, err);
    316 
    317 #else // !defined (VBOX_WITH_XPCOM)
     312        AssertComRC(rc);
     313    }
     314    rc = ::SetErrorInfo(0, err);
     315
     316#else // !defined(VBOX_WITH_XPCOM)
    318317
    319318    nsCOMPtr <nsIExceptionService> es;
    320     es = do_GetService (NS_EXCEPTIONSERVICE_CONTRACTID, &rc);
     319    es = do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID, &rc);
    321320    if (NS_SUCCEEDED(rc))
    322321    {
    323322        nsCOMPtr <nsIExceptionManager> em;
    324         rc = es->GetCurrentExceptionManager (getter_AddRefs (em));
     323        rc = es->GetCurrentExceptionManager(getter_AddRefs(em));
    325324        if (NS_SUCCEEDED(rc))
    326325        {
     
    329328            {
    330329                rc = mErrorInfo.queryInterfaceTo(ex.asOutParam());
    331                 AssertComRC (rc);
     330                AssertComRC(rc);
    332331            }
    333             rc = em->SetCurrentException (ex);
     332            rc = em->SetCurrentException(ex);
    334333        }
    335334    }
    336335
    337 #endif // !defined (VBOX_WITH_XPCOM)
     336#endif // !defined(VBOX_WITH_XPCOM)
    338337
    339338    if (SUCCEEDED(rc))
  • trunk/src/VBox/Main/glue/errorprint.cpp

    r30764 r32718  
    77
    88/*
    9  * Copyright (C) 2009 Oracle Corporation
     9 * Copyright (C) 2009-2010 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424
    2525#include <iprt/stream.h>
     26#include <iprt/message.h>
    2627#include <iprt/path.h>
    2728
     
    3132void GluePrintErrorInfo(com::ErrorInfo &info)
    3233{
    33     Utf8Str str = Utf8StrFmt("ERROR: %ls\n"
     34    Utf8Str str = Utf8StrFmt("%ls\n"
    3435                             "Details: code %Rhrc (0x%RX32), component %ls, interface %ls, callee %ls\n"
    3536                             ,
     
    4142                             info.getCalleeName().raw());
    4243    // print and log
    43     RTPrintf("%s", str.c_str());
    44     Log(("%s", str.c_str()));
     44    RTMsgError("%s", str.c_str());
     45    Log(("ERROR: %s", str.c_str()));
    4546}
    4647
     
    5556                                strFilename.c_str());
    5657    // print and log
    57     RTPrintf("%s", str.c_str());
     58    RTStrmPrintf(g_pStdErr, "%s", str.c_str());
    5859    Log(("%s", str.c_str()));
    5960}
     
    6162void GluePrintRCMessage(HRESULT rc)
    6263{
    63     Utf8Str str = Utf8StrFmt("ERROR: code %Rhra (extended info not available)\n", rc);
     64    Utf8Str str = Utf8StrFmt("Code %Rhra (extended info not available)\n", rc);
    6465    // print and log
    65     RTPrintf("%s", str.c_str());
    66     Log(("%s", str.c_str()));
     66    RTMsgError("%s", str.c_str());
     67    Log(("ERROR: %s", str.c_str()));
    6768}
    6869
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