| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Is this limitation documented? That sounds like it should be mentioned in the docs, and a free-threading porting guide.
There's an assumption I'd like to relax eventually :) |
Sorry, something went wrong.
There was a problem hiding this comment.
Was this found from a crash or by inspecting the code? Either way, I think it's worth fixing, but my understanding was that the problematic pattern involved incref/decref around the visit, i.e. something like:
Py_INCREF(obj); Py_VISIT(obj); Py_DECREF(obj);
While this code was more like:
Py_INCREF(obj); Py_DECREF(obj); Py_VISIT(obj);
I think we can make the free threaded GC less susceptible to this problem, but we should also document the things you shouldn't do in a tp_traverse handler.
Sorry, something went wrong.
| if (PyCType_Type == NULL) { | ||
| PyErr_Format(PyExc_TypeError, "expected a ctypes type, got '%N'", type); | ||
| return NULL; | ||
| } |
There was a problem hiding this comment.
We shouldn't create exceptions (or any other object) during tp_traverse handlers either. I think this should be pulled up to the tp_dealloc / tp_clear if we want to print unraisable exceptions there.
Sorry, something went wrong.
I found this from a crash that occurred while porting the parallel GC in cinder (it can call the same traverse function from multiple threads) to 3.14. |
Sorry, something went wrong.
Sounds good, I've gone ahead and added the Borrow version and switched to using it instead. |
Sorry, something went wrong.
|
Thanks! Looks great; I left some nitpicks in DinoV#2 |
Sorry, something went wrong.
_PyType_GetBaseByToken_Borrow can't fail; adjust comments
|
Sorry, @DinoV and @encukou, I could not cleanly backport this to 3.14 due to a conflict. cherry_picker da8199f8842c2830fa4015138725849863523de4 3.14 |
Sorry, something went wrong.
|
Thank you! |
Sorry, something went wrong.
…honGH-142232) (cherry picked from commit da8199f) Co-authored-by: Dino Viehland <dinoviehland@meta.com>
|
GH-142567 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
traverse functions shouldn't modify the ref count during visitation otherwise they'll cause issues in the free threaded GC. CType_Type_traverse uses _PyStgInfo_FromType_NoState to get back to the state object but this causes an incref to happen via PyType_GetBaseByToken.
Instead of using PyType_GetBaseByToken this just walks to find the CType's solid base. Because PyCType_Type adds fields and immediately descends from PyType_Type it will always be the base immediately before PyType_Type.