Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsModule.h File Reference
#include "nsIModule.h"
#include "nsIFile.h"
#include "nsIComponentManager.h"
#include "nsXPCOM.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define NS_GET_MODULE_SYMBOL   "NSGetModule"

Functions

NS_EXPORT nsresult PR_CALLBACK NSGetModule (nsIComponentManager *aCompMgr, nsIFile *location, nsIModule **return_cobj)

Define Documentation

#define NS_GET_MODULE_SYMBOL   "NSGetModule"

Definition at line 47 of file nsModule.h.


Function Documentation

NS_EXPORT nsresult PR_CALLBACK NSGetModule ( nsIComponentManager aCompMgr,
nsIFile location,
nsIModule **  return_cobj 
)

Definition at line 137 of file pyloader.cpp.

{
#ifdef XP_UNIX
       // *sob* - seems necessary to open the .so as RTLD_GLOBAL
       dlopen(PYTHON_SO,RTLD_NOW | RTLD_GLOBAL);
#endif
       PRBool bDidInitPython = !Py_IsInitialized(); // well, I will next line, anyway :-)
       if (bDidInitPython) {
              NS_TIMELINE_START_TIMER("PyXPCOM: Python initializing");
              Py_Initialize();
              if (!Py_IsInitialized()) {
                     LogError("Python initialization failed!\n");
                     return NS_ERROR_FAILURE;
              }
#ifndef NS_DEBUG
              Py_OptimizeFlag = 1;
#endif // NS_DEBUG
              AddStandardPaths();
              PyEval_InitThreads();
              NS_TIMELINE_STOP_TIMER("PyXPCOM: Python initializing");
              NS_TIMELINE_MARK_TIMER("PyXPCOM: Python initializing");
       }
       // Get the Python interpreter state
       NS_TIMELINE_START_TIMER("PyXPCOM: Python threadstate setup");
#ifndef PYXPCOM_USE_PYGILSTATE
       PyThreadState *threadStateCreated = NULL;
       PyThreadState *threadState = PyThreadState_Swap(NULL);
       if (threadState==NULL) {
              // no thread-state - set one up.
              // *sigh* - what I consider a bug is that Python
              // will deadlock unless we own the lock before creating
              // a new interpreter (it appear Py_NewInterpreter has
              // really only been tested/used with no thread lock
              PyEval_AcquireLock();
              threadState = threadStateCreated = Py_NewInterpreter();
              PyThreadState_Swap(NULL);
       }
       PyEval_ReleaseLock();
       PyEval_AcquireThread(threadState);
#else
       PyGILState_STATE state = PyGILState_Ensure();
#endif // PYXPCOM_USE_PYGILSTATE
       if (pfnEntryPoint == nsnull) {
              PyObject *mod = PyImport_ImportModule("xpcom._xpcom");
              if (mod==NULL) {
                     LogError("Could not import the Python XPCOM extension\n");
                     return NS_ERROR_FAILURE;
              }
              PyObject *obpfn = PyObject_GetAttrString(mod, "_NSGetModule_FuncPtr");
              void *pfn = NULL;
              if (obpfn) {
                     NS_ABORT_IF_FALSE(PyLong_Check(obpfn)||PyInt_Check(obpfn), "xpcom._NSGetModule_FuncPtr is not a long!");
                     pfn = PyLong_AsVoidPtr(obpfn);
              }
              pfnEntryPoint = (pfnPyXPCOM_NSGetModule)pfn;
       }
       if (pfnEntryPoint==NULL) {
              LogError("Could not load main Python entry point\n");
              return NS_ERROR_FAILURE;
       }

#ifdef MOZ_TIMELINE
       // If the timeline service is installed, see if we can install our hooks.
       if (NULL==PyImport_ImportModule("timeline_hook")) {
              if (!PyErr_ExceptionMatches(PyExc_ImportError))
                     LogError("Failed to import 'timeline_hook'");
              PyErr_Clear(); // but don't care if we can't.
       }
#endif
#ifndef PYXPCOM_USE_PYGILSTATE
       // Abandon the thread-lock, as the first thing Python does
       // is re-establish the lock (the Python thread-state story SUCKS!!!)
       if (threadStateCreated) {
              Py_EndInterpreter(threadStateCreated);
              PyEval_ReleaseLock(); // see Py_NewInterpreter call above 
       } else {
              PyEval_ReleaseThread(threadState);
              PyThreadState *threadStateSave = PyThreadState_Swap(NULL);
              if (threadStateSave)
                     PyThreadState_Delete(threadStateSave);
       }
#else
       // If we initialized Python, then we will also have acquired the thread
       // lock.  In that case, we want to leave it unlocked, so other threads
       // are free to run, even if they aren't running Python code.
       PyGILState_Release(bDidInitPython ? PyGILState_UNLOCKED : state);
#endif 

       NS_TIMELINE_STOP_TIMER("PyXPCOM: Python threadstate setup");
       NS_TIMELINE_MARK_TIMER("PyXPCOM: Python threadstate setup");
       NS_TIMELINE_START_TIMER("PyXPCOM: PyXPCOM NSGetModule entry point");
       nsresult rc = (*pfnEntryPoint)(servMgr, location, result);
       NS_TIMELINE_STOP_TIMER("PyXPCOM: PyXPCOM NSGetModule entry point");
       NS_TIMELINE_MARK_TIMER("PyXPCOM: PyXPCOM NSGetModule entry point");
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function: