VirtualBox

Changeset 69588 in vbox for trunk/src/libs/xpcom18a4/python


Ignore:
Timestamp:
Nov 5, 2017 10:45:32 AM (7 years ago)
Author:
vboxsync
Message:

python/src/modules/_xpcom.cpp: Keep track of whether we've calle com::Shutdown already to avoid assertions.

File:
1 edited

Legend:

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

    r59809 r69588  
    7676#ifdef VBOX_PYXPCOM
    7777# include <iprt/cdefs.h>
     78# include <VBox/com/com.h>
    7879# ifndef MODULE_NAME_SUFFIX
    7980#  define MANGLE_MODULE_NAME(a_szName)  a_szName
     
    618619}
    619620
    620 static void deinitVBoxPython();
     621static nsresult deinitVBoxPython();
    621622
    622623static PyObject*
    623624PyXPCOMMethod_DeinitCOM(PyObject *self, PyObject *args)
    624625{
     626    nsresult nr;
    625627    Py_BEGIN_ALLOW_THREADS;
    626     deinitVBoxPython();
     628    nr = deinitVBoxPython();
    627629    Py_END_ALLOW_THREADS;
    628     return PyInt_FromLong(0);
     630    return PyInt_FromLong(nr);
    629631}
    630632
     
    727729        {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1},
    728730#ifdef VBOX
    729     {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1},
    730     {"InterruptWait", PyXPCOMMethod_InterruptWait, 1},
    731     {"DeinitCOM",     PyXPCOMMethod_DeinitCOM, 1},
    732     {"AttachThread",  PyXPCOMMethod_AttachThread, 1},
    733     {"DetachThread",  PyXPCOMMethod_DetachThread, 1},
     731        {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1},
     732        {"InterruptWait", PyXPCOMMethod_InterruptWait, 1},
     733        {"DeinitCOM",     PyXPCOMMethod_DeinitCOM, 1},
     734        {"AttachThread",  PyXPCOMMethod_AttachThread, 1},
     735        {"DetachThread",  PyXPCOMMethod_DetachThread, 1},
    734736#endif
    735737#ifdef VBOX_DEBUG_LIFETIMES
     
    854856
    855857#ifdef VBOX_PYXPCOM
    856 #include <VBox/com/com.h>
     858# include <VBox/com/com.h>
    857859using namespace com;
    858860
    859 #include <iprt/initterm.h>
    860 #include <iprt/string.h>
    861 #include <iprt/alloca.h>
    862 #include <iprt/stream.h>
    863 
    864 #if PY_MAJOR_VERSION <= 2
     861# include <iprt/initterm.h>
     862# include <iprt/string.h>
     863# include <iprt/alloca.h>
     864# include <iprt/stream.h>
     865
     866/** Set if NS_ShutdownXPCOM has been called successfully already and we don't
     867 * need to do it again during module termination.  This avoids assertion in the
     868 * VBoxCOM glue code. */
     869static bool g_fComShutdownAlready = true;
     870
     871# if PY_MAJOR_VERSION <= 2
    865872extern "C" NS_EXPORT
    866873void
    867 #else
     874# else
    868875/** @todo r=klaus this is hacky, but as Python3 doesn't deal with ELF
    869876 * visibility, assuming that all globals are visible (which is ugly and not
    870877 * true in our case). */
    871 #undef PyMODINIT_FUNC
    872 #define PyMODINIT_FUNC extern "C" NS_EXPORT PyObject*
     878#  undef PyMODINIT_FUNC
     879#  define PyMODINIT_FUNC extern "C" NS_EXPORT PyObject*
    873880PyMODINIT_FUNC
    874 #endif
     881# endif
    875882initVBoxPython() { /* NOTE! This name is redefined at the top of the file! */
    876883  static bool s_vboxInited = false;
    877884  if (!s_vboxInited) {
    878     int rc = 0;
    879 
    880 #if defined(VBOX_PATH_APP_PRIVATE_ARCH) && defined(VBOX_PATH_SHARED_LIBS)
     885    int rc = 0; /* Error handling in this code is NON-EXISTING. Sigh. */
     886
     887# if defined(VBOX_PATH_APP_PRIVATE_ARCH) && defined(VBOX_PATH_SHARED_LIBS)
    881888    rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
    882 #else
     889# else
    883890    const char *home = getenv("VBOX_PROGRAM_PATH");
    884891    if (home) {
     
    891898      rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
    892899    }
    893 #endif
     900# endif
    894901
    895902    rc = com::Initialize();
    896 
    897 #if PY_MAJOR_VERSION <= 2
     903    g_fComShutdownAlready = false;
     904
     905# if PY_MAJOR_VERSION <= 2
    898906    init_xpcom();
    899 #else
     907# else
    900908    return init_xpcom();
    901 #endif
     909# endif
    902910  }
    903 #if PY_MAJOR_VERSION >= 3
     911# if PY_MAJOR_VERSION >= 3
    904912  return NULL;
    905 #endif
     913# endif
    906914}
    907915
    908916static
    909 void deinitVBoxPython()
    910 {
    911   com::Shutdown();
     917nsresult deinitVBoxPython()
     918{
     919  nsresult nr;
     920  if (!g_fComShutdownAlready)
     921  {
     922    nr = com::Shutdown();
     923    if (!NS_FAILED(nr))
     924      g_fComShutdownAlready = true;
     925  }
     926  else
     927    nr = NS_ERROR_NOT_INITIALIZED;
     928  return nr;
    912929}
    913930
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