Skip to content

Restore typed SAFEARRAY after SafeArrayCopy at call sites. - #1001

Merged
junkmd merged 3 commits into
enthought:mainfrom
junkmd:safearray_copy_cast
Nov 21, 2026
Merged

junkmd merged 3 commits into
enthought:mainfrom
junkmd:safearray_copy_cast

Conversation

@junkmd

@junkmd junkmd commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

SafeArrayCopy always returns a raw POINTER(tagSAFEARRAY), even when the input is a typed LP_SAFEARRAY[_CT] created by _midlSAFEARRAY.
Callers that need the typed behavior must therefore cast the result themselves.

Changes

  • At call sites that need the typed behavior (notably _get_records), apply ctypes.cast so the copied pointer has the same concrete type as the source.
  • No change to the signature or behavior of SafeArrayCopy itself.

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

  • Existing call sites that require typed behavior now cast the result
  • Untyped use of SafeArrayCopy continues to work unchanged

`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.
@junkmd junkmd added this to the 1.5.1 milestone Nov 21, 2026
@junkmd junkmd added the enhancement New feature or request label Nov 21, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.91%. Comparing base (af06669) to head (ba77fb9).

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.
📢 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 merged commit 7123b99 into enthought:main Nov 21, 2026
194 of 202 checks passed
@junkmd
junkmd deleted the safearray_copy_cast branch November 21, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants