Repository navigation
Restore typed SAFEARRAY after SafeArrayCopy at call sites. - #1001
Merged
Merged
Conversation
`SafeArrayCopy` return type annotation was `hints.LP_SAFEARRAY`. But at runtime it returns plain `POINTER(SAFEARRAY)`. This commit fixes the annotation to `_Pointer[SAFEARRAY]`. And adds a test to prove the runtime behavior. The type from `_midlSAFEARRAY` factory has `__del__` method. It calls `SafeArrayDestroy` automatically. But the plain pointer from `SafeArrayCopy` does not have `__del__`. So the test must call `SafeArrayDestroy` manually.
…Info]` and add type ignore for `SafeArrayCopy` cast.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1001 +/- ##
=======================================
Coverage 91.91% 91.91%
=======================================
Files 150 150
Lines 15674 15683 +9
=======================================
+ Hits 14406 14415 +9
Misses 1268 1268 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SafeArrayCopyalways returns a rawPOINTER(tagSAFEARRAY), even when the input is a typedLP_SAFEARRAY[_CT]created by_midlSAFEARRAY.Callers that need the typed behavior must therefore cast the result themselves.
Changes
_get_records), applyctypes.castso the copied pointer has the same concrete type as the source.SafeArrayCopyitself.Motivation
Keeps the low-level copy function simple while still allowing callers to recover the typed SAFEARRAY behavior (unpacking, ownership tracking, etc.) when they need it.
Test plan
SafeArrayCopycontinues to work unchanged