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

Cast Dib handle to int #8385

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Cast Dib handle to int #8385

merged 1 commit into from
Sep 16, 2024

Conversation

radarhere
Copy link
Member

Resolves #8383

The Dib class passes handle to core method getdc() in expose()

Pillow/src/PIL/ImageWin.py

Lines 101 to 102 in b67f018

if isinstance(handle, HWND):
dc = self.image.getdc(handle)

but despite what our Python logic would lead you to expect, it must be an integer. See the following code and https://docs.python.org/3/c-api/arg.html#numbers

Pillow/src/display.c

Lines 37 to 41 in b67f018

#if SIZEOF_VOID_P == 8
#define F_HANDLE "K"
#else
#define F_HANDLE "k"
#endif

Pillow/src/display.c

Lines 165 to 169 in b67f018

_getdc(ImagingDisplayObject *display, PyObject *args) {
HWND window;
HDC dc;
if (!PyArg_ParseTuple(args, F_HANDLE, &window)) {

So this PR casts it to an integer in Python first. The same logic also applies to draw() and query_palette().

@hugovk hugovk merged commit f85c8dc into python-pillow:main Sep 16, 2024
46 of 48 checks passed
@radarhere radarhere deleted the dib_hwnd branch September 16, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: argument 1 must be int, not HWND
2 participants