-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"a foreign function that will call a COM method" generated by ctypes.WINFUNCTYPE
works in Python3.7, does not work as same in newer Python
#99952
Comments
Unfortunatelly the bug still exist in the newest (6.12.2022) versions of Python (3.10.9, 3.11.1). For such code:
we have results:
PS: This is an important/real barrier to upgrading Python to versions newer than 3.7. |
Is the bug in the setting or the fetching of that value?
In other words, if you make a spreadsheet manually by hand with those
values, and then change your test case to just open the file and fetch
the values in that cell range, do you get the expected results?
|
The same behaviour. For such code:
we have results:
PS: py>3.7 gets last cell in the row instead of whole row. |
VARIANT("A1") and VARIANT("C1") are created by from_param() for calling com method.
|
Here is minimal reproducible code.
|
Yes! I can confim. After commented: comtypes works as expected also for Py 3.8, 3.9, 3.10, 3.11
Thanks, |
Perhaps ctypes's StructParam_Type should keep object which copied from.
|
Yes. Seems like a main reason of this bug is a different object lifetime in Py <= 3.7, and Py >= 3.8 Maybe in comtypes will be useful/enough to use (as worarround/fix) pythonapi''s IncRef(obj)/DecRef(obj) ?? from ctypes import py_object, pythonapi Py_IncRef = pythonapi.Py_IncRef Py_DecRef = pythonapi.Py_DecRef PS: Unfortunately I am also not familiar with Python and ctypes C source code :( |
Fixes a reference counting issue with `ctypes.Structure` when a `from_param()` method call is used and the structure size is larger than a C pointer `sizeof(void*)`. This problem existed for a very long time, but became more apparent in 3.8+ by change likely due to garbage collection cleanup timing changes.
…esult. (pythonGH-100169) Fixes a reference counting issue with `ctypes.Structure` when a `from_param()` method call is used and the structure size is larger than a C pointer `sizeof(void*)`. This problem existed for a very long time, but became more apparent in 3.8+ by change likely due to garbage collection cleanup timing changes.. (cherry picked from commit dfad678) Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
… result (#101339) [3.11] gh-99952: [ctypes] fix refcount issues in from_param() result. (GH-100169) Fixes a reference counting issue with `ctypes.Structure` when a `from_param()` method call is used and the structure size is larger than a C pointer `sizeof(void*)`. This problem existed for a very long time, but became more apparent in 3.8+ by change likely due to garbage collection cleanup timing changes.. (cherry picked from commit dfad678) Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
…aram() result (pythonGH-101339) [3.11] pythongh-99952: [ctypes] fix refcount issues in from_param() result. (pythonGH-100169) Fixes a reference counting issue with `ctypes.Structure` when a `from_param()` method call is used and the structure size is larger than a C pointer `sizeof(void*)`. This problem existed for a very long time, but became more apparent in 3.8+ by change likely due to garbage collection cleanup timing changes.. (cherry picked from commit dfad678) (cherry picked from commit fa7c37a) Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
…ython#100169) Fixes a reference counting issue with `ctypes.Structure` when a `from_param()` method call is used and the structure size is larger than a C pointer `sizeof(void*)`. This problem existed for a very long time, but became more apparent in 3.8+ by change likely due to garbage collection cleanup timing changes.
…param() result (GH-101339) (#101340) [3.11] gh-99952: [ctypes] fix refcount issues in from_param() result. (GH-100169) Fixes a reference counting issue with `ctypes.Structure` when a `from_param()` method call is used and the structure size is larger than a C pointer `sizeof(void*)`. This problem existed for a very long time, but became more apparent in 3.8+ by change likely due to garbage collection cleanup timing changes.. (cherry picked from commit dfad678) (cherry picked from commit fa7c37a) Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com> Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
@junkmd, can you confirm that this is now fixed in the latest bugfix releases? I believe the merged PRs should have been included in 3.10.10 and 3.11.2. |
I have installed Python 3.10.10 and Python 3.11.2 and have run the Thank you. |
Bug report
I'm contributing on enthought/comtypes.
In
comtypes
, there is a test for the behavior of Excel that is currently skipped. If I comment out theunittest.skip
marker in that test, it works in Python 3.7 and fails in Python 3.11.xl.Range[...
calls a prototype-function generated byctypes.WinFunctionType
andctypes.WINFUNCTYPE
.This is also reported in enthought/comtypes#212 and the test fails in Python 3.8 as well.
A strange callback behavior also occurs with simple COM libraries.
Therefore, I think that this may not be caused by the Excel specification.
There may be other regressions in
ctypes
callbacks that have also been reported in #82929.Also, is #97513 a possible solution to this problem?
Any opinions would be appreciated.
Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: