MCPcopy Create free account
hub / github.com/mhammond/pywin32 / CreateNewPythonInstance

Method CreateNewPythonInstance

com/win32com/src/PyFactory.cpp:114–151  ·  view source on GitHub ↗

NOTE NOTE: CreateNewPythonInstance assumes that you have the Python thread lock already acquired.

Source from the content-addressed store, hash-verified

112// NOTE NOTE: CreateNewPythonInstance assumes that you have the Python thread lock
113// already acquired.
114STDMETHODIMP CPyFactory::CreateNewPythonInstance(REFCLSID rclsid, REFCLSID rReqiid, PyObject **ppNewInstance)
115{
116 extern BOOL LoadGatewayModule(PyObject **);
117 PyObject *pPyModule;
118
119 if ( ppNewInstance == NULL )
120 return E_INVALIDARG;
121
122 if ( !LoadGatewayModule(&pPyModule) )
123 return E_FAIL;
124
125 // zap any existing errors so we can reliably check for errors
126 // after object creation.
127 PyErr_Clear();
128 PyObject *obiid = PyWinObject_FromIID(rclsid);
129 PyObject *obReqiid = PyWinObject_FromIID(rReqiid);
130 if ( !obiid || !obReqiid)
131 {
132 Py_XDECREF(pPyModule);
133 Py_XDECREF(obiid);
134 Py_XDECREF(obReqiid);
135 PyErr_Clear(); // nothing Python can do!
136 return E_OUTOFMEMORY;
137 }
138
139 *ppNewInstance = PyObject_CallMethod(pPyModule, "CreateInstance",
140 "OO", obiid, obReqiid);
141 // Check the error state before DECREFs, otherwise they may
142 // change the error state.
143 if ( !*ppNewInstance )
144 PyCom_LoggerException(NULL, "ERROR: server.policy could not create an instance.");
145 HRESULT hr = PyCom_SetCOMErrorFromPyException(IID_IClassFactory);
146 Py_DECREF(obiid);
147 Py_DECREF(obReqiid);
148 Py_DECREF(pPyModule);
149
150 return hr;
151}
152
153/*
154** Load our C <-> Python gateway module if needed

Callers

nothing calls this directly

Calls 4

LoadGatewayModuleFunction · 0.85
PyWinObject_FromIIDFunction · 0.85
PyCom_LoggerExceptionFunction · 0.85

Tested by

no test coverage detected