From f59e1ba873d8da346764f9c56724a5ef727def0d Mon Sep 17 00:00:00 2001 From: Florian Demski Date: Tue, 15 Apr 2025 08:22:02 +0200 Subject: [PATCH 1/9] fix --- CHANGES.txt | 1 + com/TestSources/PyCOMTest/PyCOMImpl.cpp | 10 ++++++++ com/TestSources/PyCOMTest/PyCOMImpl.h | 1 + com/TestSources/PyCOMTest/PyCOMTest.idl | 3 ++- com/win32com/client/build.py | 19 +++++++++++++- com/win32com/client/genpy.py | 11 ++++++++ com/win32com/client/makepy.py | 4 +++ com/win32com/test/testPyComTest.py | 34 +++++++++++++++++++++++++ 8 files changed, 81 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index fb0bd8ce0b..a801e0f560 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -15,6 +15,7 @@ Coming in build 311, as yet unreleased -------------------------------------- * Fixed a regression that broke special __dunder__ methods with CoClass. (#1870, #2493, @Avasam, @geppi) * Fixed dispatch handling for properties (@the-snork) +* Fixed struct handling in makepy generated code (@the-snork) Build 310, released 2025/03/16 ------------------------------ diff --git a/com/TestSources/PyCOMTest/PyCOMImpl.cpp b/com/TestSources/PyCOMTest/PyCOMImpl.cpp index 2303421359..2b56747fff 100644 --- a/com/TestSources/PyCOMTest/PyCOMImpl.cpp +++ b/com/TestSources/PyCOMTest/PyCOMImpl.cpp @@ -619,6 +619,16 @@ HRESULT CPyCOMTest::GetStruct(TestStruct1 *ret) return S_OK; } +HRESULT CPyCOMTest::GetOutStruct(TestStruct1 *ret) +{ + if (ret == NULL) { + return E_POINTER; + } + ret->int_value = 99; + ret->str_value = SysAllocString(L"Hello from C++"); + return S_OK; +} + HRESULT CPyCOMTest::ModifyStruct(TestStruct1 *prec) { prec->int_value = 100; diff --git a/com/TestSources/PyCOMTest/PyCOMImpl.h b/com/TestSources/PyCOMTest/PyCOMImpl.h index 7b1f83c2b5..c985bf687b 100644 --- a/com/TestSources/PyCOMTest/PyCOMImpl.h +++ b/com/TestSources/PyCOMTest/PyCOMImpl.h @@ -98,6 +98,7 @@ class CPyCOMTest : public IDispatchImpl Date: Sat, 19 Apr 2025 14:04:28 +0200 Subject: [PATCH 2/9] Update PyCOMTest.idl review --- com/TestSources/PyCOMTest/PyCOMTest.idl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com/TestSources/PyCOMTest/PyCOMTest.idl b/com/TestSources/PyCOMTest/PyCOMTest.idl index 9478f2dfc7..1f39988a8b 100644 --- a/com/TestSources/PyCOMTest/PyCOMTest.idl +++ b/com/TestSources/PyCOMTest/PyCOMTest.idl @@ -26,7 +26,7 @@ typedef enum // Missing EnumTestAttributes2 uuid(6bcdcb60-5605-11d0-ae5f-cadd4c000000), version(1.1), // an extended character in the help string should stress things... - helpstring("Python COM Test Harness 1.0 Type Library, © pywin32 contributors") + helpstring("Python COM Test Harness 1.0 Type Library, © pywin32 contributors") ] library PyCOMTestLib { @@ -70,7 +70,7 @@ library PyCOMTestLib const long LongTest2 = 0x7FFFFFFFL; const unsigned char UCharTest = 255; const char CharTest = -1; - const LPWSTR StringTest = L"Hello Wo®ld"; + const LPWSTR StringTest = L"Hello Wo®ld"; }; enum TestAttributes3{ // Note missing the enum name. @@ -260,8 +260,8 @@ library PyCOMTestLib [in, defaultvalue(1)] short sval, [out, retval] IPyCOMTest **ppout ); HRESULT GetStruct([out, retval]TestStruct1 *ret); - HRESULT GetOutStruct([ out ] TestStruct1 * ret); - HRESULT DoubleString([in] BSTR inStr, [ out, retval ] BSTR * outStr); + HRESULT GetOutStruct([out] TestStruct1 *ret); + HRESULT DoubleString([in] BSTR inStr, [out, retval] BSTR * outStr); HRESULT DoubleInOutString([in,out] BSTR *str); [restricted] HRESULT NotScriptable([in,out] int *val); From 5131e7c3f2141bdc5cc0673f4ab4b2ccfa7b5ee5 Mon Sep 17 00:00:00 2001 From: the-snork Date: Sat, 19 Apr 2025 18:04:13 +0200 Subject: [PATCH 3/9] fix --- com/TestSources/PyCOMTest/PyCOMTest.idl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/com/TestSources/PyCOMTest/PyCOMTest.idl b/com/TestSources/PyCOMTest/PyCOMTest.idl index 6cb89679bb..b63b1155c6 100644 --- a/com/TestSources/PyCOMTest/PyCOMTest.idl +++ b/com/TestSources/PyCOMTest/PyCOMTest.idl @@ -26,7 +26,7 @@ typedef enum // Missing EnumTestAttributes2 uuid(6bcdcb60-5605-11d0-ae5f-cadd4c000000), version(1.1), // an extended character in the help string should stress things... - helpstring("Python COM Test Harness 1.0 Type Library, © pywin32 contributors") + helpstring("Python COM Test Harness 1.0 Type Library, ? pywin32 contributors") ] library PyCOMTestLib { @@ -70,7 +70,7 @@ library PyCOMTestLib const long LongTest2 = 0x7FFFFFFFL; const unsigned char UCharTest = 255; const char CharTest = -1; - const LPWSTR StringTest = L"Hello Wo®ld"; + const LPWSTR StringTest = L"Hello Wo?ld"; }; enum TestAttributes3{ // Note missing the enum name. @@ -235,7 +235,6 @@ library PyCOMTestLib HRESULT GetSafeArrays([out] SAFEARRAY(QsAttribute)* attrs, [out] SAFEARRAY(enum tagQsAttribute)*attrs2, [out] SAFEARRAY(int)*ints); - HRESULT GetByteArray([in] long sizeInBytes, [out] SAFEARRAY(byte) *bytes); HRESULT ChangeDoubleSafeArray([in, out]SAFEARRAY(double)*vals); HRESULT GetSimpleCounter([out, retval] ISimpleCounter** counter); HRESULT CheckVariantSafeArray([in] SAFEARRAY(VARIANT)* data, [out, retval]int *sum); @@ -262,7 +261,7 @@ library PyCOMTestLib [out, retval] IPyCOMTest **ppout ); HRESULT GetStruct([out, retval]TestStruct1 *ret); HRESULT GetOutStruct([out] TestStruct1 *ret); - HRESULT DoubleString([in] BSTR inStr, [out, retval] BSTR * outStr); + HRESULT DoubleString([in] BSTR inStr, [out, retval] BSTR *outStr); HRESULT DoubleInOutString([in,out] BSTR *str); [restricted] HRESULT NotScriptable([in,out] int *val); @@ -300,9 +299,9 @@ library PyCOMTestLib // reserved words etc HRESULT None(); HRESULT def(); - // Test struct byref as [ in, out ] parameter. - HRESULT ModifyStruct([ in, out ] TestStruct1 * prec); - HRESULT VerifyArrayOfStructs([in] TestStruct2 * prec, [ out, retval ] VARIANT_BOOL * is_ok); + // Test struct byref as [in, out] parameter. + HRESULT ModifyStruct([in, out] TestStruct1 * prec); + HRESULT VerifyArrayOfStructs([in] TestStruct2 * prec, [out, retval] VARIANT_BOOL * is_ok); }; // Define a new class to test how Python handles derived interfaces! From e6bbc1c030d29e46aedd6c9d93150b48039b1ef7 Mon Sep 17 00:00:00 2001 From: the-snork Date: Sat, 19 Apr 2025 18:06:30 +0200 Subject: [PATCH 4/9] encoding --- com/TestSources/PyCOMTest/PyCOMTest.idl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com/TestSources/PyCOMTest/PyCOMTest.idl b/com/TestSources/PyCOMTest/PyCOMTest.idl index b63b1155c6..3f865f944f 100644 --- a/com/TestSources/PyCOMTest/PyCOMTest.idl +++ b/com/TestSources/PyCOMTest/PyCOMTest.idl @@ -26,7 +26,7 @@ typedef enum // Missing EnumTestAttributes2 uuid(6bcdcb60-5605-11d0-ae5f-cadd4c000000), version(1.1), // an extended character in the help string should stress things... - helpstring("Python COM Test Harness 1.0 Type Library, ? pywin32 contributors") + helpstring("Python COM Test Harness 1.0 Type Library, � pywin32 contributors") ] library PyCOMTestLib { @@ -70,7 +70,7 @@ library PyCOMTestLib const long LongTest2 = 0x7FFFFFFFL; const unsigned char UCharTest = 255; const char CharTest = -1; - const LPWSTR StringTest = L"Hello Wo?ld"; + const LPWSTR StringTest = L"Hello Wo�ld"; }; enum TestAttributes3{ // Note missing the enum name. From b41420e682cf3fffa069d6e97c5b79a5826ba3c9 Mon Sep 17 00:00:00 2001 From: the-snork Date: Sat, 19 Apr 2025 18:10:30 +0200 Subject: [PATCH 5/9] fix --- com/TestSources/PyCOMTest/PyCOMTest.idl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com/TestSources/PyCOMTest/PyCOMTest.idl b/com/TestSources/PyCOMTest/PyCOMTest.idl index 3f865f944f..de2d63ba1d 100644 --- a/com/TestSources/PyCOMTest/PyCOMTest.idl +++ b/com/TestSources/PyCOMTest/PyCOMTest.idl @@ -26,7 +26,7 @@ typedef enum // Missing EnumTestAttributes2 uuid(6bcdcb60-5605-11d0-ae5f-cadd4c000000), version(1.1), // an extended character in the help string should stress things... - helpstring("Python COM Test Harness 1.0 Type Library, � pywin32 contributors") + helpstring("Python COM Test Harness 1.0 Type Library, © pywin32 contributors") ] library PyCOMTestLib { @@ -70,7 +70,7 @@ library PyCOMTestLib const long LongTest2 = 0x7FFFFFFFL; const unsigned char UCharTest = 255; const char CharTest = -1; - const LPWSTR StringTest = L"Hello Wo�ld"; + const LPWSTR StringTest = L"Hello Wo©ld"; }; enum TestAttributes3{ // Note missing the enum name. From 9c1388bb260e35f7973a1439086b374113b28fd3 Mon Sep 17 00:00:00 2001 From: the-snork Date: Sat, 19 Apr 2025 18:13:02 +0200 Subject: [PATCH 6/9] encoding wars --- com/TestSources/PyCOMTest/PyCOMTest.idl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com/TestSources/PyCOMTest/PyCOMTest.idl b/com/TestSources/PyCOMTest/PyCOMTest.idl index de2d63ba1d..ced1619c53 100644 --- a/com/TestSources/PyCOMTest/PyCOMTest.idl +++ b/com/TestSources/PyCOMTest/PyCOMTest.idl @@ -70,7 +70,7 @@ library PyCOMTestLib const long LongTest2 = 0x7FFFFFFFL; const unsigned char UCharTest = 255; const char CharTest = -1; - const LPWSTR StringTest = L"Hello Wo©ld"; + const LPWSTR StringTest = L"Hello Wo®ld"; }; enum TestAttributes3{ // Note missing the enum name. From c9a1dcec078a502c244b5ea4df08376b2f81767b Mon Sep 17 00:00:00 2001 From: the-snork Date: Sat, 19 Apr 2025 18:15:13 +0200 Subject: [PATCH 7/9] Update com/win32com/client/build.py Co-authored-by: Avasam --- com/win32com/client/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com/win32com/client/build.py b/com/win32com/client/build.py index 48cbeed21d..cc7bd84c6d 100644 --- a/com/win32com/client/build.py +++ b/com/win32com/client/build.py @@ -394,7 +394,7 @@ def MakeDispatchFuncMethod(self, entry, name, bMakeClass=1): and desc[3] and desc[3].__class__.__name__ == "PyIID" ): - newVal = f"pythoncom.GetRecordFromGuids(CLSID, MajorVersion, MinorVersion, LCID, {repr(desc[3])})" + newVal = f"pythoncom.GetRecordFromGuids(CLSID, MajorVersion, MinorVersion, LCID, {desc[3]!r})" ret.append(linePrefix + "\t" + f"if {names[i+1]} == {defOutArg}:") ret.append(linePrefix + "\t\t" + f"{names[i+1]} = {newVal}") From e6f5857ad7b55a3fd1ab8e59cb39238394f352f8 Mon Sep 17 00:00:00 2001 From: the-snork Date: Sat, 19 Apr 2025 18:15:30 +0200 Subject: [PATCH 8/9] Update com/win32com/client/build.py Co-authored-by: Avasam --- com/win32com/client/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com/win32com/client/build.py b/com/win32com/client/build.py index cc7bd84c6d..48950d1c90 100644 --- a/com/win32com/client/build.py +++ b/com/win32com/client/build.py @@ -395,8 +395,8 @@ def MakeDispatchFuncMethod(self, entry, name, bMakeClass=1): and desc[3].__class__.__name__ == "PyIID" ): newVal = f"pythoncom.GetRecordFromGuids(CLSID, MajorVersion, MinorVersion, LCID, {desc[3]!r})" - ret.append(linePrefix + "\t" + f"if {names[i+1]} == {defOutArg}:") - ret.append(linePrefix + "\t\t" + f"{names[i+1]} = {newVal}") + ret.append(f"{linePrefix}\tif {names[i+1]} == {defOutArg}:") + ret.append(f"{linePrefix}\t\t{names[i+1]} = {newVal}") resclsid = entry.GetResultCLSID() if resclsid: From 29c653366477d4b0592f2082ae31a051a62d2336 Mon Sep 17 00:00:00 2001 From: the-snork Date: Sat, 19 Apr 2025 23:00:24 +0200 Subject: [PATCH 9/9] fixed merge --- com/TestSources/PyCOMTest/PyCOMTest.idl | 1 + 1 file changed, 1 insertion(+) diff --git a/com/TestSources/PyCOMTest/PyCOMTest.idl b/com/TestSources/PyCOMTest/PyCOMTest.idl index ced1619c53..e91bcb39c7 100644 --- a/com/TestSources/PyCOMTest/PyCOMTest.idl +++ b/com/TestSources/PyCOMTest/PyCOMTest.idl @@ -235,6 +235,7 @@ library PyCOMTestLib HRESULT GetSafeArrays([out] SAFEARRAY(QsAttribute)* attrs, [out] SAFEARRAY(enum tagQsAttribute)*attrs2, [out] SAFEARRAY(int)*ints); + HRESULT GetByteArray([in] long sizeInBytes, [out] SAFEARRAY(byte) *bytes); HRESULT ChangeDoubleSafeArray([in, out]SAFEARRAY(double)*vals); HRESULT GetSimpleCounter([out, retval] ISimpleCounter** counter); HRESULT CheckVariantSafeArray([in] SAFEARRAY(VARIANT)* data, [out, retval]int *sum);