VirtualBox

Changeset 101846 in vbox for trunk/src/libs/xpcom18a4


Ignore:
Timestamp:
Nov 6, 2023 9:34:26 AM (17 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159942
Message:

libs/xpcom: Little helper to query whether XPCOM was initialized to get rid of the hack in the python bindings abusing nsIThread for checking, bugref:10545

Location:
trunk/src/libs/xpcom18a4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/src/dllmain.cpp

    r59809 r101846  
    4747
    4848#include "PyXPCOM_std.h"
    49 #include <prthread.h>
    50 #include "nsIThread.h"
    5149#include "nsILocalFile.h"
    5250
     
    294292        static PRBool bHaveInitXPCOM = PR_FALSE;
    295293        if (!bHaveInitXPCOM) {
    296                 nsCOMPtr<nsIThread> thread_check;
    297                 // xpcom appears to assert if already initialized
    298                 // Is there an official way to determine this?
    299                 if (NS_FAILED(nsIThread::GetMainThread(getter_AddRefs(thread_check)))) {
     294
     295                if (!NS_IsXPCOMInitialized()) {
    300296                        // not already initialized.
    301 #ifdef XP_WIN
    302                         // On Windows, we need to locate the Mozilla bin
    303                         // directory.  This by using locating a Moz DLL we depend
    304                         // on, and assume it lives in that bin dir.  Different
    305                         // moz build types (eg, xulrunner, suite) package
    306                         // XPCOM itself differently - but all appear to require
    307                         // nspr4.dll - so this is what we use.
    308                         char landmark[MAX_PATH+1];
    309                         HMODULE hmod = GetModuleHandle("nspr4.dll");
    310                         if (hmod==NULL) {
    311                                 PyErr_SetString(PyExc_RuntimeError, "We dont appear to be linked against nspr4.dll.");
    312                                 return PR_FALSE;
    313                         }
    314                         GetModuleFileName(hmod, landmark, sizeof(landmark)/sizeof(landmark[0]));
    315                         char *end = landmark + (strlen(landmark)-1);
    316                         while (end > landmark && *end != '\\')
    317                                 end--;
    318                         if (end > landmark) *end = '\0';
    319 
    320                         nsCOMPtr<nsILocalFile> ns_bin_dir;
    321                         NS_ConvertASCIItoUCS2 strLandmark(landmark);
    322                         NS_NewLocalFile(strLandmark, PR_FALSE, getter_AddRefs(ns_bin_dir));
    323                         nsresult rv = NS_InitXPCOM2(nsnull, ns_bin_dir, nsnull);
    324 #else
    325297                        // Elsewhere, Mozilla can find it itself (we hope!)
    326298                        nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
    327 #endif // XP_WIN
    328299                        if (NS_FAILED(rv)) {
    329300                                PyErr_SetString(PyExc_RuntimeError, "The XPCOM subsystem could not be initialized");
  • trunk/src/libs/xpcom18a4/xpcom/build/nsXPCOM.h

    r11551 r101846  
    6868class nsITraceRefcnt;
    6969
     70#ifdef VBOX
     71/**
     72 * Checks whether XPCOM was initialized by a call to NS_InitXPCOM2().
     73 */
     74extern "C" NS_COM PRBool
     75NS_IsXPCOMInitialized(void);
     76#endif
     77
    7078/**
    7179 * Initialises XPCOM. You must call this method before proceeding
  • trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp

    r101837 r101846  
    310310nsIProperties     *gDirectoryService = NULL;
    311311PRBool gXPCOMShuttingDown = PR_FALSE;
     312#ifdef VBOX
     313static PRBool gXPCOMInitialized = PR_FALSE;
     314#endif
    312315
    313316// For each class that wishes to support nsIClassInfo, add a line like this
     
    469472}
    470473
     474#ifdef VBOX
     475PRBool NS_COM NS_IsXPCOMInitialized(void)
     476{
     477    return gXPCOMInitialized;
     478}
     479#endif
     480
    471481nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result,
    472482                             nsIFile* binDirectory)
     
    732742                                  NS_XPCOM_STARTUP_OBSERVER_ID);
    733743
     744#ifdef VBOX
     745    gXPCOMInitialized = PR_TRUE;
     746#endif
    734747    return NS_OK;
    735748}
     
    915928#endif
    916929
     930#ifdef VBOX
     931    gXPCOMInitialized = PR_FALSE;
     932#endif
    917933    return NS_OK;
    918934}
Note: See TracChangeset for help on using the changeset viewer.

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