Changeset 39535 in vbox for trunk/src/libs/xpcom18a4/python
- Timestamp:
- Dec 5, 2011 3:42:26 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 75219
- Location:
- trunk/src/libs/xpcom18a4/python
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/python/Makefile.kmk
r39212 r39535 72 72 VBOX_WITH_XPCOM \ 73 73 VBOX_PYXPCOM_VERSIONED 74 VBoxPythonBase_DEFS.debug = \ 75 VBOX_DEBUG_LIFETIMES 74 76 VBoxPythonBase_INCS = \ 75 77 src -
trunk/src/libs/xpcom18a4/python/src/ErrorUtils.cpp
r16909 r39535 50 50 #include <nsIConsoleService.h> 51 51 #ifdef VBOX 52 #include <nsIExceptionService.h> 53 #include <iprt/err.h> 52 # include <nsIExceptionService.h> 53 # include <iprt/err.h> 54 # include <iprt/string.h> 54 55 #endif 55 56 #include "nspr.h" // PR_fprintf … … 148 149 { 149 150 char buff[512]; 151 #ifdef VBOX /* Enable the use of VBox formatting types. */ 152 RTStrPrintfV(buff, sizeof(buff), fmt, argptr); 153 #else 150 154 // Use safer NS_ functions. 151 155 PR_vsnprintf(buff, sizeof(buff), fmt, argptr); 156 #endif 152 157 153 158 LogMessage(methodName, buff); -
trunk/src/libs/xpcom18a4/python/src/PyIID.cpp
r33977 r39535 67 67 if (size != sizeof(nsIID) || buf==NULL) { 68 68 #ifdef VBOX 69 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly % u bytes long",sizeof(nsIID));69 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", (int)sizeof(nsIID)); 70 70 #else 71 71 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", sizeof(nsIID)); -
trunk/src/libs/xpcom18a4/python/src/PyISupports.cpp
r33977 r39535 52 52 static PyObject *g_obFuncMakeInterfaceCount = NULL; // XXX - never released!!! 53 53 54 #ifdef VBOX_DEBUG_LIFETIMES 55 # include <iprt/log.h> 56 # include <iprt/stream.h> 57 58 /*static*/ RTLISTNODE Py_nsISupports::g_List; 59 /*static*/ RTONCE Py_nsISupports::g_Once = RTONCE_INITIALIZER; 60 /*static*/ RTCRITSECT Py_nsISupports::g_CritSect; 61 62 /*static*/ DECLCALLBACK(int) 63 Py_nsISupports::initOnceCallback(void *pvUser1, void *pvUser2) 64 { 65 NOREF(pvUser1); NOREF(pvUser2); 66 RTListInit(&g_List); 67 return RTCritSectInit(&g_CritSect); 68 } 69 70 /*static*/ void 71 Py_nsISupports::dumpList(void) 72 { 73 RTOnce(&g_Once, initOnceCallback, NULL, NULL); 74 RTCritSectEnter(&g_CritSect); 75 76 uint32_t i = 0; 77 Py_nsISupports *pCur; 78 RTListForEach(&g_List, pCur, Py_nsISupports, m_ListEntry) 79 { 80 nsISupports *pISup = pCur->m_obj; 81 PyXPCOM_LogWarning("#%u: %p iid=%RTuuid obj=%p", i, pCur, &pCur->m_iid, pISup); 82 i++; 83 } 84 85 RTCritSectLeave(&g_CritSect); 86 } 87 88 /*static*/ void 89 Py_nsISupports::dumpListToStdOut() 90 { 91 RTOnce(&g_Once, initOnceCallback, NULL, NULL); 92 RTCritSectEnter(&g_CritSect); 93 94 uint32_t i = 0; 95 Py_nsISupports *pCur; 96 RTListForEach(&g_List, pCur, Py_nsISupports, m_ListEntry) 97 { 98 nsISupports *pISup = pCur->m_obj; 99 RTPrintf("#%u: %p iid=%RTuuid obj=%p\n", i, pCur, &pCur->m_iid, pISup); 100 i++; 101 } 102 103 RTCritSectLeave(&g_CritSect); 104 } 105 106 PRInt32 107 _PyXPCOM_DumpInterfaces(void) 108 { 109 Py_nsISupports::dumpListToStdOut(); 110 return NS_OK; 111 } 112 113 #endif /* _DEBUG_LIFETIMES */ 114 115 116 54 117 PyObject *PyObject_FromNSInterface( nsISupports *aInterface, 55 118 const nsIID &iid, … … 75 138 PyXPCOM_DLLAddRef(); 76 139 _Py_NewReference(this); 140 141 #ifdef VBOX_DEBUG_LIFETIMES 142 RTOnce(&g_Once, initOnceCallback, NULL, NULL); 143 RTCritSectEnter(&g_CritSect); 144 PyXPCOM_LogWarning("Creating %p: iid=%RTuuid obj=%p", this, &m_iid, punk); 145 RTListAppend(&g_List, &m_ListEntry); 146 RTCritSectLeave(&g_CritSect); 147 #endif 77 148 } 78 149 79 150 Py_nsISupports::~Py_nsISupports() 80 151 { 152 #ifdef VBOX_DEBUG_LIFETIMES 153 RTCritSectEnter(&g_CritSect); 154 nsISupports *punk = m_obj; 155 PyXPCOM_LogWarning("Destroying %p: iid=%RTuuid obj=%p", this, &m_iid, punk); 156 RTListNodeRemove(&m_ListEntry); 157 RTCritSectLeave(&g_CritSect); 158 #endif 159 81 160 SafeRelease(this); 82 161 PR_AtomicDecrement(&cInterfaces); -
trunk/src/libs/xpcom18a4/python/src/PyXPCOM.h
r32229 r39535 66 66 #include "xpt_xdr.h" 67 67 68 #ifdef VBOX_DEBUG_LIFETIMES 69 # include <iprt/critsect.h> 70 # include <iprt/list.h> 71 # include <iprt/once.h> 72 #endif 73 68 74 #ifdef HAVE_LONG_LONG 69 75 // Mozilla also defines this - we undefine it to … … 77 83 78 84 #ifdef VBOX_PYXPCOM 79 // unfortunatelly, if SOLARIS is defined Python porting layer 85 // unfortunatelly, if SOLARIS is defined Python porting layer 80 86 // defines gethostname() in invalid fashion what kills compilation 81 87 # ifdef SOLARIS … … 223 229 // Interfaces - these are the "official" functions 224 230 PYXPCOM_EXPORT PyObject *PyObject_FromNSInterface( nsISupports *aInterface, 225 const nsIID &iid, 231 const nsIID &iid, 226 232 PRBool bMakeNicePyObject = PR_TRUE); 227 233 … … 242 248 class PYXPCOM_EXPORT PyXPCOM_TypeObject : public PyTypeObject { 243 249 public: 244 PyXPCOM_TypeObject( 245 const char *name, 246 PyXPCOM_TypeObject *pBaseType, 247 int typeSize, 250 PyXPCOM_TypeObject( 251 const char *name, 252 PyXPCOM_TypeObject *pBaseType, 253 int typeSize, 248 254 struct PyMethodDef* methodList, 249 255 PyXPCOM_I_CTOR ctor); … … 304 310 // optimization, but since removed. This function *always* takes a 305 311 // reference to the nsISupports. 306 static PyObject *PyObjectFromInterface(nsISupports *ps, 307 const nsIID &iid, 312 static PyObject *PyObjectFromInterface(nsISupports *ps, 313 const nsIID &iid, 308 314 PRBool bMakeNicePyObject = PR_TRUE, 309 315 PRBool bIsInternalCall = PR_FALSE); … … 328 334 // Object *must* be Py_nsISupports - there is no 329 335 // "autowrap", no "None" support, etc 330 static PRBool InterfaceFromPyISupports(PyObject *ob, 331 const nsIID &iid, 336 static PRBool InterfaceFromPyISupports(PyObject *ob, 337 const nsIID &iid, 332 338 nsISupports **ppv); 333 339 … … 343 349 static void RegisterInterface( const nsIID &iid, PyTypeObject *t); 344 350 static void InitType(); 351 #ifdef VBOX_DEBUG_LIFETIMES 352 static void dumpList(void); 353 static void dumpListToStdOut(void); 354 #endif 345 355 346 356 virtual ~Py_nsISupports(); … … 358 368 // ctor is protected - must create objects via 359 369 // PyObjectFromInterface() 360 Py_nsISupports(nsISupports *p, 361 const nsIID &iid, 370 Py_nsISupports(nsISupports *p, 371 const nsIID &iid, 362 372 PyTypeObject *type); 363 373 … … 366 376 static PyObject *MakeDefaultWrapper(PyObject *pyis, const nsIID &iid); 367 377 368 }; 369 370 // Python/XPCOM IID support 378 #ifdef VBOX_DEBUG_LIFETIMES 379 static DECLCALLBACK(int) initOnceCallback(void *pvUser1, void *pvUser2); 380 381 RTLISTNODE m_ListEntry; /**< List entry. */ 382 383 static RTONCE g_Once; /**< Init list and critsect once. */ 384 static RTCRITSECT g_CritSect; /**< Critsect protecting the list. */ 385 static RTLISTANCHOR g_List; /**< List of live interfaces.*/ 386 #endif 387 }; 388 389 // Python/XPCOM IID support 371 390 class PYXPCOM_EXPORT Py_nsIID : public PyObject 372 391 { … … 375 394 nsIID m_iid; 376 395 377 PRBool 396 PRBool 378 397 IsEqual(const nsIID &riid) { 379 398 return m_iid.Equals(riid); … … 382 401 PRBool 383 402 IsEqual(PyObject *ob) { 384 return ob && 385 ob->ob_type== &type && 403 return ob && 404 ob->ob_type== &type && 386 405 m_iid.Equals(((Py_nsIID *)ob)->m_iid); 387 406 } … … 459 478 // We also allow the underlying PyObject to be extracted 460 479 class nsIInternalPython : public nsISupports { 461 public: 480 public: 462 481 NS_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERNALPYTHON_IID) 463 482 // Get the underlying Python object with new reference added … … 475 494 476 495 // A static "constructor" - the real ctor is protected. 477 static nsresult CreateNew(PyObject *pPyInstance, 478 const nsIID &iid, 496 static nsresult CreateNew(PyObject *pPyInstance, 497 const nsIID &iid, 479 498 void **ppResult); 480 499 481 // A utility to auto-wrap an arbitary Python instance 500 // A utility to auto-wrap an arbitary Python instance 482 501 // in a COM gateway. 483 static PRBool AutoWrapPythonInstance(PyObject *ob, 484 const nsIID &iid, 502 static PRBool AutoWrapPythonInstance(PyObject *ob, 503 const nsIID &iid, 485 504 nsISupports **ppret); 486 505 … … 488 507 // A helper that creates objects to be passed for nsISupports 489 508 // objects. See extensive comments in PyG_Base.cpp. 490 PyObject *MakeInterfaceParam(nsISupports *pis, 491 const nsIID *piid, 509 PyObject *MakeInterfaceParam(nsISupports *pis, 510 const nsIID *piid, 492 511 int methodIndex = -1, 493 const XPTParamDescriptor *d = NULL, 512 const XPTParamDescriptor *d = NULL, 494 513 int paramIndex = -1); 495 514 … … 570 589 extern PYXPCOM_EXPORT PRInt32 _PyXPCOM_GetGatewayCount(void); 571 590 extern PYXPCOM_EXPORT PRInt32 _PyXPCOM_GetInterfaceCount(void); 591 #ifdef VBOX_DEBUG_LIFETIMES 592 extern PYXPCOM_EXPORT PRInt32 _PyXPCOM_DumpInterfaces(void); 593 #endif 572 594 573 595 … … 578 600 // object dies due to XPCOM reference counting, it zaps the pointer 579 601 // in its corresponding weak reference object. Thus, the weak-reference 580 // can live beyond the object (possibly with a NULL pointer back to the 581 // "real" object, but as implemented, the weak reference will never be 602 // can live beyond the object (possibly with a NULL pointer back to the 603 // "real" object, but as implemented, the weak reference will never be 582 604 // destroyed before the object 583 605 class PYXPCOM_EXPORT PyXPCOM_GatewayWeakReference : public nsIWeakReference { … … 600 622 PyXPCOM_GatewayVariantHelper( PyG_Base *gateway, 601 623 int methodIndex, 602 const nsXPTMethodInfo *info, 624 const nsXPTMethodInfo *info, 603 625 nsXPTCMiniVariant* params ); 604 626 ~PyXPCOM_GatewayVariantHelper(); … … 627 649 // Misc converters. 628 650 PyObject *PyObject_FromXPTType( const nsXPTType *d); 629 // XPTTypeDescriptor derived from XPTType - latter is automatically processed via PyObject_FromXPTTypeDescriptor XPTTypeDescriptor 651 // XPTTypeDescriptor derived from XPTType - latter is automatically processed via PyObject_FromXPTTypeDescriptor XPTTypeDescriptor 630 652 PyObject *PyObject_FromXPTTypeDescriptor( const XPTTypeDescriptor *d); 631 653 … … 655 677 // first having this thread lock. 656 678 // 657 // The second type of lock is a "global framework lock", and used whenever 2 threads 658 // of C code need access to global data. This is different than the Python 659 // lock - this lock is used when no Python code can ever be called by the 679 // The second type of lock is a "global framework lock", and used whenever 2 threads 680 // of C code need access to global data. This is different than the Python 681 // lock - this lock is used when no Python code can ever be called by the 660 682 // threads, but the C code still needs thread-safety. 661 683 … … 669 691 // 670 692 // This class magically waits for PyXPCOM framework global lock, and releases it 671 // when finished. 693 // when finished. 672 694 // NEVER new one of these objects - only use on the stack! 673 695 class CEnterLeaveXPCOMFramework { … … 684 706 // 685 707 // This class magically waits for the Python global lock, and releases it 686 // when finished. 708 // when finished. 687 709 688 710 // Nested invocations will deadlock, so be careful. … … 749 771 // _before_ we release the lock, as some of 750 772 // the sys. attributes cleared (eg, the current exception) 751 // may need the lock to invoke their destructors - 773 // may need the lock to invoke their destructors - 752 774 // specifically, when exc_value is a class instance, and 753 775 // the exception holds the last reference! -
trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp
r38636 r39535 55 55 #include "nspr.h" // PR_fprintf 56 56 #ifdef VBOX 57 # include "nsEventQueueUtils.h"57 # include "nsEventQueueUtils.h" 58 58 #endif 59 59 … … 319 319 } 320 320 321 #ifdef VBOX_DEBUG_LIFETIMES 322 // @pymethod int|pythoncom|_DumpInterfaces|Dumps the interfaces still in existance to standard output 323 static PyObject * 324 PyXPCOMMethod_DumpInterfaces(PyObject *self, PyObject *args) 325 { 326 if (!PyArg_ParseTuple(args, ":_DumpInterfaces")) 327 return NULL; 328 return PyInt_FromLong(_PyXPCOM_DumpInterfaces()); 329 } 330 #endif 331 321 332 // @pymethod int|pythoncom|_GetGatewayCount|Retrieves the number of gateway objects currently in existance 322 333 static PyObject * … … 343 354 nr = NS_ShutdownXPCOM(nsnull); 344 355 Py_END_ALLOW_THREADS; 356 357 #ifdef VBOX_DEBUG_LIFETIME 358 Py_nsISupports::dumpList(); 359 #endif 345 360 346 361 // Dont raise an exception - as we are probably shutting down … … 661 676 {"DetachThread", PyXPCOMMethod_DetachThread, 1}, 662 677 #endif 678 #ifdef VBOX_DEBUG_LIFETIMES 679 {"_DumpInterfaces", PyXPCOMMethod_DumpInterfaces, 1}, 680 #endif 663 681 // These should no longer be used - just use the logging.getLogger('pyxpcom')... 682 /* bird: The above comment refers to LogWarning and LogError. Both now removed. */ 664 683 { NULL } 665 684 };
Note:
See TracChangeset
for help on using the changeset viewer.