Skip to content
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

open memoryview object as-is they were bytes #4272

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

arthurdarcet
Copy link

it supports the same protocol and avoids an unecessary copy

Copy link
Contributor

github-actions bot commented Feb 6, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@arthurdarcet
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Feb 6, 2025
@JorjMcKie
Copy link
Collaborator

I don't think that this change makes sense.
The base library does ultimately require a memory area to work with, it cannot use memoryview objects directly.
So we would have to convert a memoryview object to bytes before calling MuPDF. This conversion (bytes(mv), respectively mv.tobytes()) however does make a copy and thus negates any assumed advantage.
I think that for a memoryview object mv passing bytes(mv) to the constructor is a negligible effort.

@arthurdarcet
Copy link
Author

arthurdarcet commented Feb 8, 2025 via email

@JorjMcKie
Copy link
Collaborator

@arthurdarcet - sorry, you are right:
I wasn't aware of that the C-code had already been changed to directly support Python's buffer protocol. Therefore all binary formats - bytes, memoryview and bytearray - are readily supported without the need for extra conversions.
Could you please use the isinstance() function to perform the checks - instead of using type(stream)?

@arthurdarcet
Copy link
Author

@JorjMcKie of course - just pushed that. I also moved some tests a bit, but logic should still be exactly the same.
I left the assert on line 2933 - but i don't think it's needed? It doesn't hurt, but it will always pass. Let me know if you want me to remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants