Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
PyXPCOM.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

protocol  PYXPCOM_EXPORT
protocol  PYXPCOM_EXPORT
protocol  PYXPCOM_EXPORT
protocol  PYXPCOM_EXPORT
class  nsIInternalPython
protocol  PYXPCOM_EXPORT
protocol  PYXPCOM_EXPORT
protocol  PYXPCOM_EXPORT
protocol  PYXPCOM_EXPORT
class  CEnterLeaveXPCOMFramework
class  CEnterLeavePython

Defines

#define PYXPCOM_EXPORT
#define NS_PYXPCOM_NO_SUCH_METHOD   NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_PYXPCOM, 0)
#define PYXPCOM_LOG_DEBUG()
#define PyUnicode_FromPRUnichar(src, size)   PyUnicode_DecodeUTF16((char*)(src),sizeof(PRUnichar)*(size),NULL,NULL)
#define NS_IINTERNALPYTHON_IID_STR   "AC7459FC-E8AB-4f2e-9C4F-ADDC53393A20"
#define NS_IINTERNALPYTHON_IID   { 0xac7459fc, 0xe8ab, 0x4f2e, { 0x9c, 0x4f, 0xad, 0xdc, 0x53, 0x39, 0x3a, 0x20 } }
#define PYGATEWAY_BASE_SUPPORT(INTERFACE, GATEWAY_BASE)
#define PyXPCOM_INTERFACE_DECLARE(ClassName, InterfaceName, Methods)
#define PyXPCOM_ATTR_INTERFACE_DECLARE(ClassName, InterfaceName, Methods)
#define PyXPCOM_INTERFACE_DEFINE(ClassName, InterfaceName, Methods)   PyXPCOM_TypeObject *ClassName::type = NULL;

Typedefs

typedef Py_nsISupports *(* PyXPCOM_I_CTOR )(nsISupports *, const nsIID &)

Functions

PYXPCOM_EXPORT PyObject * PyXPCOM_BuildPyException (nsresult res)
PYXPCOM_EXPORT nsresult PyXPCOM_SetCOMErrorFromPyException ()
PYXPCOM_EXPORT void PyXPCOM_LogWarning (const char *fmt,...)
PYXPCOM_EXPORT void PyXPCOM_LogError (const char *fmt,...)
PyObject * PyObject_FromXPTType (const nsXPTType *d)
PyObject * PyObject_FromXPTTypeDescriptor (const XPTTypeDescriptor *d)
PyObject * PyObject_FromXPTParamDescriptor (const XPTParamDescriptor *d)
PyObject * PyObject_FromXPTMethodDescriptor (const XPTMethodDescriptor *d)
PyObject * PyObject_FromXPTConstant (const XPTConstDescriptor *d)
nsIVariantPyObject_AsVariant (PyObject *ob)
PyObject * PyObject_FromVariant (nsIVariant *v)
void PyXPCOM_DLLAddRef ()
void PyXPCOM_DLLRelease ()
PYXPCOM_EXPORT void PyXPCOM_AcquireGlobalLock (void)
PYXPCOM_EXPORT void PyXPCOM_ReleaseGlobalLock (void)
PYXPCOM_EXPORT void PyXPCOM_MakePendingCalls ()
PYXPCOM_EXPORT PRBool PyXPCOM_Globals_Ensure ()
PYXPCOM_EXPORT PRBool PyXPCOM_ThreadState_Ensure ()
PYXPCOM_EXPORT void PyXPCOM_ThreadState_Free ()
PYXPCOM_EXPORT void PyXPCOM_ThreadState_Clear ()
PYXPCOM_EXPORT void PyXPCOM_InterpreterLock_Acquire ()
PYXPCOM_EXPORT void PyXPCOM_InterpreterLock_Release ()
 PyXPCOM_INTERFACE_DECLARE (Py_nsIComponentManager, nsIComponentManager, PyMethods_IComponentManager) PyXPCOM_INTERFACE_DECLARE(Py_nsIInterfaceInfoManager
PyMethods_IInterfaceInfoManager PyXPCOM_INTERFACE_DECLARE (Py_nsIEnumerator, nsIEnumerator, PyMethods_IEnumerator) PyXPCOM_INTERFACE_DECLARE(Py_nsISimpleEnumerator
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator 
PyXPCOM_INTERFACE_DECLARE (Py_nsIInterfaceInfo, nsIInterfaceInfo, PyMethods_IInterfaceInfo) PyXPCOM_INTERFACE_DECLARE(Py_nsIInputStream
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator
PyMethods_IInputStream 
PyXPCOM_ATTR_INTERFACE_DECLARE (Py_nsIClassInfo, nsIClassInfo, PyMethods_IClassInfo) PyXPCOM_ATTR_INTERFACE_DECLARE(Py_nsIVariant

Variables

nsIID Py_nsIID_NULL
PYXPCOM_EXPORT PyObject * PyXPCOM_Error
PYXPCOM_EXPORT PyInterpreterState * PyXPCOM_InterpreterState
 nsIInterfaceInfoManager
PyMethods_IInterfaceInfoManager nsISimpleEnumerator
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator 
nsIInputStream
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator
PyMethods_IInputStream 
nsIVariant

Define Documentation

#define NS_IINTERNALPYTHON_IID   { 0xac7459fc, 0xe8ab, 0x4f2e, { 0x9c, 0x4f, 0xad, 0xdc, 0x53, 0x39, 0x3a, 0x20 } }

Definition at line 341 of file PyXPCOM.h.

#define NS_IINTERNALPYTHON_IID_STR   "AC7459FC-E8AB-4f2e-9C4F-ADDC53393A20"

Definition at line 340 of file PyXPCOM.h.

Definition at line 81 of file PyXPCOM.h.

#define PYGATEWAY_BASE_SUPPORT (   INTERFACE,
  GATEWAY_BASE 
)
Value:
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr)      \
              {return PyG_Base::QueryInterface(aIID, aInstancePtr);}     \
       NS_IMETHOD_(nsrefcnt) AddRef(void) {return PyG_Base::AddRef();}    \
       NS_IMETHOD_(nsrefcnt) Release(void) {return PyG_Base::Release();}  \
       virtual void *ThisAsIID(const nsIID &iid) {                        \
              if (iid.Equals(NS_GET_IID(INTERFACE))) return (INTERFACE *)this; \
              return GATEWAY_BASE::ThisAsIID(iid);                       \
       }                                                                  \

Definition at line 448 of file PyXPCOM.h.

#define PyUnicode_FromPRUnichar (   src,
  size 
)    PyUnicode_DecodeUTF16((char*)(src),sizeof(PRUnichar)*(size),NULL,NULL)

Definition at line 121 of file PyXPCOM.h.

#define PyXPCOM_ATTR_INTERFACE_DECLARE (   ClassName,
  InterfaceName,
  Methods 
)

Definition at line 690 of file PyXPCOM.h.

Definition at line 66 of file PyXPCOM.h.

#define PyXPCOM_INTERFACE_DECLARE (   ClassName,
  InterfaceName,
  Methods 
)

Definition at line 656 of file PyXPCOM.h.

#define PyXPCOM_INTERFACE_DEFINE (   ClassName,
  InterfaceName,
  Methods 
)    PyXPCOM_TypeObject *ClassName::type = NULL;

Definition at line 726 of file PyXPCOM.h.

Definition at line 117 of file PyXPCOM.h.


Typedef Documentation

typedef Py_nsISupports*(* PyXPCOM_I_CTOR)(nsISupports *, const nsIID &)

Definition at line 134 of file PyXPCOM.h.


Function Documentation

nsIVariant* PyObject_AsVariant ( PyObject *  ob)

Definition at line 595 of file VariantUtils.cpp.

{
       nsresult nr = NS_ERROR_UNEXPECTED;
       nsCOMPtr<nsIWritableVariant> v = do_CreateInstance("@mozilla.org/variant;1", &nr); 
       if (NS_FAILED(nr)) {
              PyXPCOM_BuildPyException(nr);
              return NULL;
       }
       // *sigh* - I tried the abstract API (PyNumber_Check, etc)
       // but our COM instances too often qualify.
       BVFTResult cvt_result;
       PRUint16 dt = BestVariantTypeForPyObject(ob, &cvt_result);
       switch (dt) {
              case nsIDataType::VTYPE_BOOL:
                     nr = v->SetAsBool(ob==Py_True);
                     break;
              case nsIDataType::VTYPE_INT32:
                     nr = v->SetAsInt32(PyInt_AsLong(ob));
                     break;
              case nsIDataType::VTYPE_INT64:
                     nr = v->SetAsInt64(PyLong_AsLongLong(ob));
                     break;
              case nsIDataType::VTYPE_DOUBLE:
                     nr = v->SetAsDouble(PyFloat_AsDouble(ob));
                     break;
              case nsIDataType::VTYPE_STRING_SIZE_IS:
                     nr = v->SetAsStringWithSize(PyString_Size(ob), PyString_AsString(ob));
                     break;
              case nsIDataType::VTYPE_WSTRING_SIZE_IS:
                     if (PyUnicode_GetSize(ob) == 0) {
                            nr = v->SetAsWStringWithSize(0, (PRUnichar*)NULL);
                     }
                     else {
                            PRUint32 nch;
                            PRUnichar *p;
                            if (PyUnicode_AsPRUnichar(ob, &p, &nch) < 0) {
                                   nr = NS_ERROR_UNEXPECTED;
                                   break;
                            }
                            nr = v->SetAsWStringWithSize(nch, p);
                            nsMemory::Free(p);
                     }
                     break;
              case nsIDataType::VTYPE_INTERFACE_IS:
              {
                     nsISupports *ps = cvt_result.pis;
                     nr = v->SetAsInterface(cvt_result.iid, ps);
                     if (ps) {
                            Py_BEGIN_ALLOW_THREADS; // MUST release thread-lock, incase a Python COM object that re-acquires.
                            ps->Release();
                            Py_END_ALLOW_THREADS;
                     }
                     break;
              }
              case nsIDataType::VTYPE_ID:
                     nr = v->SetAsID(cvt_result.iid);
                     break;
              case nsIDataType::VTYPE_ARRAY:
              {
                     int seq_length = PySequence_Length(ob);
                     NS_ABORT_IF_FALSE(seq_length!=0, "VTYPE_ARRAY assumes at least one element!");
                     PyObject *first = PySequence_GetItem(ob, 0);
                     if (!first) break;
                     int array_type = BestVariantTypeForPyObject(first);
                     Py_DECREF(first);
                     // Arrays can't handle all types.  This means we lost embedded NULLs.
                     // This should really be fixed in XPCOM.
                     if (array_type == nsIDataType::VTYPE_STRING_SIZE_IS) array_type = nsIDataType::VTYPE_CHAR_STR;
                     if (array_type == nsIDataType::VTYPE_WSTRING_SIZE_IS) array_type = nsIDataType::VTYPE_WCHAR_STR;
                     PRUint32 element_size = GetArrayElementSize(array_type);
                     int cb_buffer_pointer = seq_length * element_size;
                     void *buffer_pointer;
                     if ((buffer_pointer = (void *)nsMemory::Alloc(cb_buffer_pointer)) == nsnull) {
                            PyErr_NoMemory();
                            nr = NS_ERROR_UNEXPECTED;
                            break;
                     }
                     memset(buffer_pointer, 0, cb_buffer_pointer);
                     if (FillSingleArray(buffer_pointer, ob, seq_length, element_size, array_type)) {
                            nr = v->SetAsArray(array_type, &NS_GET_IID(nsISupports), seq_length, buffer_pointer);
                            FreeSingleArray(buffer_pointer, seq_length, array_type);
                     } else
                            nr = NS_ERROR_UNEXPECTED;
                     nsMemory::Free(buffer_pointer);
                     break;
              }
              case nsIDataType::VTYPE_EMPTY:
                     v->SetAsEmpty();
                     break;
              case nsIDataType::VTYPE_EMPTY_ARRAY:
                     v->SetAsEmptyArray();
                     break;
              case (PRUint16)-1:
                     PyErr_Format(PyExc_TypeError, "Objects of type '%s' can not be converted to an nsIVariant", ob->ob_type->tp_name);
                     return NULL;
              default:
                     NS_ABORT_IF_FALSE(0, "BestVariantTypeForPyObject() returned a variant type not handled here!");
                     PyErr_Format(PyExc_TypeError, "Objects of type '%s' can not be converted to an nsIVariant", ob->ob_type->tp_name);
                     return NULL;
       }
       nsIVariant *ret;
       v->QueryInterface(NS_GET_IID(nsIVariant), (void **)&ret);
       return ret;
}

Here is the call graph for this function:

PyObject* PyObject_FromVariant ( nsIVariant v)

Definition at line 741 of file VariantUtils.cpp.

{
       if (!v) {
              Py_INCREF(Py_None);
              return Py_None;
       }
       PRUint16 dt;
       nsresult nr;
       PyObject *ret = NULL;
       nr = v->GetDataType(&dt);
       if (NS_FAILED(nr)) goto done;
       switch (dt) {
              case nsIDataType::VTYPE_VOID:
              case nsIDataType::VTYPE_EMPTY:
              case nsIDataType::VTYPE_EMPTY_ARRAY:
                     ret = Py_None;
                     Py_INCREF(Py_None);
                     break;
              case nsIDataType::VTYPE_ARRAY:
                     ret = PyObject_FromVariantArray(v);
                     break;
              case nsIDataType::VTYPE_INT8:
              case nsIDataType::VTYPE_INT16:
              case nsIDataType::VTYPE_INT32:
                     GET_FROM_V(PRInt32, v->GetAsInt32, PyInt_FromLong);
              case nsIDataType::VTYPE_UINT8:
              case nsIDataType::VTYPE_UINT16:
              case nsIDataType::VTYPE_UINT32:
                     GET_FROM_V(PRUint32, v->GetAsUint32, PyLong_FromUnsignedLong);
              case nsIDataType::VTYPE_INT64:
                     GET_FROM_V(PRInt64, v->GetAsInt64, PyLong_FromLongLong);
              case nsIDataType::VTYPE_UINT64:
                     GET_FROM_V(PRUint64, v->GetAsUint64, PyLong_FromUnsignedLongLong);
              case nsIDataType::VTYPE_FLOAT:
              case nsIDataType::VTYPE_DOUBLE:
                     GET_FROM_V(double, v->GetAsDouble, PyFloat_FromDouble);
              case nsIDataType::VTYPE_BOOL:
                     GET_FROM_V(PRBool, v->GetAsBool, MyBool_FromBool);
              default:
                     PyXPCOM_LogWarning("Converting variant to Python object - variant type '%d' unknown - using string.\n", dt);
              // Fall through to the string case
              case nsIDataType::VTYPE_CHAR:
              case nsIDataType::VTYPE_CHAR_STR:
              case nsIDataType::VTYPE_STRING_SIZE_IS:
              case nsIDataType::VTYPE_CSTRING: {
                     nsCAutoString s;
                     if (NS_FAILED(nr=v->GetAsACString(s))) goto done;
                     ret = PyObject_FromNSString(s);
                     break;
              }
              case nsIDataType::VTYPE_WCHAR:
              case nsIDataType::VTYPE_DOMSTRING:
              case nsIDataType::VTYPE_WSTRING_SIZE_IS:
              case nsIDataType::VTYPE_ASTRING: {
                     nsAutoString s;
                     if (NS_FAILED(nr=v->GetAsAString(s))) goto done;
                     ret = PyObject_FromNSString(s);
                     break;
              }
              case nsIDataType::VTYPE_ID:
                     GET_FROM_V(nsIID, v->GetAsID, Py_nsIID::PyObjectFromIID);
              case nsIDataType::VTYPE_INTERFACE:
                     GET_FROM_V(nsISupports *, v->GetAsISupports, MyObject_FromInterface);
              case nsIDataType::VTYPE_INTERFACE_IS: {
                     nsISupports *p;
                     nsIID *iid;
                     if (NS_FAILED(nr=v->GetAsInterface(&iid, (void **)&p))) goto done;
                     ret = Py_nsISupports::PyObjectFromInterface(p, *iid, PR_FALSE);
                     break;
              // case nsIDataType::VTYPE_WCHAR_STR
              // case nsIDataType::VTYPE_UTF8STRING
              }
       }
done:
       if (NS_FAILED(nr)) {
              NS_ABORT_IF_FALSE(ret==NULL, "Have an error, but also a return val!");
              PyXPCOM_BuildPyException(nr);
       }
       return ret;
}

Here is the call graph for this function:

Definition at line 106 of file Pyxpt_info.cpp.

{
       if (c==nsnull) {
              Py_INCREF(Py_None);
              return Py_None;
       }
       PyObject *ob_type = PyObject_FromXPTTypeDescriptor(&c->type);
       if (ob_type==NULL)
              return NULL;
       PyObject *v = NULL;
       switch (c->type.prefix.flags) {
              case TD_INT8:
                     v = PyInt_FromLong( c->value.i8 );
                     break;
              case TD_INT16:
                     v = PyInt_FromLong( c->value.i16 );
                     break;
              case TD_INT32:
                     v = PyInt_FromLong( c->value.i32 );
                     break;
              case TD_INT64:
                     v = PyLong_FromLongLong(c->value.i64);
                     break;
              case TD_UINT8:
                     v = PyInt_FromLong( c->value.ui8 );
                     break;
              case TD_UINT16:
                     v = PyInt_FromLong( c->value.ui16 );
                     break;
              case TD_UINT32:
                     v = PyInt_FromLong( c->value.ui32 );
                     break;
              case TD_UINT64:
                     v = PyLong_FromUnsignedLongLong(c->value.ui64);
                     break;
              case TD_FLOAT:
                     v = PyFloat_FromDouble(c->value.flt);
                     break;
              case TD_DOUBLE:
                     v = PyFloat_FromDouble(c->value.dbl);
                     break;
              case TD_BOOL:
                     v = c->value.bul ? Py_True : Py_False;
                     Py_INCREF(v);
                     break;
              case TD_CHAR:
                     v = PyString_FromStringAndSize(&c->value.ch, 1);
                     break;
              case TD_WCHAR:
                     v = PyUnicode_FromPRUnichar((PRUnichar *)&c->value.wch, 1);
                     break;
       //    TD_VOID              = 13,  
              case TD_PNSIID:
                     v = Py_nsIID::PyObjectFromIID(*c->value.iid);
                     break;
       //    TD_DOMSTRING         = 15,
              case TD_PSTRING:
                     v = PyString_FromString(c->value.str);
                     break;
              case TD_PWSTRING:
                     v = PyUnicode_FromPRUnichar((PRUnichar *)c->value.wstr, nsCRT::strlen((PRUnichar *)c->value.wstr));
                     break;
       //    TD_INTERFACE_TYPE    = 18,
       //    TD_INTERFACE_IS_TYPE = 19,
       //    TD_ARRAY             = 20,
       //    TD_PSTRING_SIZE_IS   = 21,
       //    TD_PWSTRING_SIZE_IS  = 22
       //    TD_UTF8STRING        = 23,
       //    TD_CSTRING           = 24,
       //    TD_ASTRING           = 25
              default:
                     v = PyString_FromString("Unknown type code!!");
                     break;

       }
       PyObject *ret = Py_BuildValue("sbO", c->name, ob_type, v);
       Py_DECREF(ob_type);
       Py_DECREF(v);
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 88 of file Pyxpt_info.cpp.

{
       if (d==nsnull) {
              Py_INCREF(Py_None);
              return Py_None;
       }
       PyObject *ob_params = PyTuple_New(d->num_args);
       if (ob_params==NULL)
              return NULL;
       for (int i=0;i<d->num_args;i++)
              PyTuple_SET_ITEM(ob_params, i, PyObject_FromXPTParamDescriptor(d->params+i));
       PyObject *ob_ret = PyObject_FromXPTParamDescriptor(d->result);
       PyObject *ret = Py_BuildValue("bsOO", d->flags, d->name, ob_params, ob_ret);
       Py_XDECREF(ob_ret);
       Py_XDECREF(ob_params);
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 76 of file Pyxpt_info.cpp.

{
       if (d==nsnull) {
              Py_INCREF(Py_None);
              return Py_None;
       }
       PyObject *ob = PyObject_FromXPTTypeDescriptor(&d->type);
       PyObject *ret = Py_BuildValue("bO", d->flags, ob);
       Py_DECREF(ob);
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject* PyObject_FromXPTType ( const nsXPTType d)

Definition at line 50 of file Pyxpt_info.cpp.

{
       if (d==nsnull) {
              Py_INCREF(Py_None);
              return Py_None;
       }
    // build an object using the same format as a TypeDescriptor.
       return Py_BuildValue("bzzz", 
              d->flags,
              NULL, NULL, NULL);
}

Here is the caller graph for this function:

Definition at line 62 of file Pyxpt_info.cpp.

{
       if (d==nsnull) {
              Py_INCREF(Py_None);
              return Py_None;
       }
       return Py_BuildValue("bbbh", 
              d->prefix.flags,
              d->argnum,
              d->argnum2,
              d->type.iface // this is actually a union!
              );
}

Here is the caller graph for this function:

Definition at line 167 of file dllmain.cpp.

{
       NS_PRECONDITION(g_lockMain != nsnull, "Cant acquire a NULL lock!");
       PR_Lock(g_lockMain);
}

Here is the caller graph for this function:

PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyMethods_IInputStream PyXPCOM_ATTR_INTERFACE_DECLARE ( Py_nsIClassInfo  ,
nsIClassInfo  ,
PyMethods_IClassInfo   
)

Definition at line 145 of file ErrorUtils.cpp.

{
       // Need the message etc.
       PyObject *evalue = Py_BuildValue("i", r);
       PyErr_SetObject(PyXPCOM_Error, evalue);
       Py_XDECREF(evalue);
       return NULL;
}

Definition at line 178 of file dllmain.cpp.

{
       // Must be thread-safe, although cant have the Python lock!
       CEnterLeaveXPCOMFramework _celf;
       PRInt32 cnt = PR_AtomicIncrement(&g_cLockCount);
       if (cnt==1) { // First call 
              if (!Py_IsInitialized()) {
                     Py_Initialize();
                     // Make sure our Windows framework is all setup.
                     PyXPCOM_Globals_Ensure();
                     // Make sure we have _something_ as sys.argv.
                     if (PySys_GetObject("argv")==NULL) {
                            PyObject *path = PyList_New(0);
                            PyObject *str = PyString_FromString("");
                            PyList_Append(path, str);
                            PySys_SetObject("argv", path);
                            Py_XDECREF(path);
                            Py_XDECREF(str);
                     }

                     // Must force Python to start using thread locks, as
                     // we are free-threaded (maybe, I think, sometimes :-)
                     PyEval_InitThreads();
#ifndef PYXPCOM_USE_PYGILSTATE
                     // Release Python lock, as first thing we do is re-get it.
                     ptsGlobal = PyEval_SaveThread();
#endif
                     // NOTE: We never finalize Python!!
              }
       }
}

Here is the call graph for this function:

Definition at line 209 of file dllmain.cpp.

Here is the call graph for this function:

Definition at line 496 of file xpcom.cpp.

{
       PRBool rc = PR_TRUE;

#ifndef PYXPCOM_USE_PYGILSTATE
       PyXPCOM_InterpreterState_Ensure();
#endif

       // The exception object - we load it from .py code!
       if (PyXPCOM_Error == NULL) {
              rc = PR_FALSE;
              PyObject *mod = NULL;

              mod = PyImport_ImportModule("xpcom");
              if (mod!=NULL) {
                     PyXPCOM_Error = PyObject_GetAttrString(mod, "Exception");
                     Py_DECREF(mod);
              }
              rc = (PyXPCOM_Error != NULL);
       }
       if (!rc)
              return rc;

       static PRBool bHaveInitXPCOM = PR_FALSE;
       if (!bHaveInitXPCOM) {
              nsCOMPtr<nsIThread> thread_check;
              // xpcom appears to assert if already initialized
              // Is there an official way to determine this?
              if (NS_FAILED(nsIThread::GetMainThread(getter_AddRefs(thread_check)))) {
                     // not already initialized.
#ifdef XP_WIN
                     // On Windows, we need to locate the Mozilla bin
                     // directory.  This by using locating a Moz DLL we depend
                     // on, and assume it lives in that bin dir.  Different
                     // moz build types (eg, xulrunner, suite) package
                     // XPCOM itself differently - but all appear to require
                     // nspr4.dll - so this is what we use.
                     char landmark[MAX_PATH+1];
                     HMODULE hmod = GetModuleHandle("nspr4.dll");
                     if (hmod==NULL) {
                            PyErr_SetString(PyExc_RuntimeError, "We dont appear to be linked against nspr4.dll.");
                            return PR_FALSE;
                     }
                     GetModuleFileName(hmod, landmark, sizeof(landmark)/sizeof(landmark[0]));
                     char *end = landmark + (strlen(landmark)-1);
                     while (end > landmark && *end != '\\')
                            end--;
                     if (end > landmark) *end = '\0';

                     nsCOMPtr<nsILocalFile> ns_bin_dir;
                     NS_ConvertASCIItoUCS2 strLandmark(landmark);
                     NS_NewLocalFile(strLandmark, PR_FALSE, getter_AddRefs(ns_bin_dir));
                     nsresult rv = NS_InitXPCOM2(nsnull, ns_bin_dir, nsnull);
#else
                     // Elsewhere, Mozilla can find it itself (we hope!)
                     nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
#endif // XP_WIN
                     if (NS_FAILED(rv)) {
                            PyErr_SetString(PyExc_RuntimeError, "The XPCOM subsystem could not be initialized");
                            return PR_FALSE;
                     }
              }
              // Even if xpcom was already init, we want to flag it as init!
              bHaveInitXPCOM = PR_TRUE;
       }
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyXPCOM_INTERFACE_DECLARE ( Py_nsIComponentManager  ,
nsIComponentManager  ,
PyMethods_IComponentManager   
)
PyMethods_IInterfaceInfoManager PyXPCOM_INTERFACE_DECLARE ( Py_nsIEnumerator  ,
nsIEnumerator  ,
PyMethods_IEnumerator   
)
PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyXPCOM_INTERFACE_DECLARE ( Py_nsIInterfaceInfo  ,
nsIInterfaceInfo  ,
PyMethods_IInterfaceInfo   
)

Definition at line 126 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       NS_ABORT_IF_FALSE(pData, "Have no thread data for this thread!");
       PyThreadState *thisThreadState = pData->ts;
       PyEval_AcquireThread(thisThreadState);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 135 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       NS_ABORT_IF_FALSE(pData, "Have no thread data for this thread!");
       PyThreadState *thisThreadState = pData->ts;
       PyEval_ReleaseThread(thisThreadState);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PYXPCOM_EXPORT void PyXPCOM_LogError ( const char *  fmt,
  ... 
)

Definition at line 85 of file ErrorUtils.cpp.

{
       va_list marker;
       va_start(marker, fmt);
       VLogF("PyXPCOM Error: ", fmt, marker);
       // If we have a Python exception, also log that:
       PyObject *exc_typ = NULL, *exc_val = NULL, *exc_tb = NULL;
       PyErr_Fetch( &exc_typ, &exc_val, &exc_tb);
       if (exc_typ) {
              PyErr_NormalizeException( &exc_typ, &exc_val, &exc_tb);
              nsCAutoString streamout;

              if (exc_tb) {
                     const char *szTraceback = PyTraceback_AsString(exc_tb);
                     if (szTraceback == NULL)
                            streamout += "Can't get the traceback info!";
                     else {
                            streamout += "Traceback (most recent call last):\n";
                            streamout += szTraceback;
                            PyMem_Free((void *)szTraceback);
                     }
              }
              PyObject *temp = PyObject_Str(exc_typ);
              if (temp) {
                     streamout += PyString_AsString(temp);
                     Py_DECREF(temp);
              } else
                     streamout += "Can't convert exception to a string!";
              streamout += ": ";
              if (exc_val != NULL) {
                     temp = PyObject_Str(exc_val);
                     if (temp) {
                            streamout += PyString_AsString(temp);
                            Py_DECREF(temp);
                     } else
                            streamout += "Can't convert exception value to a string!";
              }
              streamout += "\n";
              LogMessage("PyXPCOM Exception:", streamout);
       }
       PyErr_Restore(exc_typ, exc_val, exc_tb);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PYXPCOM_EXPORT void PyXPCOM_LogWarning ( const char *  fmt,
  ... 
)

Definition at line 128 of file ErrorUtils.cpp.

{
       va_list marker;
       va_start(marker, fmt);
       VLogF("PyXPCOM Warning: ", fmt, marker);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 253 of file ErrorUtils.cpp.

{
       while (1) {
              int rc = Py_MakePendingCalls();
              if (rc == 0)
                     break;
              // An exception - just report it as normal.
              // Note that a traceback is very unlikely!
              PyXPCOM_LogError("Unhandled exception detected before entering Python.\n");
              PyErr_Clear();
              // And loop around again until we are told everything is done!
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 172 of file dllmain.cpp.

{
       NS_PRECONDITION(g_lockMain != nsnull, "Cant release a NULL lock!");
       PR_Unlock(g_lockMain);
}

Here is the caller graph for this function:

Definition at line 154 of file ErrorUtils.cpp.

{
       if (!PyErr_Occurred())
              // No error occurred
              return NS_OK;
       return NS_ERROR_FAILURE;
}

Definition at line 156 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       PyThreadState *thisThreadState = pData->ts;
       PyThreadState_Clear(thisThreadState);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 103 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       if (pData==NULL) { /* First request on this thread */
              /* Check we have an interpreter state */
              if (PyXPCOM_InterpreterState==NULL) {
                            Py_FatalError("Can not setup thread state, as have no interpreter state");
              }
              pData = (ThreadData *)nsMemory::Alloc(sizeof(ThreadData));
              if (!pData)
                     Py_FatalError("Out of memory allocating thread state.");
              memset(pData, 0, sizeof(*pData));
              if (NS_FAILED( PR_SetThreadPrivate( tlsIndex, pData ) ) ) {
                     NS_ABORT_IF_FALSE(0, "Could not create thread data for this thread!");
                     Py_FatalError("Could not thread private thread data!");
              }
              pData->ts = PyThreadState_New(PyXPCOM_InterpreterState);
              return PR_TRUE; // Did create a thread state state
       }
       return PR_FALSE; // Thread state was previously created
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 146 of file dllmain.cpp.

{
       ThreadData *pData = (ThreadData *)PR_GetThreadPrivate(tlsIndex);
       if (!pData) return;
       PyThreadState *thisThreadState = pData->ts;
       PyThreadState_Delete(thisThreadState);
       PR_SetThreadPrivate(tlsIndex, NULL);
       nsMemory::Free(pData);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator nsIInputStream

Definition at line 736 of file PyXPCOM.h.

Definition at line 732 of file PyXPCOM.h.

Definition at line 734 of file PyXPCOM.h.

PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyMethods_IInputStream nsIVariant

Definition at line 738 of file PyXPCOM.h.

Definition at line 54 of file PyIID.cpp.

Definition at line 68 of file xpcom.cpp.

Definition at line 68 of file dllmain.cpp.