Skip to content

ctypes pointer set_type doesn't cache when setting _type_ #133290

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

Closed
encukou opened this issue May 2, 2025 · 0 comments
Closed

ctypes pointer set_type doesn't cache when setting _type_ #133290

encukou opened this issue May 2, 2025 · 0 comments
Assignees
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@encukou
Copy link
Member

encukou commented May 2, 2025

Bug report

In #114314 (3.13) I introduced a regression: set_type misuses PyType_GetDict by modifying it.

import ctypes
intptr = ctypes.POINTER(ctypes.c_int)
print(intptr._type_)  # uncomment to hide the issue
print(intptr._type_)
intptr.set_type(ctypes.c_float)  # a bad idea, but, it should set _type_
print(intptr._type_)

Linked PRs

@encukou encukou added 3.13 bugs and security fixes 3.14 bugs and security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels May 2, 2025
@encukou encukou self-assigned this May 2, 2025
encukou added a commit to encukou/cpython that referenced this issue May 2, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 2, 2025
(cherry picked from commit 2590774)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
encukou added a commit that referenced this issue May 2, 2025
…133295)

gh-133290: Use PyObject_SetAttr to set _type_ (GH-133292)
(cherry picked from commit 2590774)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
@encukou encukou closed this as completed May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant