Skip to content

Conversation

@julian-smith-artifex-com
Copy link
Collaborator

No description provided.

…xmap destruction.

This addresses #4155.

src/__init__.py:
    With .samples_mv, remember the memoryview and call its .release() method in
    Pixmap.__del__().
docs/pixmap.rst:
    Document improved behaviour of Pixmap.samples_mv. Also warn that
    Pixmap.samples_ptr is unsafe after destruction of the pixmap.
tests/test_pixmap.py:
    Added test_4155(), check we get ValueError when accessing memoryview after
    Pixmap is destroyed.
@jonashaag
Copy link

Thanks for the quick fix!

I assume it's not possible to keep a reference to the pixmap in the memory view? Because this implementation is still prone to crashes if someone "steals" the ._sample_mv object.

@julian-smith-artifex-com
Copy link
Collaborator Author

I didn't actually try that, but it turns out that one cannot add new members to a memoryview instance.

For examplemv._pixmap = self gives AttributeError: 'memoryview' object has no attribute '_pixmap'. Did you mean: '_samples_mv'?

So i think the fix in this PR is probably the best we can do.

@julian-smith-artifex-com
Copy link
Collaborator Author

Oh, and i think that if someone "steals" the (undocumented, internal) ._sample_mv object, then they deserve to get a crash...

@julian-smith-artifex-com julian-smith-artifex-com merged commit f877d19 into main Dec 17, 2024
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants