Skip to content

Commit dbbe37d

Browse files
committed
Merge branch 'main' of https://github.com/mhammond/pywin32 into repr-respect-subclass-name
2 parents 5523a2c + 16c4981 commit dbbe37d

File tree

15 files changed

+59
-11
lines changed

15 files changed

+59
-11
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ jobs:
157157
with:
158158
version: "0.8.4"
159159
- run: ruff format --check
160-
- run:
161-
| # Too many files to fit in a single command, also exclude vendored Scintilla and MAPIStubLibrary
160+
- run: | # Too many files to fit in a single command, also exclude vendored Scintilla and MAPIStubLibrary
162161
clang-format --Werror --dry-run $(git ls-files '*.cpp' ':!:com/win32comext/mapi/src/MAPIStubLibrary/')
163162
if ($LastExitCode -ne 0) { exit $LastExitCode }
164163
clang-format --Werror --dry-run $(git ls-files '*.h' ':!:Pythonwin/Scintilla/' ':!:com/win32comext/mapi/src/MAPIStubLibrary/')

CHANGES.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ https://mhammond.github.io/pywin32_installers.html .
1414
Coming in build 311, as yet unreleased
1515
--------------------------------------
1616
* Fixed a regression that broke special __dunder__ methods with CoClass. (#1870, #2493, @Avasam, @geppi)
17+
* Fixed a memory leak when SafeArrays are used as out parameters (@the-snork)
1718
* Fixed dispatch handling for properties (@the-snork)
19+
* The following classes will now use the correct subclass name in `repr`: (#2570, @Avasam)
20+
* `pywin.tools.browser.HLIPythonObject`
21+
* `win32com.client.VARIANT`
22+
* `win32com.client.build.MapEntry`
23+
* `win32com.server.exception.COMException`
24+
* `win32comext.axdebug.debugger.ModuleTreeNode`
25+
* `win32comext.axscript.client.pyscript.NamedScriptAttribute`
26+
* `win32comext.axscript.client.error.AXScriptException`
27+
* `win32pdhquery.QueryError`
28+
* `win32rcparser.StringDef`
1829

1930
Build 310, released 2025/03/16
2031
------------------------------

com/TestSources/PyCOMTest/PyCOMImpl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ STDMETHODIMP CPyCOMTest::GetSafeArrays(SAFEARRAY **attrs, SAFEARRAY **attrs2, SA
379379
return S_OK;
380380
}
381381

382+
STDMETHODIMP CPyCOMTest::GetByteArray(long sizeBytes, SAFEARRAY **array)
383+
{
384+
SAFEARRAYBOUND bound = {static_cast<ULONG>(sizeBytes), 0};
385+
*array = SafeArrayCreate(VT_UI1, 1, &bound);
386+
return S_OK;
387+
}
388+
382389
STDMETHODIMP CPyCOMTest::GetSimpleSafeArray(SAFEARRAY **attrs) { return MakeFillIntArray(attrs, 10, VT_I4); }
383390

384391
STDMETHODIMP CPyCOMTest::CheckVariantSafeArray(SAFEARRAY **attrs, int *result)

com/TestSources/PyCOMTest/PyCOMImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CPyCOMTest : public IDispatchImpl<IPyCOMTest, &IID_IPyCOMTest, &LIBID_PyCO
8080
STDMETHOD(SetDoubleSafeArray)(SAFEARRAY *vars, int *retSize);
8181
STDMETHOD(SetFloatSafeArray)(SAFEARRAY *vars, int *retSize);
8282
STDMETHOD(GetSafeArrays)(SAFEARRAY **attrs, SAFEARRAY **attrs2, SAFEARRAY **ints);
83+
STDMETHOD(GetByteArray)(long sizeBytes, SAFEARRAY **array);
8384
STDMETHOD(GetSimpleSafeArray)(SAFEARRAY **ints);
8485
STDMETHOD(ChangeDoubleSafeArray)(SAFEARRAY **vals);
8586
STDMETHOD(GetSimpleCounter)(ISimpleCounter **counter);

com/TestSources/PyCOMTest/PyCOMTest.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ library PyCOMTestLib
235235
HRESULT GetSafeArrays([out] SAFEARRAY(QsAttribute)* attrs,
236236
[out] SAFEARRAY(enum tagQsAttribute)*attrs2,
237237
[out] SAFEARRAY(int)*ints);
238+
HRESULT GetByteArray([in] long sizeInBytes, [out] SAFEARRAY(byte) *bytes);
238239
HRESULT ChangeDoubleSafeArray([in, out]SAFEARRAY(double)*vals);
239240
HRESULT GetSimpleCounter([out, retval] ISimpleCounter** counter);
240241
HRESULT CheckVariantSafeArray([in] SAFEARRAY(VARIANT)* data, [out, retval]int *sum);

com/TestSources/PyCOMTest/PyCOMTest.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,4 @@
161161
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
162162
<ImportGroup Label="ExtensionTargets">
163163
</ImportGroup>
164-
</Project>
164+
</Project>

com/win32com/client/combrowse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import sys
2727

2828
import pythoncom
29+
import pywintypes
2930
import win32api
3031
import win32con
3132
import win32ui
@@ -61,7 +62,7 @@ def CalculateIsExpandable(self):
6162
class HLICLSID(HLICOM):
6263
def __init__(self, myobject, name=None):
6364
if isinstance(myobject, str):
64-
myobject = pythoncom.MakeIID(myobject)
65+
myobject = pywintypes.IID(myobject)
6566
if name is None:
6667
try:
6768
name = pythoncom.ProgIDFromCLSID(myobject)

com/win32com/demos/connect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
# is cheated on - so this is still working as a fully-fledged server.
77

88
import pythoncom
9+
import pywintypes
910
import win32com.server.connect
1011
import win32com.server.util
1112

1213
# This is the IID of the Events interface both Client and Server support.
13-
IID_IConnectDemoEvents = pythoncom.MakeIID("{A4988850-49C3-11d0-AE5D-52342E000000}")
14+
IID_IConnectDemoEvents = pywintypes.IID("{A4988850-49C3-11d0-AE5D-52342E000000}")
1415

1516
# The server which implements
1617
# Create a connectable class, that has a single public method

com/win32com/server/policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _wrap_(self, object):
257257
if i[0] != "{":
258258
i = pythoncom.InterfaceNames[i]
259259
else:
260-
i = pythoncom.MakeIID(i)
260+
i = pywintypes.IID(i)
261261
self._com_interfaces_.append(i)
262262
else:
263263
self._com_interfaces_ = []

com/win32com/src/PyIDispatch.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,12 @@ PyObject *PyIDispatch::InvokeTypes(PyObject *self, PyObject *args)
517517

518518
error:
519519
if (dispparams.rgvarg) {
520-
for (i = dispparams.cArgs; i--;) VariantClear(&dispparams.rgvarg[i]);
520+
for (i = dispparams.cArgs; i--;) {
521+
if ((V_VT(&dispparams.rgvarg[i]) & ~VT_TYPEMASK) == (VT_BYREF | VT_ARRAY)) {
522+
SafeArrayDestroy(*V_ARRAYREF(&dispparams.rgvarg[i]));
523+
}
524+
VariantClear(&dispparams.rgvarg[i]);
525+
}
521526
delete[] dispparams.rgvarg;
522527
}
523528
delete[] ArgHelpers;

com/win32com/test/testDynamic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Test dynamic policy, and running object table.
22

33
import pythoncom
4+
import pywintypes
45
import winerror
56
from win32com.server.exception import COMException
67

7-
iid = pythoncom.MakeIID("{b48969a0-784b-11d0-ae71-d23f56000000}")
8+
iid = pywintypes.IID("{b48969a0-784b-11d0-ae71-d23f56000000}")
89

910

1011
class VeryPermissive:

com/win32com/test/testPyComTest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import win32com.test.util
1717
import win32timezone
1818
import winerror
19+
from win32api import CloseHandle, GetCurrentProcessId, OpenProcess
1920
from win32com.client import (
2021
VARIANT,
2122
CastTo,
@@ -24,6 +25,7 @@
2425
constants,
2526
register_record_class,
2627
)
28+
from win32process import GetProcessMemoryInfo
2729

2830
importMsg = "**** PyCOMTest is not installed ***\n PyCOMTest is a Python test specific COM client and server.\n It is likely this server is not installed on this machine\n To install the server, you must get the win32com sources\n and build it using MS Visual C++"
2931

@@ -137,6 +139,16 @@ def TestConstant(constName, pyConst):
137139
), f"Constant value wrong for {constName} - got {comConst}, wanted {pyConst}"
138140

139141

142+
def GetMemoryUsage():
143+
pid = GetCurrentProcessId()
144+
PROCESS_QUERY_INFORMATION = 0x0400
145+
PROCESS_VM_READ = 0x0010
146+
hprocess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, pid)
147+
mem_info = GetProcessMemoryInfo(hprocess)
148+
CloseHandle(hprocess)
149+
return mem_info["WorkingSetSize"]
150+
151+
140152
# Simple handler class. This demo only fires one event.
141153
class RandomEventHandler:
142154
def _Init(self):
@@ -601,6 +613,13 @@ def TestGenerated():
601613
TestApplyResult(o.SetLongLongSafeArray, (ll,), len(ll))
602614
TestApplyResult(o.SetULongLongSafeArray, (ll,), len(ll))
603615

616+
# check freeing of safe arrays
617+
mem_before = GetMemoryUsage()
618+
o.GetByteArray(50 * 1024 * 1024)
619+
mem_after = GetMemoryUsage()
620+
delta = mem_after - mem_before
621+
assert delta < 1024 * 1024, f"Memory not freed - delta {delta / (1024 * 1024)} MB"
622+
604623
# Tell the server to do what it does!
605624
TestApplyResult(o.Test2, (constants.Attr2,), constants.Attr2)
606625
TestApplyResult(o.Test3, (constants.Attr2,), constants.Attr2)

com/win32com/test/testShell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def testSimpleUnicode(self):
151151
self._testSimple(True)
152152

153153
def testComplex(self):
154-
clsid = pythoncom.MakeIID("{CD637886-DB8B-4b04-98B5-25731E1495BE}")
154+
clsid = pywintypes.IID("{CD637886-DB8B-4b04-98B5-25731E1495BE}")
155155
ctime, atime, wtime = self._getTestTimes()
156156
d = {
157157
"cFileName": "foo.txt",

com/win32comext/axscript/test/leakTest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22

33
import pythoncom
4+
import pywintypes
45
from win32com.axscript import axscript
56
from win32com.axscript.server import axsite
67
from win32com.server import connect, util
@@ -53,7 +54,7 @@ def echo(self, *args):
5354
#### Connections currently won't work, as there is no way for the engine to
5455
#### know what events we support. We need typeinfo support.
5556

56-
IID_ITestEvents = pythoncom.MakeIID("{8EB72F90-0D44-11d1-9C4B-00AA00125A98}")
57+
IID_ITestEvents = pywintypes.IID("{8EB72F90-0D44-11d1-9C4B-00AA00125A98}")
5758

5859

5960
class TestConnectServer(connect.ConnectableServer):

com/win32comext/axscript/test/testHost.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import unittest
33

44
import pythoncom
5+
import pywintypes
56
import win32com.server.policy
67
import win32com.test.util
78
from win32com.axscript import axscript
@@ -72,7 +73,7 @@ def fail(self, *args):
7273
#### Connections currently won't work, as there is no way for the engine to
7374
#### know what events we support. We need typeinfo support.
7475

75-
IID_ITestEvents = pythoncom.MakeIID("{8EB72F90-0D44-11d1-9C4B-00AA00125A98}")
76+
IID_ITestEvents = pywintypes.IID("{8EB72F90-0D44-11d1-9C4B-00AA00125A98}")
7677

7778

7879
class TestConnectServer(connect.ConnectableServer):

0 commit comments

Comments
 (0)