Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-100926: Move ctype's pointers cache to StgInfo#131282
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
gh-100926: Move ctype's pointers cache to StgInfo#131282
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
IMO, this needs a NEWS blurb. I'd even add a What's New entry --_pointer_type_cache
is nominally internal API, but it's been there for a long time and people are using it.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Thanks! I'll add both entries later today. |
I have added news and whatsnew entries, but I believe we should update them after we decided what to do with _ctypes_ptrtype_cache behaviour. |
Uh oh!
There was an error while loading.Please reload this page.
As far as I can see, this numeric ID key is only used for a check, and I think that it's OK to remove a check for obsolete functionality from a deprecated function. The feature is "incomplete pointers" -- ones that were created with a name, but weren't assigned an underlying type yet. See What I'm a bit worried about is the duplication between Should we expose the pointer type as a Python attribute? classPointerTypeCache:def__setitem__(self,cls,pointer_type):cls.pointer_type=pointer_typedef__getitem__(self,cls):try:returncls.pointer_typeexceptAttributeError:raiseKeyError(cls)def__contains__(self,cls):returnhasattr(cls,'pointer_type')_pointer_type_cache=PointerTypeCache() Would having all the info in one place be worth that? Or am I overthinking it, and we should fix the immediate issue and merge this PR as is? |
AFAIU, if we introduce I'm not that familiar with
If we allow to poison regular Python classes with our |
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
Just in my gut feeling, but would the following make sense?
|
Yeah, this is like@encukou proposed for PointerTypeCache with addition of mapping interface that would be useful for introspection for example. But please see my reply about incomplete types and non-ctypes types above. |
As far as I can see, only three kinds of keys are acceptable in
Is there a use case for putting something else in
A dict-like object, please. Subclassing There's one more aspect to think about: the registration that comtypes does isn't really the right thing for comtypes to do. comtypes needs to add some functionality to all of its types, so it defines subclasses of the ctypes (meta)classes. But, it also wants to add some functionality topointers to its types, and pointers are normally created on demand. I can't rule out another use case for registration, but I don't see one. Perhaps we can deprecate |
I'm very new to the internals of ctypes, but I agree with three of the use cases of |
Ah! Looks like you're correct, thanks! I'm not on a Windows box now to check.
So, IUnknown is a ctypes type in spirit, but not in reality :) We could expose Some concerns about having
But, given that it is an internal implementation detail, perhaps that's acceptable. |
Co-authored-by: Petr Viktorin <encukou@gmail.com>
For me, |
Looks like that's a 3.13 regression. I hope to fix it later today. |
As I wrote yesterday this should fix itsergey-miryanov@aa44997 |
PyType_Modified works now, but setattr is safer; see#133292 (separate PR since it should be backported) |
Thanks! I'll keep it in mind. |
Uh oh!
There was an error while loading.Please reload this page.
bedevere-bot commentedMay 2, 2025
🤖 New build scheduled with the buildbot fleet by@encukou for commit3129ef5 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F131282%2Fmerge If you want to schedule another build, you need to add the🔨 test-with-buildbots label again. |
Thanks! It wasn't straightforward, but I think everyone learned a bunch, and the issue is fixed :) |
@@ -277,15 +342,13 @@ class c_wchar(_SimpleCData): | |||
_type_ = "u" | |||
def _reset_cache(): | |||
_pointer_type_cache.clear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Not worth_pointer_type_cache_fallback.clear()
?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
a0bc0c4
intopython:mainUh oh!
There was an error while loading.Please reload this page.
@kumaraditya303 Could you check the |
I'll look into this by next week. |
Created thread safety fix here#133843 |
Uh oh!
There was an error while loading.Please reload this page.
This is a bit straightfoward.
I keep the global cache for manually registered pairs of pointers and classes, particularly for comtypes (gh-124520, PyCSimpleTypeAsMetaclassTest).