Skip to content

Update VT_ARRAY | VT_RECORD tests. - #982

Merged
junkmd merged 9 commits into
up1_followup_104from
record_safearray_characterization_tests
Nov 5, 2026
Merged

junkmd merged 9 commits into
up1_followup_104from
record_safearray_characterization_tests

Conversation

@junkmd

@junkmd junkmd commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related to #63

The fix itself will be done in a separate PR.

- Define `_SafeArrayGetRecordInfo` at module level using c_void_p in argtypes
  instead of `POINTER(IRecordInfo)`, eliminating the need for local import.
- Use byref for result parameter following surrounding code style.
- Add docstring and type ignore comment for return value.
Since commit 0681ffe, unpacking VT_ARRAYs containing VT_RECORDs
no longer raises `KeyError('36')`.

Update the characterization tests for `WrapBstrRecord`, `WrapValueRecord`,
and `ReverseValueRecords` to verify the expected return values on the
normal path instead of expecting a `KeyError`.
This test uses `faulthandler` and `multiprocessing` to run the test in a
separate process.
The test `call_reverse_bstr_records` was an existing test. This change converts it to a characterization test. It captures and verifies the crash without breaking the whole test suite.

The test probably crashes because of a double-free bug.

Root cause (hypothesis):
- The `VARIANT` has a `SAFEARRAY`. This `SAFEARRAY` probably shares the same
  `BSTR` pointer as `lp`.
- After the COM call returns, `VariantClear` runs. `VariantClear` probably
  frees that `BSTR`.
- Then Python runs `del lp`. This probably tries to free the same `BSTR` again.
- This probably causes a double-free and heap corruption.
@junkmd junkmd added this to the 1.5.0 / Support Python 3.15 milestone Nov 4, 2026
@junkmd junkmd added the tests enhance or fix tests label Nov 4, 2026
@junkmd
junkmd added this pull request to stack #983 November 4, 2026 00:20
@codecov-commenter

codecov-commenter commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.60870% with 12 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (up1_followup_104@87d3129). Learn more about missing BASE report.

Files with missing lines Patch % Lines
comtypes/test/test_record_safearray_bstr.py 78.18% 12 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##             up1_followup_104     #982   +/-   ##
===================================================
  Coverage                    ?   90.72%           
===================================================
  Files                       ?      147           
  Lines                       ?    15344           
  Branches                    ?        0           
===================================================
  Hits                        ?    13921           
  Misses                      ?     1423           
  Partials                    ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@junkmd

junkmd commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

While I was working on this, Python 3.15 crashed. So I wrote a test to capture the crash.

I was surprised by the CI result.
I ran the tests on all the Python versions we support, and Python 3.13 and earlier do not crash. Python 3.14 and later do.

This means #104 may have worked as it was, if it had been merged back then.

This is a delicate memory issue. I think some changes inside Python are related, but I don't fully understand it yet.

Anyway, in the next PR, I will make the production code work as intended on every supported Python version.

Updated to handle different Python versions.
Since `LP_SAFEARRAY` is also `_Pointer[tagSAFEARRAY]`,
`_Pointer[tagSAFEARRAY] | LP_SAFEARRAY` was redundant.
@junkmd
junkmd force-pushed the record_safearray_characterization_tests branch from 83d03d0 to 893f402 Compare November 4, 2026 13:09
@junkmd
junkmd marked this pull request as ready for review November 5, 2026 22:58
@junkmd
junkmd merged commit 6549d42 into main Nov 5, 2026
148 of 151 checks passed
@junkmd
junkmd deleted the record_safearray_characterization_tests branch November 5, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests enhance or fix tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants