Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
TabWidth: 4
UseTab: Never

# https://clang.llvm.org/docs/ClangFormatStyleOptions.html#macroblockbegin
MacroBlockBegin: Py_BEGIN_ALLOW_THREADS
MacroBlockEnd: Py_END_ALLOW_THREADS
5 changes: 4 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ b74bfdca97238735adbd1b20d7245cca7070900f
# 2025-11-25 renormalized line endings in adodbapi
d8f97a8c8f72263d336fc4050f83e007ac6e770d

# 3036-04-27 renamed Pythonwin folder to pythonwin
# 2026-04-27 renamed Pythonwin folder to pythonwin
5ed60c439db929d82acc09c9a85a417e406d6429

# 2026-05-04 reformatted Py_*_ALLOW_THREADS with clang-format MacroBlock
a44059e33471b9b6958e2667b9140aeec01b4dd9
57 changes: 30 additions & 27 deletions com/win32com/src/ErrorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ BOOL PyCom_SetCOMErrorFromExcepInfo(const EXCEPINFO *pexcepinfo, REFIID riid)
pICEI->SetSource(pexcepinfo->bstrSource);

IErrorInfo *pIEI;
Py_BEGIN_ALLOW_THREADS hr = pICEI->QueryInterface(IID_IErrorInfo, (LPVOID *)&pIEI);
Py_END_ALLOW_THREADS if (SUCCEEDED(hr))
{
Py_BEGIN_ALLOW_THREADS
hr = pICEI->QueryInterface(IID_IErrorInfo, (LPVOID *)&pIEI);
Py_END_ALLOW_THREADS
if (SUCCEEDED(hr)) {
SetErrorInfo(0, pIEI);
pIEI->Release();
}
Expand Down Expand Up @@ -546,17 +547,19 @@ PyObject *PyCom_BuildPyException(HRESULT errorhr, IUnknown *pUnk /* = NULL */, R
// See if it supports error info.
ISupportErrorInfo *pSEI;
HRESULT hr;
Py_BEGIN_ALLOW_THREADS hr = pUnk->QueryInterface(IID_ISupportErrorInfo, (void **)&pSEI);
Py_BEGIN_ALLOW_THREADS
hr = pUnk->QueryInterface(IID_ISupportErrorInfo, (void **)&pSEI);
if (SUCCEEDED(hr)) {
hr = pSEI->InterfaceSupportsErrorInfo(iid);
pSEI->Release(); // Finished with this object
}
Py_END_ALLOW_THREADS
if (SUCCEEDED(hr)) {
hr = pSEI->InterfaceSupportsErrorInfo(iid);
pSEI->Release(); // Finished with this object
}
Py_END_ALLOW_THREADS if (SUCCEEDED(hr))
{
IErrorInfo *pEI;
Py_BEGIN_ALLOW_THREADS hr = GetErrorInfo(0, &pEI);
Py_END_ALLOW_THREADS if (hr == S_OK)
{
Py_BEGIN_ALLOW_THREADS
hr = GetErrorInfo(0, &pEI);
Py_END_ALLOW_THREADS
if (hr == S_OK) {
obEI = PyCom_PyObjectFromIErrorInfo(pEI, errorhr);
PYCOM_RELEASE(pEI);
}
Expand Down Expand Up @@ -655,37 +658,37 @@ static PyObject *PyCom_PyObjectFromIErrorInfo(IErrorInfo *pEI, HRESULT errorhr)

HRESULT hr;

Py_BEGIN_ALLOW_THREADS hr = pEI->GetDescription(&desc);
Py_END_ALLOW_THREADS if (hr != S_OK)
{
Py_BEGIN_ALLOW_THREADS
hr = pEI->GetDescription(&desc);
Py_END_ALLOW_THREADS
if (hr != S_OK) {
obDesc = Py_None;
Py_INCREF(obDesc);
}
else
{
else {
obDesc = MakeBstrToObj(desc);
SysFreeString(desc);
}

Py_BEGIN_ALLOW_THREADS hr = pEI->GetSource(&source);
Py_END_ALLOW_THREADS if (hr != S_OK)
{
Py_BEGIN_ALLOW_THREADS
hr = pEI->GetSource(&source);
Py_END_ALLOW_THREADS
if (hr != S_OK) {
obSource = Py_None;
Py_INCREF(obSource);
}
else
{
else {
obSource = MakeBstrToObj(source);
SysFreeString(source);
}
Py_BEGIN_ALLOW_THREADS hr = pEI->GetHelpFile(&helpfile);
Py_END_ALLOW_THREADS if (hr != S_OK)
{
Py_BEGIN_ALLOW_THREADS
hr = pEI->GetHelpFile(&helpfile);
Py_END_ALLOW_THREADS
if (hr != S_OK) {
obHelpFile = Py_None;
Py_INCREF(obHelpFile);
}
else
{
else {
obHelpFile = MakeBstrToObj(helpfile);
SysFreeString(helpfile);
}
Expand Down
7 changes: 4 additions & 3 deletions com/win32com/src/PyComHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,10 @@ BOOL PyCom_InterfaceFromPyObject(PyObject *ob, REFIID iid, LPVOID *ppv, BOOL bNo
return FALSE; /* exception was set by GetI() */
/* note: we don't explicitly hold a reference to punk */
HRESULT hr;
Py_BEGIN_ALLOW_THREADS hr = punk->QueryInterface(iid, ppv);
Py_END_ALLOW_THREADS if (FAILED(hr))
{
Py_BEGIN_ALLOW_THREADS
hr = punk->QueryInterface(iid, ppv);
Py_END_ALLOW_THREADS
if (FAILED(hr)) {
PyCom_BuildPyException(hr);
return FALSE;
}
Expand Down
64 changes: 33 additions & 31 deletions com/win32com/src/PyIDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ static BOOL ExcepInfoFromIErrorInfo(EXCEPINFO *einfo, IDispatch *pDisp, HRESULT
}
ISupportErrorInfo *pSEI;
HRESULT hr;
Py_BEGIN_ALLOW_THREADS hr = pDisp->QueryInterface(IID_ISupportErrorInfo, (void **)&pSEI);
if (SUCCEEDED(hr)) {
hr = pSEI->InterfaceSupportsErrorInfo(IID_IDispatch);
pSEI->Release(); // Finished with this object
}
Py_BEGIN_ALLOW_THREADS
hr = pDisp->QueryInterface(IID_ISupportErrorInfo, (void **)&pSEI);
if (SUCCEEDED(hr)) {
hr = pSEI->InterfaceSupportsErrorInfo(IID_IDispatch);
pSEI->Release(); // Finished with this object
}
Py_END_ALLOW_THREADS

// InterfaceSupportsErrorInfo returning S_FALSE means we should ignore it.
if (FAILED(hr) || hr == S_FALSE)
{
// InterfaceSupportsErrorInfo returning S_FALSE means we should ignore it.
if (FAILED(hr) || hr == S_FALSE) {
return FALSE;
}

// ErrorInfo via IErrorInfo hence transform to EXCEPINFO
IErrorInfo *pEI;
Py_BEGIN_ALLOW_THREADS hr = GetErrorInfo(0, &pEI);
Py_BEGIN_ALLOW_THREADS
hr = GetErrorInfo(0, &pEI);
Py_END_ALLOW_THREADS

if (hr != S_OK)
{
if (hr != S_OK) {
return FALSE;
}
// These strings will be freed when PyCom_CleanupExcepInfo is called
Expand All @@ -41,26 +41,28 @@ static BOOL ExcepInfoFromIErrorInfo(EXCEPINFO *einfo, IDispatch *pDisp, HRESULT
BSTR source = NULL;
BSTR helpfile = NULL;

Py_BEGIN_ALLOW_THREADS hr = pEI->GetDescription(&desc);
if (hr == S_OK) {
einfo->bstrDescription = desc;
}
hr = pEI->GetSource(&source);
if (hr == S_OK) {
einfo->bstrSource = source;
}
hr = pEI->GetHelpFile(&helpfile);
if (hr == S_OK) {
einfo->bstrHelpFile = helpfile;
}
DWORD helpContext = 0;
hr = pEI->GetHelpContext(&helpContext);
if (hr == S_OK) {
einfo->dwHelpContext = helpContext;
}
einfo->wCode = 0;
einfo->scode = scode;
Py_END_ALLOW_THREADS PYCOM_RELEASE(pEI);
Py_BEGIN_ALLOW_THREADS
hr = pEI->GetDescription(&desc);
if (hr == S_OK) {
einfo->bstrDescription = desc;
}
hr = pEI->GetSource(&source);
if (hr == S_OK) {
einfo->bstrSource = source;
}
hr = pEI->GetHelpFile(&helpfile);
if (hr == S_OK) {
einfo->bstrHelpFile = helpfile;
}
DWORD helpContext = 0;
hr = pEI->GetHelpContext(&helpContext);
if (hr == S_OK) {
einfo->dwHelpContext = helpContext;
}
einfo->wCode = 0;
einfo->scode = scode;
Py_END_ALLOW_THREADS
PYCOM_RELEASE(pEI);
return TRUE;
}

Expand Down
Loading
Loading